diff --git a/apps/openmw/mwphysics/mtphysics.cpp b/apps/openmw/mwphysics/mtphysics.cpp index bdffcef44..50cfd808f 100644 --- a/apps/openmw/mwphysics/mtphysics.cpp +++ b/apps/openmw/mwphysics/mtphysics.cpp @@ -297,12 +297,19 @@ namespace MWPhysics return mPreviousMovementResults; } - const PtrPositionList& PhysicsTaskScheduler::resetSimulation() + const PtrPositionList& PhysicsTaskScheduler::resetSimulation(const ActorMap& actors) { std::unique_lock lock(mSimulationMutex); mMovementResults.clear(); mPreviousMovementResults.clear(); mActorsFrameData.clear(); + + for (const auto& [_, actor] : actors) + { + actor->resetPosition(); + actor->setStandingOnPtr(nullptr); + mMovementResults[actor->getPtr()] = actor->getWorldPosition(); + } return mMovementResults; } diff --git a/apps/openmw/mwphysics/mtphysics.hpp b/apps/openmw/mwphysics/mtphysics.hpp index f7a131ca2..3a761829b 100644 --- a/apps/openmw/mwphysics/mtphysics.hpp +++ b/apps/openmw/mwphysics/mtphysics.hpp @@ -34,7 +34,7 @@ namespace MWPhysics /// @return new position of each actor const PtrPositionList& moveActors(int numSteps, float timeAccum, std::vector&& actorsData, osg::Timer_t frameStart, unsigned int frameNumber, osg::Stats& stats); - const PtrPositionList& resetSimulation(); + const PtrPositionList& resetSimulation(const ActorMap& actors); // Thread safe wrappers void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, btCollisionWorld::RayResultCallback& resultCallback) const; diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index cdbad2cdd..b750970d9 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -677,14 +677,7 @@ namespace MWPhysics mTimeAccum -= numSteps * mPhysicsDt; if (skipSimulation) - { - for (auto& [_, actor] : mActors) - { - actor->resetPosition(); - actor->setStandingOnPtr(nullptr); - } - return mTaskScheduler->resetSimulation(); - } + return mTaskScheduler->resetSimulation(mActors); return mTaskScheduler->moveActors(numSteps, mTimeAccum, prepareFrameData(numSteps), frameStart, frameNumber, stats); } diff --git a/apps/openmw/mwphysics/physicssystem.hpp b/apps/openmw/mwphysics/physicssystem.hpp index 03ae78993..4137b1e09 100644 --- a/apps/openmw/mwphysics/physicssystem.hpp +++ b/apps/openmw/mwphysics/physicssystem.hpp @@ -57,6 +57,8 @@ namespace MWPhysics class Actor; class PhysicsTaskScheduler; + using ActorMap = std::map>; + struct ContactPoint { MWWorld::Ptr mObject; @@ -265,7 +267,6 @@ namespace MWPhysics std::set mAnimatedObjects; // stores pointers to elements in mObjects - using ActorMap = std::map>; ActorMap mActors; using HeightFieldMap = std::map, HeightField *>;