]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
reworked packet sending code a bit more, this is mostly just a cleanup, not a change...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 19 Feb 2007 10:15:11 +0000 (10:15 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 19 Feb 2007 10:15:11 +0000 (10:15 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6870 d7cf8633-e32d-0410-b094-e92efae38249

cl_input.c

index 59eef71c2b45192db486fed2a24b5488224d4f3f..0fc37a56b7ed77fa0e598d4119186c42e3cd319a 100644 (file)
@@ -1264,6 +1264,7 @@ void CL_SendMove(void)
        sizebuf_t buf;
        unsigned char data[1024];
        static double lastsendtime = 0;
+       double packettime;
        double msectime;
        static double oldmsectime;
 
@@ -1271,26 +1272,39 @@ void CL_SendMove(void)
        if (!cls.netcon)
                return;
 
-#if 0
-       if (cl.movement_predicted && cls.signon == SIGNONS && cls.protocol != PROTOCOL_QUAKEWORLD)
+       packettime = 1.0 / bound(10, cl_netinputpacketspersecond.value, 100);
+       // on quakeworld servers the server replies to client input, so we send
+       // packets whenever we want to
+       // on non-quakeworld servers the client replies to server updates
+       if (cls.protocol == PROTOCOL_QUAKEWORLD)
        {
-               if (!cl.movement_needupdate)
+               // don't send too often or else network connections can get clogged by a high renderer framerate
+               if (realtime < lastsendtime + packettime)
                        return;
-               cl.movement_needupdate = false;
+               cl.cmd.time = realtime;
        }
-       else
-#endif
+       else if (cl.movement_predicted || cls.signon < SIGNONS)
        {
-               double packettime = 1.0 / bound(10, cl_netinputpacketspersecond.value, 100);
                // don't send too often or else network connections can get clogged by a high renderer framerate
                if (realtime < lastsendtime + packettime)
                        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 + packettime, realtime);
+               cl.cmd.time = cls.protocol == PROTOCOL_QUAKEWORLD ? realtime : cl.time;
+       }
+       else
+       {
+               // if not predicted, we should just reply to server packets, and
+               // report the real latest packet time rather than our interpolated
+               // time
+               if (!cl.movement_needupdate && realtime < lastsendtime + packettime)
+                       return;
+               cl.cmd.time = cls.protocol == PROTOCOL_QUAKEWORLD ? realtime : cl.mtime[0];
        }
+       // 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 = bound(realtime, lastsendtime + packettime, realtime + packettime);
+       // clear the note down that we sent a packet recently
+       cl.movement_needupdate = false;
 
-       cl.cmd.time = cls.protocol == PROTOCOL_QUAKEWORLD ? realtime : cl.time;
 
        buf.maxsize = sizeof(data);
        buf.cursize = 0;