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.

feat(gameclient): frame number and network readiness on the hud plate

Olcay Seygan55e2095ac965
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 45050cfd8..c9a554c25 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -228,6 +228,7 @@ found and fixed — EA's own, not port damage.**
- 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.
- A bad connection no longer turns the match into a slideshow. The orders each player sends now go out three times, 30 ms apart, so a lost packet is covered by the next one instead of by a resend that came most of a second later while everyone waited. Three players on 120 ms links losing one packet in twenty went from 6 frames a second to 19; two on 200 ms links losing one in ten went from 6 to 23, and the 50 ms room above from 21 to 26. The copies cost a few bytes and nothing on a clean line.
+- The readout in the top right corner now carries the frame number, and in a network game how many frames the room can still play before it has to wait on somebody, out of the input delay it is running with, plus the frame rate the slowest machine has set for everyone. "ready 4/7 room 29fps" is a healthy match; ready sitting at 0 is the stall you are about to feel.
- 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/Include/GameNetwork/ConnectionManager.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h
index e19b64502..f5f41d8c8 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/ConnectionManager.h
@@ -72,6 +72,7 @@ public:
void sendLocalGameMessage(GameMessage *msg, UnsignedInt frame);
void sendCommand(NetCommandMsg *msg);
Bool allCommandsReady(UnsignedInt frame, Bool justTesting = FALSE);
+ UnsignedInt countFramesReady(UnsignedInt fromFrame, UnsignedInt maxFrames); ///< Consecutive frames from fromFrame whose commands are all in, without asking for a resend.
void handleAllCommandsReady(void);
NetCommandList *getFrameCommandList(UnsignedInt frame);
// void AddConnection(User *user, UnsignedInt slot);
diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkInterface.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkInterface.h
index b6e86a42a..6aca3c23d 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkInterface.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/NetworkInterface.h
@@ -74,6 +74,7 @@ public:
virtual UnsignedInt getRunAhead(void) = 0; ///< Get the current RunAhead value
virtual UnsignedInt getFrameRate(void) = 0; ///< Get the current allowed frame rate.
virtual UnsignedInt getPacketArrivalCushion(void) = 0; ///< Get the smallest packet arrival cushion since this was last called.
+ virtual UnsignedInt getFramesReady(void) = 0; ///< Frames from the current one whose commands are all in, up to the run-ahead. For the HUD.
// Chat functions
virtual void sendChat(UnicodeString text, Int playerMask) = 0; ///< Send a chat line using the normal system.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 502dccb24..0d705150f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -8428,6 +8428,21 @@ void InGameUI::drawHudOverlay( void )
REAL_TO_INT( m_hudLogicHz + 0.5f ), REAL_TO_INT( m_hudFps + 0.5f ),
TheDisplay->getRendererName() );
+ UnicodeString frameText;
+ frameText.format( L" frame %d", (Int)logicFrame );
+ text.concat( frameText );
+
+ // in a network game, how far ahead the room can play without waiting on anybody, out of the
+ // input delay it is running with, and the frame rate the slowest machine has set for everyone:
+ // ready falling to 0 is the stall, seen before it is felt
+ if( TheNetwork != NULL )
+ {
+ UnicodeString netText;
+ netText.format( L" ready %d/%d room %dfps", (Int)TheNetwork->getFramesReady(),
+ (Int)TheNetwork->getRunAhead(), (Int)TheNetwork->getFrameRate() );
+ text.concat( netText );
+ }
+
// the lobby's unit limit, as this player's own share and not the match total: what stands and
// what is queued, against the number the production queue refuses at
const UnsignedInt unitCap = TheGameLogic->getUnitCap();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
index 93923a213..1766e5717 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/ConnectionManager.cpp
@@ -1639,6 +1639,26 @@ Int commandsReadyDebugSpewage = 0;
/**
* Returns true if all the commands for the given frame are ready to be executed.
*/
+/**
+ * How many frames the room could play right now without waiting, counted from fromFrame. A read
+ * only: allCommandsReady asks for a resend when it finds a frame in a bad state, and this is for a
+ * readout, which must not change what goes on the wire.
+ */
+UnsignedInt ConnectionManager::countFramesReady(UnsignedInt fromFrame, UnsignedInt maxFrames) {
+ for (UnsignedInt ready = 0; ready < maxFrames; ++ready) {
+ const UnsignedInt frame = fromFrame + ready;
+ for (Int i = 0; i < MAX_SLOTS; ++i) {
+ if ((m_frameData[i] == NULL) || m_frameData[i]->getIsQuitting()) {
+ continue;
+ }
+ if (m_frameData[i]->getFrameCommandCount(frame) != m_frameData[i]->getCommandCount(frame)) {
+ return ready;
+ }
+ }
+ }
+ return maxFrames;
+}
+
Bool ConnectionManager::allCommandsReady(UnsignedInt frame, Bool justTesting /* = FALSE */) {
Bool retval = TRUE;
/* Read after the loop, and the loop can exit before ever assigning it. */
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp
index 54817118f..f004d9c27 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp
@@ -121,6 +121,7 @@ public:
inline UnsignedInt getRunAhead(void) { return m_runAhead; }
inline UnsignedInt getFrameRate(void) { return m_frameRate; }
UnsignedInt getPacketArrivalCushion(void); ///< Returns the smallest packet arrival cushion since this was last called.
+ UnsignedInt getFramesReady(void) { return m_conMgr->countFramesReady(TheGameLogic->getFrame(), m_runAhead); }
Bool isFrameDataReady( void );
Bool isPacingLogicFrames( void );
void parseUserList( const GameInfo *game );