From 6062cd4b9c7a3a3e7f05d6f12f27db4b85c14ee7 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 26 Sep 2017 13:28:15 +0400 Subject: [PATCH 1/2] Make physics framerate configurable --- apps/openmw/mwphysics/physicssystem.cpp | 7 ++++++- docs/source/reference/modding/settings/physics.rst | 13 +++++++++++++ files/settings-default.cfg | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 docs/source/reference/modding/settings/physics.rst diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index ee368ad24..068ff3186 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include // FindRecIndexVisitor @@ -1357,7 +1358,11 @@ namespace MWPhysics mMovementResults.clear(); mTimeAccum += dt; - const float physicsDt = 1.f/60.0f; + + static const float physFramerate = Settings::Manager::getFloat("physics framerate", "Physics"); + + // Allow to use a physics framerate between 10 and 60 FPS + static const float physicsDt = 1.f / std::max(10.f, std::min(60.f, physFramerate)); const int maxAllowedSteps = 20; int numSteps = mTimeAccum / (physicsDt); diff --git a/docs/source/reference/modding/settings/physics.rst b/docs/source/reference/modding/settings/physics.rst new file mode 100644 index 000000000..e4f970a79 --- /dev/null +++ b/docs/source/reference/modding/settings/physics.rst @@ -0,0 +1,13 @@ +Physics Settings +################ + +physics framerate +--------------- + +:Type: floating point +:Range: 10.0 to 60.0 +:Default: 60.0 + +Allows to set how frequently an engine will do physics calculations. A default value is 60 times per second. +This setting allows developers with low-clocked CPUs to test an engine. +Changing from default value can lead to physics bugs. Change this setting on your own risk, and reset a value to default before filling a physics-related bugreport! diff --git a/files/settings-default.cfg b/files/settings-default.cfg index aec667a9c..f4c7f0a4a 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -277,6 +277,10 @@ camera y multiplier = 1.0 # Invert the vertical axis while not in GUI mode. invert y axis = false +[Physics] +# Framerate of the physics system +physics framerate = 60.0 + [Saves] # Name of last character played, and default for loading save files. From 62177ebb30a55a1cb8b62360ee0aa70056aa903c Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 26 Sep 2017 21:19:53 +0400 Subject: [PATCH 2/2] Move physics framerate from setting to environment variable --- apps/openmw/mwphysics/physicssystem.cpp | 30 ++++++++++++------- apps/openmw/mwphysics/physicssystem.hpp | 2 ++ .../reference/modding/settings/physics.rst | 13 -------- files/settings-default.cfg | 4 --- 4 files changed, 22 insertions(+), 27 deletions(-) delete mode 100644 docs/source/reference/modding/settings/physics.rst diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 068ff3186..887189a85 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -1,5 +1,6 @@ #include "physicssystem.hpp" +#include #include #include @@ -24,7 +25,6 @@ #include #include #include -#include #include // FindRecIndexVisitor @@ -684,6 +684,7 @@ namespace MWPhysics , mWaterHeight(0) , mWaterEnabled(false) , mParentNode(parentNode) + , mPhysicsDt(1.f / 60.f) { mResourceSystem->addResourceManager(mShapeManager.get()); @@ -696,6 +697,20 @@ namespace MWPhysics // Don't update AABBs of all objects every frame. Most objects in MW are static, so we don't need this. // Should a "static" object ever be moved, we have to update its AABB manually using DynamicsWorld::updateSingleAabb. mCollisionWorld->setForceUpdateAllAabbs(false); + + // Check if a user decided to override a physics system FPS + const char* env = getenv("OPENMW_PHYSICS_FPS"); + if (env) + { + std::string str(env); + + float physFramerate = std::atof(env); + if (physFramerate > 0) + { + mPhysicsDt = 1.f / physFramerate; + std::cerr << "Warning: physics framerate was overriden (a new value is " << physFramerate << ")." << std::endl; + } + } } PhysicsSystem::~PhysicsSystem() @@ -1359,16 +1374,11 @@ namespace MWPhysics mTimeAccum += dt; - static const float physFramerate = Settings::Manager::getFloat("physics framerate", "Physics"); - - // Allow to use a physics framerate between 10 and 60 FPS - static const float physicsDt = 1.f / std::max(10.f, std::min(60.f, physFramerate)); - const int maxAllowedSteps = 20; - int numSteps = mTimeAccum / (physicsDt); + int numSteps = mTimeAccum / (mPhysicsDt); numSteps = std::min(numSteps, maxAllowedSteps); - mTimeAccum -= numSteps * physicsDt; + mTimeAccum -= numSteps * mPhysicsDt; if (numSteps) { @@ -1417,7 +1427,7 @@ namespace MWPhysics bool positionChanged = false; for (int i=0; igetPtr(), physicActor, iter->second, physicsDt, + position = MovementSolver::move(position, physicActor->getPtr(), physicActor, iter->second, mPhysicsDt, flying, waterlevel, slowFall, mCollisionWorld, mStandingCollisions); if (position != physicActor->getPosition()) positionChanged = true; @@ -1426,7 +1436,7 @@ namespace MWPhysics if (positionChanged) mCollisionWorld->updateSingleAabb(physicActor->getCollisionObject()); - float interpolationFactor = mTimeAccum / physicsDt; + float interpolationFactor = mTimeAccum / mPhysicsDt; osg::Vec3f interpolated = position * interpolationFactor + physicActor->getPreviousPosition() * (1.f - interpolationFactor); float heightDiff = position.z() - oldHeight; diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index aaf55e2b6..3ef9990f5 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -220,6 +220,8 @@ namespace MWPhysics osg::ref_ptr mParentNode; + float mPhysicsDt; + PhysicsSystem (const PhysicsSystem&); PhysicsSystem& operator= (const PhysicsSystem&); }; diff --git a/docs/source/reference/modding/settings/physics.rst b/docs/source/reference/modding/settings/physics.rst deleted file mode 100644 index e4f970a79..000000000 --- a/docs/source/reference/modding/settings/physics.rst +++ /dev/null @@ -1,13 +0,0 @@ -Physics Settings -################ - -physics framerate ---------------- - -:Type: floating point -:Range: 10.0 to 60.0 -:Default: 60.0 - -Allows to set how frequently an engine will do physics calculations. A default value is 60 times per second. -This setting allows developers with low-clocked CPUs to test an engine. -Changing from default value can lead to physics bugs. Change this setting on your own risk, and reset a value to default before filling a physics-related bugreport! diff --git a/files/settings-default.cfg b/files/settings-default.cfg index f4c7f0a4a..aec667a9c 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -277,10 +277,6 @@ camera y multiplier = 1.0 # Invert the vertical axis while not in GUI mode. invert y axis = false -[Physics] -# Framerate of the physics system -physics framerate = 60.0 - [Saves] # Name of last character played, and default for loading save files.