diff --git a/src/pp/pp_core.c b/src/pp/pp_core.c index 68a607ba..c42e246e 100644 --- a/src/pp/pp_core.c +++ b/src/pp/pp_core.c @@ -21,14 +21,14 @@ void StartupUser(void) g->average_local_to_user_snapshot_publish_dt_ns = NsFromSeconds(1) / SIM_TICKS_PER_SECOND; /* User blend clients */ - g->user_client_store = sim_client_store_acquire(); - g->user_unblended_client = sim_client_acquire(g->user_client_store); - g->user_blended_client = sim_client_acquire(g->user_client_store); + g->user_client_store = AcquireClientStore(); + g->user_unblended_client = AcquireClient(g->user_client_store); + g->user_blended_client = AcquireClient(g->user_client_store); g->ss_blended = sim_snapshot_nil(); /* Local to user client */ - g->local_to_user_client_store = sim_client_store_acquire(); - g->local_to_user_client = sim_client_acquire(g->local_to_user_client_store); + g->local_to_user_client_store = AcquireClientStore(); + g->local_to_user_client = AcquireClient(g->local_to_user_client_store); /* GPU handles */ g->world_to_ui_xf = XformIdentity; @@ -418,8 +418,8 @@ void UpdateUser(P_Window *window) u64 last_tick = g->local_to_user_client->last_tick; if (last_tick > old_last_tick) { - Snapshot *src = sim_snapshot_from_tick(g->local_to_user_client, last_tick); - sim_snapshot_acquire(g->user_unblended_client, src, src->tick); + Snapshot *src = SnapshotFromTick(g->local_to_user_client, last_tick); + AcquireSnapshot(g->user_unblended_client, src, src->tick); g->last_local_to_user_snapshot_published_at_ns = g->local_to_user_client_publish_time_ns; g->average_local_to_user_snapshot_publish_dt_ns -= g->average_local_to_user_snapshot_publish_dt_ns / 50; g->average_local_to_user_snapshot_publish_dt_ns += g->local_to_user_client_publish_dt_ns / 50; @@ -440,7 +440,7 @@ void UpdateUser(P_Window *window) } /* Predict local sim time based on average snapshot publish dt. */ - Snapshot *newest_snapshot = sim_snapshot_from_tick(g->user_unblended_client, g->user_unblended_client->last_tick); + Snapshot *newest_snapshot = SnapshotFromTick(g->user_unblended_client, g->user_unblended_client->last_tick); g->local_sim_last_known_time_ns = newest_snapshot->sim_time_ns; g->local_sim_last_known_tick = newest_snapshot->tick; if (Atomic32Fetch(&g->user_paused)) @@ -473,7 +473,7 @@ void UpdateUser(P_Window *window) Snapshot *left_snapshot = sim_snapshot_nil(); Snapshot *right_snapshot = newest_snapshot; { - Snapshot *ss = sim_snapshot_from_tick(g->user_unblended_client, g->user_unblended_client->first_tick); + Snapshot *ss = SnapshotFromTick(g->user_unblended_client, g->user_unblended_client->first_tick); while (ss->valid) { u64 next_tick = ss->next_tick; @@ -486,7 +486,7 @@ void UpdateUser(P_Window *window) { right_snapshot = ss; } - ss = sim_snapshot_from_tick(g->user_unblended_client, next_tick); + ss = SnapshotFromTick(g->user_unblended_client, next_tick); } } @@ -494,21 +494,21 @@ void UpdateUser(P_Window *window) if (left_snapshot->valid && right_snapshot->valid) { f64 blend = (f64)(g->render_time_ns - left_snapshot->sim_time_ns) / (f64)(right_snapshot->sim_time_ns - left_snapshot->sim_time_ns); - g->ss_blended = sim_snapshot_acquire_from_lerp(g->user_blended_client, left_snapshot, right_snapshot, blend); + g->ss_blended = AcquireSnapshotFromLerp(g->user_blended_client, left_snapshot, right_snapshot, blend); } else if (left_snapshot->valid) { - g->ss_blended = sim_snapshot_acquire(g->user_blended_client, left_snapshot, left_snapshot->tick); + g->ss_blended = AcquireSnapshot(g->user_blended_client, left_snapshot, left_snapshot->tick); } else if (right_snapshot->valid) { - g->ss_blended = sim_snapshot_acquire(g->user_blended_client, right_snapshot, right_snapshot->tick); + g->ss_blended = AcquireSnapshot(g->user_blended_client, right_snapshot, right_snapshot->tick); } /* Release unneeded unblended snapshots */ if (left_snapshot->tick > 0) { - sim_snapshot_release_ticks_in_range(g->user_unblended_client, 0, left_snapshot->tick - 1); + ReleaseSnapshotsInRange(g->user_unblended_client, 0, left_snapshot->tick - 1); } } else @@ -516,20 +516,20 @@ void UpdateUser(P_Window *window) /* Interp disabled, just copy latest snapshot */ g->render_time_target_ns = newest_snapshot->sim_time_ns; g->render_time_ns = newest_snapshot->sim_time_ns; - g->ss_blended = sim_snapshot_acquire(g->user_blended_client, newest_snapshot, newest_snapshot->tick); + g->ss_blended = AcquireSnapshot(g->user_blended_client, newest_snapshot, newest_snapshot->tick); /* Release unneeded unblended snapshots */ if (newest_snapshot->tick > 0) { - sim_snapshot_release_ticks_in_range(g->user_unblended_client, 0, newest_snapshot->tick - 1); + ReleaseSnapshotsInRange(g->user_unblended_client, 0, newest_snapshot->tick - 1); } } /* Release unneeded blended snapshots */ if (g->ss_blended->tick > 0) { - sim_snapshot_release_ticks_in_range(g->user_blended_client, 0, g->ss_blended->tick - 1); - sim_snapshot_release_ticks_in_range(g->user_blended_client, g->ss_blended->tick + 1, U64Max); + ReleaseSnapshotsInRange(g->user_blended_client, 0, g->ss_blended->tick - 1); + ReleaseSnapshotsInRange(g->user_blended_client, g->ss_blended->tick + 1, U64Max); } } @@ -1169,10 +1169,10 @@ void UpdateUser(P_Window *window) Vec2I32 local_tile_index = VEC2I32(tile_x, tile_y); TileKind tile = ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)]; //if (tile > -1) { - if (tile == SIM_TILE_KIND_WALL) + if (tile == TileKind_Wall) { - Vec2I32 world_tile_index = sim_world_tile_index_from_local_tile_index(chunk_index, local_tile_index); - Vec2 pos = sim_pos_from_world_tile_index(world_tile_index); + Vec2I32 world_tile_index = WorldTileIndexFromLocalTileIndex(chunk_index, local_tile_index); + Vec2 pos = PosFromWorldTileIndex(world_tile_index); Xform tile_xf = XformFromRect(RectFromVec2(pos, VEC2(tile_size, tile_size))); D_MaterialParams params = D_MATERIALPARAMS(.xf = tile_xf, .texture = tile_texture->gp_texture, .is_light = 1, .light_emittance = VEC3(0, 0, 0)); D_DrawMaterial(g->render_sig, params); @@ -1760,55 +1760,55 @@ void UpdateUser(P_Window *window) if (fire_state.num_presses || fire_state.is_held) { - control.flags |= SIM_CONTROL_FLAG_FIRE; + control.flags |= ControlFlag_Fire; } if (fire_alt_state.num_presses || fire_alt_state.is_held) { - control.flags |= SIM_CONTROL_FLAG_FIRE_ALT; + control.flags |= ControlFlag_AltFire; } if (drag_state.num_presses || drag_state.is_held) { - control.flags |= SIM_CONTROL_FLAG_DRAG; + control.flags |= ControlFlag_Drag; } if (delete_state.num_presses || delete_state.is_held) { - control.flags |= SIM_CONTROL_FLAG_DELETE; + control.flags |= ControlFlag_Delete; } if (clear_state.num_presses_and_repeats) { - control.flags |= SIM_CONTROL_FLAG_CLEAR_ALL; + control.flags |= ControlFlag_ClearAll; } if (spawn1_state.num_presses_and_repeats) { - control.flags |= SIM_CONTROL_FLAG_SPAWN1_TEST; + control.flags |= ControlFlag_SpawnTest1; } if (spawn2_state.num_presses_and_repeats) { - control.flags |= SIM_CONTROL_FLAG_SPAWN2_TEST; + control.flags |= ControlFlag_SpawnTest2; } if (spawn3_state.num_presses_and_repeats) { - control.flags |= SIM_CONTROL_FLAG_SPAWN3_TEST; + control.flags |= ControlFlag_SpawnTest3; } if (spawn4_state.num_presses_and_repeats) { - control.flags |= SIM_CONTROL_FLAG_SPAWN4_TEST; + control.flags |= ControlFlag_SpawnTest4; } if (walls_state.num_presses_and_repeats) { - control.flags |= SIM_CONTROL_FLAG_WALLS_TEST; + control.flags |= ControlFlag_TestWalls; } if (tile_state.num_presses || tile_state.is_held) { - control.flags |= SIM_CONTROL_FLAG_TILE_TEST; + control.flags |= ControlFlag_TestTiles; } if (explode_state.num_presses_and_repeats) { - control.flags |= SIM_CONTROL_FLAG_EXPLODE_TEST; + control.flags |= ControlFlag_TestExplode; } if (teleport_state.num_presses_and_repeats || (g->debug_camera && teleport_state.is_held)) { - control.flags |= SIM_CONTROL_FLAG_TELEPORT_TEST; + control.flags |= ControlFlag_TestTeleport; } if (pause_state.num_presses) @@ -1948,15 +1948,15 @@ void UpdateUser(P_Window *window) text.len += StringFormat(temp.arena, Lit("cursor world: %F, %F"), FmtFloat(world_cursor.x), FmtFloat(world_cursor.y)).len; text.len += PushString(temp.arena, Lit("\n")).len; - Vec2I32 world_tile_cursor = sim_world_tile_index_from_pos(world_cursor); + Vec2I32 world_tile_cursor = WorldTileIndexFromPos(world_cursor); text.len += StringFormat(temp.arena, Lit("cursor world tile: %F, %F"), FmtSint(world_tile_cursor.x), FmtSint(world_tile_cursor.y)).len; text.len += PushString(temp.arena, Lit("\n")).len; - Vec2I32 local_tile_cursor = sim_local_tile_index_from_world_tile_index(world_tile_cursor); + Vec2I32 local_tile_cursor = LocalTileIndexFromWorldTileIndex(world_tile_cursor); text.len += StringFormat(temp.arena, Lit("cursor local tile: %F, %F"), FmtSint(local_tile_cursor.x), FmtSint(local_tile_cursor.y)).len; text.len += PushString(temp.arena, Lit("\n")).len; - Vec2I32 tile_chunk_cursor = sim_tile_chunk_index_from_world_tile_index(world_tile_cursor); + Vec2I32 tile_chunk_cursor = TileChunkIndexFromWorldTileIndex(world_tile_cursor); text.len += StringFormat(temp.arena, Lit("cursor tile chunk: %F, %F"), FmtSint(tile_chunk_cursor.x), FmtSint(tile_chunk_cursor.y)).len; text.len += PushString(temp.arena, Lit("\n")).len; text.len += PushString(temp.arena, Lit("\n")).len; @@ -2082,15 +2082,15 @@ JobDef(UpdateUserJob, UNUSED sig, UNUSED id) void GenerateuserInputCmds(Client *user_input_client, u64 tick) { SharedUserState *g = &shared_user_state; - Snapshot *prev_user_input_ss = sim_snapshot_from_tick(user_input_client, user_input_client->last_tick); - Snapshot *user_input_ss = sim_snapshot_acquire(user_input_client, prev_user_input_ss, tick); + Snapshot *prev_user_input_ss = SnapshotFromTick(user_input_client, user_input_client->last_tick); + Snapshot *user_input_ss = AcquireSnapshot(user_input_client, prev_user_input_ss, tick); Entity *user_input_root = EntityFromId(user_input_ss, RootEntityId); /* Find / create local control cmd ent */ Entity *control_cmd = FirstWithProp(user_input_ss, Prop_Cmd); if (!control_cmd->valid) { control_cmd = AcquireSyncSrc(user_input_root); - control_cmd->cmd_kind = SIM_CMD_KIND_CONTROL; + control_cmd->cmd_kind = CmdKind_Control; control_cmd->predictor = user_input_client->player_id; EnableProp(control_cmd, Prop_Cmd); Activate(control_cmd, user_input_ss->tick); @@ -2107,7 +2107,7 @@ void GenerateuserInputCmds(Client *user_input_client, u64 tick) if (g->user_sim_cmd_chat.len > 0) { Entity *chat_cmd = AcquireSyncSrc(user_input_root); - chat_cmd->cmd_kind = SIM_CMD_KIND_CHAT; + chat_cmd->cmd_kind = CmdKind_Chat; //chat_cmd->chat_msg = ZI } #endif @@ -2149,13 +2149,13 @@ JobDef(SimJob, UNUSED sig, UNUSED id) BB_Buff snapshot_writer_bb = AcquireBitbuff(Gibi(64)); SimAccel accel = AcquireSimAccel(); - ClientStore *store = sim_client_store_acquire(); - Client *user_input_client = sim_client_acquire(store); /* Stores snapshots containing commands to be published to local client */ - Client *local_client = sim_client_acquire(store); /* Stores snapshots produced locally */ - Client *publish_client = sim_client_acquire(store); /* Stores versions of local snapshots that will be published to remote sims */ + ClientStore *store = AcquireClientStore(); + Client *user_input_client = AcquireClient(store); /* Stores snapshots containing commands to be published to local client */ + Client *local_client = AcquireClient(store); /* Stores snapshots produced locally */ + Client *publish_client = AcquireClient(store); /* Stores versions of local snapshots that will be published to remote sims */ - Client *master_client = sim_client_nil(); /* Stores snapshots received from master */ - Client *master_blended_client = sim_client_nil(); /* Stores interpolated master snapshots */ + Client *master_client = NilClient(); /* Stores snapshots received from master */ + Client *master_blended_client = NilClient(); /* Stores interpolated master snapshots */ b32 initialized_from_master = 0; @@ -2219,7 +2219,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) for (N_Event *event = host_events.first; event; event = event->next) { N_ChannelId channel_id = event->channel_id; - Client *client = sim_client_from_channel_id(store, channel_id); + Client *client = ClientFromChannelId(store, channel_id); switch (event->kind) { case N_EventKind_ChannelOpened: @@ -2229,18 +2229,18 @@ JobDef(SimJob, UNUSED sig, UNUSED id) if (is_master) { /* Create remote client */ - client = sim_client_acquire(store); - sim_client_set_channel_id(client, channel_id); + client = AcquireClient(store); + SetClientChannelId(client, channel_id); } else { /* Create master client */ if (!master_client->valid) { - client = sim_client_acquire(store); - sim_client_set_channel_id(client, channel_id); + client = AcquireClient(store); + SetClientChannelId(client, channel_id); master_client = client; - master_blended_client = sim_client_acquire(store); + master_blended_client = AcquireClient(store); } else { @@ -2286,7 +2286,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) tmp_encoded.text = BB_ReadBytesRaw(&decoder_br, tmp_encoded.len); if (!tmp_encoded.text) tmp_encoded.len = 0; - Snapshot *base_ss = sim_snapshot_from_tick(client, base_tick); + Snapshot *base_ss = SnapshotFromTick(client, base_tick); if (base_ss->tick == base_tick) { if (is_master) @@ -2368,15 +2368,15 @@ JobDef(SimJob, UNUSED sig, UNUSED id) Client *client = n->client; u64 base_tick = n->base_tick; u64 tick = n->tick; - Snapshot *base_ss = sim_snapshot_from_tick(client, base_tick); + Snapshot *base_ss = SnapshotFromTick(client, base_tick); if (base_ss->tick == base_tick) { BB_Buff bb = BitbuffFromString(n->tmp_encoded); BB_Reader br = BB_ReaderFromBuff(&bb); /* Acquire & decode snapshot */ - Snapshot *ss = sim_snapshot_acquire(client, base_ss, tick); - sim_snapshot_decode(&br, ss); + Snapshot *ss = AcquireSnapshot(client, base_ss, tick); + DecodeSnapshot(&br, ss); /* Assume all incoming ents want to be sync srcs */ for (u64 i = 0; i < ss->num_ents_reserved; ++i) @@ -2436,7 +2436,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) u64 keep_tick = MinU64(client->double_ack, local_client->last_tick); if (keep_tick > 0) { - sim_snapshot_release_ticks_in_range(client, 0, keep_tick - 1); + ReleaseSnapshotsInRange(client, 0, keep_tick - 1); } } if (client->ack < oldest_client_ack || oldest_client_ack == 0) @@ -2457,7 +2457,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) { --keep_tick; } - sim_snapshot_release_ticks_in_range(publish_client, 0, keep_tick); + ReleaseSnapshotsInRange(publish_client, 0, keep_tick); } /* Release old local snapshots */ @@ -2466,12 +2466,12 @@ JobDef(SimJob, UNUSED sig, UNUSED id) if (local_client->last_tick > keep_range) { u64 keep_tick = local_client->last_tick - keep_range; - sim_snapshot_release_ticks_in_range(local_client, 0, keep_tick); + ReleaseSnapshotsInRange(local_client, 0, keep_tick); } } /* Release unneeded user input snapshots */ - sim_snapshot_release_ticks_in_range(user_input_client, 0, local_client->first_tick - 1); + ReleaseSnapshotsInRange(user_input_client, 0, local_client->first_tick - 1); @@ -2493,8 +2493,8 @@ JobDef(SimJob, UNUSED sig, UNUSED id) ctx.user_input_client = user_input_client; ctx.master_client = master_client; ctx.publish_client = publish_client; - Snapshot *prev_world = sim_snapshot_from_tick(local_client, prev_tick); - ctx.world = sim_snapshot_acquire(local_client, prev_world, next_tick); + Snapshot *prev_world = SnapshotFromTick(local_client, prev_tick); + ctx.world = AcquireSnapshot(local_client, prev_world, next_tick); GenerateuserInputCmds(user_input_client, next_tick); StepSim(&ctx); } @@ -2517,7 +2517,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) } /* Predict master sim time based on average snapshot publish dt. */ - Snapshot *newest_snapshot = sim_snapshot_from_tick(master_client, master_client->last_tick); + Snapshot *newest_snapshot = SnapshotFromTick(master_client, master_client->last_tick); i64 master_sim_predicted_time_ns = newest_snapshot->sim_time_ns + (newest_snapshot->sim_dt_ns * tick_progress); /* Determine blend time */ @@ -2540,7 +2540,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) Snapshot *left_snapshot = sim_snapshot_nil(); Snapshot *right_snapshot = newest_snapshot; { - Snapshot *ss = sim_snapshot_from_tick(master_client, master_client->first_tick); + Snapshot *ss = SnapshotFromTick(master_client, master_client->first_tick); while (ss->valid) { u64 next_tick = ss->next_tick; @@ -2553,7 +2553,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) { right_snapshot = ss; } - ss = sim_snapshot_from_tick(master_client, next_tick); + ss = SnapshotFromTick(master_client, next_tick); } } @@ -2576,13 +2576,13 @@ JobDef(SimJob, UNUSED sig, UNUSED id) else { master_ss_is_blended = 1; - master_ss = sim_snapshot_acquire_from_lerp(master_blended_client, left_snapshot, right_snapshot, blend); + master_ss = AcquireSnapshotFromLerp(master_blended_client, left_snapshot, right_snapshot, blend); /* Release unneeded blended master snapshots */ if (master_ss->tick > 0) { - sim_snapshot_release_ticks_in_range(master_blended_client, 0, master_ss->tick - 1); - sim_snapshot_release_ticks_in_range(master_blended_client, master_ss->tick + 1, U64Max); + ReleaseSnapshotsInRange(master_blended_client, 0, master_ss->tick - 1); + ReleaseSnapshotsInRange(master_blended_client, master_ss->tick + 1, U64Max); } } } @@ -2596,7 +2596,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) u64 keep_master_tick = MinU64(left_snapshot->tick, master_client->double_ack); if (keep_master_tick > 0) { - sim_snapshot_release_ticks_in_range(master_client, 0, keep_master_tick - 1); + ReleaseSnapshotsInRange(master_client, 0, keep_master_tick - 1); } #if 0 @@ -2687,21 +2687,21 @@ JobDef(SimJob, UNUSED sig, UNUSED id) } /* Sync master with local base tick */ - Snapshot *base_ss = sim_snapshot_from_tick(local_client, step_base_tick); + Snapshot *base_ss = SnapshotFromTick(local_client, step_base_tick); if (mispredicted_tick) { if (base_ss->valid) { - sim_snapshot_sync_ents(base_ss, master_ss, master_player->id, 0); + SyncSnapshotEntities(base_ss, master_ss, master_player->id, 0); } else { - base_ss = sim_snapshot_acquire(local_client, master_ss, step_base_tick); + base_ss = AcquireSnapshot(local_client, master_ss, step_base_tick); } } /* Release any existing ticks that are about to be simulated */ - sim_snapshot_release_ticks_in_range(local_client, step_base_tick + 1, U64Max); + ReleaseSnapshotsInRange(local_client, step_base_tick + 1, U64Max); /* Step */ GenerateuserInputCmds(user_input_client, step_end_tick); @@ -2718,10 +2718,10 @@ JobDef(SimJob, UNUSED sig, UNUSED id) Snapshot *prev_ss = base_ss; while (step_tick <= step_end_tick) { - ctx.world = sim_snapshot_acquire(local_client, prev_ss, step_tick); + ctx.world = AcquireSnapshot(local_client, prev_ss, step_tick); if (!mispredicted_tick && step_tick == step_end_tick) { - sim_snapshot_sync_ents(ctx.world, master_ss, master_player->id, SIM_SYNC_FLAG_NOSYNC_PREDICTABLES); + SyncSnapshotEntities(ctx.world, master_ss, master_player->id, SyncFlag_NoSyncPredictables); } StepSim(&ctx); prev_ss = ctx.world; @@ -2742,17 +2742,17 @@ JobDef(SimJob, UNUSED sig, UNUSED id) BB_WriteUV(&msg_bw, client->highest_received_tick); /* ack */ BB_WriteUV(&msg_bw, client->ack); /* double ack */ - Snapshot *base_ss = sim_snapshot_from_tick(publish_client, client->ack); + Snapshot *base_ss = SnapshotFromTick(publish_client, client->ack); Snapshot *publish_ss; if (client == master_client) { /* If sending to master, start sending all snapshots since last ack */ - publish_ss = sim_snapshot_from_closest_tick_gte(publish_client, base_ss->tick + 1); + publish_ss = SnapshotFromClosestTickGte(publish_client, base_ss->tick + 1); } else { /* If sending to slave, only send latest snapshot */ - publish_ss = sim_snapshot_from_tick(publish_client, publish_client->last_tick); + publish_ss = SnapshotFromTick(publish_client, publish_client->last_tick); } while (publish_ss->valid) @@ -2762,13 +2762,13 @@ JobDef(SimJob, UNUSED sig, UNUSED id) { BB_WriteUV(&snapshot_bw, base_ss->tick); BB_WriteUV(&snapshot_bw, publish_ss->tick); - sim_snapshot_encode(&snapshot_bw, client, base_ss, publish_ss); + EncodeSnapshot(&snapshot_bw, client, base_ss, publish_ss); tmp_snapshot_encoded.len = BB_GetNumBytesWritten(&snapshot_bw); tmp_snapshot_encoded.text = BB_GetWrittenRaw(&snapshot_bw); } BB_WriteUV(&msg_bw, tmp_snapshot_encoded.len); BB_WriteBytes(&msg_bw, tmp_snapshot_encoded); - publish_ss = sim_snapshot_from_tick(publish_client, publish_ss->tick + 1); + publish_ss = SnapshotFromTick(publish_client, publish_ss->tick + 1); } BB_WriteUV(&msg_bw, 0); @@ -2781,12 +2781,12 @@ JobDef(SimJob, UNUSED sig, UNUSED id) /* Copy local snapshot to user client */ { - Snapshot *local_ss = sim_snapshot_from_tick(local_client, local_client->last_tick); + Snapshot *local_ss = SnapshotFromTick(local_client, local_client->last_tick); if (local_ss->valid) { /* TODO: Double buffer */ Lock lock = LockE(&g->local_to_user_client_mutex); - sim_snapshot_acquire(g->local_to_user_client, local_ss, local_ss->tick); + AcquireSnapshot(g->local_to_user_client, local_ss, local_ss->tick); i64 publish_ns = TimeNs(); if (last_publish_to_user_ns == 0) { @@ -2795,7 +2795,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) g->local_to_user_client_publish_dt_ns = publish_ns - last_publish_to_user_ns; g->local_to_user_client_publish_time_ns = publish_ns; last_publish_to_user_ns = publish_ns; - sim_snapshot_release_ticks_in_range(g->local_to_user_client, 0, local_ss->tick - 1); + ReleaseSnapshotsInRange(g->local_to_user_client, 0, local_ss->tick - 1); Unlock(&lock); } } @@ -2810,7 +2810,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) } } - sim_client_store_release(store); + ReleaseClientStore(store); ReleaseSimAccel(&accel); ReleaseBitbuff(&snapshot_writer_bb); ReleaseBitbuff(&msg_writer_bb); diff --git a/src/pp/pp_ent.c b/src/pp/pp_ent.c index 8d828b08..9d2e3800 100644 --- a/src/pp/pp_ent.c +++ b/src/pp/pp_ent.c @@ -635,7 +635,7 @@ Entity *TileChunkFromChunkIndex(Snapshot *ss, Vec2I32 chunk_index) Entity *TileChunkFromWorldTileIndex(Snapshot *ss, Vec2I32 world_tile_index) { - Vec2I32 chunk_index = sim_tile_chunk_index_from_world_tile_index(world_tile_index); + Vec2I32 chunk_index = TileChunkIndexFromWorldTileIndex(world_tile_index); Entity *chunk_ent = TileChunkFromChunkIndex(ss, chunk_index); return chunk_ent; } diff --git a/src/pp/pp_sim.c b/src/pp/pp_sim.c index 55825d65..ef8c6f97 100644 --- a/src/pp/pp_sim.c +++ b/src/pp/pp_sim.c @@ -24,8 +24,8 @@ * is used when working in contexts where id is irrelevant. */ - //////////////////////////////// - //~ Startup +//////////////////////////////// +//~ Startup SharedSimCtx shared_sim_ctx = ZI; Readonly ClientStore **_g_sim_client_store_nil = &shared_sim_ctx.nil_client_store; @@ -51,7 +51,7 @@ void StartupSim(void) /* Nil snapshot */ g->nil_snapshot = PushStruct(g->nil_arena, Snapshot); g->nil_snapshot->valid = 0; - g->nil_snapshot->client = sim_client_nil(); + g->nil_snapshot->client = NilClient(); /* Nil ent */ g->nil_ent = PushStruct(g->nil_arena, Entity); @@ -74,7 +74,7 @@ void StartupSim(void) //////////////////////////////// //~ Acquire client store -ClientStore *sim_client_store_acquire(void) +ClientStore *AcquireClientStore(void) { __prof; ClientStore *store; @@ -84,14 +84,14 @@ ClientStore *sim_client_store_acquire(void) store->arena = arena; } store->valid = 1; - store->num_client_lookup_bins = CLIENT_LOOKUP_BINS; + store->num_client_lookup_bins = ClientLookupBinsCount; store->client_lookup_bins = PushStructs(store->arena, ClientLookupBin, store->num_client_lookup_bins); store->clients_arena = AcquireArena(Gibi(64)); store->clients = PushDry(store->clients_arena, Client); return store; } -void sim_client_store_release(ClientStore *store) +void ReleaseClientStore(ClientStore *store) { __prof; for (u64 i = 0; i < store->num_clients_reserved; ++i) @@ -99,7 +99,7 @@ void sim_client_store_release(ClientStore *store) Client *client = &store->clients[i]; if (client->valid) { - sim_client_release(client); + ReleaseClient(client); } } ReleaseArena(store->clients_arena); @@ -109,10 +109,10 @@ void sim_client_store_release(ClientStore *store) //////////////////////////////// //~ Acquire client -Client *sim_client_acquire(ClientStore *store) +Client *AcquireClient(ClientStore *store) { ClientHandle handle = ZI; - Client *client = sim_client_from_handle(store, store->first_free_client); + Client *client = ClientFromHandle(store, store->first_free_client); if (client->valid) { @@ -128,19 +128,19 @@ Client *sim_client_acquire(ClientStore *store) ++store->num_clients_reserved; } ++store->num_clients_allocated; - *client = *sim_client_nil(); + *client = *NilClient(); client->store = store; client->valid = 1; client->handle = handle; client->snapshots_arena = AcquireArena(Gibi(8)); - client->num_snapshot_lookup_bins = TICK_LOOKUP_BINS; + client->num_snapshot_lookup_bins = TickLookupBinsCount; client->snapshot_lookup_bins = PushStructs(client->snapshots_arena, SnapshotLookupBin, client->num_snapshot_lookup_bins); return client; } -void sim_client_release(Client *client) +void ReleaseClient(Client *client) { /* Release internal snapshot memory */ for (u64 i = 0; i < client->num_snapshot_lookup_bins; ++i) @@ -157,7 +157,7 @@ void sim_client_release(Client *client) } /* Remove from channel lookup */ - sim_client_set_channel_id(client, N_NilChannelId); + SetClientChannelId(client, N_NilChannelId); /* Release client */ ClientStore *store = client->store; @@ -172,12 +172,12 @@ void sim_client_release(Client *client) //////////////////////////////// //~ Client lookup -u64 client_channel_hash_hash_from_channel_id(N_ChannelId channel_id) +u64 ClientChannelHashFromChannelId(N_ChannelId channel_id) { return HashFnv64(Fnv64Basis, StringFromStruct(&channel_id)); } -void sim_client_set_channel_id(Client *client, N_ChannelId channel_id) +void SetClientChannelId(Client *client, N_ChannelId channel_id) { ClientStore *store = client->store; N_ChannelId old_channel_id = client->channel_id; @@ -187,8 +187,8 @@ void sim_client_set_channel_id(Client *client, N_ChannelId channel_id) { u64 bin_index = client->channel_hash % store->num_client_lookup_bins; ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; - Client *prev = sim_client_from_handle(store, client->prev_in_bin); - Client *next = sim_client_from_handle(store, client->next_in_bin); + Client *prev = ClientFromHandle(store, client->prev_in_bin); + Client *next = ClientFromHandle(store, client->next_in_bin); if (prev->valid) { prev->next_in_bin = next->handle; @@ -209,7 +209,7 @@ void sim_client_set_channel_id(Client *client, N_ChannelId channel_id) /* Insert into channel lookup */ /* TODO: Enforce no duplicates */ - u64 channel_hash = client_channel_hash_hash_from_channel_id(channel_id); + u64 channel_hash = ClientChannelHashFromChannelId(channel_id); client->channel_id = channel_id; client->channel_hash = channel_hash; if (!N_IsChannelIdNil(channel_id)) @@ -217,7 +217,7 @@ void sim_client_set_channel_id(Client *client, N_ChannelId channel_id) u64 bin_index = channel_hash % store->num_client_lookup_bins; ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; { - Client *prev_in_bin = sim_client_from_handle(store, bin->last); + Client *prev_in_bin = ClientFromHandle(store, bin->last); if (prev_in_bin->valid) { prev_in_bin->next_in_bin = client->handle; @@ -232,13 +232,13 @@ void sim_client_set_channel_id(Client *client, N_ChannelId channel_id) } } -Client *sim_client_from_channel_id(ClientStore *store, N_ChannelId channel_id) +Client *ClientFromChannelId(ClientStore *store, N_ChannelId channel_id) { - Client *result = sim_client_nil(); - u64 channel_hash = client_channel_hash_hash_from_channel_id(channel_id); + Client *result = NilClient(); + u64 channel_hash = ClientChannelHashFromChannelId(channel_id); u64 bin_index = channel_hash % store->num_client_lookup_bins; ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; - for (Client *client = sim_client_from_handle(store, bin->first); client->valid; client = sim_client_from_handle(store, client->next_in_bin)) + for (Client *client = ClientFromHandle(store, bin->first); client->valid; client = ClientFromHandle(store, client->next_in_bin)) { if (client->channel_hash == channel_hash) { @@ -249,7 +249,7 @@ Client *sim_client_from_channel_id(ClientStore *store, N_ChannelId channel_id) return result; } -Client *sim_client_from_handle(ClientStore *store, ClientHandle handle) +Client *ClientFromHandle(ClientStore *store, ClientHandle handle) { if (handle.gen != 0 && handle.idx < store->num_clients_reserved) { @@ -259,14 +259,14 @@ Client *sim_client_from_handle(ClientStore *store, ClientHandle handle) return client; } } - return sim_client_nil(); + return NilClient(); } //////////////////////////////// //~ Acquire snapshot /* Produces a new snapshot at `tick` with data copied from `src` snapshot. */ -Snapshot *sim_snapshot_acquire(Client *client, Snapshot *src, u64 tick) +Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) { if (tick == 0) { @@ -314,7 +314,7 @@ Snapshot *sim_snapshot_acquire(Client *client, Snapshot *src, u64 tick) ss->phys_iteration = src->phys_iteration; /* Copy id lookup bins */ - ss->num_id_bins = src->num_id_bins > 0 ? src->num_id_bins : ID_LOOKUP_BINS; + ss->num_id_bins = src->num_id_bins > 0 ? src->num_id_bins : IdLookupBinsCount; ss->id_bins = PushStructsNoZero(ss->arena, EntBin, ss->num_id_bins); if (src->num_id_bins > 0) { @@ -371,27 +371,27 @@ Snapshot *sim_snapshot_acquire(Client *client, Snapshot *src, u64 tick) /* Release duplicate tick if it exists */ { - Snapshot *existing = sim_snapshot_from_tick(client, tick); + Snapshot *existing = SnapshotFromTick(client, tick); if (existing->valid) { - sim_snapshot_release(existing); + ReleaseSnapshot(existing); } } /* Linear search to insert snapshot in tick order */ { - Snapshot *prev = sim_snapshot_from_tick(client, client->last_tick); + Snapshot *prev = SnapshotFromTick(client, client->last_tick); while (prev->valid) { if (prev->tick < tick) { break; } - prev = sim_snapshot_from_tick(client, prev->prev_tick); + prev = SnapshotFromTick(client, prev->prev_tick); } if (prev->valid) { - Snapshot *next = sim_snapshot_from_tick(client, prev->next_tick); + Snapshot *next = SnapshotFromTick(client, prev->next_tick); if (next->valid) { next->prev_tick = tick; @@ -406,7 +406,7 @@ Snapshot *sim_snapshot_acquire(Client *client, Snapshot *src, u64 tick) } else { - Snapshot *first = sim_snapshot_from_tick(client, client->first_tick); + Snapshot *first = SnapshotFromTick(client, client->first_tick); if (first->valid) { ss->next_tick = first->tick; @@ -440,7 +440,7 @@ Snapshot *sim_snapshot_acquire(Client *client, Snapshot *src, u64 tick) return ss; } -void sim_snapshot_release(Snapshot *ss) +void ReleaseSnapshot(Snapshot *ss) { Client *client = ss->client; @@ -470,8 +470,8 @@ void sim_snapshot_release(Snapshot *ss) /* Remove from snapshot list */ { - Snapshot *prev = sim_snapshot_from_tick(client, ss->prev_tick); - Snapshot *next = sim_snapshot_from_tick(client, ss->next_tick); + Snapshot *prev = SnapshotFromTick(client, ss->prev_tick); + Snapshot *next = SnapshotFromTick(client, ss->next_tick); if (prev->valid) { prev->next_tick = next->tick; @@ -497,7 +497,7 @@ void sim_snapshot_release(Snapshot *ss) } /* Release all snapshots for client with tick in range [start, end] */ -void sim_snapshot_release_ticks_in_range(Client *client, u64 start, u64 end) +void ReleaseSnapshotsInRange(Client *client, u64 start, u64 end) { if (start > end) { @@ -506,7 +506,7 @@ void sim_snapshot_release_ticks_in_range(Client *client, u64 start, u64 end) end = swp; } - Snapshot *ss = sim_snapshot_from_tick(client, client->first_tick); + Snapshot *ss = SnapshotFromTick(client, client->first_tick); while (ss->valid) { u64 tick = ss->tick; @@ -515,21 +515,21 @@ void sim_snapshot_release_ticks_in_range(Client *client, u64 start, u64 end) { if (tick <= end) { - sim_snapshot_release(ss); + ReleaseSnapshot(ss); } else { break; } } - ss = sim_snapshot_from_tick(client, next_tick); + ss = SnapshotFromTick(client, next_tick); } } //////////////////////////////// //~ Snapshot lookup -Snapshot *sim_snapshot_from_tick(Client *client, u64 tick) +Snapshot *SnapshotFromTick(Client *client, u64 tick) { Snapshot *ss = sim_snapshot_nil(); if (tick > 0) @@ -549,40 +549,40 @@ Snapshot *sim_snapshot_from_tick(Client *client, u64 tick) } /* Returns the snapshot at nearest valid tick <= supplied tick */ -Snapshot *sim_snapshot_from_closest_tick_lte(Client *client, u64 tick) +Snapshot *SnapshotFromClosestTickLte(Client *client, u64 tick) { - Snapshot *ss = sim_snapshot_from_tick(client, tick); + Snapshot *ss = SnapshotFromTick(client, tick); if (!ss->valid) { /* Degenerate to linear search */ - ss = sim_snapshot_from_tick(client, client->last_tick); + ss = SnapshotFromTick(client, client->last_tick); while (ss->valid) { if (ss->tick <= tick) { break; } - ss = sim_snapshot_from_tick(client, ss->prev_tick); + ss = SnapshotFromTick(client, ss->prev_tick); } } return ss; } /* Returns the snapshot at nearest valid tick >= supplied tick */ -Snapshot *sim_snapshot_from_closest_tick_gte(Client *client, u64 tick) +Snapshot *SnapshotFromClosestTickGte(Client *client, u64 tick) { - Snapshot *ss = sim_snapshot_from_tick(client, tick); + Snapshot *ss = SnapshotFromTick(client, tick); if (!ss->valid) { /* Degenerate to linear search */ - ss = sim_snapshot_from_tick(client, client->first_tick); + ss = SnapshotFromTick(client, client->first_tick); while (ss->valid) { if (ss->tick >= tick) { break; } - ss = sim_snapshot_from_tick(client, ss->next_tick); + ss = SnapshotFromTick(client, ss->next_tick); } } return ss; @@ -591,7 +591,7 @@ Snapshot *sim_snapshot_from_closest_tick_gte(Client *client, u64 tick) //////////////////////////////// //~ Tile -Vec2I32 sim_world_tile_index_from_pos(Vec2 pos) +Vec2I32 WorldTileIndexFromPos(Vec2 pos) { Vec2I32 result = VEC2I32(pos.x * SIM_TILES_PER_UNIT_SQRT, pos.y * SIM_TILES_PER_UNIT_SQRT); result.x -= pos.x < 0; @@ -599,7 +599,7 @@ Vec2I32 sim_world_tile_index_from_pos(Vec2 pos) return result; } -Vec2 sim_pos_from_world_tile_index(Vec2I32 world_tile_index) +Vec2 PosFromWorldTileIndex(Vec2I32 world_tile_index) { Vec2 result = ZI; f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT; @@ -608,7 +608,7 @@ Vec2 sim_pos_from_world_tile_index(Vec2I32 world_tile_index) return result; } -Vec2I32 sim_local_tile_index_from_world_tile_index(Vec2I32 world_tile_index) +Vec2I32 LocalTileIndexFromWorldTileIndex(Vec2I32 world_tile_index) { Vec2I32 result = world_tile_index; result.x += result.x < 0; @@ -620,7 +620,7 @@ Vec2I32 sim_local_tile_index_from_world_tile_index(Vec2I32 world_tile_index) return result; } -Vec2I32 sim_world_tile_index_from_local_tile_index(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index) +Vec2I32 WorldTileIndexFromLocalTileIndex(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index) { Vec2I32 result = ZI; result.x = (tile_chunk_index.x * SIM_TILES_PER_CHUNK_SQRT) + local_tile_index.x; @@ -628,7 +628,7 @@ Vec2I32 sim_world_tile_index_from_local_tile_index(Vec2I32 tile_chunk_index, Vec return result; } -Vec2I32 sim_tile_chunk_index_from_world_tile_index(Vec2I32 world_tile_index) +Vec2I32 TileChunkIndexFromWorldTileIndex(Vec2I32 world_tile_index) { Vec2I32 result = world_tile_index; result.x += result.x < 0; @@ -640,9 +640,9 @@ Vec2I32 sim_tile_chunk_index_from_world_tile_index(Vec2I32 world_tile_index) return result; } -void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind) +void SetSnapshotTile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind) { - Vec2I32 chunk_index = sim_tile_chunk_index_from_world_tile_index(world_tile_index); + Vec2I32 chunk_index = TileChunkIndexFromWorldTileIndex(world_tile_index); EntityId chunk_id = TileChunkIdFromIndex(chunk_index); Entity *chunk_ent = EntityFromId(ss, chunk_id); @@ -654,14 +654,14 @@ void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile chunk_ent->tile_chunk_index = chunk_index; } - Vec2I32 local_index = sim_local_tile_index_from_world_tile_index(world_tile_index); + Vec2I32 local_index = LocalTileIndexFromWorldTileIndex(world_tile_index); chunk_ent->tile_chunk_tiles[local_index.x + (local_index.y * SIM_TILES_PER_CHUNK_SQRT)] = tile_kind; } //////////////////////////////// //~ Snapshot lerp -Snapshot *sim_snapshot_acquire_from_lerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend) +Snapshot *AcquireSnapshotFromLerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend) { __prof; @@ -672,16 +672,16 @@ Snapshot *sim_snapshot_acquire_from_lerp(Client *client, Snapshot *ss0, Snapshot b32 should_blend = 1; if (ss0->continuity_gen == ss1->continuity_gen && 0 < blend && blend < 1) { - ss = sim_snapshot_acquire(client, ss0, ss0->tick); + ss = AcquireSnapshot(client, ss0, ss0->tick); } else if (RoundF64ToI64(blend) <= 0) { - ss = sim_snapshot_acquire(client, ss0, ss0->tick); + ss = AcquireSnapshot(client, ss0, ss0->tick); should_blend = 0; } else { - ss = sim_snapshot_acquire(client, ss1, ss1->tick); + ss = AcquireSnapshot(client, ss1, ss1->tick); should_blend = 0; } @@ -719,7 +719,7 @@ Snapshot *sim_snapshot_acquire_from_lerp(Client *client, Snapshot *ss0, Snapshot //~ Snapshot sync /* Syncs entity data between snapshots */ -void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId remote_player, u32 sync_flags) +void SyncSnapshotEntities(Snapshot *local_ss, Snapshot *remote_ss, EntityId remote_player, u32 sync_flags) { __prof; @@ -744,7 +744,7 @@ void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId re if (local_ent->valid && HasProp(local_ent, Prop_SyncDst)) { b32 should_sync = EqId(local_ent->owner, remote_player) || IsNilId(remote_player); - if ((sync_flags & SIM_SYNC_FLAG_NOSYNC_PREDICTABLES) && EqId(local_ent->predictor, local_ss->local_player)) + if ((sync_flags & SyncFlag_NoSyncPredictables) && EqId(local_ent->predictor, local_ss->local_player)) { should_sync = 0; } @@ -785,7 +785,7 @@ void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId re //////////////////////////////// //~ Snapshot encode -void sim_snapshot_encode(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1) +void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1) { __prof; @@ -862,7 +862,7 @@ void sim_snapshot_encode(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapsho //////////////////////////////// //~ Snapshot decode -void sim_snapshot_decode(BB_Reader *br, Snapshot *ss) +void DecodeSnapshot(BB_Reader *br, Snapshot *ss) { __prof; @@ -954,7 +954,7 @@ void sim_snapshot_decode(BB_Reader *br, Snapshot *ss) //////////////////////////////// //~ Snapshot encode -void sim_snapshot_encode(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1) +void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1) { __prof; @@ -1035,7 +1035,7 @@ struct sim_ent_decode_queue struct sim_ent_decode_node *last; }; -void sim_snapshot_decode(BB_Reader *br, Snapshot *ss) +void DecodeSnapshot(BB_Reader *br, Snapshot *ss) { __prof; TempArena scratch = BeginScratchNoConflict(); diff --git a/src/pp/pp_sim.h b/src/pp/pp_sim.h index 0c1091f9..537d873c 100644 --- a/src/pp/pp_sim.h +++ b/src/pp/pp_sim.h @@ -12,7 +12,7 @@ Struct(ClientHandle) u32 gen; }; -#define SIM_CLIENT_NIL_HANDLE ((ClientHandle) { .gen = 0, .idx = 0 }) +#define NilClientHandle ((ClientHandle) { .gen = 0, .idx = 0 }) //////////////////////////////// @@ -99,13 +99,13 @@ Struct(Client) SnapshotLookupBin *snapshot_lookup_bins; }; -Inline Client *sim_client_nil(void) +Inline Client *NilClient(void) { extern Readonly Client **_g_sim_client_nil; return *_g_sim_client_nil; } -Inline b32 sim_client_handle_eq(ClientHandle a, ClientHandle b) +Inline b32 EqClientHandle(ClientHandle a, ClientHandle b) { return a.gen == b.gen && a.idx == b.idx; } @@ -114,36 +114,36 @@ Inline b32 sim_client_handle_eq(ClientHandle a, ClientHandle b) //~ Layer types /* Absolute layers */ -#define SIM_LAYER_FLOOR_DECALS (-300) -#define SIM_LAYER_BULLETS (-200) -#define SIM_LAYER_TRACERS (-100) -#define SIM_LAYER_SHOULDERS (0) -#define SIM_LAYER_WALLS (100) +#define Layer_FloorDecals (-300) +#define Layer_Bullets (-200) +#define Layer_Tracers (-100) +#define Layer_Shoulders (0) +#define Layer_Walls (100) /* Relative layers */ -#define SIM_LAYER_RELATIVE_DEFAULT (0) -#define SIM_LAYER_RELATIVE_WEAPON (1) +#define Layer_DefaultRelative (0) +#define Layer_RelativeWeapon (1) //////////////////////////////// //~ Control types typedef i32 ControlFlag; enum { - SIM_CONTROL_FLAG_FIRE = 1 << 0, - SIM_CONTROL_FLAG_FIRE_ALT = 1 << 1, + ControlFlag_Fire = 1 << 0, + ControlFlag_AltFire = 1 << 1, /* Testing */ - SIM_CONTROL_FLAG_DRAG = 1 << 2, - SIM_CONTROL_FLAG_DELETE = 1 << 3, - SIM_CONTROL_FLAG_CLEAR_ALL = 1 << 4, - SIM_CONTROL_FLAG_SPAWN1_TEST = 1 << 5, - SIM_CONTROL_FLAG_SPAWN2_TEST = 1 << 6, - SIM_CONTROL_FLAG_SPAWN3_TEST = 1 << 7, - SIM_CONTROL_FLAG_SPAWN4_TEST = 1 << 8, - SIM_CONTROL_FLAG_WALLS_TEST = 1 << 9, - SIM_CONTROL_FLAG_TILE_TEST = 1 << 10, - SIM_CONTROL_FLAG_EXPLODE_TEST = 1 << 11, - SIM_CONTROL_FLAG_TELEPORT_TEST = 1 << 12, + ControlFlag_Drag = 1 << 2, + ControlFlag_Delete = 1 << 3, + ControlFlag_ClearAll = 1 << 4, + ControlFlag_SpawnTest1 = 1 << 5, + ControlFlag_SpawnTest2 = 1 << 6, + ControlFlag_SpawnTest3 = 1 << 7, + ControlFlag_SpawnTest4 = 1 << 8, + ControlFlag_TestWalls = 1 << 9, + ControlFlag_TestTiles = 1 << 10, + ControlFlag_TestExplode = 1 << 11, + ControlFlag_TestTeleport = 1 << 12, }; Struct(ControlData) @@ -156,10 +156,10 @@ Struct(ControlData) typedef i32 CmdKind; enum { - SIM_CMD_KIND_INVALID, + CmdKind_Invalid, - SIM_CMD_KIND_CONTROL, - SIM_CMD_KIND_CHAT + CmdKind_Control, + CmdKind_Chat }; //////////////////////////////// @@ -167,19 +167,19 @@ typedef i32 CmdKind; enum typedef i32 TileKind; enum { - SIM_TILE_KIND_NONE, - SIM_TILE_KIND_WALL, + TileKind_None, + TileKind_Wall, - NUM_SIM_TILE_KINDS + TileKind_Count }; -StaticAssert(NUM_SIM_TILE_KINDS < 256); /* Tile kind must fit in 8 bits */ +StaticAssert(TileKind_Count < 256); /* Tile kind must fit in 8 bits */ //////////////////////////////// //~ Snapshot types typedef i32 SyncFlag; enum { - SIM_SYNC_FLAG_NOSYNC_PREDICTABLES = 1 << 0 + SyncFlag_NoSyncPredictables = 1 << 0 }; Struct(Snapshot) @@ -229,10 +229,9 @@ Inline Snapshot *sim_snapshot_nil(void) //////////////////////////////// //~ Shared state -#define CLIENT_LOOKUP_BINS 127 -#define TICK_LOOKUP_BINS 127 -#define ID_LOOKUP_BINS 4096 - +#define ClientLookupBinsCount 127 +#define TickLookupBinsCount 127 +#define IdLookupBinsCount 4096 Struct(SharedSimCtx) { @@ -248,7 +247,7 @@ extern SharedSimCtx shared_sim_ctx; /* Accessed via `sim_client_store_nil()` */ extern Readonly ClientStore **_g_sim_client_store_nil; -/* Accessed via `sim_client_nil()` */ +/* Accessed via `NilClient()` */ extern Readonly Client **_g_sim_client_nil; /* Accessed via `sim_snapshot_nil()` */ @@ -263,63 +262,63 @@ void StartupSim(void); //////////////////////////////// //~ Client store acquire operations -ClientStore *sim_client_store_acquire(void); -void sim_client_store_release(ClientStore *store); +ClientStore *AcquireClientStore(void); +void ReleaseClientStore(ClientStore *store); //////////////////////////////// //~ Client acquire operations -Client *sim_client_acquire(ClientStore *store); -void sim_client_release(Client *client); +Client *AcquireClient(ClientStore *store); +void ReleaseClient(Client *client); //////////////////////////////// //~ Client lookup operations -u64 client_channel_hash_hash_from_channel_id(N_ChannelId channel_id); -void sim_client_set_channel_id(Client *client, N_ChannelId channel_id); -Client *sim_client_from_channel_id(ClientStore *store, N_ChannelId channel_id); -Client *sim_client_from_handle(ClientStore *store, ClientHandle handle); +u64 ClientChannelHashFromChannelId(N_ChannelId channel_id); +void SetClientChannelId(Client *client, N_ChannelId channel_id); +Client *ClientFromChannelId(ClientStore *store, N_ChannelId channel_id); +Client *ClientFromHandle(ClientStore *store, ClientHandle handle); //////////////////////////////// //~ Snapshot acquire operations -Snapshot *sim_snapshot_acquire(Client *client, Snapshot *src, u64 tick); -void sim_snapshot_release(Snapshot *ss); -void sim_snapshot_release_ticks_in_range(Client *client, u64 start, u64 end); +Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick); +void ReleaseSnapshot(Snapshot *ss); +void ReleaseSnapshotsInRange(Client *client, u64 start, u64 end); //////////////////////////////// //~ Snapshot lookup operations -Snapshot *sim_snapshot_from_tick(Client *client, u64 tick); -Snapshot *sim_snapshot_from_closest_tick_lte(Client *client, u64 tick); -Snapshot *sim_snapshot_from_closest_tick_gte(Client *client, u64 tick); +Snapshot *SnapshotFromTick(Client *client, u64 tick); +Snapshot *SnapshotFromClosestTickLte(Client *client, u64 tick); +Snapshot *SnapshotFromClosestTickGte(Client *client, u64 tick); //////////////////////////////// //~ Tile operations -Vec2I32 sim_world_tile_index_from_pos(Vec2 pos); -Vec2 sim_pos_from_world_tile_index(Vec2I32 world_tile_index); -Vec2I32 sim_local_tile_index_from_world_tile_index(Vec2I32 world_tile_index); -Vec2I32 sim_world_tile_index_from_local_tile_index(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index); -Vec2I32 sim_tile_chunk_index_from_world_tile_index(Vec2I32 world_tile_index); -void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind); +Vec2I32 WorldTileIndexFromPos(Vec2 pos); +Vec2 PosFromWorldTileIndex(Vec2I32 world_tile_index); +Vec2I32 LocalTileIndexFromWorldTileIndex(Vec2I32 world_tile_index); +Vec2I32 WorldTileIndexFromLocalTileIndex(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index); +Vec2I32 TileChunkIndexFromWorldTileIndex(Vec2I32 world_tile_index); +void SetSnapshotTile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind); //////////////////////////////// //~ Snapshot lerp operations -Snapshot *sim_snapshot_acquire_from_lerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend); +Snapshot *AcquireSnapshotFromLerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend); //////////////////////////////// //~ Snapshot sync operations -void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId remote_player, u32 sync_flags); +void SyncSnapshotEntities(Snapshot *local_ss, Snapshot *remote_ss, EntityId remote_player, u32 sync_flags); //////////////////////////////// //~ Snapshot encode operations -void sim_snapshot_encode(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1); +void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1); //////////////////////////////// //~ Snapshot decode operations -void sim_snapshot_decode(BB_Reader *br, Snapshot *ss); +void DecodeSnapshot(BB_Reader *br, Snapshot *ss); diff --git a/src/pp/pp_step.c b/src/pp/pp_step.c index e4896018..f901e92e 100644 --- a/src/pp/pp_step.c +++ b/src/pp/pp_step.c @@ -40,7 +40,7 @@ Entity *SpawnTestSmg(Entity *parent) EnableProp(e, Prop_Attached); e->attach_slice = Lit("attach.wep"); - e->layer = SIM_LAYER_RELATIVE_WEAPON; + e->layer = Layer_RelativeWeapon; EnableProp(e, Prop_Smg); e->primary_fire_delay = 1.0f / 10.0f; @@ -56,7 +56,7 @@ Entity *SpawnTestLauncher(Entity *parent) EnableProp(e, Prop_Attached); e->attach_slice = Lit("attach.wep"); - e->layer = SIM_LAYER_RELATIVE_WEAPON; + e->layer = Layer_RelativeWeapon; EnableProp(e, Prop_Launcher); e->primary_fire_delay = 1.0f / 10.0f; @@ -72,7 +72,7 @@ Entity *SpawnTestChucker(Entity *parent) EnableProp(chucker, Prop_Attached); chucker->attach_slice = Lit("attach.wep"); - chucker->layer = SIM_LAYER_RELATIVE_WEAPON; + chucker->layer = Layer_RelativeWeapon; EnableProp(chucker, Prop_Chucker); chucker->primary_fire_delay = 1.0f / 10.0f; @@ -128,7 +128,7 @@ Entity *SpawnTestEmployee(Entity *parent) //e->sprite_span_name = Lit("idle.unarmed"); //e->sprite_span_name = Lit("idle.one_handed"); e->sprite_span_name = Lit("idle.two_handed"); - e->layer = SIM_LAYER_SHOULDERS; + e->layer = Layer_Shoulders; e->local_collider.points[0] = VEC2(0, 0); e->local_collider.count = 1; @@ -258,7 +258,7 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos) SetXform(e, xf); e->sprite = S_TagFromPath(Lit("sprite/tile.ase")); - e->layer = SIM_LAYER_SHOULDERS; + e->layer = Layer_Shoulders; //e->sprite_tint = Alpha32F(ColorBlue, 0.75); //e->sprite_tint = Alpha32F(ColorWhite, 1); @@ -301,7 +301,7 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos) e->sprite = S_TagFromPath(Lit("sprite/bullet.ase")); e->sprite_collider_slice = Lit("shape"); - e->layer = SIM_LAYER_SHOULDERS; + e->layer = Layer_Shoulders; EnableProp(e, Prop_Solid); @@ -328,7 +328,7 @@ void SpawnTestEntities3(Entity *parent, Vec2 pos) SetXform(e, xf); e->sprite = S_TagFromPath(Lit("sprite/box.ase")); - e->layer = SIM_LAYER_SHOULDERS; + e->layer = Layer_Shoulders; e->sprite_tint = ColorRed; @@ -352,7 +352,7 @@ void SpawnTestEntities4(Entity *parent, Vec2 pos) //e->sprite = S_TagFromPath(Lit("sprite/box.ase")); e->sprite = S_TagFromPath(Lit("sprite/tile.ase")); - e->layer = SIM_LAYER_SHOULDERS; + e->layer = Layer_Shoulders; EnableProp(e, Prop_LightTest); e->sprite_emittance = VEC3(2, 2, 2); @@ -379,7 +379,7 @@ void SpawnTestTile(Snapshot *world, Vec2 world_pos) Xform xf = XformFromTrs(.t = pos); SetXform(e, xf); - e->layer = SIM_LAYER_WALLS; + e->layer = Layer_Walls; e->sprite = S_TagFromPath(Lit("sprite/tile.ase")); e->sprite_tint = ColorRed; @@ -394,8 +394,8 @@ void SpawnTestTile(Snapshot *world, Vec2 world_pos) Quad collider_quad = QuadFromRect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y)); e->local_collider = CLD_ShapeFromQuad(collider_quad); #else - Vec2I32 tile_index = sim_world_tile_index_from_pos(world_pos); - sim_snapshot_set_tile(world, tile_index, SIM_TILE_KIND_WALL); + Vec2I32 tile_index = WorldTileIndexFromPos(world_pos); + SetSnapshotTile(world, tile_index, TileKind_Wall); #endif } @@ -511,14 +511,14 @@ void GenerateTestWalls(Snapshot *world) for (i32 tile_x = 0; tile_x < x_iterations; ++tile_x) { i32 desired_wall_dir = -1; - TileKind tile = SIM_TILE_KIND_NONE; + TileKind tile = TileKind_None; if (tile_x < SIM_TILES_PER_CHUNK_SQRT && tile_y < SIM_TILES_PER_CHUNK_SQRT) { tile = TileKindFromChunk(chunk, VEC2I32(tile_x, tile_y)); } if (tile_x < SIM_TILES_PER_CHUNK_SQRT) { - TileKind top_tile = SIM_TILE_KIND_NONE; + TileKind top_tile = TileKind_None; if (tile_y == 0) { if (top_chunk->valid) @@ -531,10 +531,10 @@ void GenerateTestWalls(Snapshot *world) { top_tile = TileKindFromChunk(chunk, VEC2I32(tile_x, tile_y - 1)); } - if (tile == SIM_TILE_KIND_WALL) + if (tile == TileKind_Wall) { /* Process wall tile */ - if (top_tile != SIM_TILE_KIND_WALL) + if (top_tile != TileKind_Wall) { desired_wall_dir = 0; } @@ -542,7 +542,7 @@ void GenerateTestWalls(Snapshot *world) else { /* Process non-wall tile */ - if (top_tile == SIM_TILE_KIND_WALL) + if (top_tile == TileKind_Wall) { desired_wall_dir = 2; } @@ -552,8 +552,8 @@ void GenerateTestWalls(Snapshot *world) /* Stop wall */ if (wall_dir >= 0 && desired_wall_dir != wall_dir) { - Vec2I32 start = sim_world_tile_index_from_local_tile_index(chunk_index, VEC2I32(wall_start, tile_y)); - Vec2I32 end = sim_world_tile_index_from_local_tile_index(chunk_index, VEC2I32(wall_end, tile_y)); + Vec2I32 start = WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(wall_start, tile_y)); + Vec2I32 end = WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(wall_end, tile_y)); struct wall_node *node = 0; if (wall_start == 0) { @@ -621,7 +621,7 @@ void GenerateTestWalls(Snapshot *world) for (i32 tile_y = 0; tile_y < y_iterations; ++tile_y) { i32 desired_wall_dir = -1; - TileKind tile = SIM_TILE_KIND_NONE; + TileKind tile = TileKind_None; if (tile_x < SIM_TILES_PER_CHUNK_SQRT && tile_y < SIM_TILES_PER_CHUNK_SQRT) { tile = TileKindFromChunk(chunk, VEC2I32(tile_x, tile_y)); @@ -629,7 +629,7 @@ void GenerateTestWalls(Snapshot *world) if (tile_y < SIM_TILES_PER_CHUNK_SQRT) { - TileKind left_tile = SIM_TILE_KIND_NONE; + TileKind left_tile = TileKind_None; if (tile_x == 0) { if (left_chunk->valid) @@ -642,10 +642,10 @@ void GenerateTestWalls(Snapshot *world) { left_tile = TileKindFromChunk(chunk, VEC2I32(tile_x - 1, tile_y)); } - if (tile == SIM_TILE_KIND_WALL) + if (tile == TileKind_Wall) { /* Process wall tile */ - if (left_tile != SIM_TILE_KIND_WALL) + if (left_tile != TileKind_Wall) { desired_wall_dir = 3; } @@ -653,7 +653,7 @@ void GenerateTestWalls(Snapshot *world) else { /* Process non-wall tile */ - if (left_tile == SIM_TILE_KIND_WALL) + if (left_tile == TileKind_Wall) { desired_wall_dir = 1; } @@ -663,8 +663,8 @@ void GenerateTestWalls(Snapshot *world) /* Stop wall */ if (wall_dir >= 0 && desired_wall_dir != wall_dir) { - Vec2I32 start = sim_world_tile_index_from_local_tile_index(chunk_index, VEC2I32(tile_x, wall_start)); - Vec2I32 end = sim_world_tile_index_from_local_tile_index(chunk_index, VEC2I32(tile_x, wall_end)); + Vec2I32 start = WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(tile_x, wall_start)); + Vec2I32 end = WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(tile_x, wall_end)); struct wall_node *node = 0; if (wall_start == 0) { @@ -720,8 +720,8 @@ void GenerateTestWalls(Snapshot *world) Entity *wall_ent = AcquireSyncSrc(root); EnableProp(wall_ent, Prop_Wall); - Vec2 start = sim_pos_from_world_tile_index(node->start); - Vec2 end = sim_pos_from_world_tile_index(node->end); + Vec2 start = PosFromWorldTileIndex(node->start); + Vec2 end = PosFromWorldTileIndex(node->end); Xform xf = XformFromPos(start); SetXform(wall_ent, xf); @@ -789,7 +789,7 @@ CollisionCallbackFuncDef(OnEntityCollision, data, step_ctx) Entity *decal = AcquireSyncSrc(root); decal->sprite = S_TagFromPath(Lit("sprite/blood.ase")); decal->sprite_tint = Rgba32F(1, 1, 1, 0.25f); - decal->layer = SIM_LAYER_FLOOR_DECALS; + decal->layer = Layer_FloorDecals; SetXform(decal, xf); f32 perp_range = 0.5; @@ -949,10 +949,10 @@ void StepSim(SimStepCtx *ctx) /* Sync ents from client */ if (player->valid) { - Snapshot *src_ss = sim_snapshot_from_tick(client, world->tick); + Snapshot *src_ss = SnapshotFromTick(client, world->tick); if (src_ss->valid) { - sim_snapshot_sync_ents(world, src_ss, player->id, 0); + SyncSnapshotEntities(world, src_ss, player->id, 0); } } } @@ -1044,7 +1044,7 @@ void StepSim(SimStepCtx *ctx) CmdKind kind = cmd_ent->cmd_kind; switch (kind) { - case SIM_CMD_KIND_CONTROL: + case CmdKind_Control: { /* Player's will send control cmds a lot, so keep it around to prevent re-creating it each time */ persist_cmd = 1; @@ -1070,21 +1070,21 @@ void StepSim(SimStepCtx *ctx) /* Debug cmds */ if (ctx->is_master) { - if (flags & SIM_CONTROL_FLAG_DRAG) + if (flags & ControlFlag_Drag) { - if (!(old_control.flags & SIM_CONTROL_FLAG_DRAG)) + if (!(old_control.flags & ControlFlag_Drag)) { player->player_dbg_drag_start = 1; } } else { - if (old_control.flags & SIM_CONTROL_FLAG_DRAG) + if (old_control.flags & ControlFlag_Drag) { player->player_dbg_drag_stop = 1; } } - if (flags & SIM_CONTROL_FLAG_DELETE) + if (flags & ControlFlag_Delete) { Entity *ent = EntityFromId(world, player->player_hovered_ent); if (ent->valid) @@ -1092,11 +1092,11 @@ void StepSim(SimStepCtx *ctx) EnableProp(ent, Prop_Release); } } - if (flags & SIM_CONTROL_FLAG_CLEAR_ALL) + if (flags & ControlFlag_ClearAll) { ClearLevelTest(ctx); } - if (flags & SIM_CONTROL_FLAG_SPAWN1_TEST) + if (flags & ControlFlag_SpawnTest1) { P_LogDebugF("Spawn test 1"); u32 count = 1; @@ -1108,7 +1108,7 @@ void StepSim(SimStepCtx *ctx) SpawnTestEntities1(root, pos); } } - if (flags & SIM_CONTROL_FLAG_SPAWN2_TEST) + if (flags & ControlFlag_SpawnTest2) { P_LogDebugF("Spawn test 2"); u32 count = 1; @@ -1120,7 +1120,7 @@ void StepSim(SimStepCtx *ctx) SpawnTestEntities2(root, pos); } } - if (flags & SIM_CONTROL_FLAG_SPAWN3_TEST) + if (flags & ControlFlag_SpawnTest3) { P_LogDebugF("Spawn test 3"); u32 count = 1; @@ -1132,7 +1132,7 @@ void StepSim(SimStepCtx *ctx) SpawnTestEntities3(root, pos); } } - if (flags & SIM_CONTROL_FLAG_SPAWN4_TEST) + if (flags & ControlFlag_SpawnTest4) { P_LogDebugF("Spawn test 4"); u32 count = 1; @@ -1144,22 +1144,22 @@ void StepSim(SimStepCtx *ctx) SpawnTestEntities4(root, pos); } } - if (flags & SIM_CONTROL_FLAG_WALLS_TEST) + if (flags & ControlFlag_TestWalls) { GenerateTestWalls(world); } - if (flags & SIM_CONTROL_FLAG_EXPLODE_TEST) + if (flags & ControlFlag_TestExplode) { P_LogDebugF("Explosion test"); SpawnTestExplosion(root, player->player_cursor_pos, 100, 2); } } - if (flags & SIM_CONTROL_FLAG_TILE_TEST) + if (flags & ControlFlag_TestTiles) { SpawnTestTile(world, player->player_cursor_pos); } - else if (old_control.flags & SIM_CONTROL_FLAG_TILE_TEST) + else if (old_control.flags & ControlFlag_TestTiles) { GenerateTestWalls(world); } @@ -1167,7 +1167,7 @@ void StepSim(SimStepCtx *ctx) } break; #if 0 - case SIM_CMD_KIND_CHAT: + case CmdKind_Chat: { struct sim_data_key msg_key = cmd_ent->cmd_chat_msg; String msg = sim_data_from_key(sim_data_store, msg_key); @@ -1398,7 +1398,7 @@ void StepSim(SimStepCtx *ctx) { ControlData *control = &ent->control; ControlFlag flags = control->flags; - if (flags & SIM_CONTROL_FLAG_FIRE) + if (flags & ControlFlag_Fire) { Entity *equipped = EntityFromId(world, ent->equipped); if (equipped->valid) @@ -1406,7 +1406,7 @@ void StepSim(SimStepCtx *ctx) ++equipped->num_primary_triggers; } } - if (flags & SIM_CONTROL_FLAG_FIRE_ALT) + if (flags & ControlFlag_AltFire) { Entity *equipped = EntityFromId(world, ent->equipped); if (equipped->valid) @@ -1414,7 +1414,7 @@ void StepSim(SimStepCtx *ctx) ++equipped->num_secondary_triggers; } } - if (flags & SIM_CONTROL_FLAG_TELEPORT_TEST) + if (flags & ControlFlag_TestTeleport) { TeleportTest(ent, control->dbg_cursor); } @@ -1484,7 +1484,7 @@ void StepSim(SimStepCtx *ctx) //bullet->bullet_launch_velocity = 0.75f; bullet->bullet_launch_velocity = 50.0f; bullet->bullet_knockback = 10; - bullet->layer = SIM_LAYER_BULLETS; + bullet->layer = Layer_Bullets; #if 1 /* Point collider */ @@ -1500,7 +1500,7 @@ void StepSim(SimStepCtx *ctx) { Entity *tracer = AcquireSyncSrc(root); tracer->tracer_fade_duration = 0.025f; - tracer->layer = SIM_LAYER_TRACERS; + tracer->layer = Layer_Tracers; EnableProp(tracer, Prop_Tracer); bullet->bullet_tracer = tracer->id; @@ -1535,7 +1535,7 @@ void StepSim(SimStepCtx *ctx) bullet->bullet_knockback = 50; bullet->bullet_explosion_strength = 100; bullet->bullet_explosion_radius = 4; - bullet->layer = SIM_LAYER_BULLETS; + bullet->layer = Layer_Bullets; /* Point collider */ bullet->local_collider.points[0] = VEC2(0, 0); @@ -1548,7 +1548,7 @@ void StepSim(SimStepCtx *ctx) { Entity *tracer = AcquireSyncSrc(root); tracer->tracer_fade_duration = 0.025f; - tracer->layer = SIM_LAYER_TRACERS; + tracer->layer = Layer_Tracers; EnableProp(tracer, Prop_Tracer); bullet->bullet_tracer = tracer->id; @@ -2069,11 +2069,11 @@ void StepSim(SimStepCtx *ctx) if (publish_client->valid && world->tick > publish_client->last_tick) { - Snapshot *prev_pub_world = sim_snapshot_from_tick(publish_client, publish_client->last_tick); - Snapshot *pub_world = sim_snapshot_acquire(publish_client, prev_pub_world, world->tick); + Snapshot *prev_pub_world = SnapshotFromTick(publish_client, publish_client->last_tick); + Snapshot *pub_world = AcquireSnapshot(publish_client, prev_pub_world, world->tick); /* Sync */ - sim_snapshot_sync_ents(pub_world, world, world_client->player_id, 0); + SyncSnapshotEntities(pub_world, world, world_client->player_id, 0); /* Mark all synced ents as both sync dsts & sync srcs */ for (u64 ent_index = 2; ent_index < pub_world->num_ents_reserved; ++ent_index)