diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 7983cdf422..dc3b6b0728 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -645,9 +645,8 @@ void OMW::Engine::prepareEngine() mResourceSystem->getSceneManager()->getShaderManager().setMaxTextureUnits(mGlMaxTextureImageUnits); mResourceSystem->getSceneManager()->setUnRefImageDataAfterApply( false); // keep to Off for now to allow better state sharing - mResourceSystem->getSceneManager()->setFilterSettings(Settings::Manager::getString("texture mag filter", "General"), - Settings::Manager::getString("texture min filter", "General"), - Settings::Manager::getString("texture mipmap", "General"), Settings::Manager::getInt("anisotropy", "General")); + mResourceSystem->getSceneManager()->setFilterSettings(Settings::general().mTextureMagFilter, + Settings::general().mTextureMinFilter, Settings::general().mTextureMipmap, Settings::general().mAnisotropy); mEnvironment.setResourceSystem(*mResourceSystem); mWorkQueue = new SceneUtil::WorkQueue(Settings::cells().mPreloadNumThreads); @@ -655,8 +654,8 @@ void OMW::Engine::prepareEngine() mScreenCaptureOperation = new SceneUtil::AsyncScreenCaptureOperation(mWorkQueue, new SceneUtil::WriteScreenshotToFileOperation(mCfgMgr.getScreenshotPath(), - Settings::Manager::getString("screenshot format", "General"), - Settings::Manager::getBool("notify on saved screenshot", "General") + Settings::general().mScreenshotFormat, + Settings::general().mNotifyOnSavedScreenshot ? std::function(ScheduleNonDialogMessageBox{}) : std::function(IgnoreString{}))); @@ -665,8 +664,7 @@ void OMW::Engine::prepareEngine() mViewer->addEventHandler(mScreenCaptureHandler); mL10nManager = std::make_unique(mVFS.get()); - mL10nManager->setPreferredLocales(Settings::Manager::getStringArray("preferred locales", "General"), - Settings::Manager::getBool("gmst overrides l10n", "General")); + mL10nManager->setPreferredLocales(Settings::general().mPreferredLocales, Settings::general().mGmstOverridesL10n); mEnvironment.setL10nManager(*mL10nManager); mLuaManager = std::make_unique(mVFS.get(), mResDir / "lua_libs"); diff --git a/apps/openmw/mwgui/console.cpp b/apps/openmw/mwgui/console.cpp index 4affff459c..2532a676e5 100644 --- a/apps/openmw/mwgui/console.cpp +++ b/apps/openmw/mwgui/console.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include "../mwscript/extensions.hpp" #include "../mwscript/interpretercontext.hpp" @@ -709,7 +709,7 @@ namespace MWGui void Console::initConsoleHistory() { const auto filePath = mCfgMgr.getUserConfigPath() / "console_history.txt"; - const size_t retrievalLimit = Settings::Manager::getSize("console history buffer size", "General"); + const size_t retrievalLimit = Settings::general().mConsoleHistoryBufferSize; // Read the previous session's commands from the file if (retrievalLimit > 0) diff --git a/apps/openmw/mwgui/debugwindow.cpp b/apps/openmw/mwgui/debugwindow.cpp index 2a9ae25664..5d3948e76d 100644 --- a/apps/openmw/mwgui/debugwindow.cpp +++ b/apps/openmw/mwgui/debugwindow.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/luamanager.hpp" @@ -132,7 +132,7 @@ namespace MWGui void DebugWindow::startLogRecording() { - sLogCircularBuffer.resize(Settings::Manager::getSize("log buffer size", "General")); + sLogCircularBuffer.resize(Settings::general().mLogBufferSize); Debug::setLogListener([](Debug::Level level, std::string_view prefix, std::string_view msg) { if (sLogCircularBuffer.empty()) return; // Log viewer is disabled. diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index 8cfeb88aba..e624f8e692 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -367,7 +367,7 @@ namespace MWGui } highlightCurrentResolution(); - const std::string& tmip = Settings::Manager::getString("texture mipmap", "General"); + const std::string& tmip = Settings::general().mTextureMipmap; mTextureFilteringButton->setCaptionWithReplacing(textureMipmappingToStr(tmip)); int waterTextureSize = Settings::Manager::getInt("rtt size", "Water"); @@ -416,7 +416,7 @@ namespace MWGui std::sort(availableLanguages.begin(), availableLanguages.end()); - std::vector currentLocales = Settings::Manager::getStringArray("preferred locales", "General"); + std::vector currentLocales = Settings::general().mPreferredLocales; if (currentLocales.empty()) currentLocales.push_back("en"); @@ -563,7 +563,7 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->interactiveMessageBox( "#{OMWEngine:ChangeRequiresRestart}", { "#{Interface:OK}" }, true); - std::vector currentLocales = Settings::Manager::getStringArray("preferred locales", "General"); + std::vector currentLocales = Settings::general().mPreferredLocales; if (currentLocales.size() <= langPriority) currentLocales.resize(langPriority + 1, "en"); @@ -573,7 +573,7 @@ namespace MWGui else currentLocales.resize(1); - Settings::Manager::setStringArray("preferred locales", "General", currentLocales); + Settings::general().mPreferredLocales.set(currentLocales); } void SettingsWindow::onGmstOverridesL10nChanged(MyGUI::Widget*) @@ -681,9 +681,9 @@ namespace MWGui void SettingsWindow::onTextureFilteringChanged(MyGUI::ComboBox* _sender, size_t pos) { if (pos == 0) - Settings::Manager::setString("texture mipmap", "General", "nearest"); + Settings::general().mTextureMipmap.set("nearest"); else if (pos == 1) - Settings::Manager::setString("texture mipmap", "General", "linear"); + Settings::general().mTextureMipmap.set("linear"); else Log(Debug::Warning) << "Unexpected option pos " << pos; apply(); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index d8e0bd13c8..4a781a4720 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -1292,11 +1292,8 @@ namespace MWRender { mViewer->stopThreading(); - mResourceSystem->getSceneManager()->setFilterSettings( - Settings::Manager::getString("texture mag filter", "General"), - Settings::Manager::getString("texture min filter", "General"), - Settings::Manager::getString("texture mipmap", "General"), - Settings::Manager::getInt("anisotropy", "General")); + mResourceSystem->getSceneManager()->setFilterSettings(Settings::general().mTextureMagFilter, + Settings::general().mTextureMinFilter, Settings::general().mTextureMipmap, Settings::general().mAnisotropy); mTerrain->updateTextureFiltering(); mWater->processChangedSettings({}); diff --git a/components/settings/categories/general.hpp b/components/settings/categories/general.hpp index 94f6848798..7bbb651ee8 100644 --- a/components/settings/categories/general.hpp +++ b/components/settings/categories/general.hpp @@ -28,7 +28,7 @@ namespace Settings SettingValue mTextureMipmap{ mIndex, "General", "texture mipmap", makeEnumSanitizerString({ "none", "nearest", "linear" }) }; SettingValue mNotifyOnSavedScreenshot{ mIndex, "General", "notify on saved screenshot" }; - SettingValue mPreferredLocales{ mIndex, "General", "preferred locales" }; + SettingValue> mPreferredLocales{ mIndex, "General", "preferred locales" }; SettingValue mGmstOverridesL10n{ mIndex, "General", "gmst overrides l10n" }; SettingValue mLogBufferSize{ mIndex, "General", "log buffer size" }; SettingValue mConsoleHistoryBufferSize{ mIndex, "General", "console history buffer size" }; diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index 6d35bab046..ce50d59ae1 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -449,6 +449,11 @@ namespace Settings setInt(setting, category, static_cast(value)); } + void Manager::set(std::string_view setting, std::string_view category, const std::vector& value) + { + setStringArray(setting, category, value); + } + void Manager::recordInit(std::string_view setting, std::string_view category) { sInitialized.emplace(category, setting); diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index 536977399f..d8b10782ad 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -104,12 +104,13 @@ namespace Settings static void set(std::string_view setting, std::string_view category, const osg::Vec2f& value); static void set(std::string_view setting, std::string_view category, const osg::Vec3f& value); static void set(std::string_view setting, std::string_view category, DetourNavigator::CollisionShapeType value); + static void set(std::string_view setting, std::string_view category, const std::vector& value); private: static std::set> sInitialized; template - static T getImpl(std::string_view setting, std::string_view category); + static T getImpl(std::string_view setting, std::string_view category) = delete; static void recordInit(std::string_view setting, std::string_view category); }; @@ -180,6 +181,13 @@ namespace Settings { return DetourNavigator::toCollisionShapeType(getInt(setting, category)); } + + template <> + inline std::vector Manager::getImpl>( + std::string_view setting, std::string_view category) + { + return getStringArray(setting, category); + } } #endif // COMPONENTS_SETTINGS_H diff --git a/components/settings/settingvalue.hpp b/components/settings/settingvalue.hpp index 435f82ab1b..cd04dbc820 100644 --- a/components/settings/settingvalue.hpp +++ b/components/settings/settingvalue.hpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace Settings { @@ -33,6 +34,7 @@ namespace Settings Vec2f, Vec3f, CollisionShapeType, + StringArray, }; template @@ -116,6 +118,12 @@ namespace Settings return SettingValueType::CollisionShapeType; } + template <> + inline constexpr SettingValueType getSettingValueType>() + { + return SettingValueType::StringArray; + } + inline constexpr std::string_view getSettingValueTypeName(SettingValueType type) { switch (type) @@ -146,6 +154,8 @@ namespace Settings return "vec3f"; case SettingValueType::CollisionShapeType: return "collision shape type"; + case SettingValueType::StringArray: + return "string array"; } return "unsupported"; } @@ -292,6 +302,18 @@ namespace Settings { if constexpr (std::is_enum_v) return stream << static_cast>(value.mValue); + else if constexpr (std::is_same_v>) + { + bool first = true; + for (const std::string& v : value.mValue) + { + if (std::exchange(first, false)) + stream << v; + else + stream << "," << v; + } + return stream; + } else return stream << value.mValue; }