From: <sv...@ww...> - 2005-04-29 01:45:39
|
Author: mkrose Date: 2005-04-28 18:45:25 -0700 (Thu, 28 Apr 2005) New Revision: 1530 Modified: trunk/CSP/CSPSim/CHANGES.current trunk/CSP/SimNet/NetworkInterface.cpp trunk/CSP/SimNet/NetworkInterface.h Log: Disable timing statistics updates after long delays between calls to process incoming packets. This should significantly improve the time skew detection that is critical for proper multiplayer synchronization. In particular, the long delay (due mainly to terrain loading) between establishing a connection to the index server and starting the main sim loop was creating a large artificial clock skew. Needs testing though. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1530 Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2005-04-29 01:38:51 UTC (rev 1529) +++ trunk/CSP/CSPSim/CHANGES.current 2005-04-29 01:45:25 UTC (rev 1530) @@ -11,6 +11,13 @@ * Remove debugging cruft from stdout. + * Disable timing statistics updates after long delays between calls to + process incoming packets. This should significantly improve the time + skew detection that is critical for proper multiplayer synchronization. + In particular, the long delay (due mainly to terrain loading) between + establishing a connection to the index server and starting the main sim + loop was creating a large artificial clock skew. Needs testing though. + 2005-04-27: onsight * Remove dead code from PhysicsModel and BaseDynamics. Modified: trunk/CSP/SimNet/NetworkInterface.cpp =================================================================== --- trunk/CSP/SimNet/NetworkInterface.cpp 2005-04-29 01:38:51 UTC (rev 1529) +++ trunk/CSP/SimNet/NetworkInterface.cpp 2005-04-29 01:45:25 UTC (rev 1530) @@ -507,7 +507,9 @@ } int latency = static_cast<int>(t_latency); assert(latency == t_latency); - peer->updateTiming(latency, last_ping_latency); + if (m_DiscardTiming == 0) { + peer->updateTiming(latency, last_ping_latency); + } } else { SIMNET_LOG(PEER, ERROR, "Ping packet does not contain timing payload"); } @@ -585,6 +587,23 @@ double start_time = simdata::get_realtime(); + // if we haven't processed incoming packets for a while then we + // shouldn't trust any timing data they may contain. + if (start_time - m_LastUpdate > 0.2) { + // discard timing data until all stale packets are processed or + // this many successive calls to processIncoming have been made + // without long delays. hopefully by then all the original + // stale packets from this iteration will have either been + // processed or dropped. + m_DiscardTiming = 100; + } else { + // if there was a long pause recently keep dropping timing + // data. once the count reaches zero we will start using + // the timing data again. + if (m_DiscardTiming > 0) --m_DiscardTiming; + } + assert(m_DiscardTiming >= 0); // paranoia + // spend up to 60% of our time slice receiving messages from the // socket. if the socket runs dry early (which it should in most // cases), we will have extra time to process those messages. @@ -619,7 +638,10 @@ queue_idx = (queue_idx - 1) & 3; queue = m_RxQueues[queue_idx]; } while (++n <= 4 && queue->isEmpty()); - if (n > 4) break; // all empty + if (n > 4) { // all empty + m_DiscardTiming = 0; // all stale packets gone! + break; + } // if only one queue isn't empty then forget about counts count = (n==4) ? 100000 : process_count[queue_idx]; } @@ -681,6 +703,7 @@ m_ActivePeers(new ActivePeerList), m_AllowUnknownPeers(false), m_Initialized(false), + m_DiscardTiming(0), m_IncomingBandwidth(0), m_OutgoingBandwidth(0), m_PacketHandlers(new PacketHandlerSet) Modified: trunk/CSP/SimNet/NetworkInterface.h =================================================================== --- trunk/CSP/SimNet/NetworkInterface.h 2005-04-29 01:38:51 UTC (rev 1529) +++ trunk/CSP/SimNet/NetworkInterface.h 2005-04-29 01:45:25 UTC (rev 1530) @@ -135,6 +135,11 @@ // Indicates whether initialize() has been called. bool m_Initialized; + // Counter indicating whether timing data should be discarded because + // processIncoming has not been called recently. Timing data should + // only be considered valid if m_DiscardTiming is zero. + int m_DiscardTiming; + // Nominal bandwidths in bytes/sec. int m_IncomingBandwidth; int m_OutgoingBandwidth; |