diff --git a/apps/openmw/mwphysics/mtphysics.cpp b/apps/openmw/mwphysics/mtphysics.cpp index 7363b9964a..bb5447341b 100644 --- a/apps/openmw/mwphysics/mtphysics.cpp +++ b/apps/openmw/mwphysics/mtphysics.cpp @@ -54,29 +54,6 @@ namespace return actorData.mPosition.z() < actorData.mSwimLevel; } - void handleFall(MWPhysics::ActorFrameData& actorData, bool simulationPerformed) - { - const float heightDiff = actorData.mPosition.z() - actorData.mOldHeight; - - const bool isStillOnGround = (simulationPerformed && actorData.mWasOnGround && actorData.mIsOnGround); - - if (isStillOnGround || actorData.mFlying || isUnderWater(actorData) || actorData.mSlowFall < 1) - actorData.mNeedLand = true; - else if (heightDiff < 0) - actorData.mFallHeight += heightDiff; - } - - void updateMechanics(MWPhysics::Actor& actor, MWPhysics::ActorFrameData& actorData) - { - auto ptr = actor.getPtr(); - - MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); - if (actorData.mNeedLand) - stats.land(ptr == MWMechanics::getPlayer() && (actorData.mFlying || isUnderWater(actorData))); - else if (actorData.mFallHeight < 0) - stats.addToFallHeight(-actorData.mFallHeight); - } - osg::Vec3f interpolateMovements(MWPhysics::Actor& actor, MWPhysics::ActorFrameData& actorData, float timeAccum, float physicsDt) { const float interpolationFactor = std::clamp(timeAccum / physicsDt, 0.0f, 1.0f); @@ -221,10 +198,8 @@ namespace MWPhysics if (mNumThreads != 0) { for (size_t i = 0; i < mActors.size(); ++i) - { - updateMechanics(*mActors[i], mActorsFrameData[i]); updateActor(*mActors[i], mActorsFrameData[i], mAdvanceSimulation, mTimeAccum, mPhysicsDt); - } + if(mAdvanceSimulation) mAsyncBudget.update(mTimer->delta_s(mAsyncStartTime, mTimeEnd), mPrevStepCount, mBudgetCursor); updateStats(frameStart, frameNumber, stats); @@ -449,11 +424,6 @@ namespace MWPhysics if (!mRemainingSteps) { - while ((job = mNextJob.fetch_add(1, std::memory_order_relaxed)) < mNumJobs) - { - handleFall(mActorsFrameData[job], mAdvanceSimulation); - } - refreshLOSCache(); mPostSimBarrier->wait([this] { afterPostSim(); }); } @@ -476,6 +446,17 @@ namespace MWPhysics void PhysicsTaskScheduler::updateActor(Actor& actor, ActorFrameData& actorData, bool simulationPerformed, float timeAccum, float dt) const { + auto ptr = actor.getPtr(); + + MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); + const float heightDiff = actorData.mPosition.z() - actorData.mOldHeight; + const bool isStillOnGround = (simulationPerformed && actorData.mWasOnGround && actorData.mIsOnGround); + + if (isStillOnGround || actorData.mFlying || isUnderWater(actorData) || actorData.mSlowFall < 1) + stats.land(ptr == MWMechanics::getPlayer() && (actorData.mFlying || isUnderWater(actorData))); + else if (heightDiff < 0) + stats.addToFallHeight(-heightDiff); + actor.setSimulationPosition(interpolateMovements(actor, actorData, timeAccum, dt)); actor.setLastStuckPosition(actorData.mLastStuckPosition); actor.setStuckFrames(actorData.mStuckFrames); @@ -524,11 +505,8 @@ namespace MWPhysics } for (size_t i = 0; i < mActors.size(); ++i) - { - handleFall(mActorsFrameData[i], mAdvanceSimulation); - updateMechanics(*mActors[i], mActorsFrameData[i]); updateActor(*mActors[i], mActorsFrameData[i], mAdvanceSimulation, mTimeAccum, mPhysicsDt); - } + refreshLOSCache(); } diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index a8c39efee2..6b2600069a 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -978,14 +978,12 @@ namespace MWPhysics , mWaterlevel(waterlevel) , mHalfExtentsZ(actor.getHalfExtents().z()) , mOldHeight(0) - , mFallHeight(0) , mStuckFrames(0) , mFlying(MWBase::Environment::get().getWorld()->isFlying(actor.getPtr())) , mWasOnGround(actor.getOnGround()) , mIsAquatic(actor.getPtr().getClass().isPureWaterCreature(actor.getPtr())) , mWaterCollision(waterCollision) , mSkipCollisionDetection(actor.skipCollisions() || !actor.getCollisionMode()) - , mNeedLand(false) { } diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index 4fb7a3518f..cf4ca40a54 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -97,14 +97,12 @@ namespace MWPhysics const float mWaterlevel; const float mHalfExtentsZ; float mOldHeight; - float mFallHeight; unsigned int mStuckFrames; const bool mFlying; const bool mWasOnGround; const bool mIsAquatic; const bool mWaterCollision; const bool mSkipCollisionDetection; - bool mNeedLand; }; struct WorldFrameData