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
Codechange: add and use the ability to store (lists of) structs in savegames #9339
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rubidium42
reviewed
Jun 7, 2021
TrueBrain
force-pushed
the
saveload-sub-struct
branch
11 times, most recently
from
June 11, 2021 07:15
2a20061
to
2178bdf
Compare
TrueBrain
force-pushed
the
saveload-sub-struct
branch
from
June 14, 2021 07:26
2178bdf
to
c4be800
Compare
TrueBrain
force-pushed
the
saveload-sub-struct
branch
from
June 14, 2021 14:13
c4be800
to
02146c8
Compare
TrueBrain
force-pushed
the
saveload-sub-struct
branch
from
June 14, 2021 14:44
02146c8
to
bb42b19
Compare
rubidium42
reviewed
Jun 14, 2021
The commits following this will use this new functionality. Currently, a few places do this manually. This has as drawback that the Save() and Load() code need to be in sync, and that any change can result in (old) savegames no longer loading. In general, it is annoying code to maintain. By putting everything in a description table, and use that for both Save() and Load(), it becomes easier to see what is going on, and hopefully less likely for people to make mistakes.
TrueBrain
force-pushed
the
saveload-sub-struct
branch
from
June 14, 2021 15:19
bb42b19
to
4229a0d
Compare
rubidium42
reviewed
Jun 14, 2021
With the new SLEG_STRUCT it is much easier to embed a struct in a struct, where the sub-struct has limitations on when it is being used. This makes both the code easier to read (less magic) and avoids the SaveLoad needing to know all these things about Stations and Vehicles.
There was a lot of code duplication for no real reason. Now with SLEG_STRUCT support, we can just re-use the code, hopefully making it easier for future-us to make changes to this, without breaking everything for old games.
TrueBrain
force-pushed
the
saveload-sub-struct
branch
from
June 14, 2021 17:49
4229a0d
to
f08773e
Compare
rubidium42
approved these changes
Jun 14, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
In a few places (stations, vehicles, towns, companies, ..) the SaveLoad code needs to handle either structs in structs, or lists of structs in structs.
This is all done manually, and not only hard to read, also easy to mess up.
Description
Introduce
SL_STRUCT
andSL_STRUCTLIST
to embed a struct in another struct.For example, for Vehicles it used to have a special
SL
command to embed the common vehicle structure. This meant that SaveLoad needed to know about Vehicles.Now, the common vehicle sub-struct is called
SlVehicleCommon
and to save it you can use:This works with structs in structs in structs in structs in structs in ... just fine too.
NOTE: I made several commits to introduce
SL_STRUCT
in the rest of the code, as I am hoping that makes reviewing easier.NOTE 2: I left a lot of odd constructs in there, just to make review easier. The code really could use a cleanup, but .. I am trying not to do everything at once, also for my own sanity :D
NOTE 3: there should be no difference before or after this PR in respect to what is written/loaded from disk.
Limitations
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.