From 1df0f2f7093e9f7b45cb1541fdc6eee5d23018e8 Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 19 Feb 2007 10:15:11 +0000 Subject: [PATCH] reworked packet sending code a bit more, this is mostly just a cleanup, not a change in logic, except that cl_movement 0 now reports the correct ping time to the server, so local players get ping 0 as they used to git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6870 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_input.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/cl_input.c b/cl_input.c index 59eef71c..0fc37a56 100644 --- a/cl_input.c +++ b/cl_input.c @@ -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; -- 2.39.2