The current preferences handling is a mess:
* it's essentially a global config object that anything can modify in any way the caller wants, which is managed across multiple source files which have their own oddities and interdependencies.
* the general preferences has its own bit of SDL event handling and while I get the idea behind `events::sdl_handler` there's no reason to have SDL events handled in the preferences instead of just calling the relevant preferences setter for each event when it happens.
* the general preferences is where most of the preferences are handled and has its `base_manager` struct, which is part of the `manager` struct in the game preferences, which is then implicitly initialized as part of game_launcher's constructor.
* the editor preferences are the only preferences in a sub-namespace `preferences::editor` while all other preferences are just in the `preferences` namespace.
* the display, editor, and lobby preferences are all dependent on including the game preferences, the credentials are dependent on including the general preferences (but not the game preferences), the game preferences are dependent on including the general preferences, and the advanced preferences are entirely their own thing which is dependent on none of the other preference functionality and manages its own singleton.
* nothing checks whether the preferences file has actually been loaded before allowing values to be read from or written to the preferences config - if you attempt to get a value too early in wesnoth's initialization it will silently just give you whatever the default value for that preference happens to be.
With this there is instead a single access point (with exceptions handled via friend functions/classes), all predefined preferences are accessed via their own setter/getter, and all mainline preferences are defined in a single file (preference_list.hpp) so it's easily findable what preferences exist and where they're used. Having the list of all mainline preferences listed out also allows the lua preferences API to provide that full list rather than just the list of the preferences that have been set so far. Also it now checks for whether the location of the preferences file is known before attempting to load the preferences file and asserts if someone attempts to use the preferences too early.
These will be changed to conditionally include system Lua headers,
e.g. "lua.h", instead of submodule Lua headers, e.g. "module/lua/lua.h".
If a header named "lua.h" includes "lua.h", the build will fail due to
recursion.
This can't be solved using angle brackets to include system headers,
because macos builds won't find them:
In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/registry.cpp:30:
In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/composite/aspect.hpp:24:
In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/lua/lua_object.hpp:25:
/Users/runner/work/wesnoth/wesnoth/src/lua/lua.h:4:14: error: 'lua.h' file not found with <angled> include; use "quotes" instead
#include <lua.h>
^~~~~~~
"lua.h"
Renamed with (requires GNU sed):
$ for f in src/lua/*.h; do
> git mv "${f}" "src/lua/wrapper_${f#src/lua/}";
> done
$ git grep -El -- '#[ \t]*include[ \t]+"lua/[^"]+[.]h"' src | \
> xargs sed -Ei -- '
> s|(#[ \t]*include[ \t]+"lua/)(lua[.]h")( )?|\1wrapper_\2|;
> s|(#[ \t]*include[ \t]+"lua/)(lualib[.]h")( )?|\1wrapper_\2|;
> s|(#[ \t]*include[ \t]+"lua/)(lauxlib[.]h")( )?|\1wrapper_\2|;
> '
Note that using it on wesnoth.preferences only returns preferences that are currently set and may omit some preferences that are possible but currently unset. However, it DOES include all registered advanced preferences even if they are unset.
This additionally:
* Makes all copyright notices identical aside from the starting year for Wesnoth-specific source files. Files not included: mariadbpp, lua, spirit po, xbrz, and bcrypt (crypt_blowfish).
* Removes all attribution from the files, since the vast majority of them are outdated or seemingly just outright incorrect. For example, I would guess that Dave is no longer the sole author of the majority of Wesnoth's current code.
Change all includes to start at the base instead of assuming the directory where included from.
This makes it more apparent exactly which header has been included, since many have the same name.
This also allows moving all header files out of the src directory.
* Changed the plugin preference API to use luaW_pushscalar() and
luaW_toscalar() to handle preference values.
* Set the __metatable field in the "preferences" table, which blocks Lua
code from changing the metatable and allows developers to query where the
metatable originates.
* Added empty lines to the end of new files.