From 07df2d0a6cde35514b97684cef7cd96d3f021d04 Mon Sep 17 00:00:00 2001 From: realpoke Date: Fri, 4 Sep 2026 16:45:14 +0200 Subject: [PATCH] fix: Interpolate clock stretch factor in log space Clock stretch factors are speed multipliers, so they compose geometrically: the neutral value is 1.0, and slowing down by some amount is the reciprocal of speeding up by that same amount. Interpolate in log space so that a clock difference of zero yields exactly 1.0, and clock_stretch_max and its reciprocal are reached at +/- one tick of difference. The old linear interpolation produced a neutral factor of ~1.5 for clock_stretch_max of 2.0, desynchronizing the simulation even when clocks matched. --- addons/netfox/network-time.gd | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/addons/netfox/network-time.gd b/addons/netfox/network-time.gd index 6f5a7df6..faa8b282 100644 --- a/addons/netfox/network-time.gd +++ b/addons/netfox/network-time.gd @@ -534,13 +534,10 @@ func _loop() -> void: # Ignore diffs under 1ms clock_diff = sign(clock_diff) * max(abs(clock_diff) - 0.001, 0.) - var clock_stretch_min := 1. / clock_stretch_max - # var clock_stretch_f = (1. + clock_diff / (1. * ticktime)) / 2. - var clock_stretch_f := inverse_lerp(-ticktime, +ticktime, clock_diff) - clock_stretch_f = clampf(clock_stretch_f, 0., 1.) + var clock_stretch_t: float = clampf(clock_diff / ticktime, -1., 1.) var previous_stretch_factor := _clock_stretch_factor - _clock_stretch_factor = lerpf(clock_stretch_min, clock_stretch_max, clock_stretch_f) + _clock_stretch_factor = pow(clock_stretch_max, clock_stretch_t) # Detect editor pause var clock_step := _clock.get_time() - _last_process_time