载入中...
搜索中...
未找到
GpuAgentWorld.cpp
浏览该文件的文档.
2
3#include "common/Diagnostic.h"
4
5namespace eve::gpuagents {
6
8 if (name.empty()) {
10 Diagnostic::error(DiagnosticCode::InvalidArgument, "backend name is empty", "name", {}, "gpuagents"));
11 }
12 if (!backend) {
14 Diagnostic::error(DiagnosticCode::InvalidArgument, "backend is null", "backend", {}, "gpuagents"));
15 }
16 if (backends_.count(name) != 0) {
18 Diagnostic::error(DiagnosticCode::AlreadyExists, "backend name already registered", name, {}, "gpuagents"));
19 }
20 backends_.emplace(std::move(name), backend);
21 return Result<void>::success();
22}
23
25 if (backends_.erase(name) == 0) {
27 Diagnostic::error(DiagnosticCode::NotFound, "backend not registered", name, {}, "gpuagents"));
28 }
29 return Result<void>::success();
30}
31
32EffectBackend* GpuAgentWorld::find(const std::string& name) const {
33 const auto it = backends_.find(name);
34 return it == backends_.end() ? nullptr : it->second;
35}
36
39 snap.waterCurrent = waterCurrent_;
40 snap.windVelocity = wind_;
41 snap.groundY = groundY_;
42 snap.ceilingY = ceilingY_;
43 snap.goals = goals_;
44 snap.dangers = dangers_;
45 snap.nutrients = nutrients_;
46 snap.obstacles = &obstacles_;
47 snap.surface = includeSurface ? const_cast<SurfaceField*>(&surface_) : nullptr;
48 return snap;
49}
50
52 for (auto& [name, backend] : backends_) {
53 (void)name;
54 if (!backend) {
56 Diagnostic::error(DiagnosticCode::PreconditionViolation, "registered backend is null", name, {},
57 "gpuagents"));
58 }
59 const bool needSurface = backend->kind() == EffectKind::LifeNetwork;
60 EnvironmentSnapshot snap = makeSnapshot(needSurface);
61 auto stepped = backend->step(dt, snap);
62 if (!stepped.ok()) return stepped;
63 }
64 return Result<void>::success();
65}
66
67} // namespace eve::gpuagents
Stable, structured diagnostics shared by engine modules.
std::string name
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
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
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Binds an EffectProfile to a GpuAgentSimulation and optional renderer.
EffectBackend * find(const std::string &name) const
Look up a registered backend by name. @ownership Borrowed; World does not own the returned pointer....
Result< void > unregisterBackend(const std::string &name)
Remove a named backend registration without destroying the backend. @ownership Does not take or relea...
EnvironmentSnapshot makeSnapshot(bool includeSurface) const
Build an environment snapshot for the current World state.
Result< void > registerBackend(std::string name, EffectBackend *backend)
Register a borrowed backend under a unique name.
Result< void > stepAll(float dt)
Step every registered backend with a shared environment snapshot.
2.5D surface + life-field textures for Life Network.
Read-only environment semantics prepared by GpuAgentWorld each tick.
std::vector< EnvironmentMarker > nutrients
SurfaceField * surface
optional; Life Network writes trails here
std::vector< EnvironmentMarker > goals
std::vector< EnvironmentMarker > dangers