载入中...
搜索中...
未找到
GpuAgentSimulation.cpp
浏览该文件的文档.
29 Diagnostic::error(DiagnosticCode::InvalidArgument, "unknown EffectKind", "kind", {}, "gpuagents"));
36 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "maxAgents must be positive",
41 Diagnostic::error(DiagnosticCode::InvalidArgument, "fixedDt must be positive", "fixedDt", {}, "gpuagents"));
63 Diagnostic::error(DiagnosticCode::InvalidArgument, "solver is null", "solver", {}, "gpuagents"));
67 Diagnostic::error(DiagnosticCode::InvalidArgument, "solver kind mismatch", "solver", {}, "gpuagents"));
73Result<void> GpuAgentSimulation::initialize(int count, const std::function<AgentState(int)>& spawnFn) {
80 Diagnostic::error(DiagnosticCode::InvalidArgument, "spawnFn is empty", "spawnFn", {}, "gpuagents"));
83 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "initialize count out of range",
149 Diagnostic::error(DiagnosticCode::InvalidArgument, "backend name is empty", "name", {}, "gpuagents"));
153 Diagnostic::error(DiagnosticCode::InvalidArgument, "backend is null", "backend", {}, "gpuagents"));
157 Diagnostic::error(DiagnosticCode::AlreadyExists, "backend name already registered", name, {}, "gpuagents"));
212 const float a = static_cast<float>((static_cast<std::uint32_t>(i) * 1103515245u + seed) & 0xFFFFu) / 65535.f;
213 const float b = static_cast<float>(((static_cast<std::uint32_t>(i) * 12345u) ^ seed) & 0xFFFFu) / 65535.f;
244Result<void> GpuAgents::spawnCloud(EffectBackend* backend, int count, float centerX, float centerY, float centerZ,
248 Diagnostic::error(DiagnosticCode::InvalidArgument, "backend is null", "backend", {}, "gpuagents"));
251 return Result<void>::failure(Diagnostic::error(DiagnosticCode::PreconditionViolation, "backend not configured",
263 case EffectKind::Bird: s.velocity = glm::normalize(dir + glm::vec3(0.f, 0.2f, 0.f)) * 6.f; break;
274 s.rotation = lookRotation(glm::length(s.velocity) > 1e-4f ? s.velocity : glm::vec3(0.f, 0.f, 1.f));
279Result<void> GpuAgents::captureSurface(GpuAgentWorld* world, const std::vector<float>& positions,
288 DiagnosticCode::InvalidArgument, "positions must be interleaved xyz floats", "positions", {}, "gpuagents"));
295 return SurfaceCapture::captureFromTriangles(world->surface(), verts, indices, glm::vec3(originX, originY, originZ),
299Result<void> GpuAgents::syncLifeFieldBinding(GpuAgentWorld* world, LifeFieldMaterialBinding* binding) const {
302 Diagnostic::error(DiagnosticCode::InvalidArgument, "world or binding is null", "binding", {}, "gpuagents"));
312 "GpuAgentWorld", std::function<GpuAgentWorld*()>([]() -> GpuAgentWorld* { return nullptr; }), true);
330 world.addFunc("initFlatSurface", [](GpuAgentWorld* w, float ox, float oy, float oz, float size, int res) {
336 "GpuAgentEffectBackend", std::function<EffectBackend*()>([]() -> EffectBackend* { return nullptr; }), true);
338 backend.addFunc("aliveCount", [](EffectBackend* b) { return b ? b->simulation().aliveCount() : 0; });
339 backend.addFunc("instanceCount", [](EffectBackend* b) { return b ? b->renderer().instanceCount() : 0; });
353 cls.addFunc("spawnCloud", [](GpuAgents* m, EffectBackend* b, int count, float x, float y, float z, float spread) {
357 cls.addFunc("registerBackend", [](GpuAgents*, GpuAgentWorld* w, const std::string& name, EffectBackend* b) {
362 cls.addFunc("captureSurface", [](GpuAgents* m, GpuAgentWorld* w, ssq::Array positions, ssq::Array indices, float ox,
370 for (size_t i = 0; i < indices.size(); ++i) idx.push_back(static_cast<std::uint32_t>(indices.get<int>(i)));
EVEngine assertion entry point, backed by zeroerr.
#define EV_PARAM_CHECK(cond,...)
Validate a function parameter / public API precondition.
Definition Assert.h:30
Stable, structured diagnostics shared by engine modules.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Binds an EffectProfile to a GpuAgentSimulation and optional renderer.
Definition EffectBackend.h:19
Result< void > setSolver(std::unique_ptr< IAgentSolver > solver)
Replace the solver instance (tests / custom kernels). @ownership Simulation takes ownership.
Definition GpuAgentSimulation.cpp:60
Result< void > initialize(int count, const std::function< AgentState(int)> &spawnFn)
Spawn count alive agents using spawnFn(index) -> AgentState.
Definition GpuAgentSimulation.cpp:73
Result< void > configure(const EffectProfile &profile)
Configure capacity and bind a solver for the profile kind.
Definition GpuAgentSimulation.cpp:34
Result< void > step(float dt, const EnvironmentSnapshot &env)
Advance wall-clock dt via fixed substeps.
Definition GpuAgentSimulation.cpp:119
World-level registry for GPU agent simulations and environment semantics.
Definition GpuAgentWorld.h:27
EffectBackend * find(const std::string &name) const
Look up a registered backend by name. @ownership Borrowed; World does not own the returned pointer....
Definition GpuAgentSimulation.cpp:171
Result< void > unregisterBackend(const std::string &name)
Remove a named backend registration without destroying the backend. @ownership Does not take or relea...
Definition GpuAgentSimulation.cpp:163
EnvironmentSnapshot makeSnapshot(bool includeSurface) const
Build an environment snapshot for the current World state.
Definition GpuAgentSimulation.cpp:176
Result< void > registerBackend(std::string name, EffectBackend *backend)
Register a borrowed backend under a unique name.
Definition GpuAgentSimulation.cpp:146
void setWaterCurrent(float x, float y, float z)
Set uniform water current.
Definition GpuAgentWorld.h:43
Result< void > stepAll(float dt)
Step every registered backend with a shared environment snapshot.
Definition GpuAgentSimulation.cpp:190
void setVerticalBounds(float groundY, float ceilingY)
Set ground / ceiling heights for bird clearance.
Definition GpuAgentWorld.h:47
GPU Agents module — extensible fixed-step agent FX simulation.
Definition GpuAgents.h:29
Result< void > captureSurface(GpuAgentWorld *world, const std::vector< float > &positions, const std::vector< std::uint32_t > &indices, float originX, float originY, float originZ, float worldSize, int resolution) const
Orthographic triangle bake into a world's surface field.
Definition GpuAgentSimulation.cpp:279
EffectBackend * newBackend(int kind, int maxAgents)
Create a configured EffectBackend.
Definition GpuAgentSimulation.cpp:236
EffectProfile makeProfile(int kind, int maxAgents) const
Build a default EffectProfile value for script helpers.
Definition GpuAgentSimulation.cpp:226
GpuAgentWorld * newWorld()
Create an empty World. @ownership Caller / script VM owns the returned world; delete or let the VM fr...
Definition GpuAgentSimulation.cpp:224
Result< void > syncLifeFieldBinding(GpuAgentWorld *world, LifeFieldMaterialBinding *binding) const
Pack a world's surface into CPU LifeField / SurfaceData RGBA buffers.
Definition GpuAgentSimulation.cpp:299
Result< void > spawnCloud(EffectBackend *backend, int count, float centerX, float centerY, float centerZ, float spread) const
Spawn a simple school / flock / petal cloud into a backend.
Definition GpuAgentSimulation.cpp:244
Packs SurfaceField channels into Graphics-uploadable RGBA8 textures.
Definition LifeFieldMaterialBinding.h:37
static Result< void > captureFromTriangles(SurfaceField &out, std::span< const glm::vec3 > positions, std::span< const std::uint32_t > indices, const glm::vec3 &originMin, float worldSize, int resolution, float baseHeight=0.f)
Bake triangle positions into out over the given XZ domain.
Definition SurfaceCapture.cpp:56
2.5D surface + life-field textures for Life Network.
Definition SurfaceField.h:16
Definition AgentInstanceRenderer.cpp:5
glm::quat lookRotation(const glm::vec3 &forward, const glm::vec3 &upHint=glm::vec3(0.f, 1.f, 0.f))
Builds a facing quaternion from a unit forward and approximate up.
Definition AgentState.h:36
@ LifeNetwork
@ InvalidArgument
@ NotFound
@ PreconditionViolation
@ AlreadyExists
Standardized per-agent simulation output shared by all effect kinds.
Definition AgentState.h:12
Type-erased profile bundle owned by an EffectBackend.
Definition EffectProfile.h:130
static EffectProfile makePetal(int maxAgents=512)
Factory for a default petal profile.
Definition EffectProfile.h:188
const EffectProfileBase & base() const
Returns the shared base slice for the active kind.
Definition EffectProfile.h:138
static EffectProfile makeBird(int maxAgents=256)
Factory for a default bird profile.
Definition EffectProfile.h:179
static EffectProfile makeFish(int maxAgents=256)
Factory for a default fish profile.
Definition EffectProfile.h:160
static EffectProfile makeLife(int maxAgents=128, int resolution=64)
Factory for a default life-network profile.
Definition EffectProfile.h:169
Read-only environment semantics prepared by GpuAgentWorld each tick.
Definition EnvironmentSnapshot.h:26
const ObstacleField * obstacles
Definition EnvironmentSnapshot.h:36
std::vector< EnvironmentMarker > nutrients
Definition EnvironmentSnapshot.h:34
std::vector< EnvironmentMarker > goals
Definition EnvironmentSnapshot.h:32
std::vector< EnvironmentMarker > dangers
Definition EnvironmentSnapshot.h:33
glm::vec3 waterCurrent
Definition EnvironmentSnapshot.h:27
glm::vec3 windVelocity
Definition EnvironmentSnapshot.h:28