MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / agent_loop

Function agent_loop

modules/benchmarks-cpp/src/ia_loop.cpp:347–376  ·  view source on GitHub ↗

Main agent loop processing

Source from the content-addressed store, hash-verified

345
346// Main agent loop processing
347void agent_loop(ReducerContext& ctx, GameEnemyAiAgentState& agent,
348 const GameTargetableState& agent_targetable,
349 const std::vector<GameTargetableState>& surrounding_agents,
350 uint64_t current_time_ms) {
351 uint64_t entity_id = agent.entity_id;
352
353 auto coordinates_opt = ctx.db[game_mobile_entity_state_entity_id].find(entity_id);
354 if (!coordinates_opt) {
355 LOG_PANIC("GameMobileEntityState Entity ID not found");
356 return;
357 }
358
359 auto agent_entity_opt = ctx.db[game_enemy_state_entity_id].find(entity_id);
360 if (!agent_entity_opt) {
361 LOG_PANIC("GameEnemyState Entity ID not found");
362 return;
363 }
364 const auto& agent_entity = *agent_entity_opt;
365
366 auto agent_herd_opt = ctx.db[game_herd_cache_id].find(agent_entity.herd_id);
367 if (!agent_herd_opt) {
368 LOG_PANIC("GameHerdCache Entity ID not found");
369 return;
370 }
371 const auto& agent_herd = *agent_herd_opt;
372
373 SmallHexTile agent_herd_coordinates = agent_herd.location;
374
375 move_agent(ctx, agent, agent_herd_coordinates, current_time_ms);
376}
377
378// Main game loop for enemy AI processing
379SPACETIMEDB_REDUCER(game_loop_enemy_ia, ReducerContext& ctx, uint64_t players) {

Callers 1

SPACETIMEDB_REDUCERFunction · 0.70

Calls 2

move_agentFunction · 0.70
findMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…