|
|
|
@ -177,43 +177,11 @@ namespace MWPhysics
|
|
|
|
|
mDeferAabbUpdate = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mPreStepBarrier = std::make_unique<Misc::Barrier>(mNumThreads, [&]()
|
|
|
|
|
{
|
|
|
|
|
if (mDeferAabbUpdate)
|
|
|
|
|
updateAabbs();
|
|
|
|
|
if (!mRemainingSteps)
|
|
|
|
|
return;
|
|
|
|
|
for (auto& data : mActorsFrameData)
|
|
|
|
|
if (data.mActor.lock())
|
|
|
|
|
{
|
|
|
|
|
std::unique_lock lock(mCollisionWorldMutex);
|
|
|
|
|
MovementSolver::unstuck(data, mCollisionWorld);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
mPreStepBarrier = std::make_unique<Misc::Barrier>(mNumThreads);
|
|
|
|
|
|
|
|
|
|
mPostStepBarrier = std::make_unique<Misc::Barrier>(mNumThreads, [&]()
|
|
|
|
|
{
|
|
|
|
|
if (mRemainingSteps)
|
|
|
|
|
{
|
|
|
|
|
--mRemainingSteps;
|
|
|
|
|
updateActorsPositions();
|
|
|
|
|
}
|
|
|
|
|
mNextJob.store(0, std::memory_order_release);
|
|
|
|
|
});
|
|
|
|
|
mPostStepBarrier = std::make_unique<Misc::Barrier>(mNumThreads);
|
|
|
|
|
|
|
|
|
|
mPostSimBarrier = std::make_unique<Misc::Barrier>(mNumThreads, [&]()
|
|
|
|
|
{
|
|
|
|
|
mNewFrame = false;
|
|
|
|
|
if (mLOSCacheExpiry >= 0)
|
|
|
|
|
{
|
|
|
|
|
std::unique_lock lock(mLOSCacheMutex);
|
|
|
|
|
mLOSCache.erase(
|
|
|
|
|
std::remove_if(mLOSCache.begin(), mLOSCache.end(),
|
|
|
|
|
[](const LOSRequest& req) { return req.mStale; }),
|
|
|
|
|
mLOSCache.end());
|
|
|
|
|
}
|
|
|
|
|
mTimeEnd = mTimer->tick();
|
|
|
|
|
});
|
|
|
|
|
mPostSimBarrier = std::make_unique<Misc::Barrier>(mNumThreads);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PhysicsTaskScheduler::~PhysicsTaskScheduler()
|
|
|
|
@ -525,7 +493,7 @@ namespace MWPhysics
|
|
|
|
|
if (!mNewFrame)
|
|
|
|
|
mHasJob.wait(lock, [&]() { return mQuit || mNewFrame; });
|
|
|
|
|
|
|
|
|
|
mPreStepBarrier->wait();
|
|
|
|
|
mPreStepBarrier->wait([this] { afterPreStep(); });
|
|
|
|
|
|
|
|
|
|
int job = 0;
|
|
|
|
|
while (mRemainingSteps && (job = mNextJob.fetch_add(1, std::memory_order_relaxed)) < mNumJobs)
|
|
|
|
@ -537,7 +505,7 @@ namespace MWPhysics
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mPostStepBarrier->wait();
|
|
|
|
|
mPostStepBarrier->wait([this] { afterPostStep(); });
|
|
|
|
|
|
|
|
|
|
if (!mRemainingSteps)
|
|
|
|
|
{
|
|
|
|
@ -552,7 +520,7 @@ namespace MWPhysics
|
|
|
|
|
|
|
|
|
|
if (mLOSCacheExpiry >= 0)
|
|
|
|
|
refreshLOSCache();
|
|
|
|
|
mPostSimBarrier->wait();
|
|
|
|
|
mPostSimBarrier->wait([this] { afterPostSim(); });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -633,4 +601,42 @@ namespace MWPhysics
|
|
|
|
|
std::shared_lock lock(mCollisionWorldMutex);
|
|
|
|
|
mDebugDrawer->step();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhysicsTaskScheduler::afterPreStep()
|
|
|
|
|
{
|
|
|
|
|
if (mDeferAabbUpdate)
|
|
|
|
|
updateAabbs();
|
|
|
|
|
if (!mRemainingSteps)
|
|
|
|
|
return;
|
|
|
|
|
for (auto& data : mActorsFrameData)
|
|
|
|
|
if (data.mActor.lock())
|
|
|
|
|
{
|
|
|
|
|
std::unique_lock lock(mCollisionWorldMutex);
|
|
|
|
|
MovementSolver::unstuck(data, mCollisionWorld);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhysicsTaskScheduler::afterPostStep()
|
|
|
|
|
{
|
|
|
|
|
if (mRemainingSteps)
|
|
|
|
|
{
|
|
|
|
|
--mRemainingSteps;
|
|
|
|
|
updateActorsPositions();
|
|
|
|
|
}
|
|
|
|
|
mNextJob.store(0, std::memory_order_release);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PhysicsTaskScheduler::afterPostSim()
|
|
|
|
|
{
|
|
|
|
|
mNewFrame = false;
|
|
|
|
|
if (mLOSCacheExpiry >= 0)
|
|
|
|
|
{
|
|
|
|
|
std::unique_lock lock(mLOSCacheMutex);
|
|
|
|
|
mLOSCache.erase(
|
|
|
|
|
std::remove_if(mLOSCache.begin(), mLOSCache.end(),
|
|
|
|
|
[](const LOSRequest& req) { return req.mStale; }),
|
|
|
|
|
mLOSCache.end());
|
|
|
|
|
}
|
|
|
|
|
mTimeEnd = mTimer->tick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|