Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gamenetwork): cap frame grouping at one logic frame

Olcay Seygan0cc2cdef5167
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 29cc3637c..513750cc5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -226,6 +226,7 @@ found and fixed — EA's own, not port damage.**
- Input delay is measured from simulation speed now, not your graphics card.
- One player's slow graphics card no longer slows the whole match. A network game runs at the pace of its slowest machine, and a machine that could only draw 16 pictures a second also only advanced the game 16 times a second, so everybody played in slow motion. It now skips pictures to keep up with the game, the way single player already did. Two machines on one desk: with one of them held to 16 pictures a second the match used to run at half speed, and with it held to 10 the match now runs at 28 of its 30 frames a second, the two machines agreeing on every frame.
- One lost packet costs a round trip instead of a flat two seconds.
+- A link that drops the odd packet no longer drags the whole room into slow motion. The game held its outgoing packets back for up to half its input delay, replies included, so it measured every connection as far slower than it was and waited longer and longer for anything lost. Three players on a 50 ms link losing one packet in fifty used to sink from 30 frames a second to 13; they hold 21 now, and two players losing one in a hundred hold 27.
- Two players who each lost the other's last packet no longer freeze until the disconnect screen. Each asked the other to send it again, and each only resent what it had already played, which was nothing, so on a link with a tenth of a second of delay and one packet in twenty lost the match stopped for good one second in. Now the packet goes again and the match carries on.
- A desynced match stops at once instead of playing on as two games.
- A single lost packet no longer freezes the match for twenty seconds. The game now asks for the
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp
index 5ffe61a4a..54817118f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp
@@ -666,6 +666,16 @@ void Network::processRunAheadCommand(NetRunAheadCommandMsg *msg) {
m_frameRate = msg->getFrameRate();
time_t frameGrouping = (1000 * m_runAhead) / m_frameRate; // number of miliseconds between packet sends
frameGrouping = frameGrouping / 2; // since we only want the latency for one way to be a factor.
+ /* No longer than one logic frame. Every send waits out the grouping, acks included, so every
+ round trip the game measures carries up to two of them - and the measured round trip is what
+ sizes the run-ahead, which sizes the grouping. On a 50 ms link losing 2% of its packets
+ three seats measured 0.95 s, the retry timeout grew to 832 ms and the room fell from 30 frames
+ a second to 12. EA's half a run-ahead was for a 2003 modem; a frame's orders fit one
+ datagram now, and one per frame per peer is nothing. */
+ const time_t oneLogicFrameMS = 1000 / m_frameRate;
+ if (frameGrouping > oneLogicFrameMS) {
+ frameGrouping = oneLogicFrameMS;
+ }
// DEBUG_LOG(("Network::processRunAheadCommand - trying to set frame grouping to %d. run ahead = %d, m_frameRate = %d\n", frameGrouping, m_runAhead, m_frameRate));
if (frameGrouping < 1) {
frameGrouping = 1; // Having a value less than 1 doesn't make sense.