engine: client: fix framerate depending player move

This commit is contained in:
Alibek Omarov 2024-06-02 04:13:36 +03:00
parent a9c0a4be23
commit 0796c14e79
2 changed files with 24 additions and 7 deletions

View file

@ -587,21 +587,36 @@ CL_CreateCmd
*/ */
static void CL_CreateCmd( void ) static void CL_CreateCmd( void )
{ {
usercmd_t nullcmd, *cmd; usercmd_t nullcmd, *cmd;
runcmd_t *pcmd; runcmd_t *pcmd;
vec3_t angles; qboolean active;
qboolean active; double accurate_ms;
int input_override; vec3_t angles;
int i, ms; int input_override;
int i, ms;
if( cls.state < ca_connected || cls.state == ca_cinematic ) if( cls.state < ca_connected || cls.state == ca_cinematic )
return; return;
// store viewangles in case it's will be freeze // store viewangles in case it's will be freeze
VectorCopy( cl.viewangles, angles ); VectorCopy( cl.viewangles, angles );
ms = bound( 1, host.frametime * 1000, 255 );
input_override = 0; 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_SetSolidEntities();
CL_PushPMStates(); CL_PushPMStates();
CL_SetSolidPlayers( cl.playernum ); CL_SetSolidPlayers( cl.playernum );

View file

@ -276,6 +276,8 @@ typedef struct
model_t *worldmodel; // pointer to world model_t *worldmodel; // pointer to world
int lostpackets; // count lost packets and show dialog in menu int lostpackets; // count lost packets and show dialog in menu
double frametime_remainder;
} client_t; } client_t;
/* /*