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): restore facing and an empty state machine on load
Olcay Seygan995b07bb904a
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Thing.h b/GeneralsMD/Code/GameEngine/Include/Common/Thing.hindex a0360b6bc..43d1a0186 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Thing.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Thing.h@@ -121,6 +121,8 @@ public:inline const Coord3D *getPosition() const { return &m_cachedPos; }inline Real getOrientation() const { return m_cachedAngle; }+ /// for a load: the angle as it stood when saved, which the one setTransformMatrix derives from the matrix is a few bits off+ void restoreOrientation( Real angle ) { m_cachedAngle = angle; m_cacheFlags &= ~VALID_DIRVECTOR; }const Coord3D *getUnitDirectionVector2D() const;void getUnitDirectionVector2D(Coord3D& dir) const;void getUnitDirectionVector3D(Coord3D& dir) const;diff --git a/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cppindex b0a9a8da4..c61527216 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/StateMachine.cpp@@ -859,8 +859,9 @@ void StateMachine::xfer( Xfer *xfer )xfer->xferUnsignedInt(&curStateID);if (xfer->getXferMode() == XFER_LOAD) {// We are going to jump into the current state. We don't call onEnter or onExit, because the- // state was already active when we saved.- m_currentState = internalGetState( curStateID );+ // state was already active when we saved. A machine saved with no state gets none back: the+ // block further down is read into the default state, which is where the save wrote it from.+ m_currentState = ( curStateID == INVALID_STATE_ID ) ? NULL : internalGetState( curStateID );}Bool snapshotAllStates = false;@@ -903,8 +904,8 @@ void StateMachine::xfer( Xfer *xfer )// A machine can stand with no current state (halt and clear both leave it so), and the file// needs some state's block here, so the default one is written in its place. It used to be// assigned as well. A replay checkpoint is a save taken mid-playback: a unit with no state in- // the recording got an idle one in the playback and went on thinking. A load has already- // taken the default for an id it cannot find, a few lines up.+ // the recording got an idle one in the playback and went on thinking. A load reads the same+ // block into the default state and leaves the machine without one, as it was saved.//State *state = m_currentState;if( state == NULL )diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex 806696c9a..618cbff08 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -4321,13 +4321,14 @@ void Object::crc( Xfer *xfer )* 8: Kris: Conversion of object status bits from UnsignedInt to BitFlags<>* 9: Extra sighting for reveal to all with different range units* 10: each player's memory of it while it is out of their sight+ * 11: the cached angle, which the matrix does not give back bit for bit*///-------------------------------------------------------------------------------------------------void Object::xfer( Xfer *xfer ){// version- const XferVersion currentVersion = 10;+ const XferVersion currentVersion = 11;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -4351,6 +4352,18 @@ void Object::xfer( Xfer *xfer )//if( xfer->getXferMode() == XFER_LOAD )setTransformMatrix(&mtx);++ //+ // And the load derives that same angle, so the angle itself goes into the file: a jump back in+ // a replay is a load, and the playback carries on from it against the recording's CRCs.+ //+ if( version >= 11 )+ {+ Real angle = getOrientation();+ xfer->xferReal( &angle );+ if( xfer->getXferMode() == XFER_LOAD )+ restoreOrientation( angle );+ }}else{