载入中...
搜索中...
未找到
NpcAiECS.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/ECS.h"
6#include "npc_ai/NpcAi.h"
7
8#include <cstddef>
9#include <span>
10#include <string>
11#include <string_view>
12#include <vector>
13
14namespace eve::npc_ai {
15
25
27 [[nodiscard]] static Result<NpcAgentState> create(NpcAiWorld& world, std::string_view behaviorId);
29 [[nodiscard]] Result<void> releaseAgent(NpcAiWorld& world);
30};
31
34 std::string activeState;
35 std::vector<std::string> activePath;
36 std::uint64_t lastTick = 0;
37
39 void replace(const AgentSnapshot& snapshot) {
40 activeState = snapshot.activeState;
41 activePath = snapshot.activePath;
42 lastTick = snapshot.lastTick;
43 }
44};
45
51
54 std::string_view name;
55 std::string_view entityScope;
56 std::string_view view;
57 std::string_view readSet;
58 std::string_view writeSet;
59 std::string_view structuralChanges;
60 std::string_view events;
61 std::string_view services;
62 std::string_view phase;
63 std::string_view determinism;
64};
65
67[[nodiscard]] std::span<const NpcAiSystemContract> npcAiSystemContracts() noexcept;
68
71public:
83 template <class EntityRoot>
86 std::size_t linked = 0;
87 {
88 auto view = ecs::View<EntityRoot, NpcAgentState, NpcAiProjection>();
89 for (auto it = view.begin(); it != view.end(); ++it) {
90 auto [state, projection] = *it;
91 (void)projection;
92 auto current = world.snapshot(state->agent);
93 if (!current.ok()) return Result<NpcAiEcsStepReport>::failure(current.status());
94 ++linked;
95 }
96 }
97
98 auto advanced = world.tick(context);
99 if (!advanced.ok()) return Result<NpcAiEcsStepReport>::failure(advanced.status());
100
101 {
102 auto view = ecs::View<EntityRoot, NpcAgentState, NpcAiProjection>();
103 for (auto it = view.begin(); it != view.end(); ++it) {
104 auto [state, projection] = *it;
105 auto current = world.snapshot(state->agent);
106 if (!current.ok()) return Result<NpcAiEcsStepReport>::failure(current.status());
107 projection->replace(current.value());
108 }
109 }
111 return Result<NpcAiEcsStepReport>::success({linked, advanced.value()});
112 }
113};
114
115} // namespace eve::npc_ai
#define EVENGINE_API_PLATFORM
Definition Export.h:107
World3D * world
glm::mat4 view
double current
const VegetationPresetContext & context
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
Gameplay-decision phase adapter over a caller-selected existing entity root.
Definition NpcAiECS.h:70
static Result< NpcAiEcsStepReport > step(NpcAiWorld &world, const TickContext &context)
Preflights every link, advances the AI world once, then publishes projections.
Definition NpcAiECS.h:85
Authoritative owner and deterministic scheduler for NPC AI agents.
Definition NpcAi.h:216
std::span< const NpcAiSystemContract > npcAiSystemContracts() noexcept
Returns immutable process-lifetime metadata for the NPC AI ECS phase.
Definition NpcAiECS.cpp:25
AgentSnapshot public API.
Definition NpcAi.h:142
std::uint64_t lastTick
Definition NpcAi.h:149
std::string activeState
Definition NpcAi.h:145
std::vector< std::string > activePath
Definition NpcAi.h:146
Authoritative gameplay-entity link to one module-owned NPC agent.
Definition NpcAiECS.h:23
NpcAiEcsStepReport public API.
Definition NpcAiECS.h:47
Cold derived, local-only projection for rendering, editor and gameplay inspection.
Definition NpcAiECS.h:33
std::vector< std::string > activePath
Definition NpcAiECS.h:35
void replace(const AgentSnapshot &snapshot)
Atomically replaces derived fields from an owning runtime snapshot.
Definition NpcAiECS.h:39
NpcAiSystemContract public API.
Definition NpcAiECS.h:53
std::string_view entityScope
Definition NpcAiECS.h:55
std::string_view determinism
Definition NpcAiECS.h:63
std::string_view structuralChanges
Definition NpcAiECS.h:59
Input time and work limits for one deterministic simulation update.
Definition NpcAi.h:125
TickReport public API.
Definition NpcAi.h:133