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

Function game_loop_enemy_ia

modules/benchmarks/src/ia_loop.rs:393–415  ·  view source on GitHub ↗
(ctx: &ReducerContext, players: u64)

Source from the content-addressed store, hash-verified

391// We check only for a single pass in the game loop.
392#[spacetimedb::reducer]
393pub fn game_loop_enemy_ia(ctx: &ReducerContext, players: u64) {
394 let mut count = 0;
395 let current_time_ms = moment_milliseconds();
396
397 for mut agent in ctx.db.game_enemy_ai_agent_state().iter() {
398 let agent_targetable = ctx
399 .db
400 .game_targetable_state()
401 .entity_id()
402 .find(agent.entity_id)
403 .expect("No TargetableState for AgentState entity");
404
405 let surrounding_agents = get_targetables_near_quad(ctx, agent_targetable.entity_id, players);
406
407 agent.action = AgentAction::Fighting;
408
409 agent_loop(ctx, agent, agent_targetable, &surrounding_agents, current_time_ms);
410
411 count += 1;
412 }
413
414 log::info!("ENEMY IA LOOP PLAYERS: {players}, processed: {count}");
415}
416
417#[spacetimedb::reducer]
418pub fn init_game_ia_loop(ctx: &ReducerContext, initial_load: u32) {

Callers 3

run_game_ia_loopMethod · 0.85
SPACETIMEDB_REDUCERFunction · 0.85
run_game_ia_loopFunction · 0.85

Calls 6

moment_millisecondsFunction · 0.70
agent_loopFunction · 0.70
iterMethod · 0.65
findMethod · 0.45
entity_idMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…