Commit Graph

353 Commits (56085be9bda8d5682c15544a058d988a6ae00b3b)

Author SHA1 Message Date
Peter Nelson 56085be9bd Codechange: Move includes for common STL headers to stdafx. 1 year ago
Rubidium e9c03f0dad Cleanup: remnants of C-style strings in saveload 1 year ago
Rubidium 68ff3fd062 Change: include fmt.h C++ headers in stdafx.h
This to prevent compilation issues between runs with and without precompiled
headers. Also remove the headers from the rest of the code base as they are
not needed there anymore, although they do relatively little harm.
1 year ago
Tyler Trahan 6501f84b4a
Codechange: Move calendar date functions inside TimerGameCalendar (#10753) 1 year ago
Patric Stout 018a26d9b6
Fix: crash in emscripten when saving games (#10758)
Don't allocate 128KB on stack, but rather on the heap.
1 year ago
Peter Nelson 00bf42353a Codechange: Place gamelog into its own class, along with internal data.
Data is now stored in vectors to avoid manual memory management and
passing lengths around.
1 year ago
Rubidium 1f3b7e2efd Codechange: use std::string instead of stredup for saveload error messages 1 year ago
Rubidium ee723f26ba Codechange: Make FileToSaveLoad's title std::string and simplify assignments 1 year ago
Patric Stout 7aa2b9ab0a
Codechange: move all date-related variables inside the timer (#10706) 1 year ago
Charles Pigott b282664242 Codechange: Replace all usages of alloca/AllocaM with more modern/less discouraged alternatives 1 year ago
Charles Pigott ce24709576 Add: Some additional debugging information when chunk sizes are incorrect 1 year ago
Charles Pigott 8aea13a85b Codechange: Use fmt for SlErrorCorruptFmt 1 year ago
Rubidium 4e65ec1dc4 Codechange: do not declare functions in blocks 1 year ago
rubidium42 1951af07c0 Codechange: do not hide parameters with local variables 1 year ago
PeterN 961e66df30
Fix #10224: Don't fiddle with fast-forward when saving. (#10230)
The original comment about saving with fast-forward on was written 18 years
ago, and predates lots of changes to how saveload work.
1 year ago
Loïc Guilloux 4f9893cc98
Fix 55a1171: Restore skipping of "colour" character (#10244) 1 year ago
dP 5e14a20b3b
Feature: [GS] Scriptable league tables (#10001) 2 years ago
Loïc Guilloux 460991ecf4
Feature: Persistant rotation of numbered auto/netsave after restart (#9397)
It was always starting from 0 on openttd restart.
Now the most recent auto/netsave number will be used as a base to generate the next filename.
3 years ago
Stephan a70aa5df49
Add #9188: netsave now keeps multiple version around, similar to autosave (#9395) 3 years ago
Patric Stout c1f13e0372
Fix: reduce the amount of debug messages on -dsl=2 (#9420)
LoadCheck makes it sound like something is really broken while
loading savegames, while it really is perfectly normal, as most
chunks do not implement LoadCheck.
3 years ago
glx22 6e627f35ac Cleanup: Remove now unneeded ChunkHandler members 3 years ago
glx22 c1a9fe6fbd Codechange: Use static array of references to ChunkHandler 3 years ago
glx22 f371a5ad70 Codechange: Preparation for ChunkHandler subclassing 3 years ago
Patric Stout 7dd5fd6ed4 Feature: framework to make savegames self-descriptive
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.
3 years ago
Patric Stout 8e91527251 Codechange: mark chunks that are not stored as CH_READONLY
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.
3 years ago
Patric Stout b9ab9e4d05 Codechange: add the ability to save/load a std::vector
std::vector<bool> is not possible, as .. that is a nice special
case in C++.

This new type will be used in next commit.
3 years ago
Patric Stout 97b94bdc9a Change: prefix SL_ARR with the length of the array
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.
3 years ago
Patric Stout f67af5cbe5 Codechange: make it more obvious SlArray supports SLE_VAR_NULL
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.
3 years ago
Patric Stout d5cda58158 Codechange: use SL_NULL if you want to store null-bytes or load to nothing
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.
3 years ago
Patric Stout 0d2e3437e3 Change: switch SL_DEQUE and SL_REFLIST length field to a gamma
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.
3 years ago
Patric Stout 75e7451151 Change: indicate in the savegame if a SL_STRUCT contains any data
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.
3 years ago
Patric Stout a146bcfe93 Change: store length of SL_STRUCTLIST in the savegame
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.
3 years ago
Patric Stout 4e4720f217 Codechange: remove the special station/vehicle code from SaveLoad
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.
3 years ago
Patric Stout 4600d289b5 Codechange: ability to store structs and list of structs in savegames
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.
3 years ago
rubidium42 55a11710a6 Codechange: convert printf DEBUG statements to fmt Debug statements 3 years ago
Patric Stout 8f323855b1 Codechange: rename SL_LST to SL_REFLIST to highlight the "reference" part
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.
3 years ago
Patric Stout aa6443d57a Codechange: refactor SlList to use SlStorageHelper 3 years ago
Patric Stout 23857af693 Codechange: refactor SlDequeueHelper to work with unsigned and be more generic
Future additions will start using it for std::list too.
3 years ago
Patric Stout a2147d437e Codechange: use wrappers to get Var[Mem|File]Type, instead of GB() 3 years ago
Patric Stout fba86f711f Codechange: move GetVariableAddress inside SlObjectMember
Also move it to static, as nobody else is using it.
3 years ago
Patric Stout 1e564b333f
Codechange: make [Save|Load]Settings() behave more like other Save/Load code (#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.
3 years ago
Patric Stout 264991dfa5 Codechange: move SLF_NO_NETWORK_SYNC into settings
It is a settings-only flag, so don't pollute SaveLoad code with it.
3 years ago
Patric Stout 414e12d26b Codechange: move SLF_NOT_IN_SAVE into settings
It is a settings-only flag, so don't pollute SaveLoad code with it.
3 years ago
glx22 c27afdf3f6 Codechange: Remove FOR_ALL_CHUNK_HANDLERS
Co-Authored-By: Patric Stout <truebrain@openttd.org>
3 years ago
Patric Stout 28e90769f7 Codechange: use "[[maybe_unused]]" instead of a wide variety of other ways 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.
3 years ago
Patric Stout 9fff00ba20
Codechange: C++-ify lists for SaveLoad (#9323)
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.
3 years ago
Patric Stout ca9a7df752
Codechange: rename str_validate to StrMakeValid(InPlace) (#9304)
This to be more explicit the function changes the value, and not
returns yes/no.
3 years ago
rubidium42 44ca7d9377 Change: Use gender-neutral pronouns 3 years ago
rubidium42 0f062b3882 Codechange: clean up C-string support from settings 3 years ago
rubidium42 95386dc2b8 Codechange: move misc settings to std::string 3 years ago