From 60f686ee43c7ecc494b08d5182dadf8312ea3aeb Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 14 Feb 2018 05:53:44 +0200 Subject: [PATCH] [General] Implement setting of physics framerate as part of GameSettings --- apps/openmw-mp/Script/Functions/Settings.cpp | 8 +++++++ apps/openmw-mp/Script/Functions/Settings.hpp | 14 ++++++++++++ apps/openmw/mwbase/world.hpp | 10 +++++++++ apps/openmw/mwmp/LocalPlayer.cpp | 1 + .../player/ProcessorGameSettings.hpp | 3 +++ apps/openmw/mwphysics/physicssystem.cpp | 22 +++++++++++++++++++ apps/openmw/mwphysics/physicssystem.hpp | 10 +++++++++ apps/openmw/mwworld/worldimp.cpp | 13 +++++++++++ apps/openmw/mwworld/worldimp.hpp | 10 +++++++++ components/openmw-mp/Base/BasePlayer.hpp | 1 + .../Packets/Player/PacketGameSettings.cpp | 1 + 11 files changed, 93 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Settings.cpp b/apps/openmw-mp/Script/Functions/Settings.cpp index 24e914036..eaee5a56c 100644 --- a/apps/openmw-mp/Script/Functions/Settings.cpp +++ b/apps/openmw-mp/Script/Functions/Settings.cpp @@ -17,6 +17,14 @@ void SettingFunctions::SetDifficulty(unsigned short pid, int difficulty) player->difficulty = difficulty; } +void SettingFunctions::SetPhysicsFramerate(unsigned short pid, double physicsFramerate) +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->physicsFramerate = physicsFramerate; +} + void SettingFunctions::SetConsoleAllowed(unsigned short pid, bool state) { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Settings.hpp b/apps/openmw-mp/Script/Functions/Settings.hpp index e0db786fe..763a5e69e 100644 --- a/apps/openmw-mp/Script/Functions/Settings.hpp +++ b/apps/openmw-mp/Script/Functions/Settings.hpp @@ -5,6 +5,8 @@ #define SETTINGSAPI \ {"SetDifficulty", SettingFunctions::SetDifficulty},\ + {"SetPhysicsFramerate", SettingFunctions::SetPhysicsFramerate},\ + \ {"SetConsoleAllowed", SettingFunctions::SetConsoleAllowed},\ {"SetBedRestAllowed", SettingFunctions::SetBedRestAllowed},\ {"SetWildernessRestAllowed", SettingFunctions::SetWildernessRestAllowed},\ @@ -28,6 +30,18 @@ public: */ static void SetDifficulty(unsigned short pid, int difficulty); + /** + * \brief Set the physics framerate for a player. + * + * This changes the physics framerate for that player in the server memory, but does not by itself + * send a packet. + * + * \param pid The player ID. + * \param bool The physics framerate. + * \return void + */ + static void SetPhysicsFramerate(unsigned short pid, double physicsFramerate); + /** * \brief Set whether the console is allowed for a player. * diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index bc4beda7c..8767b0f09 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -318,6 +318,16 @@ namespace MWBase End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to set the physics framerate from elsewhere + */ + virtual void World::setPhysicsFramerate(float physFramerate) = 0; + /* + End of tes3mp addition + */ + virtual bool castRay (float x1, float y1, float z1, float x2, float y2, float z2) = 0; ///< cast a Ray and return true if there is an object in the ray path. diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 03e370d4f..c3c69108f 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -48,6 +48,7 @@ LocalPlayer::LocalPlayer() charGenStage.end = 1; difficulty = 0; + physicsFramerate = 60.0; consoleAllowed = false; bedRestAllowed = true; wildernessRestAllowed = true; diff --git a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp index f5e5aaebd..dc3027bdd 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorGameSettings.hpp @@ -2,6 +2,7 @@ #define OPENMW_PROCESSORGAMESETTINGS_HPP #include "apps/openmw/mwbase/environment.hpp" +#include "apps/openmw/mwworld/worldimp.hpp" #include "apps/openmw/mwgui/windowmanagerimp.hpp" #include "../PlayerProcessor.hpp" @@ -28,6 +29,8 @@ namespace mwmp (!player->bedRestAllowed || !player->wildernessRestAllowed || !player->waitAllowed)) MWBase::Environment::get().getWindowManager()->popGuiMode(); } + + MWBase::Environment::get().getWorld()->setPhysicsFramerate(player->physicsFramerate); } } }; diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 174560e6b..6efab6f32 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -794,6 +794,28 @@ namespace MWPhysics return true; } + /* + Start of tes3mp addition + + Make it possible to set the physics framerate from elsewhere + */ + void PhysicsSystem::setPhysicsFramerate(float physFramerate) + { + if (physFramerate > 0 && physFramerate < 100) + { + mPhysicsDt = 1.f / physFramerate; + std::cerr << "Warning: physics framerate was overridden (a new value is " << physFramerate << ")." << std::endl; + } + else + { + std::cerr << "Warning: attempted to override physics framerate with new value of " << physFramerate << + ", but it was outside accepted values." << std::endl; + } + } + /* + End of tes3mp addition + */ + class DeepestNotMeContactTestResultCallback : public btCollisionWorld::ContactResultCallback { const btCollisionObject* mMe; diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index 3ef9990f5..b458f936e 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -170,6 +170,16 @@ namespace MWPhysics bool isOnSolidGround (const MWWorld::Ptr& actor) const; + /* + Start of tes3mp addition + + Make it possible to set the physics framerate from elsewhere + */ + void setPhysicsFramerate(float physFramerate); + /* + End of tes3mp addition + */ + private: void updateWater(); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 93b6f03c3..0a3dba047 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1522,6 +1522,19 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to set the physics framerate from elsewhere + */ + void World::setPhysicsFramerate(float physFramerate) + { + mPhysics->setPhysicsFramerate(physFramerate); + } + /* + End of tes3mp addition + */ + void World::doPhysics(float duration) { mPhysics->stepSimulation(duration); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index de3e20c7e..153c41c47 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -417,6 +417,16 @@ namespace MWWorld End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it possible to set the physics framerate from elsewhere + */ + void World::setPhysicsFramerate(float physFramerate); + /* + End of tes3mp addition + */ + bool castRay (float x1, float y1, float z1, float x2, float y2, float z2) override; ///< cast a Ray and return true if there is an object in the ray path. diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 1a024c6a9..04aafb4d4 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -253,6 +253,7 @@ namespace mwmp CurrentContainer currentContainer; int difficulty; + float physicsFramerate; bool consoleAllowed; bool bedRestAllowed; bool wildernessRestAllowed; diff --git a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp index c02527e8d..24c275e71 100644 --- a/components/openmw-mp/Packets/Player/PacketGameSettings.cpp +++ b/components/openmw-mp/Packets/Player/PacketGameSettings.cpp @@ -14,6 +14,7 @@ void PacketGameSettings::Packet(RakNet::BitStream *bs, bool send) PlayerPacket::Packet(bs, send); RW(player->difficulty, send); + RW(player->physicsFramerate, send); RW(player->consoleAllowed, send); RW(player->bedRestAllowed, send); RW(player->wildernessRestAllowed, send);