Skip to content

Instantly share code, notes, and snippets.

@Langerz82
Created February 10, 2020 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Langerz82/d92d4b442c5dfe4379d53c266a16507f to your computer and use it in GitHub Desktop.
Save Langerz82/d92d4b442c5dfe4379d53c266a16507f to your computer and use it in GitHub Desktop.
diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp
index 1299fde0d..dd0839d60 100644
--- a/apps/openmw/engine.cpp
+++ b/apps/openmw/engine.cpp
@@ -232,6 +232,7 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
, mFSStrict (false)
, mScriptBlacklistUse (true)
, mNewGame (false)
+ , mPhysicsFPS(60)
, mCfgMgr(configurationManager)
{
MWClass::registerClasses();
@@ -565,7 +566,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
// Create the world
mEnvironment.setWorld( new MWWorld::World (mViewer, rootNode, mResourceSystem.get(), mWorkQueue.get(),
mFileCollections, mContentFiles, mEncoder, mActivationDistanceOverride, mCellName,
- mStartupScript, mResDir.string(), mCfgMgr.getUserDataPath().string()));
+ mStartupScript, mResDir.string(), mCfgMgr.getUserDataPath().string(), mPhysicsFPS));
mEnvironment.getWorld()->setupPlayer();
input->setPlayer(&mEnvironment.getWorld()->getPlayer());
diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp
index a00cf474a..e4ed8afba 100644
--- a/apps/openmw/engine.hpp
+++ b/apps/openmw/engine.hpp
@@ -113,6 +113,8 @@ namespace OMW
osg::Timer_t mStartTick;
+ int mPhysicsFPS;
+
// not implemented
Engine (const Engine&);
Engine& operator= (const Engine&);
@@ -203,6 +205,9 @@ namespace OMW
void setRandomSeed(unsigned int seed);
+ void setPhysicsFPS(int fps) { mPhysicsFPS = fps; }
+ int getPhysicsFPS() { return mPhysicsFPS; }
+
private:
Files::ConfigurationManager& mCfgMgr;
};
diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp
index a39dd2e39..713acd69d 100644
--- a/apps/openmw/main.cpp
+++ b/apps/openmw/main.cpp
@@ -75,6 +75,9 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
("start", bpo::value<Files::EscapeHashString>()->default_value(""),
"set initial cell")
+ ("physics-fps", bpo::value<int>()->default_value(60),
+ "sets the physics fps")
+
("content", bpo::value<Files::EscapeStringVector>()->default_value(Files::EscapeStringVector(), "")
->multitoken(), "content file(s): esm/esp, or omwgame/omwaddon")
@@ -176,6 +179,9 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
std::cout << ToUTF8::encodingUsingMessage(encoding) << std::endl;
engine.setEncoding(ToUTF8::calculateEncoding(encoding));
+ // physics-fps settings
+ engine.setPhysicsFPS(variables["physics-fps"].as<int>());
+
// directory settings
engine.enableFSStrict(variables["fs-strict"].as<bool>());
diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp
index e2bf08d82..6a59f4db1 100644
--- a/apps/openmw/mwmechanics/actors.cpp
+++ b/apps/openmw/mwmechanics/actors.cpp
@@ -1426,6 +1426,14 @@ namespace MWMechanics
else
ptr.getRefData().getBaseNode()->setNodeMask(MWRender::Mask_Actor);
+ PtrActorMap::iterator iter = mActors.find(ptr);
+ if (iter != mActors.end())
+ {
+ if (ptr == player)
+ return;
+ iter->first.getClass().getCreatureStats(iter->first).setPhysicsFPS(ceil(dist / (mActorsProcessingRange / 10)));
+ }
+
// Fade away actors on large distance (>90% of actor's processing distance)
float visibilityRatio = 1.0;
float fadeStartDistance = mActorsProcessingRange*0.9f;
diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp
index 1c377540a..6b6a5bebf 100644
--- a/apps/openmw/mwmechanics/creaturestats.cpp
+++ b/apps/openmw/mwmechanics/creaturestats.cpp
@@ -24,7 +24,7 @@ namespace MWMechanics
mHitRecovery(false), mBlock(false), mMovementFlags(0),
mFallHeight(0), mRecalcMagicka(false), mLastRestock(0,0), mGoldPool(0), mActorId(-1), mHitAttemptActorId(-1),
mDeathAnimation(-1), mTimeOfDeath(), mGreetingState(Greet_None),
- mGreetingTimer(0), mTargetAngleRadians(0), mIsTurningToPlayer(false), mLevel (0)
+ mGreetingTimer(0), mTargetAngleRadians(0), mIsTurningToPlayer(false), mLevel (0), mPhysicsFPS(1)
{
for (int i=0; i<4; ++i)
mAiSettings[i] = 0;
diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp
index 7c4a83db1..039e8b0d7 100644
--- a/apps/openmw/mwmechanics/creaturestats.hpp
+++ b/apps/openmw/mwmechanics/creaturestats.hpp
@@ -82,6 +82,7 @@ namespace MWMechanics
float mTargetAngleRadians;
bool mIsTurningToPlayer;
+ int mPhysicsFPS;
public:
typedef std::pair<int, std::string> SummonKey; // <ESM::MagicEffect index, spell ID>
private:
@@ -304,6 +305,10 @@ namespace MWMechanics
/// assigned this function will return false).
static void cleanup();
+
+ void setPhysicsFPS(int fps) { mPhysicsFPS = fps; }
+ int getPhysicsFPS() { return mPhysicsFPS; }
+
};
}
diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp
index 31325cf21..012ecd3fb 100644
--- a/apps/openmw/mwphysics/physicssystem.cpp
+++ b/apps/openmw/mwphysics/physicssystem.cpp
@@ -1280,6 +1280,16 @@ namespace MWPhysics
continue;
Actor* physicActor = foundActor->second;
+ int ActorPhysicsFPS;
+ if (MWMechanics::getPlayer() == (physicActor))
+ {
+ ActorPhysicsFPS = 1;
+ }
+ else
+ {
+ ActorPhysicsFPS = physicActor->getPtr().getClass().getCreatureStats(physicActor->getPtr()).getPhysicsFPS();
+ }
+
float waterlevel = -std::numeric_limits<float>::max();
const MWWorld::CellStore *cell = iter->first.getCell();
if(cell->getCell()->hasWater())
@@ -1311,7 +1321,8 @@ namespace MWPhysics
osg::Vec3f position = physicActor->getPosition();
float oldHeight = position.z();
bool positionChanged = false;
- for (int i=0; i<numSteps; ++i)
+
+ for (int i=0; i<numSteps; i += ((numSteps + ActorPhysicsFPS) < numSteps ? ActorPhysicsFPS : 1))
{
position = MovementSolver::move(position, physicActor->getPtr(), physicActor, iter->second, mPhysicsDt,
flying, waterlevel, slowFall, mCollisionWorld, mStandingCollisions);
@@ -1322,7 +1333,7 @@ namespace MWPhysics
if (positionChanged)
mCollisionWorld->updateSingleAabb(physicActor->getCollisionObject());
- float interpolationFactor = mTimeAccum / mPhysicsDt;
+ float interpolationFactor = mTimeAccum / (mPhysicsDt / ActorPhysicsFPS);
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 364a59ab1..b92033b5f 100644
--- a/apps/openmw/mwphysics/physicssystem.hpp
+++ b/apps/openmw/mwphysics/physicssystem.hpp
@@ -59,6 +59,9 @@ namespace MWPhysics
PhysicsSystem (Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Group> parentNode);
~PhysicsSystem ();
+ void setPhysicsFPS(int fps) { mPhysicsFPS = fps; }
+ int getPhysicsFPS() { return mPhysicsFPS; }
+
void setUnrefQueue(SceneUtil::UnrefQueue* unrefQueue);
Resource::BulletShapeManager* getShapeManager();
@@ -191,6 +194,8 @@ namespace MWPhysics
void updateWater();
+ int mPhysicsFPS;
+
osg::ref_ptr<SceneUtil::UnrefQueue> mUnrefQueue;
btBroadphaseInterface* mBroadphase;
diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp
index 71948119a..9389fc3a7 100644
--- a/apps/openmw/mwworld/worldimp.cpp
+++ b/apps/openmw/mwworld/worldimp.cpp
@@ -159,7 +159,8 @@ namespace MWWorld
const std::vector<std::string>& contentFiles,
ToUTF8::Utf8Encoder* encoder, int activationDistanceOverride,
const std::string& startCell, const std::string& startupScript,
- const std::string& resourcePath, const std::string& userDataPath)
+ const std::string& resourcePath, const std::string& userDataPath,
+ int physicsFPS)
: mResourceSystem(resourceSystem), mLocalScripts (mStore),
mSky (true), mCells (mStore, mEsm),
mGodMode(false), mScriptsEnabled(true), mContentFiles (contentFiles), mUserDataPath(userDataPath),
@@ -197,6 +198,7 @@ namespace MWWorld
mSwimHeightScale = mStore.get<ESM::GameSetting>().find("fSwimHeightScale")->mValue.getFloat();
mPhysics.reset(new MWPhysics::PhysicsSystem(resourceSystem, rootNode));
+ mPhysics.get()->setPhysicsFPS(physicsFPS);
if (auto navigatorSettings = DetourNavigator::makeSettingsFromSettingsManager())
{
diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp
index ed622b5b8..3208abf06 100644
--- a/apps/openmw/mwworld/worldimp.hpp
+++ b/apps/openmw/mwworld/worldimp.hpp
@@ -200,7 +200,8 @@ namespace MWWorld
const std::vector<std::string>& contentFiles,
ToUTF8::Utf8Encoder* encoder, int activationDistanceOverride,
const std::string& startCell, const std::string& startupScript,
- const std::string& resourcePath, const std::string& userDataPath);
+ const std::string& resourcePath, const std::string& userDataPath,
+ int physicsFPS);
virtual ~World();
@@ -726,6 +727,7 @@ namespace MWWorld
osg::Vec3f getPathfindingHalfExtents(const MWWorld::ConstPtr& actor) const override;
bool hasCollisionWithDoor(const MWWorld::ConstPtr& door, const osg::Vec3f& position, const osg::Vec3f& destination) const override;
+
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment