From 2923174f9a63bbee66731a8aa4e5c2eedfb18aed Mon Sep 17 00:00:00 2001 From: madsbuvi Date: Thu, 25 Feb 2021 22:52:57 +0100 Subject: [PATCH] Added a list of setting overrides --- CMakeLists.txt | 3 ++ apps/openmw/engine.cpp | 12 ++++++ components/settings/settings.cpp | 70 ++++++++++++++++++++++++++++++-- components/settings/settings.hpp | 11 +++++ files/settings-overrides-vr.cfg | 58 ++++++++++++++++++++++++++ 5 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 files/settings-overrides-vr.cfg diff --git a/CMakeLists.txt b/CMakeLists.txt index c58a866a0..2cea60ce1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -371,6 +371,9 @@ endif (APPLE) configure_resource_file(${OpenMW_SOURCE_DIR}/files/settings-default.cfg "${OpenMW_BINARY_DIR}" "settings-default.cfg") +configure_resource_file(${OpenMW_SOURCE_DIR}/files/settings-overrides-vr.cfg + "${OpenMW_BINARY_DIR}" "settings-overrides-vr.cfg") + configure_resource_file(${OpenMW_SOURCE_DIR}/files/openmw.appdata.xml "${OpenMW_BINARY_DIR}" "openmw.appdata.xml") diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 98c3326a2..6de50b57b 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -509,6 +509,18 @@ std::string OMW::Engine::loadSettings (Settings::Manager & settings) if (boost::filesystem::exists(settingspath)) settings.loadUser(settingspath); + +#ifdef USE_OPENXR + const std::string localoverrides = (mCfgMgr.getLocalPath() / "settings-overrides-vr.cfg").string(); + const std::string globaloverrides = (mCfgMgr.getGlobalPath() / "settings-overrides-vr.cfg").string(); + if (boost::filesystem::exists(localoverrides)) + settings.loadOverrides(localoverrides); + else if (boost::filesystem::exists(globaloverrides)) + settings.loadOverrides(globaloverrides); + else + throw std::runtime_error("No settings overrides file found! Make sure the file \"settings-overrides-vr.cfg\" was properly installed."); +#endif + return settingspath; } diff --git a/components/settings/settings.cpp b/components/settings/settings.cpp index b29dadcdc..629c954de 100644 --- a/components/settings/settings.cpp +++ b/components/settings/settings.cpp @@ -10,6 +10,7 @@ namespace Settings CategorySettingValueMap Manager::mDefaultSettings = CategorySettingValueMap(); CategorySettingValueMap Manager::mUserSettings = CategorySettingValueMap(); +CategorySettingValueMap Manager::mSettingsOverrides = CategorySettingValueMap(); CategorySettingVector Manager::mChangedSettings = CategorySettingVector(); void Manager::clear() @@ -17,6 +18,7 @@ void Manager::clear() mDefaultSettings.clear(); mUserSettings.clear(); mChangedSettings.clear(); + mSettingsOverrides.clear(); } void Manager::loadDefault(const std::string &file) @@ -25,12 +27,18 @@ void Manager::loadDefault(const std::string &file) parser.loadSettingsFile(file, mDefaultSettings); } -void Manager::loadUser(const std::string &file) +void Manager::loadUser(const std::string& file) { SettingsFileParser parser; parser.loadSettingsFile(file, mUserSettings); } +void Manager::loadOverrides(const std::string& file) +{ + SettingsFileParser parser; + parser.loadSettingsFile(file, mSettingsOverrides); +} + void Manager::saveUser(const std::string &file) { SettingsFileParser parser; @@ -40,7 +48,11 @@ void Manager::saveUser(const std::string &file) std::string Manager::getString(const std::string &setting, const std::string &category) { CategorySettingValueMap::key_type key = std::make_pair(category, setting); - CategorySettingValueMap::iterator it = mUserSettings.find(key); + CategorySettingValueMap::iterator it = mSettingsOverrides.find(key); + if (it != mSettingsOverrides.end()) + return it->second; + + it = mUserSettings.find(key); if (it != mUserSettings.end()) return it->second; @@ -101,8 +113,11 @@ osg::Vec3f Manager::getVector3 (const std::string& setting, const std::string& c void Manager::setString(const std::string &setting, const std::string &category, const std::string &value) { CategorySettingValueMap::key_type key = std::make_pair(category, setting); + CategorySettingValueMap::iterator found = mSettingsOverrides.find(key); + if (found != mSettingsOverrides.end()) + return; - CategorySettingValueMap::iterator found = mUserSettings.find(key); + found = mUserSettings.find(key); if (found != mUserSettings.end()) { if (found->second == value) @@ -163,4 +178,53 @@ void Manager::resetPendingChanges() mChangedSettings.clear(); } + +void Manager::overrideString(const std::string& setting, const std::string& category, const std::string& value) +{ + CategorySettingValueMap::key_type key = std::make_pair(category, setting); + + CategorySettingValueMap::iterator found = mUserSettings.find(key); + if (found != mUserSettings.end()) + { + if (found->second == value) + return; + } + + mSettingsOverrides[key] = value; +} + +void Manager::overrideInt(const std::string& setting, const std::string& category, const int value) +{ + std::ostringstream stream; + stream << value; + overrideString(setting, category, stream.str()); +} + +void Manager::overrideFloat(const std::string& setting, const std::string& category, const float value) +{ + std::ostringstream stream; + stream << value; + overrideString(setting, category, stream.str()); +} + +void Manager::overrideBool(const std::string& setting, const std::string& category, const bool value) +{ + overrideString(setting, category, value ? "true" : "false"); +} + +void Manager::overrideVector2(const std::string& setting, const std::string& category, const osg::Vec2f value) +{ + std::ostringstream stream; + stream << value.x() << " " << value.y(); + overrideString(setting, category, stream.str()); +} + +void Manager::overrideVector3(const std::string& setting, const std::string& category, const osg::Vec3f value) +{ + std::ostringstream stream; + stream << value.x() << ' ' << value.y() << ' ' << value.z(); + overrideString(setting, category, stream.str()); +} + + } diff --git a/components/settings/settings.hpp b/components/settings/settings.hpp index ecc5aa5fd..d902cd371 100644 --- a/components/settings/settings.hpp +++ b/components/settings/settings.hpp @@ -19,6 +19,7 @@ namespace Settings public: static CategorySettingValueMap mDefaultSettings; static CategorySettingValueMap mUserSettings; + static CategorySettingValueMap mSettingsOverrides; static CategorySettingVector mChangedSettings; ///< tracks all the settings that were changed since the last apply() call @@ -32,6 +33,9 @@ namespace Settings void loadUser (const std::string& file); ///< load file as user settings + void loadOverrides (const std::string& file); + ///< load file as settings overrides + void saveUser (const std::string& file); ///< save user settings to file @@ -55,6 +59,13 @@ namespace Settings static void setBool (const std::string& setting, const std::string& category, const bool value); static void setVector2 (const std::string& setting, const std::string& category, const osg::Vec2f value); static void setVector3 (const std::string& setting, const std::string& category, const osg::Vec3f value); + + static void overrideInt(const std::string& setting, const std::string& category, const int value); + static void overrideFloat(const std::string& setting, const std::string& category, const float value); + static void overrideString(const std::string& setting, const std::string& category, const std::string& value); + static void overrideBool(const std::string& setting, const std::string& category, const bool value); + static void overrideVector2(const std::string& setting, const std::string& category, const osg::Vec2f value); + static void overrideVector3(const std::string& setting, const std::string& category, const osg::Vec3f value); }; } diff --git a/files/settings-overrides-vr.cfg b/files/settings-overrides-vr.cfg new file mode 100644 index 000000000..cb81c4bf1 --- /dev/null +++ b/files/settings-overrides-vr.cfg @@ -0,0 +1,58 @@ +# WARNING: This is a special config file that should not be edited by the user. +# Any settings listed in this file will be absolute and not modifiable by user settings. +# This is to prevent the use of settings that are incompatible with VR. +# Ignoring this and removing/editing lines in this file will either have no effect or break your game. + +[Camera] +# Automatically enable preview mode when player doesn't move. +preview if stand still = false + +# Enables head bobbing in first person mode +head bobbing = false + +[GUI] +# Scales GUI window and widget size. (<1.0 is smaller, >1.0 is larger). +scaling factor = 1.0 + +# Size of in-game fonts +font size = 16 + +# Stretch menus, load screens, etc. to the window aspect ratio. +stretch menu background = false + +# Red flash visually showing player damage. +hit fader = false + +# Werewolf overlay border around screen or window. +werewolf overlay = false + +# Controls whether Arrow keys, Movement keys, Tab/Shift-Tab and Spacebar/Enter/Activate may be used to navigate GUI buttons. +keyboard navigation = true + +[HUD] + +# Displays the crosshair or reticle when not in GUI mode. +crosshair = false + +[Game] +# Always use the best mode of attack: e.g. chop, slash or thrust. +best attack = false + +[Video] +# OpenMW takes complete control of the screen. +fullscreen = false + +# Enable vertical syncing to reduce tearing defects. +vsync = false + +# Maximum frames per second. 0.0 is unlimited, or >0.0 to limit. +framerate limit = 0 + +# Type of screenshot to take (regular, cylindrical, spherical or planet), optionally followed by +# screenshot width, height and cubemap resolution in pixels. (e.g. spherical 1600 1000 1200) +screenshot type = regular + +[Stereo] + +# Enable/disable stereo view. +stereo enabled = true \ No newline at end of file