summaryrefslogtreecommitdiff
path: root/src/saveload
AgeCommit message (Collapse)Author
2021-07-02Add: store headers for chunks with SL_STRUCTLISTPatric Stout
2021-07-02Add: store headers for most savegame chunksPatric Stout
When a header is added, the chunk changes from CH_ARRAY type to CH_TABLE type.
2021-07-02Feature: framework to make savegames self-descriptivePatric Stout
We won't be able to make it fully self-descriptive (looking at you MAP-chunks), but anything else can. With this framework, we can add headers for each chunk explaining how each chunk looks like in detail. They also will all be tables, making it a lot easier to read in external tooling, and opening the way to consider a database (like SQLite) to use as savegame format. Lastly, with the headers in the savegame, you can freely add fields without needing a savegame version bump; older versions of OpenTTD will simply ignore the new field. This also means we can remove all the SLE_CONDNULL, as they are irrelevant. The next few commits will start using this framework.
2021-06-26Codechange: instead of "naked" initializer lists, declare the type in the ↵rubidium42
saveload macros This to help variant's constructor to be able to resolve the constructor of the setting
2021-06-17Cleanup: simplify some boolean expressionsRubidium
2021-06-17Cleanup: use true/false instead of 1/0 where applicableRubidium
2021-06-15Codechange: mark chunks that are not stored as CH_READONLYPatric Stout
This makes it easier to spot chunks that have a save_proc that is a nullptr, but also prevents confusion, where it looks like the CH_ type of a chunk has influence on how it is being read. It is not, it is only used for saving.
2021-06-15Change: rework GLOG chunk to be more like the restPatric Stout
Basically it is very similar to Vehicles, where there first is a type field, followed by data of that type. So this commit makes it looks like how Vehicles solved that. This removes a lot of custom "keeping track of length" stuff.
2021-06-15Change: rework several CH_RIFF chunks to use CH_ARRAY insteadPatric Stout
This adds two byte extra to those chunks, and might feel a bit silly at first. But in later changes we will prefix CH_ARRAY with a table header, and then this change shines. Without this, we could still add headers to these chunks, but any external reader wouldn't know if the CH_RIFF has them or not. This way is much more practical, as they are now more like any other chunk.
2021-06-15Codechange: add the ability to save/load a std::vectorPatric Stout
std::vector<bool> is not possible, as .. that is a nice special case in C++. This new type will be used in next commit.
2021-06-15Change: prefix SL_ARR with the length of the arrayPatric Stout
This means that during loading we can validate that what is saved is also that what is expected. Additionally, this makes all list types similar to how they are stored on disk: First a gamma to indicate length, followed by the data. The size still depends on the type.
2021-06-15Codechange: make it more obvious SlArray supports SLE_VAR_NULLPatric Stout
In the end, the code was already doing the right thing, but a few functions deep, and not really obvious. When validating what objects can handle SLE_VAR_NULL, it is nicer to just have this obvious.
2021-06-15Codechange: use SL_NULL if you want to store null-bytes or load to nothingPatric Stout
Using SL_ARR for this gives us a bit of trouble later on, where we add a length-field to SL_ARR. This of course is not the intention of SLE_CONDNULL. So better seperate it.
2021-06-15Change: switch SL_DEQUE and SL_REFLIST length field to a gammaPatric Stout
The current SaveLoad is a bit inconsistent how long a length field is. Sometimes it is a 32bit, sometimes a gamma. Make it consistent across the board by making them all gammas.
2021-06-15Change: indicate in the savegame if a SL_STRUCT contains any dataPatric Stout
This helps external tooling to understand if a SL_STRUCT should be skipped when reading. Basically, this transforms an SL_STRUCT into a SL_STRUCTLIST with either 0 or 1 length.
2021-06-15Change: store length of SL_STRUCTLIST in the savegamePatric Stout
This wasn't consistently done, and often variables were used that were read by an earlier blob. By moving it next to the struct itself, the code becomes a bit more self-contained and easier to read. Additionally, this allows for external tooling to know how many structs to expect, instead of having to know where to find the length-field or a hard-coded value that can change at any moment.
2021-06-14Codechange: use SLE_STRUCT(LIST) for Linkgraph chunksPatric Stout
2021-06-14Codechange: move Save/Load functions of same chunk next to each otherPatric Stout
2021-06-14Codechange: use SLE_STRUCT(LIST) for GameScript chunksPatric Stout
2021-06-14Codechange: use as much of STNN code for STNS as possiblePatric Stout
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.
2021-06-14Codechange: use SLE_STRUCT(LIST) for Station chunksPatric Stout
2021-06-14Codechange: use SLE_STRUCT(LIST) for Company chunksPatric Stout
2021-06-14Codechange: use SLE_STRUCT(LIST) for Town chunksPatric Stout
2021-06-14Codechange: remove the special station/vehicle code from SaveLoadPatric Stout
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.
2021-06-14Codechange: ability to store structs and list of structs in savegamesPatric Stout
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.
2021-06-13Fix 81062163: for (really) old games, station bus/truck station cache was ↵Patric Stout
not updated (#9366)
2021-06-13Codechange: convert printf DEBUG statements to fmt Debug statementsrubidium42
2021-06-10Feature: Configurable subsidy durationTyler Trahan
2021-06-10Codechange: rework CHTS-chunk save/load to be more like the othersPatric Stout
2021-06-10Codechange: rename SL_LST to SL_REFLIST to highlight the "reference" partPatric Stout
You can easily mistake SlList / SL_LST to be a list of SL_VAR, but it is a list of SL_REF. With this rename, it hopefully saves a few people from "wtf?" moments.
2021-06-10Codechange: refactor SlList to use SlStorageHelperPatric Stout
2021-06-10Codechange: refactor SlDequeueHelper to work with unsigned and be more genericPatric Stout
Future additions will start using it for std::list too.
2021-06-10Codechange: use wrappers to get Var[Mem|File]Type, instead of GB()Patric Stout
2021-06-10Codechange: move GetVariableAddress inside SlObjectMemberPatric Stout
Also move it to static, as nobody else is using it.
2021-06-08Fix: compatible NewGRFs in crash-log reported wrong md5 (#9340)Patric Stout
The text suggests it reports the original md5, but it does in fact report the replaced md5. Now it reports both.
2021-06-07Codechange: make [Save|Load]Settings() behave more like other Save/Load code ↵Patric Stout
(#9335) Prepare the full description and send it to SlObject. This does require some code to be able to read to a SLE_VAR_NULL, like strings etc, as there is no way to know their length beforehand.
2021-06-06Codechange: merge guiflags and flags in settings .ini filesPatric Stout
It was rather confusing which one was for what, especially as some SaveLoad flags were settings-only. Clean up this mess a bit by having only Setting flags.
2021-06-06Codechange: move SLF_NO_NETWORK_SYNC into settingsPatric Stout
It is a settings-only flag, so don't pollute SaveLoad code with it.
2021-06-06Codechange: move SLF_NOT_IN_SAVE into settingsPatric Stout
It is a settings-only flag, so don't pollute SaveLoad code with it.
2021-06-06Codechange: remove the unused SLF_HEX flagPatric Stout
2021-06-06Codechange: Remove FOR_ALL_CHUNK_HANDLERSglx22
Co-Authored-By: Patric Stout <truebrain@openttd.org>
2021-06-03Codechange: use "[[maybe_unused]]" instead of a wide variety of other ways ↵Patric Stout
we had While at it, replace OTTD_ASSERT with WITH_ASSERT, as this is always set if assert() is valid. No matter if NDEBUG is set or not.
2021-05-31Codechange: C++-ify lists for SaveLoad (#9323)Patric Stout
Basically, this changes "SaveLoad *" to either: 1) "SaveLoadTable" if a list of SaveLoads was meant 2) "SaveLoad &" if a single entry was meant As added bonus, this removes SL_END / SLE_END / SLEG_END. This also adds core/span.hpp, a "std::span"-lite.
2021-05-30Codechange: add a wrapper function to find all settings based on prefix (#9312)Patric Stout
2021-05-29Codechange: rename str_validate to StrMakeValid(InPlace) (#9304)Patric Stout
This to be more explicit the function changes the value, and not returns yes/no.
2021-05-27Codechange: use initializer_lists for the settings tablesrubidium42
Not using vectors as those require copying from the initializer list and that makes unique_ptrs to the actual SettingDesc objects later impossible.
2021-05-27Codechange: let SettingDesc extend SettingDescBaserubidium42
2021-05-15Change: Use gender-neutral pronounsrubidium42
2021-05-15Fix: empty undocumented branchesrubidium42
2021-05-15Fix: comparison of narrow type to wide type in loop (potential for infinite ↵Rubidium
loops)