+void CL_ClientMovement_Physics_Walk(cl_clientmovement_state_t *s)
+{
+ vec_t friction;
+ vec_t wishspeed;
+ vec_t addspeed;
+ vec_t accelspeed;
+ vec_t f;
+ vec3_t forward;
+ vec3_t right;
+ vec3_t up;
+ vec3_t wishvel;
+ vec3_t wishdir;
+ vec3_t yawangles;
+ trace_t trace;
+
+ // jump if on ground with jump button pressed but only if it has been
+ // released at least once since the last jump
+ if (s->cmd.jump)
+ {
+ if (s->onground && (s->cmd.canjump || !cl_movement_track_canjump.integer)) // FIXME remove this cvar again when canjump logic actually works, or maybe keep it for mods that allow "pogo-ing"
+ {
+ s->velocity[2] += cl.movevars_jumpvelocity;
+ s->onground = false;
+ s->cmd.canjump = false;
+ }
+ }
+ else
+ s->cmd.canjump = true;
+
+ // calculate movement vector
+ VectorSet(yawangles, 0, s->cmd.viewangles[1], 0);
+ AngleVectors(yawangles, forward, right, up);
+ VectorMAM(s->cmd.forwardmove, forward, s->cmd.sidemove, right, wishvel);
+
+ // split wishvel into wishspeed and wishdir
+ wishspeed = VectorLength(wishvel);
+ if (wishspeed)
+ VectorScale(wishvel, 1 / wishspeed, wishdir);
+ else
+ VectorSet( wishdir, 0.0, 0.0, 0.0 );
+ // check if onground
+ if (s->onground)
+ {
+ wishspeed = min(wishspeed, cl.movevars_maxspeed);
+ if (s->crouched)
+ wishspeed *= 0.5;
+
+ // apply edge friction
+ f = sqrt(s->velocity[0] * s->velocity[0] + s->velocity[1] * s->velocity[1]);
+ if (f > 0)
+ {
+ friction = cl.movevars_friction;
+ if (cl.movevars_edgefriction != 1)
+ {
+ vec3_t neworigin2;
+ vec3_t neworigin3;
+ // note: QW uses the full player box for the trace, and yet still
+ // uses s->origin[2] + s->mins[2], which is clearly an bug, but
+ // this mimics it for compatibility
+ VectorSet(neworigin2, s->origin[0] + s->velocity[0]*(16/f), s->origin[1] + s->velocity[1]*(16/f), s->origin[2] + s->mins[2]);
+ VectorSet(neworigin3, neworigin2[0], neworigin2[1], neworigin2[2] - 34);
+ if (cls.protocol == PROTOCOL_QUAKEWORLD)
+ trace = CL_TraceBox(neworigin2, s->mins, s->maxs, neworigin3, MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_PLAYERCLIP, true, true, NULL, false);
+ else
+ trace = CL_TraceLine(neworigin2, neworigin3, MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_PLAYERCLIP, true, true, NULL, false);
+ if (trace.fraction == 1 && !trace.startsolid)
+ friction *= cl.movevars_edgefriction;
+ }
+ // apply ground friction
+ f = 1 - s->cmd.frametime * friction * ((f < cl.movevars_stopspeed) ? (cl.movevars_stopspeed / f) : 1);
+ f = max(f, 0);
+ VectorScale(s->velocity, f, s->velocity);
+ }
+ addspeed = wishspeed - DotProduct(s->velocity, wishdir);
+ if (addspeed > 0)
+ {
+ accelspeed = min(cl.movevars_accelerate * s->cmd.frametime * wishspeed, addspeed);
+ VectorMA(s->velocity, accelspeed, wishdir, s->velocity);
+ }
+ s->velocity[2] -= cl.movevars_gravity * cl.movevars_entgravity * s->cmd.frametime;
+ if (cls.protocol == PROTOCOL_QUAKEWORLD)
+ s->velocity[2] = 0;
+ if (VectorLength2(s->velocity))
+ CL_ClientMovement_Move(s);
+ }
+ else
+ {
+ if (s->waterjumptime <= 0)
+ {
+ // apply air speed limit
+ vec_t accel, wishspeed0, wishspeed2, accelqw;
+ qboolean accelerating;
+
+ accelqw = cl.movevars_airaccel_qw;
+ wishspeed0 = wishspeed;
+ wishspeed = min(wishspeed, cl.movevars_maxairspeed);
+ if (s->crouched)
+ wishspeed *= 0.5;
+ accel = cl.movevars_airaccelerate;
+
+ accelerating = (DotProduct(s->velocity, wishdir) > 0);
+ wishspeed2 = wishspeed;
+
+ // CPM: air control
+ if(cl.movevars_airstopaccelerate != 0)
+ if(DotProduct(s->velocity, wishdir) < 0)
+ accel = cl.movevars_airstopaccelerate;
+ if(s->cmd.forwardmove == 0 && s->cmd.sidemove != 0)
+ {
+ if(cl.movevars_maxairstrafespeed)
+ {
+ if(wishspeed > cl.movevars_maxairstrafespeed)
+ wishspeed = cl.movevars_maxairstrafespeed;
+ if(cl.movevars_maxairstrafespeed < cl.movevars_maxairspeed)
+ accelqw = 1;
+ // otherwise, CPMA-style air acceleration misbehaves a lot
+ // if partially non-QW acceleration is used (as in, strafing
+ // would get faster than moving forward straight)
+ }
+ if(cl.movevars_airstrafeaccelerate)
+ {
+ accel = cl.movevars_airstrafeaccelerate;
+ if(cl.movevars_airstrafeaccelerate > cl.movevars_airaccelerate)
+ accelqw = 1;
+ // otherwise, CPMA-style air acceleration misbehaves a lot
+ // if partially non-QW acceleration is used (as in, strafing
+ // would get faster than moving forward straight)
+ }
+ }
+ // !CPM
+
+ if(cl.movevars_warsowbunny_turnaccel && accelerating && s->cmd.sidemove == 0 && s->cmd.forwardmove != 0)
+ CL_ClientMovement_Physics_PM_AirAccelerate(s, wishdir, wishspeed2);
+ else
+ CL_ClientMovement_Physics_PM_Accelerate(s, wishdir, wishspeed, wishspeed0, accel, accelqw, cl.movevars_airaccel_sideways_friction / cl.movevars_maxairspeed);
+
+ if(cl.movevars_aircontrol)
+ CL_ClientMovement_Physics_CPM_PM_Aircontrol(s, wishdir, wishspeed2);
+ }
+ s->velocity[2] -= cl.movevars_gravity * cl.movevars_entgravity * s->cmd.frametime;
+ CL_ClientMovement_Move(s);
+ }
+}
+
+void CL_ClientMovement_PlayerMove(cl_clientmovement_state_t *s)
+{
+ //Con_Printf(" %f", frametime);
+ if (!s->cmd.jump)
+ s->cmd.canjump = true;
+ s->waterjumptime -= s->cmd.frametime;
+ CL_ClientMovement_UpdateStatus(s);
+ if (s->waterlevel >= WATERLEVEL_SWIMMING)
+ CL_ClientMovement_Physics_Swim(s);
+ else
+ CL_ClientMovement_Physics_Walk(s);
+}
+
+extern cvar_t slowmo;
+void CL_UpdateMoveVars(void)
+{
+ if (cls.protocol == PROTOCOL_QUAKEWORLD)
+ {
+ cl.moveflags = 0;
+ }
+ else if (cl.stats[STAT_MOVEVARS_TICRATE])
+ {
+ cl.moveflags = cl.stats[STAT_MOVEFLAGS];
+ cl.movevars_ticrate = cl.statsf[STAT_MOVEVARS_TICRATE];
+ cl.movevars_timescale = cl.statsf[STAT_MOVEVARS_TIMESCALE];
+ cl.movevars_gravity = cl.statsf[STAT_MOVEVARS_GRAVITY];
+ cl.movevars_stopspeed = cl.statsf[STAT_MOVEVARS_STOPSPEED] ;
+ cl.movevars_maxspeed = cl.statsf[STAT_MOVEVARS_MAXSPEED];
+ cl.movevars_spectatormaxspeed = cl.statsf[STAT_MOVEVARS_SPECTATORMAXSPEED];
+ cl.movevars_accelerate = cl.statsf[STAT_MOVEVARS_ACCELERATE];
+ cl.movevars_airaccelerate = cl.statsf[STAT_MOVEVARS_AIRACCELERATE];
+ cl.movevars_wateraccelerate = cl.statsf[STAT_MOVEVARS_WATERACCELERATE];
+ cl.movevars_entgravity = cl.statsf[STAT_MOVEVARS_ENTGRAVITY];
+ cl.movevars_jumpvelocity = cl.statsf[STAT_MOVEVARS_JUMPVELOCITY];
+ cl.movevars_edgefriction = cl.statsf[STAT_MOVEVARS_EDGEFRICTION];
+ cl.movevars_maxairspeed = cl.statsf[STAT_MOVEVARS_MAXAIRSPEED];
+ cl.movevars_stepheight = cl.statsf[STAT_MOVEVARS_STEPHEIGHT];
+ cl.movevars_airaccel_qw = cl.statsf[STAT_MOVEVARS_AIRACCEL_QW];
+ cl.movevars_airaccel_sideways_friction = cl.statsf[STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION];
+ cl.movevars_friction = cl.statsf[STAT_MOVEVARS_FRICTION];
+ cl.movevars_wallfriction = cl.statsf[STAT_MOVEVARS_WALLFRICTION];
+ cl.movevars_waterfriction = cl.statsf[STAT_MOVEVARS_WATERFRICTION];
+ cl.movevars_airstopaccelerate = cl.statsf[STAT_MOVEVARS_AIRSTOPACCELERATE];
+ cl.movevars_airstrafeaccelerate = cl.statsf[STAT_MOVEVARS_AIRSTRAFEACCELERATE];
+ cl.movevars_maxairstrafespeed = cl.statsf[STAT_MOVEVARS_MAXAIRSTRAFESPEED];
+ cl.movevars_aircontrol = cl.statsf[STAT_MOVEVARS_AIRCONTROL];
+ cl.movevars_warsowbunny_airforwardaccel = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL];
+ cl.movevars_warsowbunny_accel = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_ACCEL];
+ cl.movevars_warsowbunny_topspeed = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED];
+ cl.movevars_warsowbunny_turnaccel = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL];
+ cl.movevars_warsowbunny_backtosideratio = cl.statsf[STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO];
+ }
+ else
+ {
+ cl.moveflags = 0;
+ cl.movevars_ticrate = slowmo.value / bound(1.0f, cl_netfps.value, 1000.0f);
+ cl.movevars_timescale = slowmo.value;
+ cl.movevars_gravity = sv_gravity.value;
+ cl.movevars_stopspeed = cl_movement_stopspeed.value;
+ cl.movevars_maxspeed = cl_movement_maxspeed.value;
+ cl.movevars_spectatormaxspeed = cl_movement_maxspeed.value;
+ cl.movevars_accelerate = cl_movement_accelerate.value;
+ cl.movevars_airaccelerate = cl_movement_airaccelerate.value < 0 ? cl_movement_accelerate.value : cl_movement_airaccelerate.value;
+ cl.movevars_wateraccelerate = cl_movement_wateraccelerate.value < 0 ? cl_movement_accelerate.value : cl_movement_wateraccelerate.value;
+ cl.movevars_friction = cl_movement_friction.value;
+ cl.movevars_wallfriction = cl_movement_wallfriction.value;
+ cl.movevars_waterfriction = cl_movement_waterfriction.value < 0 ? cl_movement_friction.value : cl_movement_waterfriction.value;
+ cl.movevars_entgravity = 1;
+ cl.movevars_jumpvelocity = cl_movement_jumpvelocity.value;
+ cl.movevars_edgefriction = cl_movement_edgefriction.value;
+ cl.movevars_maxairspeed = cl_movement_maxairspeed.value;
+ cl.movevars_stepheight = cl_movement_stepheight.value;
+ cl.movevars_airaccel_qw = cl_movement_airaccel_qw.value;
+ cl.movevars_airaccel_sideways_friction = cl_movement_airaccel_sideways_friction.value;
+ cl.movevars_airstopaccelerate = 0;
+ cl.movevars_airstrafeaccelerate = 0;
+ cl.movevars_maxairstrafespeed = 0;
+ cl.movevars_aircontrol = 0;
+ cl.movevars_warsowbunny_airforwardaccel = 0;
+ cl.movevars_warsowbunny_accel = 0;
+ cl.movevars_warsowbunny_topspeed = 0;
+ cl.movevars_warsowbunny_turnaccel = 0;
+ cl.movevars_warsowbunny_backtosideratio = 0;
+ }
+
+ if(!(cl.moveflags & MOVEFLAG_VALID))
+ {
+ if(gamemode == GAME_NEXUIZ)
+ cl.moveflags = MOVEFLAG_Q2AIRACCELERATE;
+ }
+}
+
+void CL_ClientMovement_Replay(void)
+{
+ int i;
+ double totalmovemsec;
+ cl_clientmovement_state_t s;
+
+ if (cl.movement_predicted && !cl.movement_replay)
+ return;
+
+ // set up starting state for the series of moves
+ memset(&s, 0, sizeof(s));
+ VectorCopy(cl.entities[cl.playerentity].state_current.origin, s.origin);
+ VectorCopy(cl.mvelocity[0], s.velocity);
+ s.crouched = true; // will be updated on first move
+ //Con_Printf("movement replay starting org %f %f %f vel %f %f %f\n", s.origin[0], s.origin[1], s.origin[2], s.velocity[0], s.velocity[1], s.velocity[2]);
+
+ totalmovemsec = 0;
+ for (i = 0;i < CL_MAX_USERCMDS;i++)
+ if (cl.movecmd[i].sequence > cls.servermovesequence)
+ totalmovemsec += cl.movecmd[i].msec;
+ cl.movement_predicted = totalmovemsec >= cl_movement_minping.value && cls.servermovesequence && (cl_movement.integer && !cls.demoplayback && cls.signon == SIGNONS && cl.stats[STAT_HEALTH] > 0 && !cl.intermission);
+ //Con_Printf("%i = %.0f >= %.0f && %i && (%i && %i && %i == %i && %i > 0 && %i\n", cl.movement_predicted, totalmovemsec, cl_movement_minping.value, cls.servermovesequence, cl_movement.integer, !cls.demoplayback, cls.signon, SIGNONS, cl.stats[STAT_HEALTH], !cl.intermission);
+ if (cl.movement_predicted)
+ {
+ //Con_Printf("%ims\n", cl.movecmd[0].msec);
+
+ // replay the input queue to predict current location
+ // note: this relies on the fact there's always one queue item at the end
+
+ // find how many are still valid
+ for (i = 0;i < CL_MAX_USERCMDS;i++)
+ if (cl.movecmd[i].sequence <= cls.servermovesequence)
+ break;
+ // now walk them in oldest to newest order
+ for (i--;i >= 0;i--)
+ {
+ s.cmd = cl.movecmd[i];
+ if (i < CL_MAX_USERCMDS - 1)
+ s.cmd.canjump = cl.movecmd[i+1].canjump;
+ // if a move is more than 50ms, do it as two moves (matching qwsv)
+ //Con_Printf("%i ", s.cmd.msec);
+ if(s.cmd.frametime > 0.0005)
+ {
+ if (s.cmd.frametime > 0.05)
+ {
+ s.cmd.frametime /= 2;
+ CL_ClientMovement_PlayerMove(&s);
+ }
+ CL_ClientMovement_PlayerMove(&s);
+ cl.movecmd[i].canjump = s.cmd.canjump;
+ }
+ }
+ //Con_Printf("\n");
+ CL_ClientMovement_UpdateStatus(&s);
+ }
+ else
+ {
+ // get the first movement queue entry to know whether to crouch and such
+ s.cmd = cl.movecmd[0];
+ }
+
+ if (cls.demoplayback) // for bob, speedometer
+ VectorCopy(cl.mvelocity[0], cl.movement_velocity);
+ else
+ {
+ cl.movement_replay = false;
+ // update the interpolation target position and velocity
+ VectorCopy(s.origin, cl.movement_origin);
+ VectorCopy(s.velocity, cl.movement_velocity);
+ }
+
+ // update the onground flag if appropriate
+ if (cl.movement_predicted)
+ {
+ // when predicted we simply set the flag according to the UpdateStatus
+ cl.onground = s.onground;
+ }
+ else
+ {
+ // when not predicted, cl.onground is cleared by cl_parse.c each time
+ // an update packet is received, but can be forced on here to hide
+ // server inconsistencies in the onground flag
+ // (which mostly occur when stepping up stairs at very high framerates
+ // where after the step up the move continues forward and not
+ // downward so the ground is not detected)
+ //
+ // such onground inconsistencies can cause jittery gun bobbing and
+ // stair smoothing, so we set onground if UpdateStatus says so
+ if (s.onground)
+ cl.onground = true;
+ }
+
+ // react to onground state changes (for gun bob)
+ if (cl.onground)
+ {
+ if (!cl.oldonground)
+ cl.hitgroundtime = cl.movecmd[0].time;
+ cl.lastongroundtime = cl.movecmd[0].time;
+ }
+ cl.oldonground = cl.onground;
+}
+
+void QW_MSG_WriteDeltaUsercmd(sizebuf_t *buf, usercmd_t *from, usercmd_t *to)
+{
+ int bits;
+
+ bits = 0;
+ if (to->viewangles[0] != from->viewangles[0])
+ bits |= QW_CM_ANGLE1;
+ if (to->viewangles[1] != from->viewangles[1])
+ bits |= QW_CM_ANGLE2;
+ if (to->viewangles[2] != from->viewangles[2])
+ bits |= QW_CM_ANGLE3;
+ if (to->forwardmove != from->forwardmove)
+ bits |= QW_CM_FORWARD;
+ if (to->sidemove != from->sidemove)
+ bits |= QW_CM_SIDE;
+ if (to->upmove != from->upmove)
+ bits |= QW_CM_UP;
+ if (to->buttons != from->buttons)
+ bits |= QW_CM_BUTTONS;
+ if (to->impulse != from->impulse)
+ bits |= QW_CM_IMPULSE;
+
+ MSG_WriteByte(buf, bits);
+ if (bits & QW_CM_ANGLE1)
+ MSG_WriteAngle16i(buf, to->viewangles[0]);
+ if (bits & QW_CM_ANGLE2)
+ MSG_WriteAngle16i(buf, to->viewangles[1]);
+ if (bits & QW_CM_ANGLE3)
+ MSG_WriteAngle16i(buf, to->viewangles[2]);
+ if (bits & QW_CM_FORWARD)
+ MSG_WriteShort(buf, (short) to->forwardmove);
+ if (bits & QW_CM_SIDE)
+ MSG_WriteShort(buf, (short) to->sidemove);
+ if (bits & QW_CM_UP)
+ MSG_WriteShort(buf, (short) to->upmove);
+ if (bits & QW_CM_BUTTONS)
+ MSG_WriteByte(buf, to->buttons);
+ if (bits & QW_CM_IMPULSE)
+ MSG_WriteByte(buf, to->impulse);
+ MSG_WriteByte(buf, to->msec);
+}