set tick sim time right before publishing

This commit is contained in:
jacob 2025-01-29 11:39:05 -06:00
parent f0a25248c3
commit 79cc9e15e5
3 changed files with 9 additions and 9 deletions

View File

@ -504,7 +504,6 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
* ========================== */ * ========================== */
++G.tick.tick_id; ++G.tick.tick_id;
G.tick.simtime_ns = sys_time_ns();
G.tick.dt_ns = NS_FROM_SECONDS(max_f64(0.0, (1.0 / GAME_FPS) * G.tick.timescale)); G.tick.dt_ns = NS_FROM_SECONDS(max_f64(0.0, (1.0 / GAME_FPS) * G.tick.timescale));
G.tick.time_ns += G.tick.dt_ns; G.tick.time_ns += G.tick.dt_ns;
@ -1327,6 +1326,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
* ========================== */ * ========================== */
/* Publish tick */ /* Publish tick */
G.tick.publishtime_ns = sys_time_ns();
publish_game_tick(); publish_game_tick();
__profframe("Game"); __profframe("Game");

View File

@ -291,13 +291,13 @@ INTERNAL struct interp_ticks pull_ticks(i64 blend_time_ns)
from_tick = oldest_tick; from_tick = oldest_tick;
to_tick = newest_tick; to_tick = newest_tick;
for (struct blend_tick *bt = G.head_blend_tick; bt; bt = bt->next) { for (struct blend_tick *bt = G.head_blend_tick; bt; bt = bt->next) {
i64 bt_time_ns = bt->world.simtime_ns; i64 bt_time_ns = bt->world.publishtime_ns;
if (bt_time_ns < blend_time_ns && bt_time_ns > from_tick->simtime_ns) { if (bt_time_ns < blend_time_ns && bt_time_ns > from_tick->publishtime_ns) {
from_tick = &bt->world; from_tick = &bt->world;
} }
if (bt_time_ns > blend_time_ns && bt_time_ns < to_tick->simtime_ns) { if (bt_time_ns > blend_time_ns && bt_time_ns < to_tick->publishtime_ns) {
to_tick = &bt->world; to_tick = &bt->world;
} }
} }
@ -309,8 +309,8 @@ INTERNAL struct interp_ticks pull_ticks(i64 blend_time_ns)
u64 bts_to_free_count = 0; u64 bts_to_free_count = 0;
for (struct blend_tick *bt = G.head_blend_tick; bt; bt = bt->next) { for (struct blend_tick *bt = G.head_blend_tick; bt; bt = bt->next) {
i64 bt_time_ns = bt->world.simtime_ns; i64 bt_time_ns = bt->world.publishtime_ns;
if (bt_time_ns < from_tick->simtime_ns) { if (bt_time_ns < from_tick->publishtime_ns) {
*arena_push(scratch.arena, struct blend_tick *) = bt; *arena_push(scratch.arena, struct blend_tick *) = bt;
++bts_to_free_count; ++bts_to_free_count;
} }
@ -518,8 +518,8 @@ INTERNAL void user_update(void)
f32 tick_blend = 0; f32 tick_blend = 0;
{ {
i64 t0_time_ns = t0->simtime_ns; i64 t0_time_ns = t0->publishtime_ns;
i64 t1_time_ns = t1->simtime_ns; i64 t1_time_ns = t1->publishtime_ns;
if (t1_time_ns > t0_time_ns) { if (t1_time_ns > t0_time_ns) {
f64 t0_t1_elapsed = SECONDS_FROM_NS(t1_time_ns - t0_time_ns); f64 t0_t1_elapsed = SECONDS_FROM_NS(t1_time_ns - t0_time_ns);
f64 t0_blend_elapsed = SECONDS_FROM_NS(blend_time_ns - t0_time_ns); f64 t0_blend_elapsed = SECONDS_FROM_NS(blend_time_ns - t0_time_ns);

View File

@ -6,7 +6,7 @@
struct world { struct world {
u64 continuity_gen; /* Starts at 1 */ u64 continuity_gen; /* Starts at 1 */
u64 tick_id; /* Starts at 1 */ u64 tick_id; /* Starts at 1 */
i64 simtime_ns; /* When was this tick simulated in program time */ i64 publishtime_ns; /* When was this tick simulated in program time */
/* World time */ /* World time */
f64 timescale; f64 timescale;