cvar_t cl_movement_edgefriction = {0, "cl_movement_edgefriction", "2"};
cvar_t cl_movement_stepheight = {0, "cl_movement_stepheight", "18"};
cvar_t cl_movement_accelerate = {0, "cl_movement_accelerate", "10"};
+cvar_t cl_movement_jumpvelocity = {0, "cl_movement_jumpvelocity", "270"};
cvar_t cl_gravity = {0, "cl_gravity", "800"};
cvar_t cl_slowmo = {0, "cl_slowmo", "1"};
int bump;
int contents;
int crouch;
+ int onground;
double edgefriction;
double simulatedtime;
- double currenttime;
- double newtime;
double frametime;
double t;
vec_t wishspeed;
n = cl.movement_numqueue;
cl.movement_numqueue = 0;
// calculate time to execute for
- currenttime = cl.mtime[0];
- simulatedtime = currenttime + cl_movement_latency.value / 1000.0;
+ simulatedtime = cl.mtime[0] + cl_movement_latency.value / 1000.0;
for (i = 0;i < n;i++)
if (cl.movement_queue[i].time >= cl.mtime[0] && cl.movement_queue[i].time <= simulatedtime)
cl.movement_queue[cl.movement_numqueue++] = cl.movement_queue[i];
// add to input queue if there is room
- if (cl.movement_numqueue < sizeof(cl.movement_queue)/sizeof(cl.movement_queue[0]))
+ if (cl.movement_numqueue < sizeof(cl.movement_queue)/sizeof(cl.movement_queue[0]) && cl.mtime[0] > cl.mtime[1])
{
// add to input queue
cl.movement_queue[cl.movement_numqueue].time = simulatedtime;
+ cl.movement_queue[cl.movement_numqueue].frametime = cl.mtime[0] - cl.mtime[1];
VectorCopy(cl.viewangles, cl.movement_queue[cl.movement_numqueue].viewangles);
cl.movement_queue[cl.movement_numqueue].move[0] = cl.cmd.forwardmove;
cl.movement_queue[cl.movement_numqueue].move[1] = cl.cmd.sidemove;
// fetch current starting values
VectorCopy(cl_entities[cl.playerentity].state_current.origin, currentorigin);
VectorCopy(cl.mvelocity[0], currentvelocity);
+ // check if onground
+ VectorSet(currentorigin2, currentorigin[0], currentorigin[1], currentorigin[2] + 1);
+ VectorSet(neworigin2, currentorigin[0], currentorigin[1], currentorigin[2] - 1);
+ trace = CL_TraceBox(currentorigin2, cl_playercrouchmins, cl_playercrouchmaxs, neworigin2, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_PLAYERCLIP, true);
+ onground = trace.fraction < 1 && trace.plane.normal[2] > 0.7;
// FIXME: try minor nudges in various directions if startsolid to find a
// safe place to start the walk (due to network compression in some
// protocols this starts in solid)
//currentorigin[2] += (1.0 / 32.0); // slight nudge to get out of the floor
crouch = false; // this will be updated on first move
- //Con_Printf("%f: ", currenttime);
+ //Con_Printf("%f: ", cl.mtime[0]);
// replay input queue, and remove any stale queue items
// note: this relies on the fact there's always one queue item at the end
// abort if client movement is disabled
cl.movement = cl_movement.integer && cl.stats[STAT_HEALTH] > 0 && !cls.demoplayback;
if (!cl.movement)
cl.movement_numqueue = 0;
- for (i = 0;i <= cl.movement_numqueue;i++)
+ for (i = 0;i < cl.movement_numqueue;i++)
{
- newtime = (i >= cl.movement_numqueue) ? simulatedtime : cl.movement_queue[i].time;
- frametime = newtime - currenttime;
- if (frametime <= 0)
- continue;
+ client_movementqueue_t *q = cl.movement_queue + bound(0, i, cl.movement_numqueue - 1);
+ frametime = q->frametime;
//Con_Printf(" %f", frametime);
- currenttime = newtime;
- if (i >= 1 && i <= cl.movement_numqueue)
- if (i > 0 || (cl_movement.integer & 8))
- if (i < cl.movement_numqueue - 1 || (cl_movement.integer & 16))
+ //if (frametime > 0)
{
- client_movementqueue_t *q = cl.movement_queue + i - 1;
if (q->crouch)
{
// wants to crouch, this always works...
else
{
// walk
- VectorSet(yawangles, 0, cl.viewangles[1], 0);
+ if (onground && q->jump)
+ {
+ currentvelocity[2] += cl_movement_jumpvelocity.value;
+ onground = false;
+ }
+ VectorSet(yawangles, 0, q->viewangles[1], 0);
AngleVectors(yawangles, forward, right, up);
VectorMAM(q->move[0], forward, q->move[1], right, wishvel);
wishspeed = VectorLength(wishvel);
if (crouch)
wishspeed *= 0.5;
// check if onground
- VectorSet(currentorigin2, currentorigin[0], currentorigin[1], currentorigin[2] + 1);
- VectorSet(neworigin2, currentorigin[0], currentorigin[1], currentorigin[2] - 1);
- trace = CL_TraceBox(currentorigin2, playermins, playermaxs, neworigin2, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_PLAYERCLIP, true);
- if (trace.fraction < 1 && trace.plane.normal[2] > 0.7)
+ if (onground)
{
// apply ground friction
f = sqrt(currentvelocity[0] * currentvelocity[0] + currentvelocity[1] * currentvelocity[1]);
currentvelocity[2] -= cl_gravity.value * frametime;
}
}
- if (i > 0 || (cl_movement.integer & 2))
- if (i < cl.movement_numqueue - 1 || (cl_movement.integer & 4))
+ //if (i < cl.movement_numqueue - 1 || (cl_movement.integer & 4))
{
if (crouch)
{
VectorCopy(trace.endpos, currentorigin);
break;
}
+ if (trace.plane.normal[2] > 0.7)
+ onground = true;
t *= 1 - trace.fraction;
if (trace.fraction >= 0.001)
VectorCopy(trace.endpos, currentorigin);
}
}
}
- //Con_Printf(" :%f\n", currenttime);
// store replay location
VectorCopy(cl.movement_origin, cl.movement_oldorigin);
VectorCopy(currentorigin, cl.movement_origin);
Cvar_RegisterVariable(&cl_movement_edgefriction);
Cvar_RegisterVariable(&cl_movement_stepheight);
Cvar_RegisterVariable(&cl_movement_accelerate);
+ Cvar_RegisterVariable(&cl_movement_jumpvelocity);
Cvar_RegisterVariable(&cl_gravity);
Cvar_RegisterVariable(&cl_slowmo);