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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameengine): size network catch-up by game speed, add netgame test hooks
Olcay Seygan5e14f6747a51
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.hindex 03631ea97..4ac5571db 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h@@ -446,6 +446,7 @@ public:Int m_traceMoveID; ///< -tracemove [id]: log one movement line a frame for this object (0 = off, -1 = the first unit that gets blocked)Real m_slowFrameMS; ///< -slowframe <ms>: a logic frame over this long logs its own breakdown (default 20)Int m_drawDelayMS; ///< -drawdelay <ms>: sleep this long in every client pass, a slow graphics card on demand (0 = off)+ Int m_drawDelayJitterMS; ///< -drawdelay <ms> <jitter>: up to this much more, different every passBool m_showLanes; ///< -showlanes: draw every moving unit's route, the lane it was handed and the offset it keptInt m_uiDrill; ///< -uidrill <n>: every n frames, minimise the command bar and re-apply its scheme, logging where it landed (0 = off)Int m_resDrillFrame; ///< -resdrill <frame> [w] [h]: change the resolution at that logic frame, from inside a running match (0 = off)@@ -459,6 +460,7 @@ public:Bool m_autoSkirmishTakeover; ///< -takeover: give every -autoskirmish slot a driverless human seat, so nothing thinks unless a scenario says soAsciiString m_autoSkirmishSide[ MAX_PLAYER_COUNT ]; ///< -side <slot> <faction>: name that slot's faction instead of drawing it from the seedAsciiString m_netGameHosts; ///< -netgame <ip>[,<ip>...]: the slot list of a LAN game started from the command line (empty = off)+ Bool m_netGameStarted; ///< that -netgame passed its checks and StartAutomatedGame ran, so every seat has this command lineInt m_netGameLocalSlot; ///< -netslot <n>: which of those addresses this copy of the game isAsciiString m_lanPlayerName; ///< -lanname <name>: the name this copy takes in the LAN lobby (empty = the one in the preferences)Bool m_lanLobbyOnStart; ///< -lanlobby: open the LAN lobby instead of stopping at the main menudiff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cppindex ba18e806a..1c05537a1 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp@@ -2013,7 +2013,11 @@ Int parseSlowFrame(char *args[], int num)/* -drawdelay <ms> sleeps that long in every client pass, which is what a weak graphics card lookslike to the engine: the picture takes longer while the logic frame costs what it always did.A network game paces itself on the slowest machine in the room, so the question "does one slow- renderer slow everybody" needs a slow renderer on this machine, next to a fast one. */+ renderer slow everybody" needs a slow renderer on this machine, next to a fast one.++ An optional second number adds up to that much more, different on every pass, because a real+ card does not take the same time twice and a network catch-up that runs a varying number of+ logic frames per picture is the case worth testing. */Int parseDrawDelay(char *args[], int num){if (TheWritableGlobalData && num > 1 && args[1])@@ -2021,6 +2025,11 @@ Int parseDrawDelay(char *args[], int num)const Int ms = atoi(args[1]);if (ms > 0)TheWritableGlobalData->m_drawDelayMS = ms;+ if (num > 2 && args[2] && isdigit((unsigned char)args[2][0]))+ {+ TheWritableGlobalData->m_drawDelayJitterMS = atoi(args[2]);+ return 3;+ }return 2;}return 1;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cppindex 8ab99480c..a5136062b 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp@@ -580,6 +580,7 @@ static void startAutoNetGame( void )TheLAN->StartAutomatedGame( mapName, TheGlobalData->m_fixedSeed, slotIPs, numSlots,TheGlobalData->m_netGameLocalSlot );+ TheWritableGlobalData->m_netGameStarted = TRUE;}/** -----------------------------------------------------------------------------------------------@@ -2137,7 +2138,15 @@ void GameEngine::update( void )#endifTheGameClient->UPDATE();if (TheGlobalData->m_drawDelayMS > 0)- ::Sleep( TheGlobalData->m_drawDelayMS );+ {+ // The jitter is the performance counter's low bits: client side, and no random stream+ // either half of the game draws from is touched.+ Int64 now;+ QueryPerformanceCounter( (LARGE_INTEGER *)&now );+ const Int jitter = TheGlobalData->m_drawDelayJitterMS > 0+ ? (Int)( now % ( TheGlobalData->m_drawDelayJitterMS + 1 ) ) : 0;+ ::Sleep( TheGlobalData->m_drawDelayMS + jitter );+ }TheMessageStream->propagateMessages();if (TheNetwork != NULL)@@ -2256,7 +2265,7 @@ void GameEngine::update( void )// frame that is itself over budget cannot pull the loop into a spiral.Int logicTicksThisPass = 0;const Int maxTicksThisPass = GameEngine_logicCatchupMaxFrames(- networkPaced ? (Int)TheNetwork->getFrameRate() : m_maxFPS );+ networkPaced ? TheGlobalData->m_framesPerSecondLimit : m_maxFPS );/* Bounded by the clock as well as by the count - see LOGIC_CATCHUP_BUDGET_MS. Three25ms ticks back to back with no picture in between is the 113ms freeze; one of themplus the render is a dropped frame nobody files a bug about. */diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cppindex d070ac25a..ced1a9c0e 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp@@ -723,6 +723,7 @@ GlobalData::GlobalData()m_traceMoveID = 0; // no movement tracem_slowFrameMS = 20.0f; // a frame worth a line in the log; -slowframe lowers it for a huntm_drawDelayMS = 0; // client passes run as fast as the machine does unless -drawdelay slows them+ m_drawDelayJitterMS = 0;m_showLanes = FALSE; // the lane overlay is a diagnostic, off unless -showlanes asks for itm_uiDrill = 0; // nobody presses the minimise button; -uidrill is how a script presses itm_resDrillFrame = 0; // the resolution stays where it started unless -resdrill changes it mid-match@@ -737,6 +738,7 @@ GlobalData::GlobalData()for( Int slot = 0; slot < MAX_PLAYER_COUNT; slot++ )m_autoSkirmishSide[ slot ].clear(); // every faction still comes out of the seed unless -side names onem_netGameHosts.clear(); // no network game from the command line+ m_netGameStarted = FALSE;m_netGameLocalSlot = 0;m_lanPlayerName.clear(); // the lobby name comes out of the preferences unless -lanname says otherwisem_lanLobbyOnStart = FALSE;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cppindex 1ee38f160..8a5269514 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp@@ -589,6 +589,27 @@ static void handleCommand( const AsciiString &command )return;}+ /* The quit menu's Exit, which in a network game is the other half of "quit": the process goes+ on, the player surrenders and the match is left through the network, so everybody else sees+ a player leave on an agreed frame rather than a connection drop. exitQuitMenu in QuitMenu.cpp+ posts the same two messages. */+ if (command == "leave")+ {+ if (TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame())+ {+ replyError( "leave needs a match in progress" );+ return;+ }+ if (TheGameLogic->isInMultiplayerGame() && !TheGameLogic->isInSkirmishGame())+ {+ GameMessage *surrender = TheMessageStream->appendMessage( GameMessage::MSG_SELF_DESTRUCT );+ surrender->appendBooleanArgument( TRUE );+ }+ TheMessageStream->appendMessage( GameMessage::MSG_CLEAR_GAME_DATA );+ replyOk( "\"leaving\":true" );+ return;+ }+/* key <KEY_name> [ALT] [CTRL] [SHIFT]One press and release, carried the way Keyboard.cpp carries a real one, so the command map, thetranslators and whatever network message sits behind them all see a key. The keyboard itselfdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex a54476930..78d2990f1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -1170,7 +1170,14 @@ void GameLogic::startNewGame( Bool loadingSaveGame )is written. */if (isInMultiplayerGame()){- TheWritableGlobalData->m_scenarioFile.clear(); // -scenario+ /* A -netgame match is the exception for -scenario: it has no lobby, every machine in it was+ started from a script with the same command line, and a busy network game is the one load+ the multiplayer catch-up could not otherwise be tested under. Only one that actually+ started, though: a -netgame that failed its own checks leaves this copy at the menus, and+ a LAN lobby joined from there is an ordinary match. The file itself is agreed on by+ nobody, so this stays a test route; a replay of it needs the same -scenario again. */+ if (!TheGlobalData->m_netGameStarted)+ TheWritableGlobalData->m_scenarioFile.clear(); // -scenarioTheWritableGlobalData->m_peaceTime = 0; // -peacetime, and the host's options string is read belowTheWritableGlobalData->m_unitLimit = FALSE; // -unitlimit, the same}diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cppindex 60ea89473..5ffe61a4a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/Network.cpp@@ -805,10 +805,12 @@ Bool Network::timeForNewFrame() {// if (m_nextFrameTime + frameDelay < curTime) {/* GameEngine::update pays this debt back with logic frames run between two pictures, up to- the same cap the single player pacer keeps. EA forgave it past two frames, when a pass+ the same count the single player pacer keeps. EA forgave it past two frames, when a passonly ever ran one; a slow picture then lost the frames it owed and the whole room slowed- down to its rate. */- if ((m_nextFrameTime + (GameEngine_logicCatchupMaxFrames(m_frameRate) * frameDelay)) < curTime) {+ down to its rate. The count comes from the game speed and not from the room's rate: tied+ to the room, a room that slowed down could pay back less and slowed down further, and a+ 250ms picture took two machines from 30 frames a second to 4. */+ if ((m_nextFrameTime + (GameEngine_logicCatchupMaxFrames(TheGlobalData->m_framesPerSecondLimit) * frameDelay)) < curTime) {// If we get too far behind on our framerate we need to reset the nextFrameTime thing.m_nextFrameTime = curTime;// DEBUG_LOG(("Initializing m_nextFrameTime to %I64d\n", m_nextFrameTime));