Refactor all references to settings to use new Settings type

Signed-off-by: Lucca Jiménez Könings <development@jimkoen.com>
This commit is contained in:
Lucca Jiménez Könings
2024-05-15 12:52:09 +02:00
parent 13e641b3a3
commit 8c15b87628
13 changed files with 168 additions and 243 deletions

View File

@@ -102,8 +102,7 @@ public:
static std::string PPS() { return mPPS; }
static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; }
static TSettings Settings;
static inline struct Settings SettingsSingleton { };
static inline struct Settings Settings { };
static std::vector<std::string> GetBackendUrlsInOrder() {
return {
@@ -225,13 +224,13 @@ void RegisterThread(const std::string& str);
#define luaprint(x) Application::Console().Write(_this_location + std::string("[LUA] ") + (x))
#define beammp_debug(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) { \
Application::Console().Write(_this_location + std::string("[DEBUG] ") + (x)); \
} \
} while (false)
#define beammp_event(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) { \
Application::Console().Write(_this_location + std::string("[EVENT] ") + (x)); \
} \
} while (false)
@@ -239,7 +238,7 @@ void RegisterThread(const std::string& str);
#if defined(DEBUG)
#define beammp_trace(x) \
do { \
if (Application::Settings.DebugModeEnabled) { \
if (Application::Settings.getAsBool(Settings::Key::General_Debug)) { \
Application::Console().Write(_this_location + std::string("[TRACE] ") + (x)); \
} \
} while (false)

View File

@@ -17,6 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "Sync.h"
#include <cstdint>
#include <fmt/core.h>
#include <fmt/format.h>
@@ -24,7 +25,6 @@
#include <string>
#include <unordered_map>
#include <variant>
#include "Sync.h"
struct ComposedKey {
std::string Category;
@@ -83,9 +83,9 @@ struct Settings {
General_Debug
};
Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap = std::unordered_map<Key, SettingsTypeVariant>{
{ General_Description, "BeamMP Default Description" },
{ General_Tags, "Freeroam" },
Sync<std::unordered_map<Key, SettingsTypeVariant>> SettingsMap = std::unordered_map<Key, SettingsTypeVariant> {
{ General_Description, std::string("BeamMP Default Description") },
{ General_Tags, std::string("Freeroam") },
{ General_MaxPlayers, 8 },
{ General_Name, "BeamMP Server" },
{ General_Map, "/levels/gridmap_v2/info.json" },
@@ -112,7 +112,7 @@ struct Settings {
SettingsAccessMask // Console read/write permissions
>;
Sync<std::unordered_map<ComposedKey, SettingsAccessControl>> InputAccessMapping = std::unordered_map<ComposedKey, SettingsAccessControl>{
Sync<std::unordered_map<ComposedKey, SettingsAccessControl>> InputAccessMapping = std::unordered_map<ComposedKey, SettingsAccessControl> {
{ { "General", "Description" }, { General_Description, write } },
{ { "General", "Tags" }, { General_Tags, write } },
{ { "General", "MaxPlayers" }, { General_MaxPlayers, write } },