From: SmallJoker Date: Mon, 17 Feb 2020 18:26:32 +0000 (+0100) Subject: Settings: Fix game minetest.conf flags overriding defaults (#9404) X-Git-Tag: 5.2.0~109 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e8a8185d24897ccf964327017effae81aa1c9d40;p=oweals%2Fminetest.git Settings: Fix game minetest.conf flags overriding defaults (#9404) The game minetest.conf flags directly overwrote the global minetest.conf default values, resulting in unwanted erased mapgen flags. * Fix set_mapgen_setting --- diff --git a/src/content/subgames.cpp b/src/content/subgames.cpp index 39cdc056f..bf947cf85 100644 --- a/src/content/subgames.cpp +++ b/src/content/subgames.cpp @@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "settings.h" #include "log.h" #include "util/strfnd.h" -#include "defaultsettings.h" // for override_default_settings +#include "defaultsettings.h" // for set_default_settings #include "mapgen/mapgen.h" // for MapgenParams #include "util/string.h" @@ -298,7 +298,7 @@ bool loadGameConfAndInitWorld(const std::string &path, const SubgameSpec &gamesp set_default_settings(g_settings); Settings game_defaults; getGameMinetestConfig(gamespec.path, game_defaults); - override_default_settings(g_settings, &game_defaults); + g_settings->overrideDefaults(&game_defaults); infostream << "Initializing world at " << path << std::endl; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 754ce3547..b6e385a90 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -498,10 +498,3 @@ void set_default_settings(Settings *settings) #endif } -void override_default_settings(Settings *settings, Settings *from) -{ - std::vector names = from->getNames(); - for (const auto &name : names) { - settings->setDefault(name, from->get(name)); - } -} diff --git a/src/map_settings_manager.cpp b/src/map_settings_manager.cpp index a0ff1c754..7ef4bf12e 100644 --- a/src/map_settings_manager.cpp +++ b/src/map_settings_manager.cpp @@ -32,6 +32,7 @@ MapSettingsManager::MapSettingsManager(Settings *user_settings, m_user_settings(user_settings) { assert(m_user_settings != NULL); + Mapgen::setDefaultSettings(m_map_settings); } diff --git a/src/settings.cpp b/src/settings.cpp index 3728fabf2..55404319e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1048,6 +1048,30 @@ void Settings::setDefault(const std::string &name, const FlagDesc *flagdesc, setDefault(name, writeFlagString(flags, flagdesc, U32_MAX)); } +void Settings::overrideDefaults(Settings *other) +{ + for (const auto &setting : other->m_settings) { + if (setting.second.is_group) { + setGroupDefault(setting.first, setting.second.group); + continue; + } + const FlagDesc *flagdesc = getFlagDescFallback(setting.first); + if (flagdesc) { + // Flags cannot be copied directly. + // 1) Get the current set flags + u32 flags = getFlagStr(setting.first, flagdesc, nullptr); + // 2) Set the flags as defaults + other->setDefault(setting.first, flagdesc, flags); + // 3) Get the newly set flags and override the default setting value + setDefault(setting.first, flagdesc, + other->getFlagStr(setting.first, flagdesc, nullptr)); + continue; + } + // Also covers FlagDesc settings + setDefault(setting.first, setting.second.value); + } +} + const FlagDesc *Settings::getFlagDescFallback(const std::string &name) const { auto it = m_flags.find(name); diff --git a/src/settings.h b/src/settings.h index b42e36d10..0c9a155db 100644 --- a/src/settings.h +++ b/src/settings.h @@ -222,6 +222,8 @@ public: **************/ void setDefault(const std::string &name, const FlagDesc *flagdesc, u32 flags); + // Takes the provided setting values and uses them as new defaults + void overrideDefaults(Settings *other); const FlagDesc *getFlagDescFallback(const std::string &name) const; void registerChangedCallback(const std::string &name,