Merge branch 'fix_fargoth_hiding_crash' into 'master'

Use weak_ptr for Actor and Projectile simulations (#6515)

Closes #6515

See merge request OpenMW/openmw!1573
ptmikheev-master-patch-42253
psi29a 3 years ago
commit 063af50dee

@ -118,7 +118,10 @@ namespace
const btCollisionWorld* mCollisionWorld;
void operator()(MWPhysics::ActorSimulation& sim) const
{
auto& [actor, frameData] = sim;
auto& [actorPtr, frameData] = sim;
const auto actor = actorPtr.lock();
if (actor == nullptr)
return;
actor->applyOffsetChange();
frameData.mPosition = actor->getPosition();
if (frameData.mWaterCollision && frameData.mPosition.z() < frameData.mWaterlevel && actor->canMoveToWaterSurface(frameData.mWaterlevel, mCollisionWorld))
@ -157,7 +160,10 @@ namespace
btCollisionWorld* mCollisionWorld;
void operator()(MWPhysics::ActorSimulation& sim) const
{
auto& [actor, frameData] = sim;
auto& [actorPtr, frameData] = sim;
const auto actor = actorPtr.lock();
if (actor == nullptr)
return;
if (actor->setPosition(frameData.mPosition))
{
frameData.mPosition = actor->getPosition(); // account for potential position change made by script
@ -167,7 +173,10 @@ namespace
}
void operator()(MWPhysics::ProjectileSimulation& sim) const
{
auto& [proj, frameData] = sim;
auto& [projPtr, frameData] = sim;
const auto proj = projPtr.lock();
if (proj == nullptr)
return;
proj->setPosition(frameData.mPosition);
proj->updateCollisionObjectPosition();
mCollisionWorld->updateSingleAabb(proj->getCollisionObject());
@ -197,7 +206,10 @@ namespace
const MWPhysics::PhysicsTaskScheduler* scheduler;
void operator()(MWPhysics::ActorSimulation& sim) const
{
auto& [actor, frameData] = sim;
auto& [actorPtr, frameData] = sim;
const auto actor = actorPtr.lock();
if (actor == nullptr)
return;
auto ptr = actor->getPtr();
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
@ -229,7 +241,10 @@ namespace
}
void operator()(MWPhysics::ProjectileSimulation& sim) const
{
auto& [proj, frameData] = sim;
auto& [projPtr, frameData] = sim;
const auto proj = projPtr.lock();
if (proj == nullptr)
return;
proj->setSimulationPosition(::interpolateMovements(*proj, mTimeAccum, mPhysicsDt));
}
};

@ -117,8 +117,8 @@ namespace MWPhysics
osg::Vec3f mStormDirection;
};
using ActorSimulation = std::pair<std::shared_ptr<Actor>, ActorFrameData>;
using ProjectileSimulation = std::pair<std::shared_ptr<Projectile>, ProjectileFrameData>;
using ActorSimulation = std::pair<std::weak_ptr<Actor>, ActorFrameData>;
using ProjectileSimulation = std::pair<std::weak_ptr<Projectile>, ProjectileFrameData>;
using Simulation = std::variant<ActorSimulation, ProjectileSimulation>;
class PhysicsSystem : public RayCastingInterface

Loading…
Cancel
Save