Merge branch 'restore_absolute_position_handling' into 'master'

Restore pre-async handling of absolute actors positionning

See merge request OpenMW/openmw!486
pull/593/head
Alexei Dobrohotov 4 years ago
commit e9a8636d18

@ -74,7 +74,7 @@ Actor::Actor(const MWWorld::Ptr& ptr, const Resource::BulletShape* shape, Physic
updateRotation(); updateRotation();
updateScale(); updateScale();
resetPosition(); updatePosition();
addCollisionMask(getCollisionMask()); addCollisionMask(getCollisionMask());
updateCollisionObjectPosition(); updateCollisionObjectPosition();
} }
@ -119,30 +119,34 @@ int Actor::getCollisionMask() const
return collisionMask; return collisionMask;
} }
void Actor::updatePositionUnsafe() void Actor::updatePosition()
{ {
if (!mWorldPositionChanged && mWorldPosition != mPtr.getRefData().getPosition().asVec3()) std::scoped_lock lock(mPositionMutex);
mWorldPositionChanged = true; updateWorldPosition();
mWorldPosition = mPtr.getRefData().getPosition().asVec3(); mPreviousPosition = mWorldPosition;
mPosition = mWorldPosition;
mSimulationPosition = mWorldPosition;
mStandingOnPtr = nullptr;
mSkipSimulation = true;
} }
void Actor::updatePosition() void Actor::updateWorldPosition()
{ {
std::scoped_lock lock(mPositionMutex); if (mWorldPosition != mPtr.getRefData().getPosition().asVec3())
updatePositionUnsafe(); mWorldPositionChanged = true;
mWorldPosition = mPtr.getRefData().getPosition().asVec3();
} }
osg::Vec3f Actor::getWorldPosition() const osg::Vec3f Actor::getWorldPosition() const
{ {
std::scoped_lock lock(mPositionMutex);
return mWorldPosition; return mWorldPosition;
} }
void Actor::setSimulationPosition(const osg::Vec3f& position) void Actor::setSimulationPosition(const osg::Vec3f& position)
{ {
if (!mResetSimulation) if (!mSkipSimulation)
mSimulationPosition = position; mSimulationPosition = position;
mResetSimulation = false; mSkipSimulation = false;
} }
osg::Vec3f Actor::getSimulationPosition() const osg::Vec3f Actor::getSimulationPosition() const
@ -150,8 +154,9 @@ osg::Vec3f Actor::getSimulationPosition() const
return mSimulationPosition; return mSimulationPosition;
} }
void Actor::updateCollisionObjectPositionUnsafe() void Actor::updateCollisionObjectPosition()
{ {
std::scoped_lock lock(mPositionMutex);
mShape->setLocalScaling(Misc::Convert::toBullet(mScale)); mShape->setLocalScaling(Misc::Convert::toBullet(mScale));
osg::Vec3f scaledTranslation = mRotation * osg::componentMultiply(mMeshTranslation, mScale); osg::Vec3f scaledTranslation = mRotation * osg::componentMultiply(mMeshTranslation, mScale);
osg::Vec3f newPosition = scaledTranslation + mPosition; osg::Vec3f newPosition = scaledTranslation + mPosition;
@ -161,12 +166,6 @@ void Actor::updateCollisionObjectPositionUnsafe()
mWorldPositionChanged = false; mWorldPositionChanged = false;
} }
void Actor::updateCollisionObjectPosition()
{
std::scoped_lock lock(mPositionMutex);
updateCollisionObjectPositionUnsafe();
}
osg::Vec3f Actor::getCollisionObjectPosition() const osg::Vec3f Actor::getCollisionObjectPosition() const
{ {
std::scoped_lock lock(mPositionMutex); std::scoped_lock lock(mPositionMutex);
@ -189,18 +188,6 @@ void Actor::adjustPosition(const osg::Vec3f& offset)
mPositionOffset += offset; mPositionOffset += offset;
} }
void Actor::resetPosition()
{
std::scoped_lock lock(mPositionMutex);
updatePositionUnsafe();
mPreviousPosition = mWorldPosition;
mPosition = mWorldPosition;
mSimulationPosition = mWorldPosition;
mStandingOnPtr = nullptr;
mWorldPositionChanged = false;
mResetSimulation = true;
}
osg::Vec3f Actor::getPosition() const osg::Vec3f Actor::getPosition() const
{ {
return mPosition; return mPosition;
@ -214,8 +201,6 @@ osg::Vec3f Actor::getPreviousPosition() const
void Actor::updateRotation () void Actor::updateRotation ()
{ {
std::scoped_lock lock(mPositionMutex); std::scoped_lock lock(mPositionMutex);
if (mRotation == mPtr.getRefData().getBaseNode()->getAttitude())
return;
mRotation = mPtr.getRefData().getBaseNode()->getAttitude(); mRotation = mPtr.getRefData().getBaseNode()->getAttitude();
} }
@ -246,7 +231,6 @@ osg::Vec3f Actor::getHalfExtents() const
osg::Vec3f Actor::getOriginalHalfExtents() const osg::Vec3f Actor::getOriginalHalfExtents() const
{ {
std::scoped_lock lock(mPositionMutex);
return mHalfExtents; return mHalfExtents;
} }
@ -283,7 +267,6 @@ void Actor::setWalkingOnWater(bool walkingOnWater)
void Actor::setCanWaterWalk(bool waterWalk) void Actor::setCanWaterWalk(bool waterWalk)
{ {
std::scoped_lock lock(mPositionMutex);
if (waterWalk != mCanWaterWalk) if (waterWalk != mCanWaterWalk)
{ {
mCanWaterWalk = waterWalk; mCanWaterWalk = waterWalk;

@ -60,7 +60,7 @@ namespace MWPhysics
* Set mWorldPosition to the position in the Ptr's RefData. This is used by the physics simulation to account for * Set mWorldPosition to the position in the Ptr's RefData. This is used by the physics simulation to account for
* when an object is "instantly" moved/teleported as opposed to being moved by the physics simulation. * when an object is "instantly" moved/teleported as opposed to being moved by the physics simulation.
*/ */
void updatePosition(); void updateWorldPosition();
osg::Vec3f getWorldPosition() const; osg::Vec3f getWorldPosition() const;
/** /**
@ -93,7 +93,7 @@ namespace MWPhysics
* Returns true if the new position is different. * Returns true if the new position is different.
*/ */
bool setPosition(const osg::Vec3f& position); bool setPosition(const osg::Vec3f& position);
void resetPosition(); void updatePosition();
void adjustPosition(const osg::Vec3f& offset); void adjustPosition(const osg::Vec3f& offset);
osg::Vec3f getPosition() const; osg::Vec3f getPosition() const;
@ -155,8 +155,6 @@ namespace MWPhysics
void updateCollisionMask(); void updateCollisionMask();
void addCollisionMask(int collisionMask); void addCollisionMask(int collisionMask);
int getCollisionMask() const; int getCollisionMask() const;
void updateCollisionObjectPositionUnsafe();
void updatePositionUnsafe();
bool mCanWaterWalk; bool mCanWaterWalk;
std::atomic<bool> mWalkingOnWater; std::atomic<bool> mWalkingOnWater;
@ -180,7 +178,7 @@ namespace MWPhysics
osg::Vec3f mPreviousPosition; osg::Vec3f mPreviousPosition;
osg::Vec3f mPositionOffset; osg::Vec3f mPositionOffset;
bool mWorldPositionChanged; bool mWorldPositionChanged;
bool mResetSimulation; bool mSkipSimulation;
btTransform mLocalTransform; btTransform mLocalTransform;
mutable std::mutex mPositionMutex; mutable std::mutex mPositionMutex;

@ -272,8 +272,8 @@ namespace MWPhysics
mActorsFrameData.clear(); mActorsFrameData.clear();
for (const auto& [_, actor] : actors) for (const auto& [_, actor] : actors)
{ {
actor->resetPosition(); actor->updatePosition();
actor->setSimulationPosition(actor->getWorldPosition()); // resetPosition skip next simulation, now we need to "consume" it actor->setSimulationPosition(actor->getWorldPosition()); // updatePosition skip next simulation, now we need to "consume" it
actor->updateCollisionObjectPosition(); actor->updateCollisionObjectPosition();
mMovedActors.emplace_back(actor->getPtr()); mMovedActors.emplace_back(actor->getPtr());
} }

@ -437,7 +437,6 @@ namespace MWPhysics
ActorMap::iterator found = mActors.find(ptr); ActorMap::iterator found = mActors.find(ptr);
if (found == mActors.end()) if (found == mActors.end())
return ptr.getRefData().getPosition().asVec3(); return ptr.getRefData().getPosition().asVec3();
resetPosition(ptr);
return MovementSolver::traceDown(ptr, position, found->second.get(), mCollisionWorld.get(), maxHeight); return MovementSolver::traceDown(ptr, position, found->second.get(), mCollisionWorld.get(), maxHeight);
} }
@ -642,17 +641,6 @@ namespace MWPhysics
if (foundActor != mActors.end()) if (foundActor != mActors.end())
{ {
foundActor->second->updatePosition(); foundActor->second->updatePosition();
mTaskScheduler->updateSingleAabb(foundActor->second);
return;
}
}
void PhysicsSystem::resetPosition(const MWWorld::ConstPtr &ptr)
{
ActorMap::iterator foundActor = mActors.find(ptr);
if (foundActor != mActors.end())
{
foundActor->second->resetPosition();
mTaskScheduler->updateSingleAabb(foundActor->second, true); mTaskScheduler->updateSingleAabb(foundActor->second, true);
return; return;
} }
@ -940,7 +928,7 @@ namespace MWPhysics
void ActorFrameData::updatePosition() void ActorFrameData::updatePosition()
{ {
mActorRaw->updatePosition(); mActorRaw->updateWorldPosition();
mPosition = mActorRaw->getPosition(); mPosition = mActorRaw->getPosition();
if (mMoveToWaterSurface) if (mMoveToWaterSurface)
{ {

@ -143,7 +143,6 @@ namespace MWPhysics
void updateScale (const MWWorld::Ptr& ptr); void updateScale (const MWWorld::Ptr& ptr);
void updateRotation (const MWWorld::Ptr& ptr); void updateRotation (const MWWorld::Ptr& ptr);
void updatePosition (const MWWorld::Ptr& ptr); void updatePosition (const MWWorld::Ptr& ptr);
void resetPosition(const MWWorld::ConstPtr &ptr);
void addHeightField (const float* heights, int x, int y, float triSize, float sqrtVerts, float minH, float maxH, const osg::Object* holdObject); void addHeightField (const float* heights, int x, int y, float triSize, float sqrtVerts, float minH, float maxH, const osg::Object* holdObject);

@ -1356,7 +1356,6 @@ namespace MWWorld
} }
moveObject(ptr, ptr.getCell(), pos.x(), pos.y(), pos.z()); moveObject(ptr, ptr.getCell(), pos.x(), pos.y(), pos.z());
mPhysics->resetPosition(ptr);
} }
void World::fixPosition() void World::fixPosition()

Loading…
Cancel
Save