-
Notifications
You must be signed in to change notification settings - Fork 229
fix(object): Save and load game object list in correct order #2161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
e4dc439
d342157
61a136a
3d0f067
964c0c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4241,13 +4241,14 @@ void GameLogic::prepareLogicForObjectLoad( void ) | |
| * this version breaks compatibility with previous versions. (CBD) | ||
| * 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: Save objects in reverse order so they load in correct order. Reverse object list for old saves. | ||
| */ | ||
| // ------------------------------------------------------------------------------------------------ | ||
| void GameLogic::xfer( Xfer *xfer ) | ||
| { | ||
|
|
||
| // version | ||
| const XferVersion currentVersion = 9; | ||
| const XferVersion currentVersion = 10; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if an old game tries to load a new save it will just fail gracefully. I don't think this will be an issue - if someone asks a friend with TSH to create a .sav and share it with them maybe? But why would that ever happen? If we need to be able to load new saves on old game, we could use RETAIL_COMPATIBLE_XFER_SAVE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I think the way it would work is that version 10 isn't known by retail and isn't checked so it will load the list the same way it always did which will be the new correct order for saves saved after this version, the old incorrect order for save from before this. This new version checks on load so the order loaded will be correct for builds after this PR is merged no matter what version wrote the save. |
||
| XferVersion version = currentVersion; | ||
| xfer->xferVersion( &version, currentVersion ); | ||
|
|
||
|
|
@@ -4281,7 +4282,13 @@ void GameLogic::xfer( Xfer *xfer ) | |
| if( xfer->getXferMode() == XFER_SAVE ) | ||
| { | ||
|
|
||
| // TheSuperHackers @bugfix bobtista 27/01/2026 Save objects in reverse order (newest first) | ||
| // so they load in the correct order (oldest objects at head of list). | ||
| Object *lastObj = nullptr; | ||
| for( obj = getFirstObject(); obj; obj = obj->getNextObject() ) | ||
| lastObj = obj; | ||
|
xezon marked this conversation as resolved.
|
||
|
|
||
| for( obj = lastObj; obj; obj = obj->getPrevObject() ) | ||
| { | ||
|
|
||
| // get the object TOC entry for this template | ||
|
|
@@ -4364,6 +4371,25 @@ void GameLogic::xfer( Xfer *xfer ) | |
|
|
||
| } | ||
|
|
||
| // TheSuperHackers @bugfix bobtista 27/01/2026 Reverse object list for old saves. | ||
|
bobtista marked this conversation as resolved.
Outdated
|
||
| // Old saves stored objects oldest-first, which results in reversed order when loaded | ||
| // since objects are prepended during creation. Version 10+ saves in reverse order. | ||
| if ( version < 10 ) | ||
|
xezon marked this conversation as resolved.
Outdated
|
||
| { | ||
| Object *prev = nullptr; | ||
| Object *current = m_objList; | ||
| Object *next = nullptr; | ||
| while ( current != nullptr ) | ||
| { | ||
| next = current->getNextObject(); | ||
| current->friend_setNextObject( prev ); | ||
| current->friend_setPrevObject( next ); | ||
| prev = current; | ||
| current = next; | ||
| } | ||
| m_objList = prev; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // campaign info | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.