1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00

Do not lock mutex in MWPhysics::Actor constructor

This commit is contained in:
elsid 2022-09-16 23:47:39 +02:00
parent bd98404890
commit bceca33699
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
2 changed files with 18 additions and 4 deletions

View file

@ -93,13 +93,13 @@ Actor::Actor(const MWWorld::Ptr& ptr, const Resource::BulletShape* shape, Physic
mCollisionObject->setCollisionShape(mShape.get());
mCollisionObject->setUserPointer(this);
updateScale();
updateScaleUnsafe();
if(!mRotationallyInvariant)
setRotation(mPtr.getRefData().getBaseNode()->getAttitude());
mRotation = mPtr.getRefData().getBaseNode()->getAttitude();
addCollisionMask(getCollisionMask());
updateCollisionObjectPosition();
updateCollisionObjectPositionUnsafe();
}
Actor::~Actor()
@ -167,6 +167,11 @@ osg::Vec3f Actor::getScaledMeshTranslation() const
void Actor::updateCollisionObjectPosition()
{
std::scoped_lock lock(mPositionMutex);
updateCollisionObjectPositionUnsafe();
}
void Actor::updateCollisionObjectPositionUnsafe()
{
mShape->setLocalScaling(Misc::Convert::toBullet(mScale));
osg::Vec3f newPosition = getScaledMeshTranslation() + mPosition;
@ -228,6 +233,11 @@ bool Actor::isRotationallyInvariant() const
void Actor::updateScale()
{
std::scoped_lock lock(mPositionMutex);
updateScaleUnsafe();
}
void Actor::updateScaleUnsafe()
{
float scale = mPtr.getCellRef().getScale();
osg::Vec3f scaleVec(scale,scale,scale);

View file

@ -189,7 +189,7 @@ namespace MWPhysics
osg::Vec3f mScale;
osg::Vec3f mPositionOffset;
bool mWorldPositionChanged;
bool mWorldPositionChanged = false;
bool mSkipSimulation = true;
mutable std::mutex mPositionMutex;
@ -207,6 +207,10 @@ namespace MWPhysics
Actor(const Actor&);
Actor& operator=(const Actor&);
inline void updateScaleUnsafe();
inline void updateCollisionObjectPositionUnsafe();
};
}