From 65211946e05375fe6b8854739b0a73c26d5a53c8 Mon Sep 17 00:00:00 2001 From: jacob Date: Mon, 10 Feb 2025 16:08:35 -0600 Subject: [PATCH] decrease rendering latency by incrementing smooth time by initial guess --- src/config.h | 2 +- src/user.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/config.h b/src/config.h index 4a1c2322..2c6132c0 100644 --- a/src/config.h +++ b/src/config.h @@ -54,7 +54,7 @@ * = * * 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 COLLIDER_DEBUG 0 diff --git a/src/user.c b/src/user.c index 48fcec3e..2dff926b 100644 --- a/src/user.c +++ b/src/user.c @@ -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); /* 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? */ - 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; 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 i64 render_time_ns = G.sim_time_smoothed_ns - (USER_INTERP_RATIO * newest_snapshot->real_dt_ns);