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(gamelogic): start a new game only from a standing start
Olcay Seygan81ae5bb359b1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ad959980e..ac1153eb9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -303,6 +303,13 @@ map. Ctrl+A is still everything at once.on its own — from twelve frames a second to thirty in about six seconds. A room held down by amachine that really is that slow settles just above it and stays there instead of surging andfalling back.+- **An online match could be forced into a disconnect screen with no way out.** The command that+ starts a new game was obeyed no matter what the machine was doing — including in the middle of a+ match. The player who received it quietly restarted into a different game; everybody else was+ left waiting on turns from someone who was no longer in the same game at all, which is a wait that+ never ends. A game now only starts when there is no game running, none being shut down, and no map+ part way through loading.+- **The repair for a corrupted order was turned off for the first two seconds of every game.** Whena player's orders for a moment arrive damaged rather than late, the game throws them away and asksthat player to send them again — and that request is answered only if the moment in question isdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.hindex 0e681ff16..f5d325fad 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h@@ -400,6 +400,19 @@ inline Real GameLogic::getHeight( void ) { return m_height; }inline UnsignedInt GameLogic::getFrame( void ) { return m_frame; }inline Bool GameLogic::isInGame( void ) { return !(m_gameMode == GAME_NONE); }++//+// MSG_NEW_GAME arrives over the message stream like any other command, so a game already in+// progress can be handed one. Starting a second game on top of the first tears down the state the+// first one is still running on, and in a network game the other machines - which were not told to+// start anything - sit in the disconnect screen waiting for a player who is now somewhere else+// entirely, with no frame that will ever arrive to end the wait. A new game only begins from a+// standing start.+//+inline Bool IsReadyToStartNewGame( Bool inGame, Bool clearingGameData, Bool loadingMap )+{+ return !inGame && !clearingGameData && !loadingMap;+}inline void GameLogic::setGameMode( Int mode ) { m_gameMode = mode; }inline Int GameLogic::getGameMode( void ) { return m_gameMode; }inline Bool GameLogic::isInLanGame( void ) { return (m_gameMode == GAME_LAN); }diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex 5aa9bc8a5..1f72ee1e5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -469,6 +469,13 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )//---------------------------------------------------------------------------------------------case GameMessage::MSG_NEW_GAME:{+ if( !IsReadyToStartNewGame( isInGame(), isClearingGameData(), isLoadingMap() ) )+ {+ DEBUG_CRASH( ("MSG_NEW_GAME while the last one is still going (inGame=%d, clearingData=%d, loadingMap=%d)",+ isInGame(), isClearingGameData(), isLoadingMap()) );+ break;+ }+//DEBUG_ASSERTCRASH(msg->getArgumentCount() == 1 || msg->getArgumentCount() == 2, ("%d arguments to MSG_NEW_GAME", msg->getArgumentCount()));Int gameMode = msg->getArgument( 0 )->integer;Int rankPoints = 0;diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex b00686d8b..2aeba72a5 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -3675,3 +3675,28 @@ TEST(netcommand_list_orders_a_burst_of_acks_by_acknowledged_command)list->deleteInstance();}++//////////////////////////////////////////////////////////////////////////////+// Starting a new game+//////////////////////////////////////////////////////////////////////////////++/* MSG_NEW_GAME comes down the message stream like any other command, and the dispatcher used to+ act on it whatever the game was doing. Handed one mid-match, a machine tears down the game the+ others are still playing and they wait in the disconnect screen for frames that never come. */+TEST(a_new_game_only_starts_from_a_standing_start)+{+ // nothing running: the only state a new game may begin from+ CHECK( IsReadyToStartNewGame( FALSE, FALSE, FALSE ) );++ // each of the three on its own is enough to refuse+ CHECK( !IsReadyToStartNewGame( TRUE, FALSE, FALSE ) ); // a match is already running+ CHECK( !IsReadyToStartNewGame( FALSE, TRUE, FALSE ) ); // the last one is still being torn down+ CHECK( !IsReadyToStartNewGame( FALSE, FALSE, TRUE ) ); // a map is part way through loading++ // and no combination of them lets one through+ Bool refusedEveryBusyState = TRUE;+ for( Int bits = 1; bits < 8; ++bits )+ if( IsReadyToStartNewGame( (bits & 1) != 0, (bits & 2) != 0, (bits & 4) != 0 ) )+ refusedEveryBusyState = FALSE;+ CHECK( refusedEveryBusyState );+}