]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_input.c
Modified path for Transfusion gfx files
[xonotic/darkplaces.git] / cl_input.c
index de203112b7f004b649f7511776816a889588c348..c3fd63acbd1e3cafeec7778be352ce8f1599bc93 100644 (file)
@@ -59,7 +59,6 @@ kbutton_t     in_button9, in_button10, in_button11, in_button12, in_button13, in_but
 
 int                    in_impulse;
 
-extern cvar_t sys_ticrate;
 
 
 void KeyDown (kbutton_t *b)
@@ -287,6 +286,8 @@ cvar_t in_pitch_max = {0, "in_pitch_max", "90", "how far upward you can aim (qua
 
 cvar_t m_filter = {CVAR_SAVE, "m_filter","0", "smoothes mouse movement, less responsive but smoother aiming"};
 
+cvar_t cl_netinputpacketspersecond = {CVAR_SAVE, "cl_netinputpacketspersecond","50", "how many input packets to send to server each second"};
+
 
 /*
 ================
@@ -533,7 +534,7 @@ void CL_ClientMovement_Input(qboolean buttonjump, qboolean buttoncrouch)
                                cl.movement_queue[cl.movement_numqueue++] = cl.movement_queue[i];
        }
        // add to input queue if there is room
-       if (cl_movement.integer && cl.movement_numqueue < (int)(sizeof(cl.movement_queue)/sizeof(cl.movement_queue[0])) && cl.mtime[0] > cl.mtime[1])
+       if (cl.movement_numqueue < (int)(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].sequence = cl.movesequence;
@@ -547,10 +548,6 @@ void CL_ClientMovement_Input(qboolean buttonjump, qboolean buttoncrouch)
                cl.movement_queue[cl.movement_numqueue].crouch = buttoncrouch;
                cl.movement_numqueue++;
        }
-       cl.movement = cl_movement.integer && cl.stats[STAT_HEALTH] > 0 && !cls.demoplayback && !cl.intermission;
-       // clear queue if client movement is disabled
-       if (!cl.movement)
-               cl.movement_numqueue = 0;
        cl.movement_replay = true;
 }
 
@@ -584,6 +581,7 @@ void CL_ClientMovement_Replay(void)
        trace_t trace;
        trace_t trace2;
        trace_t trace3;
+
        if (!cl.movement_replay)
                return;
        cl.movement_replay = false;
@@ -607,7 +605,7 @@ void CL_ClientMovement_Replay(void)
        // replay the input queue to predict current location
        // note: this relies on the fact there's always one queue item at the end
 
-       for (i = 0;i < cl.movement_numqueue;i++)
+       for (i = 0;cl.movement && i < cl.movement_numqueue;i++)
        {
                client_movementqueue_t *q = cl.movement_queue + bound(0, i, cl.movement_numqueue - 1);
                frametime = q->frametime;
@@ -799,12 +797,14 @@ void CL_ClientMovement_Replay(void)
 CL_SendMove
 ==============
 */
+extern cvar_t cl_netinputpacketspersecond;
 void CL_SendMove(void)
 {
        int i;
        int bits;
        sizebuf_t buf;
        unsigned char data[128];
+       static double lastsendtime = 0;
 #define MOVEAVERAGING 0
 #if MOVEAVERAGING
        static float forwardmove, sidemove, upmove, total; // accumulation
@@ -819,8 +819,23 @@ void CL_SendMove(void)
        upmove += cl.cmd.upmove;
        total++;
 #endif
-       if (cls.signon != SIGNONS)
-               return;
+
+       if (cl_movement.integer)
+       {
+               if (!cl.movement_needupdate)
+                       return;
+               cl.movement_needupdate = false;
+               cl.movement = cl.stats[STAT_HEALTH] > 0 && !cls.demoplayback && !cl.intermission;
+       }
+       else
+       {
+               cl.movement = false;
+               if (realtime < lastsendtime + 1.0 / bound(10, cl_netinputpacketspersecond.value, 100))
+                       return;
+               // don't let it fall behind if CL_SendMove hasn't been called recently
+               // (such is the case when framerate is too low for instance)
+               lastsendtime = max(lastsendtime + 1.0 / bound(10, cl_netinputpacketspersecond.value, 100), realtime);
+       }
 #if MOVEAVERAGING
        // average the accumulated changes
        total = 1.0f / total;
@@ -1001,6 +1016,8 @@ void CL_SendMove(void)
        // nothing to send
        if (!buf.cursize)
                return;
+       if (cls.signon != SIGNONS)
+               return;
 
        // FIXME: bits & 16 is +button5, Nexuiz specific
        CL_ClientMovement_Input((bits & 2) != 0, (bits & 16) != 0);
@@ -1104,5 +1121,7 @@ void CL_InitInput (void)
        Cvar_RegisterVariable(&in_pitch_min);
        Cvar_RegisterVariable(&in_pitch_max);
        Cvar_RegisterVariable(&m_filter);
+
+       Cvar_RegisterVariable(&cl_netinputpacketspersecond);
 }