decrease rendering latency by incrementing smooth time by initial guess

This commit is contained in:
jacob 2025-02-10 16:08:35 -06:00
parent f04a81fbb0
commit 65211946e0
2 changed files with 6 additions and 5 deletions

View File

@ -54,7 +54,7 @@
* <Delay ms> = <USER_INTERP_RATIO> * <Tick interval> * <Delay ms> = <USER_INTERP_RATIO> * <Tick interval>
* E.g: At 1.5, the user thread will render 75ms back in time (if sim thread runs at 50FPS) * E.g: At 1.5, the user thread will render 75ms back in time (if sim thread runs at 50FPS)
*/ */
#define USER_INTERP_RATIO 1.1 #define USER_INTERP_RATIO 1.5
#define USER_INTERP_ENABLED 1 #define USER_INTERP_ENABLED 1
#define COLLIDER_DEBUG 0 #define COLLIDER_DEBUG 0

View File

@ -470,13 +470,14 @@ INTERNAL void user_update(void)
struct sim_snapshot *newest_snapshot = sim_snapshot_from_tick(G.sim_snapshot_store, G.sim_snapshot_store->last_tick); struct sim_snapshot *newest_snapshot = sim_snapshot_from_tick(G.sim_snapshot_store, G.sim_snapshot_store->last_tick);
/* Calculate sim time based on last received snapshot time, /* Calculate sim time based on last received snapshot time,
* then smooth it out to prevent sudden jumps in rendering due to snapshot receive time variance. */ * then smooth it out to prevent sudden jumps in rendering due
* to variance in snapshot receive time. */
/* TODO: Use a value that indicates desired dt to next frame, rather than real dt from last frame? */ /* TODO: Use a value that indicates desired dt to next frame, rather than real dt from last frame? */
f64 sim_time_smooth_rate_ns = SECONDS_FROM_NS(G.real_dt_ns) / 0.05; f64 sim_time_smoothed_correction_rate = SECONDS_FROM_NS(G.real_dt_ns) / 0.05;
i64 time_since_newest_tick_ns = G.real_time_ns - newest_snapshot->received_at_ns; i64 time_since_newest_tick_ns = G.real_time_ns - newest_snapshot->received_at_ns;
G.sim_time_ns = newest_snapshot->real_time_ns + time_since_newest_tick_ns; G.sim_time_ns = newest_snapshot->real_time_ns + time_since_newest_tick_ns;
G.sim_time_smoothed_ns += (G.sim_time_ns - G.sim_time_smoothed_ns) * sim_time_smooth_rate_ns; G.sim_time_smoothed_ns += G.real_dt_ns;
G.sim_time_smoothed_ns += (G.sim_time_ns - G.sim_time_smoothed_ns) * sim_time_smoothed_correction_rate;
#if USER_INTERP_ENABLED #if USER_INTERP_ENABLED
i64 render_time_ns = G.sim_time_smoothed_ns - (USER_INTERP_RATIO * newest_snapshot->real_dt_ns); i64 render_time_ns = G.sim_time_smoothed_ns - (USER_INTERP_RATIO * newest_snapshot->real_dt_ns);