mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 08:15:35 +00:00
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
This commit is contained in:
commit
063af50dee
2 changed files with 22 additions and 7 deletions
|
@ -118,7 +118,10 @@ namespace
|
||||||
const btCollisionWorld* mCollisionWorld;
|
const btCollisionWorld* mCollisionWorld;
|
||||||
void operator()(MWPhysics::ActorSimulation& sim) const
|
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();
|
actor->applyOffsetChange();
|
||||||
frameData.mPosition = actor->getPosition();
|
frameData.mPosition = actor->getPosition();
|
||||||
if (frameData.mWaterCollision && frameData.mPosition.z() < frameData.mWaterlevel && actor->canMoveToWaterSurface(frameData.mWaterlevel, mCollisionWorld))
|
if (frameData.mWaterCollision && frameData.mPosition.z() < frameData.mWaterlevel && actor->canMoveToWaterSurface(frameData.mWaterlevel, mCollisionWorld))
|
||||||
|
@ -157,7 +160,10 @@ namespace
|
||||||
btCollisionWorld* mCollisionWorld;
|
btCollisionWorld* mCollisionWorld;
|
||||||
void operator()(MWPhysics::ActorSimulation& sim) const
|
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))
|
if (actor->setPosition(frameData.mPosition))
|
||||||
{
|
{
|
||||||
frameData.mPosition = actor->getPosition(); // account for potential position change made by script
|
frameData.mPosition = actor->getPosition(); // account for potential position change made by script
|
||||||
|
@ -167,7 +173,10 @@ namespace
|
||||||
}
|
}
|
||||||
void operator()(MWPhysics::ProjectileSimulation& sim) const
|
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->setPosition(frameData.mPosition);
|
||||||
proj->updateCollisionObjectPosition();
|
proj->updateCollisionObjectPosition();
|
||||||
mCollisionWorld->updateSingleAabb(proj->getCollisionObject());
|
mCollisionWorld->updateSingleAabb(proj->getCollisionObject());
|
||||||
|
@ -197,7 +206,10 @@ namespace
|
||||||
const MWPhysics::PhysicsTaskScheduler* scheduler;
|
const MWPhysics::PhysicsTaskScheduler* scheduler;
|
||||||
void operator()(MWPhysics::ActorSimulation& sim) const
|
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();
|
auto ptr = actor->getPtr();
|
||||||
|
|
||||||
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
|
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
|
||||||
|
@ -229,7 +241,10 @@ namespace
|
||||||
}
|
}
|
||||||
void operator()(MWPhysics::ProjectileSimulation& sim) const
|
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));
|
proj->setSimulationPosition(::interpolateMovements(*proj, mTimeAccum, mPhysicsDt));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -117,8 +117,8 @@ namespace MWPhysics
|
||||||
osg::Vec3f mStormDirection;
|
osg::Vec3f mStormDirection;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ActorSimulation = std::pair<std::shared_ptr<Actor>, ActorFrameData>;
|
using ActorSimulation = std::pair<std::weak_ptr<Actor>, ActorFrameData>;
|
||||||
using ProjectileSimulation = std::pair<std::shared_ptr<Projectile>, ProjectileFrameData>;
|
using ProjectileSimulation = std::pair<std::weak_ptr<Projectile>, ProjectileFrameData>;
|
||||||
using Simulation = std::variant<ActorSimulation, ProjectileSimulation>;
|
using Simulation = std::variant<ActorSimulation, ProjectileSimulation>;
|
||||||
|
|
||||||
class PhysicsSystem : public RayCastingInterface
|
class PhysicsSystem : public RayCastingInterface
|
||||||
|
|
Loading…
Reference in a new issue