From da079fcfd8d1ea265412cb500e56deb56b06f322 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 1 May 2022 02:38:02 +0300 Subject: [PATCH] [General] Add VR settings to GameSettings packet --- apps/openmw-mp/Script/Functions/Settings.cpp | 14 +++++++++ apps/openmw-mp/Script/Functions/Settings.hpp | 29 ++++++++++++++++-- .../player/ProcessorGameSettings.hpp | 12 +++++++- components/openmw-mp/Base/BasePlayer.hpp | 1 + .../Packets/Player/PacketGameSettings.cpp | 30 +++++++++++++++++-- 5 files changed, 80 insertions(+), 6 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Settings.cpp b/apps/openmw-mp/Script/Functions/Settings.cpp index 88c42a78c..42889d4de 100644 --- a/apps/openmw-mp/Script/Functions/Settings.cpp +++ b/apps/openmw-mp/Script/Functions/Settings.cpp @@ -78,6 +78,20 @@ void SettingFunctions::ClearGameSettingValues(unsigned short pid) { player->gameSettings.clear(); } +void SettingFunctions::SetVRSettingValue(unsigned short pid, const char* setting, const char* value) { + Player* player; + GET_PLAYER(pid, player, ); + + player->vrSettings[setting] = value; +} + +void SettingFunctions::ClearVRSettingValues(unsigned short pid) { + Player* player; + GET_PLAYER(pid, player, ); + + player->vrSettings.clear(); +} + void SettingFunctions::SendSettings(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Settings.hpp b/apps/openmw-mp/Script/Functions/Settings.hpp index 86b99f37d..ad0a942b8 100644 --- a/apps/openmw-mp/Script/Functions/Settings.hpp +++ b/apps/openmw-mp/Script/Functions/Settings.hpp @@ -16,6 +16,9 @@ {"SetGameSettingValue", SettingFunctions::SetGameSettingValue},\ {"ClearGameSettingValues", SettingFunctions::ClearGameSettingValues},\ \ + {"SetVRSettingValue", SettingFunctions::SetVRSettingValue},\ + {"ClearVRSettingValues", SettingFunctions::ClearVRSettingValues},\ + \ {"SendSettings", SettingFunctions::SendSettings} class SettingFunctions @@ -125,15 +128,37 @@ public: static void SetGameSettingValue(unsigned short pid, const char* setting, const char* value); /** - * \brief Clear the settings values + * \brief Clear the Game setting values stored for a player. * - * Clear any changes done by SetGameSettingValue + * Clear any changes done by SetGameSettingValue() * * \param pid The player ID. * \return void */ static void ClearGameSettingValues(unsigned short pid); + /** + * \brief Set value for a VR setting. + * + * This overrides the setting value set in OpenMW Launcher. Only applies to the VR category. + * + * \param pid The player ID. + * \param setting Name of a setting in the VR category + * \param value Value of the setting (as a string) + * \return void + */ + static void SetVRSettingValue(unsigned short pid, const char* setting, const char* value); + + /** + * \brief Clear the VR setting values stored for a player. + * + * Clear any changes done by SetVRSettingValue() + * + * \param pid The player ID. + * \return void + */ + static void ClearVRSettingValues(unsigned short pid); + /** * \brief Send a PlayerSettings packet to the player affected by it. * diff --git a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp index 28751d201..4d49c0414 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp @@ -12,6 +12,7 @@ namespace mwmp class ProcessorGameSettings final: public PlayerProcessor { const std::string GAME_SETTING_CATEGORY = "Game"; + const std::string VR_SETTING_CATEGORY = "VR"; public: ProcessorGameSettings() { @@ -51,9 +52,18 @@ namespace mwmp MWBase::Environment::get().getWorld()->setPhysicsFramerate(player->physicsFramerate); - for (auto setting : player->gameSettings) { + for (auto setting : player->gameSettings) + { Settings::Manager::setString(setting.first, GAME_SETTING_CATEGORY, setting.second); } + + // Only read VR settings for players using a VR build +#ifdef USE_OPENXR + for (auto setting : player->vrSettings) + { + Settings::Manager::setString(setting.first, VR_SETTING_CATEGORY, setting.second); + } +#endif } } }; diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 9ece0e742..f567b7bb3 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -253,6 +253,7 @@ namespace mwmp std::string chatMessage; CharGenState charGenState; std::map gameSettings; + std::map vrSettings; std::string sound; Animation animation; diff --git a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp index cff2061d1..9485cfb23 100644 --- a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp +++ b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp @@ -21,12 +21,12 @@ void PacketGameSettings::Packet(RakNet::BitStream *newBitstream, bool send) RW(player->enforcedLogLevel, send); RW(player->physicsFramerate, send); - uint32_t gameSettingCount = static_cast(player->gameSettings.size()); - RW(gameSettingCount, send); - std::string mapIndex; std::string mapValue; + uint32_t gameSettingCount = static_cast(player->gameSettings.size()); + RW(gameSettingCount, send); + if (send) { for (auto&& gameSetting : player->gameSettings) @@ -47,4 +47,28 @@ void PacketGameSettings::Packet(RakNet::BitStream *newBitstream, bool send) player->gameSettings[mapIndex] = mapValue; } } + + uint32_t vrSettingCount = static_cast(player->vrSettings.size()); + RW(vrSettingCount, send); + + if (send) + { + for (auto&& vrSetting : player->vrSettings) + { + mapIndex = vrSetting.first; + mapValue = vrSetting.second; + RW(mapIndex, send, false); + RW(mapValue, send, false); + } + } + else + { + player->vrSettings.clear(); + for (unsigned int n = 0; n < vrSettingCount; n++) + { + RW(mapIndex, send, false); + RW(mapValue, send, false); + player->vrSettings[mapIndex] = mapValue; + } + } }