Commit Graph

46 Commits

Author SHA1 Message Date
Rubidium c9276c2959 Codechange: replace x.size() == 0 with x.empty() 2023-10-20 23:05:43 +02:00
Rubidium eaae0bb5e7 Codechange: automatic adding of _t to (u)int types, and WChar to char32_t
for i in `find src -type f|grep -v 3rdparty/fmt|grep -v 3rdparty/catch2|grep -v 3rdparty/opengl|grep -v stdafx.h`; do sed 's/uint16& /uint16 \&/g;s/int8\([ >*),;[]\)/int8_t\1/g;s/int16\([ >*),;[]\)/int16_t\1/g;s/int32\([ >*),;[]\)/int32_t\1/g;s/int64\([ >*),;[]\)/int64_t\1/g;s/ uint32(/ uint32_t(/g;s/_uint8_t/_uint8/;s/Uint8_t/Uint8/;s/ft_int64_t/ft_int64/g;s/uint64$/uint64_t/;s/WChar/char32_t/g;s/char32_t char32_t/char32_t WChar/' -i $i; done
2023-07-19 19:30:14 +02:00
PeterN 078e27bd84
Fix #10619: Crash loading linkgraph for older savegames. (#10620) 2023-04-09 19:28:55 +01:00
Michael Lutz aab580e0ac Codechange: [Linkgraph] Drop node/edge wrappers from LinkGraph. 2023-02-26 21:41:24 +01:00
Michael Lutz 7352f812e6 Codechange: [Linkgraph] Only store present link graph edges and not all possible edges. 2023-02-26 21:41:24 +01:00
Michael Lutz fe27db3dfd Codechange: [Linkgraph] Store edges in each node and not in a global matrix. 2023-02-26 21:41:24 +01:00
Nicolas Chappe 977604ef08 Feature: [Linkgraph] Prioritize faster routes for passengers, mail and express cargo
Passengers usually prefer fast paths to short paths.
Average travel times of links are updated in real-time for use in Dijkstra's algorithm,
and newer travel times weigh more, just like capacities.
2021-08-17 14:57:59 +02:00
Patric Stout 8f5d0ecde3
Codechange: split settings.ini over several files (#9421)
This reduced the load on compilers, as currently for example MacOS
doesn't like the huge settings-tables.

Additionally, nobody can find settings, as the list is massive and
unordered. By splitting it, it becomes a little bit more sensible.
2021-07-09 21:16:03 +02:00
glx22 6e627f35ac Cleanup: Remove now unneeded ChunkHandler members 2021-07-06 22:29:08 +02:00
glx22 2c941cd8b3 Codechange: Use ChunkHandlers sub-classes 2021-07-06 22:29:08 +02:00
glx22 c1a9fe6fbd Codechange: Use static array of references to ChunkHandler 2021-07-06 22:29:08 +02:00
Patric Stout 3826703bc3 Add: store headers for chunks with SL_STRUCTLIST 2021-07-02 22:21:58 +02:00
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.
2021-07-02 22:21:58 +02:00
Patric Stout 88edfd4ef1 Change: rework several CH_RIFF chunks to use CH_ARRAY instead
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-15 19:36:15 +02:00
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.
2021-06-15 16:45:04 +02:00
Patric Stout 7b135a8269 Codechange: use SLE_STRUCT(LIST) for Linkgraph chunks 2021-06-14 21:58:05 +02:00
Patric Stout 5cd0c65787 Codechange: move Save/Load functions of same chunk next to each other 2021-06-14 21:58:05 +02:00
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.
2021-06-10 19:18:24 +02:00
glx22 c27afdf3f6 Codechange: Remove FOR_ALL_CHUNK_HANDLERS
Co-Authored-By: Patric Stout <truebrain@openttd.org>
2021-06-06 19:35:06 +02:00
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.
2021-05-31 22:26:44 +02:00
Patric Stout 0c96884700
Codechange: add a wrapper function to find all settings based on prefix (#9312) 2021-05-30 10:55:52 +02:00
rubidium42 3bb6ce8827 Codechange: use initializer_lists for the settings tables
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-27 18:49:43 +02:00
rubidium42 425d50372f Codechange: let SettingDesc extend SettingDescBase 2021-05-27 18:49:43 +02:00
Rubidium bb9121dbd4 Fix: comparison of narrow type to wide type in loop (potential for infinite loops) 2021-05-15 10:16:10 +02:00
Milek7 aade177d79
Fix: Corrupted savegame could cause heap corruption by writing outside link graph edge matrix. (#9046) 2021-04-17 19:19:37 +01:00
Michael Lutz 7845434270 Codechange: Don't use cpp_offsetof in the save/load code.
Many of the member variables that are used in save/load are inside types
that are not standard layout types. Using pointer arithmetics to determine
addresses of members inside types that are not standard layout is generally
undefined behaviour. If we'd use C++17, it is conditionally supported, which means
each compiler may or may not support it. And even then using it for individual
array elements is syntactically not supported the the standard offsetof function.

Unfortunately, the trickery employed for saving linkgraph settings causes quite some
clutter in the settings ini files.
2021-02-13 20:08:53 +01:00
Jonathan G Rennison 0c5dc5d41e Change: [Linkgraph] Pause the game when linkgraph jobs lag (#6470)
Check if the job is still running two date fract ticks before it is due
to join, and if so pause the game until its done.
When loading a game, check if the game would block immediately due to
a job which is scheduled to be joined within two date fract ticks,
and if so pause the game until its done.
This avoids the main thread being blocked on a thread join, which appears
to the user as if the game is unresponsive, as the UI does not repaint
and cannot be interacted with.
Show if pause is due to link graph job in status bar, update network
messages.
This does not apply for network clients.
2020-12-22 15:17:57 +01:00
glx 09fa39c5b5 Codechange: Replace linkgraph related FOR_ALL with range-based for loops 2019-12-21 20:13:03 +01:00
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 2019-11-10 17:59:20 +00:00
PeterN 83c1678f9e
Fix #7577: Check if linkgraph station index is valid before dereferencing. (#7583) 2019-05-10 21:36:03 +01:00
peter1138 4f052fc2a4 Cleanup: Fix alignment after NULL -> nullptr change. 2019-04-13 20:35:10 +01:00
Henry Wilson 7c8e7c6b6e Codechange: Use null pointer literal instead of the NULL macro 2019-04-10 23:22:20 +02:00
Henry Wilson c01a2e2a81 Codechange: Removed SmallVector completely 2019-03-26 20:15:57 +00:00
Henry Wilson a0f36a50e6 Codechange: Replaced SmallVector::Append() with std::vector::[push|emplace]_back() 2019-03-26 20:15:57 +00:00
Henry Wilson a690936ed7 Codechange: Replace SmallVector::Length() with std::vector::size() 2019-03-26 20:15:57 +00:00
Peter Nelson 9de12521ec Codechange: Convert saveload numbers to enum values.
(This was mostly achieved with a few in-place regexes)
2019-02-02 21:39:06 +00:00
Peter Nelson ea4ea62816 Codechange: Make saveload version upper bound exclusive, i.e. version object was removed instead of version object last appeared. 2019-02-02 21:39:06 +00:00
Charles Pigott f5b1115039 Doc: Lots and lots of doxymentation fixes 2018-10-31 12:35:54 +01:00
frosch 780e595933 (svn r27178) -Fix [FS#5969]: Data race due to lazy initialisation of objects. 2015-03-07 18:27:01 +00:00
fonsinchen 957f5ca117 (svn r26646) -Fix [FS#6041]: Save locations instead of distances in link graphs to reduce size. 2014-06-14 13:35:39 +00:00
rubidium 9270d94e7e (svn r26589) -Fix: SIGSEGV on all big endian architectures that tried to load e.g. the 1.4 intro game or anything else with more than 0 linkgraph nodes that was saved on little endian 2014-05-16 17:38:59 +00:00
rubidium 0463dbdc9e (svn r26482) -Codechange: add an include that allows us to undefine/redefine "unsafe" functions to prevent them from being used, and thus having to care about certain aspects of their return values 2014-04-23 20:13:33 +00:00
fonsinchen 29e987f3fc (svn r25898) -Codechange: Add second timestamp for 'restricted links' to all edges. 2013-10-22 16:13:28 +00:00
fonsinchen ec2d36a4a4 (svn r25897) -Fix: Dates are int32, not uint32, and should be saved as such. 2013-10-22 16:12:08 +00:00
fonsinchen 3d0a0e8e48 (svn r25358) -Codechange: save and load link graph jobs and the schedule 2013-06-09 13:02:05 +00:00
rubidium 0cc3d8df4b (svn r25258) -Codechange: save linkgraph (fonsinchen) 2013-05-19 14:17:02 +00:00