diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index f044e890..9dbd9819 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -587,21 +587,36 @@ CL_CreateCmd */ static void CL_CreateCmd( void ) { - usercmd_t nullcmd, *cmd; - runcmd_t *pcmd; - vec3_t angles; - qboolean active; - int input_override; - int i, ms; + usercmd_t nullcmd, *cmd; + runcmd_t *pcmd; + qboolean active; + double accurate_ms; + vec3_t angles; + int input_override; + int i, ms; if( cls.state < ca_connected || cls.state == ca_cinematic ) return; // store viewangles in case it's will be freeze VectorCopy( cl.viewangles, angles ); - ms = bound( 1, host.frametime * 1000, 255 ); input_override = 0; + // fix rounding error and framerate depending player move + accurate_ms = host.frametime * 1000; + ms = (int)accurate_ms; + cl.frametime_remainder += accurate_ms - ms; // accumulate rounding error each frame + + // add a ms if error accumulates enough + if( cl.frametime_remainder > 1.0 ) + { + cl.frametime_remainder = 0.0; + ms++; + } + + // ms can't be negative, rely on error accumulation only if FPS > 1000 + ms = Q_min( ms, 255 ); + CL_SetSolidEntities(); CL_PushPMStates(); CL_SetSolidPlayers( cl.playernum ); diff --git a/engine/client/client.h b/engine/client/client.h index b1397091..fc055aa6 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -276,6 +276,8 @@ typedef struct model_t *worldmodel; // pointer to world int lostpackets; // count lost packets and show dialog in menu + + double frametime_remainder; } client_t; /*