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): load the world in the order it was saved in
Olcay Seygan130b0993ed18
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7bf0d0a74..158d1ab37 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -136,6 +136,8 @@ found and fixed — EA's own, not port damage.**- An aircraft carrier remembers the order it was given, and each runway its own ramp.- A barracks that has already put its mob on the street does not put a second one out after a load.- Effects tied together - a smoke column and its embers - stay tied together across a save.+- A loaded save puts the world back in the order it was saved in, so the match plays on from where it was instead of resolving everything backwards.+- And it shows you your own memory of the fog, not everyone else's: a loaded game used to draw what every player remembered on top of the world.- Saved units come back with the map's weapons, not the stock ones.- Restarting a skirmish restarts the same skirmish, with a replay that plays back.- Replays sound and look the way they did when you played them.diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.hindex 8829375d2..f131e57eb 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h@@ -195,6 +195,13 @@ public:Object* getNextObject() { return m_next; }const Object* getNextObject() const { return m_next; }+ Object* getPrevObject() { return m_prev; }+ const Object* getPrevObject() const { return m_prev; }++ // only the save/load code relinks the global list by hand, to put a loaded list back in the+ // order it was saved in+ void friend_setNextObject( Object *obj ) { m_next = obj; }+ void friend_setPrevObject( Object *obj ) { m_prev = obj; }void updateObjValuesFromMapProperties(Dict* properties); ///< Brings in properties set in the editor.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex 85ec8b2f2..e783b7d93 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -5002,13 +5002,15 @@ void GameLogic::prepareLogicForObjectLoad( void )* 5: Added xfering the BuildAssistant's sell list.* 9: Added m_rankPointsToAddAtGameStart, or else on a load game, your RestartGame button will forget your exp* 10: xfer m_superweaponRestriction+ * 11: objects are written back to front, so that loading - which prepends each one - rebuilds+ * the list in the order it was saved in. Version 10 and earlier are reversed on load.*/// ------------------------------------------------------------------------------------------------void GameLogic::xfer( Xfer *xfer ){// version- const XferVersion currentVersion = 10;+ const XferVersion currentVersion = 11;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -5042,7 +5044,15 @@ void GameLogic::xfer( Xfer *xfer )if( xfer->getXferMode() == XFER_SAVE ){+ // Save the list backwards. Loading creates each object in turn and every new object is+ // prepended to the list, so a list saved front to back comes back reversed - and the order+ // of that list is the order everything iterates objects in, which is the order the+ // simulation resolves things in. Written back to front, the prepending puts it right.+ Object *lastObj = NULL;for( obj = getFirstObject(); obj; obj = obj->getNextObject() )+ lastObj = obj;++ for( obj = lastObj; obj; obj = obj->getPrevObject() ){// get the object TOC entry for this template@@ -5125,6 +5135,24 @@ void GameLogic::xfer( Xfer *xfer )} // end for, i+ // A save written before version 11 stored the list front to back, and the prepending above+ // therefore built it backwards. Turn it round, so an old save loads in the order it was+ // played in rather than in the mirror of it.+ if( version <= 10 )+ {+ Object *prev = NULL;+ Object *current = m_objList;+ while( current != NULL )+ {+ Object *next = current->getNextObject();+ current->friend_setNextObject( prev );+ current->friend_setPrevObject( next );+ prev = current;+ current = next;+ }+ m_objList = prev;+ }+} // end else// campaign infodiff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cppindex a2990536c..fde292d3b 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp@@ -748,23 +748,32 @@ void W3DGhostObject::xfer( Xfer *xfer )// xfer dataxfer->xferSnapshot( objectSnapshot );- // add snapshot to the scene- objectSnapshot->addToScene();-- } // end for, j+ } // end for, j} // end else, load} // end for, i//- // since there is a snapshot for this object, there cannot be a regular object/drawable- // in the world, we need to remove it+ // Put the local player's remembered version of this object into the scene. Every player's+ // snapshots used to be added as they were read, so a loaded game drew what each of the other+ // players remembers on top of the world - buildings and units in places only they had seen.//- if( m_parentObject &&- m_parentSnapshots[ ThePlayerList->getLocalPlayer()->getPlayerIndex() ] != NULL &&- xfer->getXferMode() == XFER_LOAD )- removeParentObject();+ if( xfer->getXferMode() == XFER_LOAD )+ {+ const Int localIndex = ThePlayerList->getLocalPlayer()->getPlayerIndex();+ if( m_parentSnapshots[ localIndex ] != NULL )+ {+ addToScene( localIndex );++ //+ // since there is a snapshot for this object, there cannot be a regular object/drawable+ // in the world, we need to remove it+ //+ if( m_parentObject )+ removeParentObject();+ }+ }// count of partition shroudedness info to followUnsignedByte shroudednessCount = 0;