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): resend our announced frames when a peer on the same frame asks

Olcay Seygan124c47b0c334
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7620b32de..0e2c89469 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.
+- 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
missing frame back after a fifth of a second instead of waiting out the disconnect timer, so
diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h
index 879308226..e19b64502 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h
@@ -134,6 +134,7 @@ public:
void notifyOthersOfCurrentFrame(Int frame);
void sendFrameDataToPlayer(UnsignedInt playerID, UnsignedInt startingFrame);
void sendSingleFrameToPlayer(UnsignedInt playerID, UnsignedInt frame);
+ void sendSlotFrameToPlayer(UnsignedInt playerID, UnsignedInt slot, UnsignedInt frame);
void notifyOthersOfNewFrame(UnsignedInt frame);
UnsignedInt getNextPacketRouterSlot(UnsignedInt playerID); ///< returns the packet router player that comes after the given player.
@@ -193,6 +194,7 @@ private:
Transport *m_transport;
UnsignedInt m_localSlot;
+ Int m_lastFrameTickSent; ///< the newest frame processFrameTick has announced; its command count is final
UnsignedInt m_packetRouterSlot;
UnsignedInt m_packetRouterFallback[MAX_SLOTS];
UnsignedInt m_localAddr;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
index 39a3279f8..93923a213 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
@@ -197,6 +197,7 @@ void ConnectionManager::init()
m_keepAliveNextSlot = 0;
m_localSlot = -1;
+ m_lastFrameTickSent = -1;
#ifdef MEMORYPOOL_DEBUG
TheMemoryPoolFactory->debugSetInitFillerIndex(m_localSlot);
#endif
@@ -294,6 +295,7 @@ void ConnectionManager::reset()
m_netCommandWrapperList->reset();
m_localSlot = -1;
+ m_lastFrameTickSent = -1;
#ifdef MEMORYPOOL_DEBUG
TheMemoryPoolFactory->debugSetInitFillerIndex(m_localSlot);
#endif
@@ -1500,6 +1502,8 @@ void ConnectionManager::processFrameTick(UnsignedInt frame) {
msg->setPlayerID(m_localSlot);
m_frameMetrics.doPerFrameMetrics(frame);
+ if ((Int)frame > m_lastFrameTickSent)
+ m_lastFrameTickSent = (Int)frame;
DEBUG_LOG(("ConnectionManager::processFrameTick - sending frame info for frame %d, ID %d, command count %d\n", frame, msg->getID(), commandCount));
@@ -2582,6 +2586,18 @@ void ConnectionManager::sendFrameDataToPlayer(UnsignedInt playerID, UnsignedInt
for (UnsignedInt frame = startingFrame; frame < TheGameLogic->getFrame(); ++frame) {
sendSingleFrameToPlayer(playerID, frame);
}
+
+ /* EA stopped at the frame this machine is on, which is enough for a player who fell behind and
+ nothing for one on the same frame: when both machines lose the other's frame info for the
+ frame they are both on, each asks, each finds nothing below its own frame to send, and the
+ match hangs until the disconnect screen. -latAvg 120 -packetloss 5 did it at frame 30 on the
+ retail pacing as well as with the network catch-up. Our own frames from here up to the last
+ one announced are final - processFrameTick only runs once no command can land on that frame
+ any more - so those go too. Other players' frames past ours are not ours to vouch for. */
+ const Int firstUnplayed = ((Int)startingFrame > (Int)TheGameLogic->getFrame()) ? (Int)startingFrame : (Int)TheGameLogic->getFrame();
+ for (Int frame = firstUnplayed; frame <= m_lastFrameTickSent; ++frame) {
+ sendSlotFrameToPlayer(playerID, m_localSlot, frame);
+ }
DEBUG_LOG(("ConnectionManager::sendFrameDataToPlayer - done sending commands to player %d\n", playerID));
}
@@ -2591,35 +2607,41 @@ void ConnectionManager::sendSingleFrameToPlayer(UnsignedInt playerID, UnsignedIn
return;
}
- UnsignedByte relay = 1 << playerID;
-
DEBUG_LOG(("ConnectionManager::sendFrameDataToPlayer - sending data for frame %d\n", frame));
for (Int i = 0; i < MAX_SLOTS; ++i) {
if ((m_frameData[i] != NULL) && (i != playerID)) { // no need to send his own commands to him.
- NetCommandList *list = m_frameData[i]->getFrameCommandList(frame);
- if (list != NULL) {
- NetCommandRef *ref = list->getFirstMessage();
- while (ref != NULL) {
- DEBUG_LOG(("ConnectionManager::sendFrameDataToPlayer - sending command %d from player %d to player %d using relay 0x%x\n", ref->getCommand()->getID(), i, playerID, relay));
- sendLocalCommandDirect(ref->getCommand(), relay);
- ref = ref->getNext();
- }
- }
- UnsignedInt frameCommandCount = m_frameData[i]->getFrameCommandCount(frame);
- NetFrameCommandMsg *msg = newInstance(NetFrameCommandMsg);
- msg->setExecutionFrame(frame);
- msg->setCommandCount(frameCommandCount);
- if (DoesCommandRequireACommandID(msg->getNetCommandType())) {
- msg->setID(GenerateNextCommandID());
- }
- msg->setPlayerID(i);
- DEBUG_LOG(("ConnectionManager::sendFrameDataToPlayer - sending frame info from player %d to player %d for frame %d with command count %d and ID %d and relay %d\n", i, playerID, msg->getExecutionFrame(), msg->getCommandCount(), msg->getID(), relay));
- sendLocalCommandDirect(msg, relay);
- msg->detach();
+ sendSlotFrameToPlayer(playerID, i, frame);
}
}
}
+/** One slot's commands for one frame, then its frame info, the way sendSingleFrameToPlayer always
+ sent every slot's. */
+void ConnectionManager::sendSlotFrameToPlayer(UnsignedInt playerID, UnsignedInt slot, UnsignedInt frame) {
+ UnsignedByte relay = 1 << playerID;
+
+ NetCommandList *list = m_frameData[slot]->getFrameCommandList(frame);
+ if (list != NULL) {
+ NetCommandRef *ref = list->getFirstMessage();
+ while (ref != NULL) {
+ DEBUG_LOG(("ConnectionManager::sendFrameDataToPlayer - sending command %d from player %d to player %d using relay 0x%x\n", ref->getCommand()->getID(), slot, playerID, relay));
+ sendLocalCommandDirect(ref->getCommand(), relay);
+ ref = ref->getNext();
+ }
+ }
+ UnsignedInt frameCommandCount = m_frameData[slot]->getFrameCommandCount(frame);
+ NetFrameCommandMsg *msg = newInstance(NetFrameCommandMsg);
+ msg->setExecutionFrame(frame);
+ msg->setCommandCount(frameCommandCount);
+ if (DoesCommandRequireACommandID(msg->getNetCommandType())) {
+ msg->setID(GenerateNextCommandID());
+ }
+ msg->setPlayerID(slot);
+ DEBUG_LOG(("ConnectionManager::sendFrameDataToPlayer - sending frame info from player %d to player %d for frame %d with command count %d and ID %d and relay %d\n", slot, playerID, msg->getExecutionFrame(), msg->getCommandCount(), msg->getID(), relay));
+ sendLocalCommandDirect(msg, relay);
+ msg->detach();
+}
+
UnsignedInt ConnectionManager::getNextPacketRouterSlot(UnsignedInt playerID) {
return nextPacketRouterSlot(m_packetRouterFallback, MAX_SLOTS, playerID);
}