summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/settings.cpp5
-rw-r--r--src/settings_internal.h3
-rw-r--r--src/table/settings.h.preamble2
-rw-r--r--src/table/settings/company_settings.ini2
-rw-r--r--src/table/settings/currency_settings.ini2
-rw-r--r--src/table/settings/gameopt_settings.ini2
-rw-r--r--src/table/settings/misc_settings.ini2
-rw-r--r--src/table/settings/settings.ini2
-rw-r--r--src/table/settings/win32_settings.ini2
-rw-r--r--src/table/settings/window_settings.ini2
10 files changed, 13 insertions, 11 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 5e3ba5be7..9d0e125b0 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -87,6 +87,7 @@ std::string _config_file; ///< Configuration file of OpenTTD
typedef std::list<ErrorMessageData> ErrorList;
static ErrorList _settings_error_list; ///< Errors while loading minimal settings.
+typedef span<const SettingVariant> SettingTable;
typedef void SettingDescProc(IniFile *ini, const SettingTable &desc, const char *grpname, void *object, bool only_startup);
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
@@ -98,9 +99,9 @@ static bool IsSignedVarMemType(VarType vt);
* @param desc The type of the iterator of the value in SettingTable.
* @return The actual pointer to SettingDesc.
*/
-static const SettingDesc *GetSettingDesc(const std::unique_ptr<const SettingDesc> &desc)
+static constexpr const SettingDesc *GetSettingDesc(const SettingVariant &desc)
{
- return desc.get();
+ return std::visit([](auto&& arg) -> const SettingDesc * { return &arg; }, desc);
}
/**
diff --git a/src/settings_internal.h b/src/settings_internal.h
index 5b35d328a..0e6637a5b 100644
--- a/src/settings_internal.h
+++ b/src/settings_internal.h
@@ -10,6 +10,7 @@
#ifndef SETTINGS_INTERNAL_H
#define SETTINGS_INTERNAL_H
+#include <variant>
#include "saveload/saveload.h"
enum SettingFlag : uint16 {
@@ -299,7 +300,7 @@ struct NullSettingDesc : SettingDesc {
bool IsSameValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
};
-typedef std::initializer_list<std::unique_ptr<const SettingDesc>> SettingTable;
+typedef std::variant<IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc> SettingVariant;
const SettingDesc *GetSettingFromName(const std::string_view name);
void GetSettingSaveLoadByPrefix(const std::string_view prefix, std::vector<SaveLoad> &saveloads);
diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble
index c9b47626c..5fd1a9bac 100644
--- a/src/table/settings.h.preamble
+++ b/src/table/settings.h.preamble
@@ -54,7 +54,7 @@ static size_t ConvertLandscape(const char *value);
* on the appropriate macro.
*/
-#define NSD(type, ...) std::unique_ptr<const SettingDesc>(new type##SettingDesc(__VA_ARGS__))
+#define NSD(type, ...) SettingVariant { std::in_place_type<type##SettingDesc>, __VA_ARGS__ }
/* Macros for various objects to go in the configuration file.
* This section is for global variables */
diff --git a/src/table/settings/company_settings.ini b/src/table/settings/company_settings.ini
index 71f99d5a2..e5019305f 100644
--- a/src/table/settings/company_settings.ini
+++ b/src/table/settings/company_settings.ini
@@ -12,7 +12,7 @@ static void UpdateAllServiceInterval(int32 new_value);
static bool CanUpdateServiceInterval(VehicleType type, int32 &new_value);
static void UpdateServiceInterval(VehicleType type, int32 new_value);
-static const SettingTable _company_settings{
+static const SettingVariant _company_settings[] = {
[post-amble]
};
[templates]
diff --git a/src/table/settings/currency_settings.ini b/src/table/settings/currency_settings.ini
index c8ba3d76c..d0950db8e 100644
--- a/src/table/settings/currency_settings.ini
+++ b/src/table/settings/currency_settings.ini
@@ -7,7 +7,7 @@
; Settings for the in-game custom currency.
[pre-amble]
-static const SettingTable _currency_settings{
+static const SettingVariant _currency_settings[] = {
[post-amble]
};
[templates]
diff --git a/src/table/settings/gameopt_settings.ini b/src/table/settings/gameopt_settings.ini
index ce28def63..447400623 100644
--- a/src/table/settings/gameopt_settings.ini
+++ b/src/table/settings/gameopt_settings.ini
@@ -33,7 +33,7 @@ static std::initializer_list<const char*> _osk_activation{"disabled", "double",
static std::initializer_list<const char*> _settings_profiles{"easy", "medium", "hard"};
static std::initializer_list<const char*> _news_display{ "off", "summarized", "full"};
-static const SettingTable _gameopt_settings{
+static const SettingVariant _gameopt_settings[] = {
/* In version 4 a new difficulty setting has been added to the difficulty settings,
* town attitude towards demolishing. Needs special handling because some dimwit thought
* it funny to have the GameDifficulty struct be an array while it is a struct of
diff --git a/src/table/settings/misc_settings.ini b/src/table/settings/misc_settings.ini
index 453c6e816..9f73573b2 100644
--- a/src/table/settings/misc_settings.ini
+++ b/src/table/settings/misc_settings.ini
@@ -20,7 +20,7 @@ extern bool _allow_hidpi_window;
#define WITHOUT_COCOA
#endif
-static const SettingTable _misc_settings{
+static const SettingVariant _misc_settings[] = {
[post-amble]
};
[templates]
diff --git a/src/table/settings/settings.ini b/src/table/settings/settings.ini
index 6fe4d9d51..a0a835364 100644
--- a/src/table/settings/settings.ini
+++ b/src/table/settings/settings.ini
@@ -49,7 +49,7 @@ static void UpdateClientConfigValues();
* assigns its own value. If the setting was company-based, that would mean that
* vehicles could decide on different moments that they are heading back to a
* service depot, causing desyncs on a massive scale. */
-const SettingTable _settings{
+static const SettingVariant _settings[] = {
[post-amble]
};
[templates]
diff --git a/src/table/settings/win32_settings.ini b/src/table/settings/win32_settings.ini
index df1e0cb27..51b579629 100644
--- a/src/table/settings/win32_settings.ini
+++ b/src/table/settings/win32_settings.ini
@@ -12,7 +12,7 @@
#if defined(_WIN32) && !defined(DEDICATED)
extern bool _window_maximize;
-static const SettingTable _win32_settings{
+static const SettingVariant _win32_settings[] = {
[post-amble]
};
#endif /* _WIN32 */
diff --git a/src/table/settings/window_settings.ini b/src/table/settings/window_settings.ini
index 3a7669754..d9327aa92 100644
--- a/src/table/settings/window_settings.ini
+++ b/src/table/settings/window_settings.ini
@@ -9,7 +9,7 @@
[pre-amble]
-static const SettingTable _window_settings{
+static const SettingVariant _window_settings[] = {
[post-amble]
};
[templates]