From 413a0fb2e5a52e6763a8ee1a27400e0f90d4e53e Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 2 Jun 2024 13:08:53 +0300 Subject: [PATCH] engine: client: improve accumulating rounding error, thanks @SNMetamorph for suggestion --- engine/client/cl_main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 9dbd9819..9a69be6a 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -608,10 +608,12 @@ static void CL_CreateCmd( void ) cl.frametime_remainder += accurate_ms - ms; // accumulate rounding error each frame // add a ms if error accumulates enough - if( cl.frametime_remainder > 1.0 ) + if( cl.frametime_remainder >= 1.0 ) { - cl.frametime_remainder = 0.0; - ms++; + int ms2 = (int)cl.frametime_remainder; + + ms += ms2; + cl.frametime_remainder -= ms2; } // ms can't be negative, rely on error accumulation only if FPS > 1000