fix(skirmish): Improve determinism for restarted games by resetting slot values#2373
fix(skirmish): Improve determinism for restarted games by resetting slot values#2373Caball009 wants to merge 4 commits intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Include/GameNetwork/GameInfo.h | Adds m_saveOriginalSetup bool field and getter to GameSlot, and renames saveOffOriginalInfo() to saveOriginalSetup() |
| Core/GameEngine/Source/GameNetwork/GameInfo.cpp | Initialises m_saveOriginalSetup = TRUE in reset(), sets it to FALSE in saveOriginalSetup() as a one-shot latch, ensuring the flag correctly tracks whether the first-start originals have been captured |
| Generals/Code/GameEngine/Include/GameLogic/GameLogic.h | Adds free-function declaration const char* toString(GameMode mode) to support debug-log messaging in the new restart logic |
| Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp | Implements toString(GameMode) and the core determinism fix: on restart restores the slot's original color/position/template before random seeding, so the logical seed progresses identically to the first start |
| GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h | Mirrors the Generals header — adds the same toString(GameMode) declaration for the Zero Hour code path |
| GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp | Mirrors the Generals implementation — same toString function and identical restart-determinism fix applied to the Zero Hour build |
Sequence Diagram
sequenceDiagram
participant User
participant GameLogic
participant GameSlot
participant Seed as LogicalSeed
Note over User,Seed: First Game Start
User->>GameLogic: startNewGame()
GameLogic->>GameSlot: getSaveOriginalSetup() returns TRUE
GameLogic->>GameSlot: saveOriginalSetup() saves color and pos and template
Note over GameSlot: latch set to FALSE
GameLogic->>Seed: populateRandomSideAndColor()
GameLogic->>Seed: populateRandomStartPosition()
Note over Seed: Seed advances and resolves random slots
Note over User,Seed: Game Restart
User->>GameLogic: startNewGame()
GameLogic->>GameSlot: getSaveOriginalSetup() returns FALSE
GameLogic->>GameSlot: restore original color and pos and template
GameLogic->>Seed: populateRandomSideAndColor()
GameLogic->>Seed: populateRandomStartPosition()
Note over Seed: Seed advances identically to first start
Reviews (5): Last reviewed commit: "Replicated in Generals." | 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. |
|
|
||
| void saveOffOriginalInfo(); | ||
| void saveOriginalSetup(); | ||
| Bool getSaveOriginalSetup() const { return m_saveOriginalSetup; } |
There was a problem hiding this comment.
It appears a bit confusing to read.
Would it make sense to flip the meaning from getSaveOriginalSetup to hasSavedOriginalSetup? Maybe the new boolean value isn't even necessary and the save can be inferred from the saved values:
m_origPlayerTemplate = -1;
m_origStartPos = -1;
m_origColor = -1;
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: