mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-24 22:43:47 +00:00
Guard the Bullet drawing method with a read lock on the
btCollisionWorld. It closes a race on the collision shapes coordinates.
This commit is contained in:
parent
dbd6e3bfee
commit
b58244ac26
@ -9,6 +9,7 @@
|
||||
#include "components/settings/settings.hpp"
|
||||
#include "../mwmechanics/actorutil.hpp"
|
||||
#include "../mwmechanics/movement.hpp"
|
||||
#include "../mwrender/bulletdebugdraw.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/player.hpp"
|
||||
|
||||
@ -137,11 +138,12 @@ namespace
|
||||
|
||||
namespace MWPhysics
|
||||
{
|
||||
PhysicsTaskScheduler::PhysicsTaskScheduler(float physicsDt, btCollisionWorld *collisionWorld)
|
||||
PhysicsTaskScheduler::PhysicsTaskScheduler(float physicsDt, btCollisionWorld *collisionWorld, MWRender::DebugDrawer* debugDrawer)
|
||||
: mDefaultPhysicsDt(physicsDt)
|
||||
, mPhysicsDt(physicsDt)
|
||||
, mTimeAccum(0.f)
|
||||
, mCollisionWorld(collisionWorld)
|
||||
, mDebugDrawer(debugDrawer)
|
||||
, mNumJobs(0)
|
||||
, mRemainingSteps(0)
|
||||
, mLOSCacheExpiry(Settings::Manager::getInt("lineofsight keep inactive cache", "Physics"))
|
||||
@ -626,4 +628,10 @@ namespace MWPhysics
|
||||
mTimeBegin = mTimer->tick();
|
||||
mFrameNumber = frameNumber;
|
||||
}
|
||||
|
||||
void PhysicsTaskScheduler::debugDraw()
|
||||
{
|
||||
std::shared_lock lock(mCollisionWorldMutex);
|
||||
mDebugDrawer->step();
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,17 @@ namespace Misc
|
||||
class Barrier;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
class DebugDrawer;
|
||||
}
|
||||
|
||||
namespace MWPhysics
|
||||
{
|
||||
class PhysicsTaskScheduler
|
||||
{
|
||||
public:
|
||||
PhysicsTaskScheduler(float physicsDt, btCollisionWorld* collisionWorld);
|
||||
PhysicsTaskScheduler(float physicsDt, btCollisionWorld* collisionWorld, MWRender::DebugDrawer* debugDrawer);
|
||||
~PhysicsTaskScheduler();
|
||||
|
||||
/// @brief move actors taking into account desired movements and collisions
|
||||
@ -49,6 +54,7 @@ namespace MWPhysics
|
||||
void removeCollisionObject(btCollisionObject* collisionObject);
|
||||
void updateSingleAabb(std::weak_ptr<PtrHolder> ptr, bool immediate=false);
|
||||
bool getLineOfSight(const std::weak_ptr<Actor>& actor1, const std::weak_ptr<Actor>& actor2);
|
||||
void debugDraw();
|
||||
|
||||
private:
|
||||
void syncComputation();
|
||||
@ -68,6 +74,7 @@ namespace MWPhysics
|
||||
float mPhysicsDt;
|
||||
float mTimeAccum;
|
||||
btCollisionWorld* mCollisionWorld;
|
||||
MWRender::DebugDrawer* mDebugDrawer;
|
||||
std::vector<LOSRequest> mLOSCache;
|
||||
std::set<std::weak_ptr<PtrHolder>, std::owner_less<std::weak_ptr<PtrHolder>>> mUpdateAabb;
|
||||
|
||||
|
@ -97,8 +97,8 @@ namespace MWPhysics
|
||||
}
|
||||
}
|
||||
|
||||
mTaskScheduler = std::make_unique<PhysicsTaskScheduler>(mPhysicsDt, mCollisionWorld.get());
|
||||
mDebugDrawer = std::make_unique<MWRender::DebugDrawer>(mParentNode, mCollisionWorld.get(), mDebugDrawEnabled);
|
||||
mTaskScheduler = std::make_unique<PhysicsTaskScheduler>(mPhysicsDt, mCollisionWorld.get(), mDebugDrawer.get());
|
||||
}
|
||||
|
||||
PhysicsSystem::~PhysicsSystem()
|
||||
@ -827,7 +827,7 @@ namespace MWPhysics
|
||||
void PhysicsSystem::debugDraw()
|
||||
{
|
||||
if (mDebugDrawEnabled)
|
||||
mDebugDrawer->step();
|
||||
mTaskScheduler->debugDraw();
|
||||
}
|
||||
|
||||
bool PhysicsSystem::isActorStandingOn(const MWWorld::Ptr &actor, const MWWorld::ConstPtr &object) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user