]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_input.c
significant cleanup of CL_UpdateEntities, GL_UpdateNetworkEntity, CL_LinkNetworkEntit...
[xonotic/darkplaces.git] / cl_input.c
index 900f1cea63a62bc392f375c4f4adaa7be99cbc98..358cb33d9e700fe297015bc509706d5e9d6d1705 100644 (file)
@@ -517,10 +517,9 @@ void CL_Move (void)
 
 #include "cl_collision.h"
 
-extern void V_CalcRefdef(void);
 void CL_UpdatePrydonCursor(void)
 {
-       vec3_t temp, scale;
+       vec3_t temp;
 
        if (!cl_prydoncursor.integer)
                VectorClear(cl.cmd.cursor_screen);
@@ -551,18 +550,10 @@ void CL_UpdatePrydonCursor(void)
        cl.cmd.cursor_screen[1] = bound(-1, cl.cmd.cursor_screen[1], 1);
        cl.cmd.cursor_screen[2] = 1;
 
-       scale[0] = -r_view.frustum_x;
-       scale[1] = -r_view.frustum_y;
-       scale[2] = 1;
-
-       // trace distance
-       VectorScale(scale, 1000000, scale);
-
        // calculate current view matrix
-       V_CalcRefdef();
-       VectorClear(temp);
-       Matrix4x4_Transform(&r_view.matrix, temp, cl.cmd.cursor_start);
-       VectorSet(temp, cl.cmd.cursor_screen[2] * scale[2], cl.cmd.cursor_screen[0] * scale[0], cl.cmd.cursor_screen[1] * scale[1]);
+       Matrix4x4_OriginFromMatrix(&r_view.matrix, cl.cmd.cursor_start);
+       // calculate direction vector of cursor in viewspace by using frustum slopes
+       VectorSet(temp, cl.cmd.cursor_screen[2] * 1000000, cl.cmd.cursor_screen[0] * -r_view.frustum_x * 1000000, cl.cmd.cursor_screen[1] * -r_view.frustum_y * 1000000);
        Matrix4x4_Transform(&r_view.matrix, temp, cl.cmd.cursor_end);
        // trace from view origin to the cursor
        cl.cmd.cursor_fraction = CL_SelectTraceLine(cl.cmd.cursor_start, cl.cmd.cursor_end, cl.cmd.cursor_impact, cl.cmd.cursor_normal, &cl.cmd.cursor_entitynumber, (chase_active.integer || cl.intermission) ? &cl.entities[cl.playerentity].render : NULL, false);
@@ -1110,6 +1101,7 @@ void CL_ClientMovement_Replay(void)
        VectorCopy(cl.mvelocity[0], s.velocity);
        s.crouched = true; // will be updated on first move
        s.canjump = cl.movement_replay_canjump;
+       //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]);
 
        // set up movement variables
        if (cls.protocol == PROTOCOL_QUAKEWORLD)
@@ -1151,7 +1143,7 @@ void CL_ClientMovement_Replay(void)
                s.movevars_airaccel_sideways_friction = cl_movement_airaccel_sideways_friction.value;
        }
 
-       cl.movement_predicted = (cl_movement.integer && cls.signon == SIGNONS && cl.stats[STAT_HEALTH] > 0 && !cl.intermission) && ((cls.protocol != PROTOCOL_DARKPLACES6 && cls.protocol != PROTOCOL_DARKPLACES7) || cl.servermovesequence);
+       cl.movement_predicted = (cl_movement.integer && !cls.demoplayback && cls.signon == SIGNONS && cl.stats[STAT_HEALTH] > 0 && !cl.intermission) && ((cls.protocol != PROTOCOL_DARKPLACES6 && cls.protocol != PROTOCOL_DARKPLACES7) || cl.servermovesequence);
        if (cl.movement_predicted)
        {
                //Con_Printf("%f: ", cl.mtime[0]);
@@ -1176,9 +1168,9 @@ void CL_ClientMovement_Replay(void)
                // get the first movement queue entry to know whether to crouch and such
                s.q = cl.movement_queue[0];
        }
+
        // store replay location
        CL_ClientMovement_UpdateStatus(&s);
-       cl.onground = s.onground;
        cl.movement_time[1] = cl.movement_time[0];
        cl.movement_time[0] = cl.movement_queue[cl.movement_numqueue-1].time;
        VectorCopy(cl.movement_origin, cl.movement_oldorigin);
@@ -1186,6 +1178,27 @@ void CL_ClientMovement_Replay(void)
        VectorCopy(s.velocity, cl.movement_velocity);
        //VectorCopy(s.origin, cl.entities[cl.playerentity].state_current.origin);
        //VectorSet(cl.entities[cl.playerentity].state_current.angles, 0, cl.viewangles[1], 0);
+
+       // update the onground flag if appropriate
+       // when not predicted, cl.onground is only cleared by cl_parse.c, but can
+       // be set forcefully here to hide server inconsistencies in the onground
+       // flag (such as when stepping up stairs, the onground flag tends to turn
+       // off briefly due to precision errors, particularly at high framerates),
+       // such inconsistencies can mess up the gun bobbing and stair smoothing,
+       // so they must be avoided.
+       if (cl.movement_predicted)
+               cl.onground = s.onground;
+       else if (s.onground)
+               cl.onground = true;
+
+       // react to onground state changes (for gun bob)
+       if (cl.onground)
+       {
+               if (!cl.oldonground)
+                       cl.hitgroundtime = cl.time;
+               cl.lastongroundtime = cl.time;
+       }
+       cl.oldonground = cl.onground;
 }
 
 void QW_MSG_WriteDeltaUsercmd(sizebuf_t *buf, qw_usercmd_t *from, qw_usercmd_t *to)
@@ -1534,6 +1547,19 @@ void CL_SendMove(void)
                // PROTOCOL_DARKPLACES7 = 71 bytes per packet
        }
 
+       if (cls.protocol != PROTOCOL_QUAKEWORLD)
+       {
+               // acknowledge any recently received data blocks
+               for (i = 0;i < CL_MAX_DOWNLOADACKS && (cls.dp_downloadack[i].start || cls.dp_downloadack[i].size);i++)
+               {
+                       MSG_WriteByte(&buf, clc_ackdownloaddata);
+                       MSG_WriteLong(&buf, cls.dp_downloadack[i].start);
+                       MSG_WriteShort(&buf, cls.dp_downloadack[i].size);
+                       cls.dp_downloadack[i].start = 0;
+                       cls.dp_downloadack[i].size = 0;
+               }
+       }
+
        // send the reliable message (forwarded commands) if there is one
        NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol);