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