Rework input accumulation to be a bit smoother.

This commit is contained in:
Shpoike 2023-07-25 13:13:11 +01:00
parent 7ea16154f9
commit 9f5d6f0355
5 changed files with 76 additions and 76 deletions

View file

@ -265,7 +265,7 @@ Returns 0.25 if a key was pressed and released during the frame,
1.0 if held for the entire time 1.0 if held for the entire time
=============== ===============
*/ */
float CL_KeyState (kbutton_t *key) float CL_KeyState (kbutton_t *key, qboolean isfinal)
{ {
float val; float val;
qboolean impulsedown, impulseup, down; qboolean impulsedown, impulseup, down;
@ -304,6 +304,7 @@ float CL_KeyState (kbutton_t *key)
val = 0.25; // pressed and released this frame val = 0.25; // pressed and released this frame
} }
if (isfinal)
key->state &= 1; // clear impulses key->state &= 1; // clear impulses
return val; return val;
@ -345,19 +346,19 @@ void CL_AdjustAngles (void)
if (!(in_strafe.state & 1)) if (!(in_strafe.state & 1))
{ {
cl.viewangles[YAW] -= speed*cl_yawspeed.value*CL_KeyState (&in_right); cl.viewangles[YAW] -= speed*cl_yawspeed.value*CL_KeyState (&in_right, true);
cl.viewangles[YAW] += speed*cl_yawspeed.value*CL_KeyState (&in_left); cl.viewangles[YAW] += speed*cl_yawspeed.value*CL_KeyState (&in_left, true);
cl.viewangles[YAW] = anglemod(cl.viewangles[YAW]); cl.viewangles[YAW] = anglemod(cl.viewangles[YAW]);
} }
if (in_klook.state & 1) if (in_klook.state & 1)
{ {
V_StopPitchDrift (); V_StopPitchDrift ();
cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * CL_KeyState (&in_forward); cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * CL_KeyState (&in_forward, true);
cl.viewangles[PITCH] += speed*cl_pitchspeed.value * CL_KeyState (&in_back); cl.viewangles[PITCH] += speed*cl_pitchspeed.value * CL_KeyState (&in_back, true);
} }
up = CL_KeyState (&in_lookup); up = CL_KeyState (&in_lookup, true);
down = CL_KeyState(&in_lookdown); down = CL_KeyState(&in_lookdown, true);
cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * up; cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * up;
cl.viewangles[PITCH] += speed*cl_pitchspeed.value * down; cl.viewangles[PITCH] += speed*cl_pitchspeed.value * down;
@ -385,7 +386,7 @@ CL_BaseMove
Send the intended movement message to the server Send the intended movement message to the server
================ ================
*/ */
void CL_BaseMove (usercmd_t *cmd) void CL_BaseMove (usercmd_t *cmd, qboolean isfinal)
{ {
Q_memset (cmd, 0, sizeof(*cmd)); Q_memset (cmd, 0, sizeof(*cmd));
@ -396,20 +397,20 @@ void CL_BaseMove (usercmd_t *cmd)
if (in_strafe.state & 1) if (in_strafe.state & 1)
{ {
cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_right); cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_right, isfinal);
cmd->sidemove -= cl_sidespeed.value * CL_KeyState (&in_left); cmd->sidemove -= cl_sidespeed.value * CL_KeyState (&in_left, isfinal);
} }
cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_moveright); cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_moveright, isfinal);
cmd->sidemove -= cl_sidespeed.value * CL_KeyState (&in_moveleft); cmd->sidemove -= cl_sidespeed.value * CL_KeyState (&in_moveleft, isfinal);
cmd->upmove += cl_upspeed.value * CL_KeyState (&in_up); cmd->upmove += cl_upspeed.value * CL_KeyState (&in_up, isfinal);
cmd->upmove -= cl_upspeed.value * CL_KeyState (&in_down); cmd->upmove -= cl_upspeed.value * CL_KeyState (&in_down, isfinal);
if (! (in_klook.state & 1) ) if (! (in_klook.state & 1) )
{ {
cmd->forwardmove += cl_forwardspeed.value * CL_KeyState (&in_forward); cmd->forwardmove += cl_forwardspeed.value * CL_KeyState (&in_forward, isfinal);
cmd->forwardmove -= cl_backspeed.value * CL_KeyState (&in_back); cmd->forwardmove -= cl_backspeed.value * CL_KeyState (&in_back, isfinal);
} }
// //
@ -423,50 +424,49 @@ void CL_BaseMove (usercmd_t *cmd)
} }
} }
void CL_FinishMove(usercmd_t *cmd) void CL_FinishMove(usercmd_t *cmd, qboolean isfinal)
{ {
unsigned int bits; static kbutton_t *buttons[] = {
&in_attack,
&in_jump,
&in_button3,
&in_button4,
&in_button3,
&in_button6,
&in_button7,
&in_button8,
};
unsigned int bits, i;
// //
// send button bits // send button bits
// //
bits = 0; bits = 0;
if ( in_attack.state & 3 ) for (i = 0; i < countof(buttons); i++)
bits |= 1; {
in_attack.state &= ~2; if ( buttons[i]->state & 3 )
{
if (in_jump.state & 3) bits |= 1<<i;
bits |= 2; if (isfinal)
in_jump.state &= ~2; buttons[i]->state &= ~2;
}
if (in_button3.state & 3) }
bits |= 4;
in_button3.state &= ~2;
if (in_button4.state & 3)
bits |= 8;
in_button4.state &= ~2;
if (in_button5.state & 3)
bits |= 16;
in_button5.state &= ~2;
if (in_button6.state & 3)
bits |= 32;
in_button6.state &= ~2;
if (in_button7.state & 3)
bits |= 64;
in_button7.state &= ~2;
if (in_button8.state & 3)
bits |= 128;
in_button8.state &= ~2;
cmd->buttons = bits; cmd->buttons = bits;
cmd->impulse = in_impulse; cmd->impulse = in_impulse;
if (isfinal)
in_impulse = 0; in_impulse = 0;
cmd->forwardmove+= cl.accummoves[0];
cmd->sidemove += cl.accummoves[1];
cmd->upmove += cl.accummoves[2];
if (isfinal)
cl.accummoves[0]=cl.accummoves[1]=cl.accummoves[2]=0;
cmd->sequence = cl.movemessages;
cmd->servertime = cl.time;
cmd->seconds = cmd->servertime - cl.lastcmdtime;
} }
/* /*
@ -572,14 +572,17 @@ void CL_SendMove (const usercmd_t *cmd)
} }
in_impulse = 0; in_impulse = 0;
cl.movecmds[cl.movemessages&MOVECMDS_MASK] = *cmd; cl.movecmds[(cl.movemessages++)&MOVECMDS_MASK] = *cmd;
// //
// allways dump the first two message, because it may contain leftover inputs // allways dump the first two message, because it may contain leftover inputs
// from the last level // from the last level
// //
if (++cl.movemessages <= 2) if (cl.movemessages <= 2)
buf.cursize = dump; {
buf.cursize = dump; //don't actually send it...
cl.movecmds[(cl.movemessages-1)&MOVECMDS_MASK].seconds = 0; //and don't predict forwards. should fix prediction going weird at the start of the map.
}
else else
S_Voip_Transmit(clcfte_voicechat, &buf);/*Spike: Add voice data*/ S_Voip_Transmit(clcfte_voicechat, &buf);/*Spike: Add voice data*/
} }

View file

@ -1203,10 +1203,12 @@ void CL_AccumulateCmd (void)
CL_AdjustAngles (); CL_AdjustAngles ();
//accumulate movement from other devices //accumulate movement from other devices
CL_BaseMove (&cl.pendingcmd, false);
IN_Move (&cl.pendingcmd); IN_Move (&cl.pendingcmd);
CL_FinishMove(&cl.pendingcmd, false);
} }
else
cl.pendingcmd.seconds = cl.mtime[0] - cl.pendingcmd.servertime; cl.lastcmdtime = cl.mtime[0];
} }
/* /*
@ -1222,17 +1224,9 @@ void CL_SendCmd (void)
return; return;
// get basic movement from keyboard // get basic movement from keyboard
CL_BaseMove (&cmd); CL_BaseMove (&cmd, true);
IN_Move (&cmd);
// allow mice or other external controllers to add to the move CL_FinishMove(&cmd, true);
cmd.forwardmove += cl.pendingcmd.forwardmove;
cmd.sidemove += cl.pendingcmd.sidemove;
cmd.upmove += cl.pendingcmd.upmove;
cmd.sequence = cl.movemessages;
cmd.servertime = cl.time;
cmd.seconds = cmd.servertime - cl.pendingcmd.servertime;
CL_FinishMove(&cmd);
if (cl.qcvm.extfuncs.CSQC_Input_Frame && !cl.qcvm.nogameaccess) if (cl.qcvm.extfuncs.CSQC_Input_Frame && !cl.qcvm.nogameaccess)
{ {
@ -1246,9 +1240,12 @@ void CL_SendCmd (void)
if (cls.signon == SIGNONS) if (cls.signon == SIGNONS)
CL_SendMove (&cmd); // send the unreliable message CL_SendMove (&cmd); // send the unreliable message
else else
{
CL_SendMove (NULL); CL_SendMove (NULL);
memset(&cl.pendingcmd, 0, sizeof(cl.pendingcmd)); cmd.seconds = 0; //not sent, don't predict it either.
cl.pendingcmd.servertime = cmd.servertime; }
cl.pendingcmd.seconds = 0;
cl.lastcmdtime = cmd.servertime;
if (cls.demoplayback) if (cls.demoplayback)
{ {

View file

@ -171,6 +171,8 @@ typedef struct
usercmd_t movecmds[64]; // ringbuffer of previous movement commands (journal for prediction) usercmd_t movecmds[64]; // ringbuffer of previous movement commands (journal for prediction)
#define MOVECMDS_MASK (countof(cl.movecmds)-1) #define MOVECMDS_MASK (countof(cl.movecmds)-1)
usercmd_t pendingcmd; // accumulated state from mice+joysticks. usercmd_t pendingcmd; // accumulated state from mice+joysticks.
vec3_t accummoves; //mostly to accumulate mouse movement for mouse-strafe
float lastcmdtime; //should use movecmds... mneh, might be uninitialised.
// information for local display // information for local display
int stats[MAX_CL_STATS]; // health, etc int stats[MAX_CL_STATS]; // health, etc
@ -411,8 +413,8 @@ void CL_SendCmd (void);
void CL_SendMove (const usercmd_t *cmd); void CL_SendMove (const usercmd_t *cmd);
int CL_ReadFromServer (void); int CL_ReadFromServer (void);
void CL_AdjustAngles (void); void CL_AdjustAngles (void);
void CL_BaseMove (usercmd_t *cmd); void CL_BaseMove (usercmd_t *cmd, qboolean isfinal);
void CL_FinishMove(usercmd_t *cmd); void CL_FinishMove(usercmd_t *cmd, qboolean isfinal);
void CL_Download_Data(void); void CL_Download_Data(void);
qboolean CL_CheckDownloads(void); qboolean CL_CheckDownloads(void);

View file

@ -870,7 +870,7 @@ void IN_MouseMove(usercmd_t *cmd)
return; return;
if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) )) if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
cmd->sidemove += m_side.value * dmx; cl.accummoves[1] += m_side.value * dmx;
else else
cl.viewangles[YAW] -= m_yaw.value * dmx * cl.csqc_sensitivity; cl.viewangles[YAW] -= m_yaw.value * dmx * cl.csqc_sensitivity;
@ -892,9 +892,9 @@ void IN_MouseMove(usercmd_t *cmd)
else else
{ {
if ((in_strafe.state & 1) && noclip_anglehack) if ((in_strafe.state & 1) && noclip_anglehack)
cmd->upmove -= m_forward.value * dmy; cl.accummoves[2] -= m_forward.value * dmy;
else else
cmd->forwardmove -= m_forward.value * dmy; cl.accummoves[0] -= m_forward.value * dmy;
} }
} }

View file

@ -7306,8 +7306,6 @@ static void PF_cs_getinputstate(void)
if (seq == cl.movemessages) if (seq == cl.movemessages)
{ //the partial/pending frame! { //the partial/pending frame!
G_FLOAT(OFS_RETURN) = 1; G_FLOAT(OFS_RETURN) = 1;
cl.pendingcmd.seconds = cl.time - cl.pendingcmd.servertime; //make sure this is kept current. its important for smoothness.
cl.pendingcmd.sequence = seq;
PR_GetSetInputs(&cl.pendingcmd, true); PR_GetSetInputs(&cl.pendingcmd, true);
} }
else if (cl.movecmds[seq&MOVECMDS_MASK].sequence == seq) else if (cl.movecmds[seq&MOVECMDS_MASK].sequence == seq)