mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-09 01:01:07 +00:00
Rework input accumulation to be a bit smoother.
This commit is contained in:
parent
7ea16154f9
commit
9f5d6f0355
5 changed files with 76 additions and 76 deletions
111
Quake/cl_input.c
111
Quake/cl_input.c
|
@ -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
|
||||
===============
|
||||
*/
|
||||
float CL_KeyState (kbutton_t *key)
|
||||
float CL_KeyState (kbutton_t *key, qboolean isfinal)
|
||||
{
|
||||
float val;
|
||||
qboolean impulsedown, impulseup, down;
|
||||
|
@ -304,7 +304,8 @@ float CL_KeyState (kbutton_t *key)
|
|||
val = 0.25; // pressed and released this frame
|
||||
}
|
||||
|
||||
key->state &= 1; // clear impulses
|
||||
if (isfinal)
|
||||
key->state &= 1; // clear impulses
|
||||
|
||||
return val;
|
||||
}
|
||||
|
@ -345,19 +346,19 @@ void CL_AdjustAngles (void)
|
|||
|
||||
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_left);
|
||||
cl.viewangles[YAW] -= speed*cl_yawspeed.value*CL_KeyState (&in_right, true);
|
||||
cl.viewangles[YAW] += speed*cl_yawspeed.value*CL_KeyState (&in_left, true);
|
||||
cl.viewangles[YAW] = anglemod(cl.viewangles[YAW]);
|
||||
}
|
||||
if (in_klook.state & 1)
|
||||
{
|
||||
V_StopPitchDrift ();
|
||||
cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * CL_KeyState (&in_forward);
|
||||
cl.viewangles[PITCH] += speed*cl_pitchspeed.value * CL_KeyState (&in_back);
|
||||
cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * CL_KeyState (&in_forward, true);
|
||||
cl.viewangles[PITCH] += speed*cl_pitchspeed.value * CL_KeyState (&in_back, true);
|
||||
}
|
||||
|
||||
up = CL_KeyState (&in_lookup);
|
||||
down = CL_KeyState(&in_lookdown);
|
||||
up = CL_KeyState (&in_lookup, true);
|
||||
down = CL_KeyState(&in_lookdown, true);
|
||||
|
||||
cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * up;
|
||||
cl.viewangles[PITCH] += speed*cl_pitchspeed.value * down;
|
||||
|
@ -385,7 +386,7 @@ CL_BaseMove
|
|||
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));
|
||||
|
||||
|
@ -396,20 +397,20 @@ void CL_BaseMove (usercmd_t *cmd)
|
|||
|
||||
if (in_strafe.state & 1)
|
||||
{
|
||||
cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_right);
|
||||
cmd->sidemove -= cl_sidespeed.value * CL_KeyState (&in_left);
|
||||
cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_right, isfinal);
|
||||
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_moveleft);
|
||||
cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_moveright, isfinal);
|
||||
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_down);
|
||||
cmd->upmove += cl_upspeed.value * CL_KeyState (&in_up, isfinal);
|
||||
cmd->upmove -= cl_upspeed.value * CL_KeyState (&in_down, isfinal);
|
||||
|
||||
if (! (in_klook.state & 1) )
|
||||
{
|
||||
cmd->forwardmove += cl_forwardspeed.value * CL_KeyState (&in_forward);
|
||||
cmd->forwardmove -= cl_backspeed.value * CL_KeyState (&in_back);
|
||||
cmd->forwardmove += cl_forwardspeed.value * CL_KeyState (&in_forward, isfinal);
|
||||
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
|
||||
//
|
||||
bits = 0;
|
||||
|
||||
if ( in_attack.state & 3 )
|
||||
bits |= 1;
|
||||
in_attack.state &= ~2;
|
||||
|
||||
if (in_jump.state & 3)
|
||||
bits |= 2;
|
||||
in_jump.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;
|
||||
for (i = 0; i < countof(buttons); i++)
|
||||
{
|
||||
if ( buttons[i]->state & 3 )
|
||||
{
|
||||
bits |= 1<<i;
|
||||
if (isfinal)
|
||||
buttons[i]->state &= ~2;
|
||||
}
|
||||
}
|
||||
|
||||
cmd->buttons = bits;
|
||||
cmd->impulse = in_impulse;
|
||||
|
||||
in_impulse = 0;
|
||||
if (isfinal)
|
||||
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;
|
||||
|
||||
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
|
||||
// from the last level
|
||||
//
|
||||
if (++cl.movemessages <= 2)
|
||||
buf.cursize = dump;
|
||||
if (cl.movemessages <= 2)
|
||||
{
|
||||
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
|
||||
S_Voip_Transmit(clcfte_voicechat, &buf);/*Spike: Add voice data*/
|
||||
}
|
||||
|
|
|
@ -1203,10 +1203,12 @@ void CL_AccumulateCmd (void)
|
|||
CL_AdjustAngles ();
|
||||
|
||||
//accumulate movement from other devices
|
||||
CL_BaseMove (&cl.pendingcmd, false);
|
||||
IN_Move (&cl.pendingcmd);
|
||||
CL_FinishMove(&cl.pendingcmd, false);
|
||||
}
|
||||
|
||||
cl.pendingcmd.seconds = cl.mtime[0] - cl.pendingcmd.servertime;
|
||||
else
|
||||
cl.lastcmdtime = cl.mtime[0];
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1222,17 +1224,9 @@ void CL_SendCmd (void)
|
|||
return;
|
||||
|
||||
// get basic movement from keyboard
|
||||
CL_BaseMove (&cmd);
|
||||
|
||||
// allow mice or other external controllers to add to the move
|
||||
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);
|
||||
CL_BaseMove (&cmd, true);
|
||||
IN_Move (&cmd);
|
||||
CL_FinishMove(&cmd, true);
|
||||
|
||||
if (cl.qcvm.extfuncs.CSQC_Input_Frame && !cl.qcvm.nogameaccess)
|
||||
{
|
||||
|
@ -1246,9 +1240,12 @@ void CL_SendCmd (void)
|
|||
if (cls.signon == SIGNONS)
|
||||
CL_SendMove (&cmd); // send the unreliable message
|
||||
else
|
||||
{
|
||||
CL_SendMove (NULL);
|
||||
memset(&cl.pendingcmd, 0, sizeof(cl.pendingcmd));
|
||||
cl.pendingcmd.servertime = cmd.servertime;
|
||||
cmd.seconds = 0; //not sent, don't predict it either.
|
||||
}
|
||||
cl.pendingcmd.seconds = 0;
|
||||
cl.lastcmdtime = cmd.servertime;
|
||||
|
||||
if (cls.demoplayback)
|
||||
{
|
||||
|
|
|
@ -171,6 +171,8 @@ typedef struct
|
|||
usercmd_t movecmds[64]; // ringbuffer of previous movement commands (journal for prediction)
|
||||
#define MOVECMDS_MASK (countof(cl.movecmds)-1)
|
||||
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
|
||||
int stats[MAX_CL_STATS]; // health, etc
|
||||
|
@ -411,8 +413,8 @@ void CL_SendCmd (void);
|
|||
void CL_SendMove (const usercmd_t *cmd);
|
||||
int CL_ReadFromServer (void);
|
||||
void CL_AdjustAngles (void);
|
||||
void CL_BaseMove (usercmd_t *cmd);
|
||||
void CL_FinishMove(usercmd_t *cmd);
|
||||
void CL_BaseMove (usercmd_t *cmd, qboolean isfinal);
|
||||
void CL_FinishMove(usercmd_t *cmd, qboolean isfinal);
|
||||
|
||||
void CL_Download_Data(void);
|
||||
qboolean CL_CheckDownloads(void);
|
||||
|
|
|
@ -870,7 +870,7 @@ void IN_MouseMove(usercmd_t *cmd)
|
|||
return;
|
||||
|
||||
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
|
||||
cl.viewangles[YAW] -= m_yaw.value * dmx * cl.csqc_sensitivity;
|
||||
|
||||
|
@ -892,9 +892,9 @@ void IN_MouseMove(usercmd_t *cmd)
|
|||
else
|
||||
{
|
||||
if ((in_strafe.state & 1) && noclip_anglehack)
|
||||
cmd->upmove -= m_forward.value * dmy;
|
||||
cl.accummoves[2] -= m_forward.value * dmy;
|
||||
else
|
||||
cmd->forwardmove -= m_forward.value * dmy;
|
||||
cl.accummoves[0] -= m_forward.value * dmy;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7306,8 +7306,6 @@ static void PF_cs_getinputstate(void)
|
|||
if (seq == cl.movemessages)
|
||||
{ //the partial/pending frame!
|
||||
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);
|
||||
}
|
||||
else if (cl.movecmds[seq&MOVECMDS_MASK].sequence == seq)
|
||||
|
|
Loading…
Reference in a new issue