Commit Graph

515 Commits

Author SHA1 Message Date
Rubidium c71f06e59b Feature: parse the console settings the same way as config settings
Now you can use things like `set server_game_type public` instead of having to
guess the number, which would not be written into the configuration file nor
would it be shown when doing `set server_game_type`.
2021-07-11 23:11:05 +02:00
Rubidium 178ea3196b Remove: includes to network/core/config.h from headers when only three cpp files need it 2021-07-11 22:13:59 +02:00
Rubidium f6955a304c Fix: ensure no more than the allowed number of NewGRFs are loaded from the configuration 2021-07-11 11:20:07 +02:00
Rubidium 01139d3368 Codechange: access the name of a setting via an accessor function 2021-07-09 22:53:30 +02:00
glx22 89ab8b79a5 Codechange: Remove FOR_EACH_SET_BIT 2021-07-09 21:36:09 +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
Rubidium 7e7a4aad72 Codechange: split off the settings saveload code from the main settings handling logic 2021-07-06 21:32:47 +02:00
rubidium42 25ca6a75bc Codechange: split off the settings table and all the callbacks from the main settings handling logic 2021-07-06 21:32:47 +02:00
glx22 b4aedc8bee Codechange: ensure xxx_setting_tables are initialised after their content 2021-07-06 21:32:47 +02:00
Patric Stout cdb3dd0493 Add: store headers for most savegame chunks
When a header is added, the chunk changes from CH_ARRAY type to
CH_TABLE type.
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 75b6051b7a Change: move sensitive information to secrets.cfg and private information to private.cfg
We often ask people for their openttd.cfg, which now includes their
passwords, usernames, etc. It is easy for people to overlook this,
unwillingly sharing information they shouldn't.

By splitting this information over either private.cfg or secrets.cfg,
we make it more obvious they shouldn't be sharing those files, and
hint to what is inside them.
2021-07-02 14:30:14 +02:00
Patric Stout 4f3bf84af4 Codechange: simplify SaveVersionInConfig()
Clearly someone really wanted to generalize the function, but
in reality it makes it a lot longer than needed. Let's keep it
simple.
2021-07-02 14:30:14 +02:00
Patric Stout 66dc0ce196 Codechange: C++-ify the usage of IniFile in settings.cpp
Instead of creating the object on heap and use a pointer, create
the object on stack and use a guaranteed-not-null pointer.
The size of IniFile doesn't warrent the forcing to heap.

Additionally, use a subclass instead of a function to do some
initial bookkeeping on an IniFile meant to read a configuration.
2021-07-02 14:30:14 +02:00
Patric Stout a42251fc72 Codechange: move network-related settings out of settings.ini
This to prepare the code to split up network-related settings
into private / secrets / generic.
2021-07-02 14:30:14 +02:00
SamuXarick 003b6a0c85
Fix ea9715d: not all setting values were clamped properly (#9401) 2021-06-28 00:58:54 +02:00
rubidium42 98e653dacc Fix #9386: compilers failing to compile with LTO by using variants instead of new + unique_ptr
With std::variant all memory can be figured out at compile time, so the compiler needs to keep track of fewer elements. It also saves out a unique_ptr and its memory management, over a slight impact for resolving a setting.
2021-06-26 20:28:34 +02:00
rubidium42 c93fcbcb28 Codechange: introduce helper to convert from the iterated type to the actual SettingDesc 2021-06-26 20:28:34 +02:00
rubidium42 f029fd0f3b Codechange: remove overloading on UpdateServiceInterval
One UpdateServiceInterval has two parameters to update the service interval for a vehicle type, the other for all vehicle types at once. Rename the latter to help with function resolution for the introduction of variants.
2021-06-26 20:28:34 +02:00
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.
2021-06-15 19:36:15 +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
Rubidium d31a535c87 Cleanup: remove some unneeded c_str() calls 2021-06-15 06:13:00 +02:00
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.
2021-06-14 21:58:05 +02:00
rubidium42 eb6cdadc4d Codechange: replace IConsolePrintF with IConsolePrint and fmt formatting
Also make some strings more consistent with the rest of the console strings.
2021-06-13 15:25:31 +02:00
rubidium42 efd4ba4797 Change: unify the style of console error messages and convert to fmt
Always start with a capital, do not add "ERROR: " in front of it.
2021-06-13 15:25:31 +02:00
rubidium42 55a11710a6 Codechange: convert printf DEBUG statements to fmt Debug statements 2021-06-13 12:45:45 +02:00
rubidium42 bf500c39c9 Codechange: make the name of SettingDesc a std::string 2021-06-13 10:26:58 +02:00
rubidium42 ca9c50607e Codechange: use StrStartsWith/StrEndsWith when finding settings 2021-06-13 10:26:58 +02:00
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.
2021-06-07 23:03:12 +02:00
Patric Stout 648ee88a02 Codechange: merge guiflags and flags in settings .ini files
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-06 21:45:01 +02:00
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.
2021-06-06 21:45:01 +02:00
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.
2021-06-06 21:45:01 +02:00
Patric Stout 7572603c9d Codechange: remove the unused SLF_HEX flag 2021-06-06 21:45:01 +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 feb2ddbefa
Codechange: rename SettingGuiFlag to SettingFlag (#9332)
It is a lovely organicly grown enum, where it started off with
GUI-only flags, and after that a few flags got added that can be
considered GUI-only (the GUI disables/enables based on them), to
only have flags added that has nothing to do with the GUI.

So be less confusing, and rename them to what they do.

Additionally, I took this opportunity to rename 0ISDISABLED to
reflect what it really does.
2021-06-03 21:18:29 +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
Patric Stout e9e4588db1
Codechange: use setting name instead of index for HandleOldDiffCustom() (#9311) 2021-05-30 10:40:59 +02:00
Patric Stout d70fb74ac6
Codechange: use setting name instead of index for CmdChange(Company)Setting (#9306)
This is mostly done as there are now constraints on settings.ini you might not
expected. For example, conditional settings always have to come last, as otherwise
they would influence the index.
2021-05-29 23:27:01 +02:00
glx22 5799402f7a Codechange: Rename window related DeleteXXX to match new behaviour 2021-05-29 21:08:25 +02:00
rubidium42 ef991b1772 Codechange: [Network] Use std::string in CommandPacket 2021-05-29 19:02:18 +02:00
rubidium42 2e136285e1 Codechange: move from C-string to std::string for DoCommand 2021-05-29 19:02:18 +02:00
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.
2021-05-29 11:21:38 +02:00
rubidium42 08308d808c Codechange: use separate pre and post callbacks for int settings 2021-05-29 10:07:30 +02:00
rubidium42 e2f5d9e561 Codechange: use separate pre and post callbacks for string settings 2021-05-29 10:07:30 +02:00
rubidium42 ea9715d970 Codechange: split Write_ValidateSetting to get separate functions for making ints valid and writing ints 2021-05-29 10:07:30 +02:00
rubidium42 208952f2ba Codechange: split Write_ValidateSetting to get separate functions for making strings valid and writing strings 2021-05-29 10:07:30 +02:00
rubidium42 8372c679e3 Codechange: add helper functions to read an int setting value 2021-05-27 18:49:43 +02:00
rubidium42 86c9ef8134 Codechange: remove SettingDescType in lieu of the actual classes 2021-05-27 18:49:43 +02:00
rubidium42 e666a962b1 Codechange: let OneOfMany and ManyOfMany be their own classes as well 2021-05-27 18:49:43 +02:00