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

Function insert_world

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

Source from the content-addressed store, hash-verified

215
216#[spacetimedb::reducer]
217pub fn insert_world(ctx: &ReducerContext, players: u64) {
218 for (i, id) in (0..players).enumerate() {
219 let next_action_timestamp = if i & 2 == 2 {
220 moment_milliseconds() + 2000 // Check every 2secs
221 } else {
222 moment_milliseconds()
223 };
224
225 ctx.db.game_enemy_ai_agent_state().insert(GameEnemyAiAgentState {
226 entity_id: id,
227 next_action_timestamp,
228 last_move_timestamps: vec![id, 0, id * 2],
229 action: AgentAction::Idle,
230 });
231
232 ctx.db.game_live_targetable_state().insert(GameLiveTargetableState {
233 entity_id: id,
234 quad: id as i64,
235 });
236
237 ctx.db.game_targetable_state().insert(GameTargetableState {
238 entity_id: id,
239 quad: id as i64,
240 });
241
242 ctx.db.game_mobile_entity_state().insert(GameMobileEntityState {
243 entity_id: id,
244 location_x: id as i32,
245 location_y: id as i32,
246 timestamp: next_action_timestamp,
247 });
248
249 ctx.db.game_enemy_state().insert(GameEnemyState {
250 entity_id: id,
251 herd_id: id as i32,
252 });
253
254 ctx.db.game_herd_cache().insert(GameHerdCache {
255 id: id as i32,
256 dimension_id: id as u32,
257 current_population: id as i32 * 2,
258 max_population: id as i32 * 4,
259 spawn_eagerness: id as f32,
260 roaming_distance: id as i32,
261 location: SmallHexTile {
262 x: id as i32,
263 z: id as i32,
264 dimension: id as u32 * 2,
265 },
266 });
267 }
268 log::info!("INSERT WORLD PLAYERS: {players}");
269}
270
271fn get_targetables_near_quad(ctx: &ReducerContext, entity_id: u64, num_players: u64) -> Vec<GameTargetableState> {
272 let mut result = Vec::with_capacity(4);

Callers 3

init_game_ia_loopMethod · 0.85
SPACETIMEDB_REDUCERFunction · 0.85
init_game_ia_loopFunction · 0.85

Calls 2

moment_millisecondsFunction · 0.70
insertMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…