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

Function agentLoop

modules/benchmarks-ts/src/ia_loop.ts:252–279  ·  view source on GitHub ↗
(
  ctx: ReducerCtx<S>,
  agent: GameEnemyAiAgentState,
  agentTargetable: GameTargetableState,
  surroundingAgents: GameTargetableState[],
  currentTimeMs: bigint
)

Source from the content-addressed store, hash-verified

250}
251
252function agentLoop(
253 ctx: ReducerCtx<S>,
254 agent: GameEnemyAiAgentState,
255 agentTargetable: GameTargetableState,
256 surroundingAgents: GameTargetableState[],
257 currentTimeMs: bigint
258) {
259 const entityId = agent.entity_id;
260
261 const coordinates = ctx.db.gameMobileEntityState.entity_id.find(entityId);
262 if (coordinates == null) {
263 throw new Error('GameMobileEntityState Entity ID not found');
264 }
265
266 const agentEntity = ctx.db.gameEnemyState.entity_id.find(entityId);
267 if (agentEntity == null) {
268 throw new Error('GameEnemyState Entity ID not found');
269 }
270
271 const agentHerd = ctx.db.gameHerdCache.id.find(agentEntity.herd_id);
272 if (agentHerd == null) {
273 throw new Error('GameHerdCache Entity ID not found');
274 }
275
276 const agentHerdCoordinates = agentHerd.location;
277
278 moveAgent(ctx, agent, agentHerdCoordinates, currentTimeMs);
279}
280
281export const gameLoopEnemyIa = spacetimedb.reducer(
282 { name: 'game_loop_enemy_ia' },

Callers 1

ia_loop.tsFile · 0.85

Calls 2

moveAgentFunction · 0.85
findMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…