]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_input.c
removed unused applytime field from usercmd_t
[xonotic/darkplaces.git] / cl_input.c
index 9012907d6604de4fba0d966ea824ffddcfa6b0d6..b46bb1423f00124918dcfaa600c500d11a040f6a 100644 (file)
@@ -258,6 +258,7 @@ cvar_t cl_movement_friction = {0, "cl_movement_friction", "4"};
 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"};
 
@@ -401,8 +402,8 @@ void CL_Move (void)
                {
                        // mouse interacting with the scene, mostly stationary view
                        V_StopPitchDrift();
-                       cl.cmd.cursor_screen[0] += in_mouse_x * sensitivity.value / vid.realwidth;
-                       cl.cmd.cursor_screen[1] += in_mouse_y * sensitivity.value / vid.realheight;
+                       cl.cmd.cursor_screen[0] += in_mouse_x * sensitivity.value / vid.width;
+                       cl.cmd.cursor_screen[1] += in_mouse_y * sensitivity.value / vid.height;
                }
                else if (in_strafe.state & 1)
                {
@@ -448,22 +449,22 @@ void CL_UpdatePrydonCursor(void)
        /*
        if (cl.cmd.cursor_screen[0] < -1)
        {
-               cl.viewangles[YAW] -= m_yaw.value * (cl.cmd.cursor_screen[0] - -1) * vid.realwidth * sensitivity.value * cl.viewzoom;
+               cl.viewangles[YAW] -= m_yaw.value * (cl.cmd.cursor_screen[0] - -1) * vid.width * sensitivity.value * cl.viewzoom;
                cl.cmd.cursor_screen[0] = -1;
        }
        if (cl.cmd.cursor_screen[0] > 1)
        {
-               cl.viewangles[YAW] -= m_yaw.value * (cl.cmd.cursor_screen[0] - 1) * vid.realwidth * sensitivity.value * cl.viewzoom;
+               cl.viewangles[YAW] -= m_yaw.value * (cl.cmd.cursor_screen[0] - 1) * vid.width * sensitivity.value * cl.viewzoom;
                cl.cmd.cursor_screen[0] = 1;
        }
        if (cl.cmd.cursor_screen[1] < -1)
        {
-               cl.viewangles[PITCH] += m_pitch.value * (cl.cmd.cursor_screen[1] - -1) * vid.realheight * sensitivity.value * cl.viewzoom;
+               cl.viewangles[PITCH] += m_pitch.value * (cl.cmd.cursor_screen[1] - -1) * vid.height * sensitivity.value * cl.viewzoom;
                cl.cmd.cursor_screen[1] = -1;
        }
        if (cl.cmd.cursor_screen[1] > 1)
        {
-               cl.viewangles[PITCH] += m_pitch.value * (cl.cmd.cursor_screen[1] - 1) * vid.realheight * sensitivity.value * cl.viewzoom;
+               cl.viewangles[PITCH] += m_pitch.value * (cl.cmd.cursor_screen[1] - 1) * vid.height * sensitivity.value * cl.viewzoom;
                cl.cmd.cursor_screen[1] = 1;
        }
        */
@@ -495,10 +496,9 @@ void CL_ClientMovement(qboolean buttonjump, qboolean buttoncrouch)
        int bump;
        int contents;
        int crouch;
+       int onground;
        double edgefriction;
        double simulatedtime;
-       double currenttime;
-       double newtime;
        double frametime;
        double t;
        vec_t wishspeed;
@@ -525,16 +525,16 @@ void CL_ClientMovement(qboolean buttonjump, qboolean buttoncrouch)
        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;
@@ -546,31 +546,30 @@ void CL_ClientMovement(qboolean buttonjump, qboolean buttoncrouch)
        // 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...
@@ -638,7 +637,12 @@ void CL_ClientMovement(qboolean buttonjump, qboolean buttoncrouch)
                        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);
@@ -648,10 +652,7 @@ void CL_ClientMovement(qboolean buttonjump, qboolean buttoncrouch)
                                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]);
@@ -686,8 +687,7 @@ void CL_ClientMovement(qboolean buttonjump, qboolean buttoncrouch)
                                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)
                        {
@@ -727,6 +727,8 @@ void CL_ClientMovement(qboolean buttonjump, qboolean buttoncrouch)
                                        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);
@@ -735,7 +737,6 @@ void CL_ClientMovement(qboolean buttonjump, qboolean buttoncrouch)
                        }
                }
        }
-       //Con_Printf(" :%f\n", currenttime);
        // store replay location
        VectorCopy(cl.movement_origin, cl.movement_oldorigin);
        VectorCopy(currentorigin, cl.movement_origin);
@@ -987,6 +988,7 @@ void CL_InitInput (void)
        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);