mirror of
https://github.com/OpenMW/openmw.git
synced 2025-07-12 10:41:43 +00:00
Merge branch 'settings_default' into 'master'
Avoid using Settings::Manager::mDefaultSettings directly in the engine (#6876) See merge request OpenMW/openmw!2959
This commit is contained in:
commit
ebf6f50523
5 changed files with 48 additions and 19 deletions
|
@ -26,7 +26,7 @@
|
||||||
#include <components/resource/resourcesystem.hpp>
|
#include <components/resource/resourcesystem.hpp>
|
||||||
#include <components/resource/scenemanager.hpp>
|
#include <components/resource/scenemanager.hpp>
|
||||||
#include <components/sceneutil/lightmanager.hpp>
|
#include <components/sceneutil/lightmanager.hpp>
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/values.hpp>
|
||||||
#include <components/vfs/manager.hpp>
|
#include <components/vfs/manager.hpp>
|
||||||
#include <components/widgets/sharedstatebutton.hpp>
|
#include <components/widgets/sharedstatebutton.hpp>
|
||||||
|
|
||||||
|
@ -620,21 +620,16 @@ namespace MWGui
|
||||||
if (selectedButton == 1 || selectedButton == -1)
|
if (selectedButton == 1 || selectedButton == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
constexpr std::array<const char*, 6> settings = {
|
Settings::shaders().mLightBoundsMultiplier.reset();
|
||||||
"light bounds multiplier",
|
Settings::shaders().mMaximumLightDistance.reset();
|
||||||
"maximum light distance",
|
Settings::shaders().mLightFadeStart.reset();
|
||||||
"light fade start",
|
Settings::shaders().mMinimumInteriorBrightness.reset();
|
||||||
"minimum interior brightness",
|
Settings::shaders().mMaxLights.reset();
|
||||||
"max lights",
|
Settings::shaders().mLightingMethod.reset();
|
||||||
"lighting method",
|
|
||||||
};
|
|
||||||
for (const auto& setting : settings)
|
|
||||||
Settings::Manager::setString(
|
|
||||||
setting, "Shaders", Settings::Manager::mDefaultSettings[{ "Shaders", setting }]);
|
|
||||||
|
|
||||||
auto lightingMethod = SceneUtil::LightManager::getLightingMethodFromString(
|
const SceneUtil::LightingMethod lightingMethod
|
||||||
Settings::Manager::mDefaultSettings[{ "Shaders", "lighting method" }]);
|
= SceneUtil::LightManager::getLightingMethodFromString(Settings::shaders().mLightingMethod);
|
||||||
auto lightIndex = mLightingMethodButton->findItemIndexWith(lightingMethodToStr(lightingMethod));
|
const std::size_t lightIndex = mLightingMethodButton->findItemIndexWith(lightingMethodToStr(lightingMethod));
|
||||||
mLightingMethodButton->setIndexSelected(lightIndex);
|
mLightingMethodButton->setIndexSelected(lightIndex);
|
||||||
updateMaxLightsComboBox(mMaxLights);
|
updateMaxLightsComboBox(mMaxLights);
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,9 @@ namespace Settings
|
||||||
parser.loadSettingsFile(additionalDefaults, mDefaultSettings, false, true);
|
parser.loadSettingsFile(additionalDefaults, mDefaultSettings, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!loadEditorSettings)
|
||||||
|
Settings::Values::initDefaults();
|
||||||
|
|
||||||
// Load "settings.cfg" or "openmw-cs.cfg" from the last config dir as user settings. This path will be used to
|
// Load "settings.cfg" or "openmw-cs.cfg" from the last config dir as user settings. This path will be used to
|
||||||
// save modified settings.
|
// save modified settings.
|
||||||
auto settingspath = paths.back() / userSettingsFile;
|
auto settingspath = paths.back() / userSettingsFile;
|
||||||
|
|
|
@ -23,10 +23,25 @@ namespace Settings
|
||||||
: mCategory(category)
|
: mCategory(category)
|
||||||
, mName(name)
|
, mName(name)
|
||||||
, mSanitizer(std::move(sanitizer))
|
, mSanitizer(std::move(sanitizer))
|
||||||
, mValue(sanitize(Settings::Manager::get<T>(name, category)))
|
, mValue(sanitize(Settings::Manager::get<T>(mName, mCategory)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingValue(SettingValue&& other)
|
||||||
|
: mCategory(other.mCategory)
|
||||||
|
, mName(other.mName)
|
||||||
|
, mSanitizer(std::move(other.mSanitizer))
|
||||||
|
, mDefaultValue(std::move(other.mValue))
|
||||||
|
, mValue(sanitize(Settings::Manager::get<T>(mName, mCategory)))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingValue(const SettingValue& other) = delete;
|
||||||
|
|
||||||
|
SettingValue& operator=(const SettingValue& other) = delete;
|
||||||
|
|
||||||
|
SettingValue& operator=(SettingValue&& other) = delete;
|
||||||
|
|
||||||
const T& get() const { return mValue; }
|
const T& get() const { return mValue; }
|
||||||
|
|
||||||
operator const T&() const { return mValue; }
|
operator const T&() const { return mValue; }
|
||||||
|
@ -39,10 +54,13 @@ namespace Settings
|
||||||
Settings::Manager::set(mName, mCategory, mValue);
|
Settings::Manager::set(mName, mCategory, mValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reset() { set(mDefaultValue); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string_view mCategory;
|
const std::string_view mCategory;
|
||||||
const std::string_view mName;
|
const std::string_view mName;
|
||||||
const std::unique_ptr<const Sanitizer<T>> mSanitizer;
|
std::unique_ptr<const Sanitizer<T>> mSanitizer;
|
||||||
|
T mDefaultValue{};
|
||||||
T mValue{};
|
T mValue{};
|
||||||
|
|
||||||
T sanitize(const T& value) const
|
T sanitize(const T& value) const
|
||||||
|
|
|
@ -1,12 +1,24 @@
|
||||||
#include "values.hpp"
|
#include "values.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace Settings
|
namespace Settings
|
||||||
{
|
{
|
||||||
Values* Values::sValues = nullptr;
|
Values* Values::sValues = nullptr;
|
||||||
|
|
||||||
void Values::init()
|
void Values::initDefaults()
|
||||||
{
|
{
|
||||||
|
if (Values::sValues != nullptr)
|
||||||
|
throw std::logic_error("Default settings already initialized");
|
||||||
static Values values;
|
static Values values;
|
||||||
Values::sValues = &values;
|
Values::sValues = &values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Values::init()
|
||||||
|
{
|
||||||
|
if (Values::sValues == nullptr)
|
||||||
|
throw std::logic_error("Default settings are not initialized");
|
||||||
|
static Values values(std::move(*Values::sValues));
|
||||||
|
Values::sValues = &values;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,8 @@ namespace Settings
|
||||||
StereoViewCategory mStereoView;
|
StereoViewCategory mStereoView;
|
||||||
PostProcessingCategory mPostProcessing;
|
PostProcessingCategory mPostProcessing;
|
||||||
|
|
||||||
|
static void initDefaults();
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -195,7 +197,6 @@ namespace Settings
|
||||||
{
|
{
|
||||||
return values().mPostProcessing;
|
return values().mPostProcessing;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue