fix(skirmish): Improve determinism for restarted games by resetting slot values#2373
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Include/GameNetwork/GameInfo.h | Adds m_hasSavedOriginalSetup bool field and renames saveOffOriginalInfo to saveOriginalSetup; exposes new hasSavedOriginalSetup() accessor. |
| Core/GameEngine/Source/GameNetwork/GameInfo.cpp | Initialises m_hasSavedOriginalSetup to FALSE in reset(), sets it to TRUE at the end of saveOriginalSetup(), and updates call-site rename inside SkirmishGameInfo::xfer. |
| Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp | Adds toString(GameMode) helper and replaces the unconditional saveOriginalSetup() call in startNewGame with the flag-guarded restore-or-save pattern for deterministic restarts. |
| GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp | Mirror of Generals change: identical toString(GameMode) helper and restore-or-save logic added to Zero Hour's startNewGame. |
| Generals/Code/GameEngine/Include/GameLogic/GameLogic.h | Adds const char* toString(GameMode mode) free-function declaration. |
| GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h | Mirror of Generals header: adds const char* toString(GameMode mode) declaration. |
Sequence Diagram
sequenceDiagram
participant GL as GameLogic::startNewGame
participant GS as GameSlot
participant Rng as populateRandom*
Note over GL,Rng: First start
GL->>GS: hasSavedOriginalSetup() → false
GL->>GS: saveOriginalSetup() [stores color/pos/template, sets flag=true]
GL->>Rng: populateRandomSideAndColor / populateRandomStartPosition
Rng->>GS: setColor / setStartPos / setPlayerTemplate (resolved values)
Note over GL,Rng: Restart
GL->>GS: hasSavedOriginalSetup() → true
GL->>GS: setColor(origColor) / setStartPos(origPos) / setPlayerTemplate(origTemplate)
Note over GS: Slots reset to pre-random values
GL->>Rng: populateRandomSideAndColor / populateRandomStartPosition
Rng->>GS: setColor / setStartPos / setPlayerTemplate (same resolved values as first start)
Reviews (6): Last reviewed commit: "Changed from 'getSaveOriginalSetup' to '..." | Re-trigger Greptile
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
Outdated
Show resolved
Hide resolved
GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
Outdated
Show resolved
Hide resolved
xezon
left a comment
There was a problem hiding this comment.
Greptile is still complaining about something?
Yes, that was a good point. I think it could have affected the randomization of AI players if a game was loaded from inside another game or replay. GeneralsGameCode/Core/GameEngine/Source/GameNetwork/GameInfo.cpp Lines 1594 to 1600 in 637dbba It should work correctly now because Replication in Generals still needs doing. |
e5d4698 to
0239428
Compare
|
I can replicate in Generals unless there are other changes desired. |
Restarted skirmish games may not start with the same logical seed value as the first start. This depends on whether there are players with a random color / position / faction. Those random values are determined by using and updating the logical seed on the first start, after which the random values are stored. That means that for restarted games the logical seed isn't used or updated for those purposes. This PR resets those values to improve determinism for restarted games.
You can put a breakpoint after
GameLogic::startNewGameand compare the values oftheGameLogicSeedfor the first start and following starts and see how the values for the first start deviate from restarts.TODO: