1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 06:23:53 +00:00

Revert "Merge pull request #2204 from elsid/fix_navigator_update"

This reverts commit 26fb0e7a0f, reversing
changes made to 42b2391303.
This commit is contained in:
Bret Curtis 2019-03-04 11:06:15 +01:00
parent 84ce9814fd
commit 14c93b3df0
15 changed files with 26 additions and 104 deletions

View file

@ -134,7 +134,6 @@ namespace MWBase
virtual MWWorld::Player& getPlayer() = 0; virtual MWWorld::Player& getPlayer() = 0;
virtual MWWorld::Ptr getPlayerPtr() = 0; virtual MWWorld::Ptr getPlayerPtr() = 0;
virtual MWWorld::ConstPtr getPlayerConstPtr() const = 0;
virtual const MWWorld::ESMStore& getStore() const = 0; virtual const MWWorld::ESMStore& getStore() const = 0;
@ -616,9 +615,6 @@ namespace MWBase
virtual void removeActorPath(const MWWorld::ConstPtr& actor) const = 0; virtual void removeActorPath(const MWWorld::ConstPtr& actor) const = 0;
virtual void setNavMeshNumberToRender(const std::size_t value) = 0; virtual void setNavMeshNumberToRender(const std::size_t value) = 0;
/// Return physical half extents of the given actor to be used in pathfinding
virtual osg::Vec3f getPathfindingHalfExtents(const MWWorld::ConstPtr& actor) const = 0;
}; };
} }

View file

@ -135,9 +135,9 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
{ {
if (wasShortcutting || doesPathNeedRecalc(dest, actor.getCell())) // if need to rebuild path if (wasShortcutting || doesPathNeedRecalc(dest, actor.getCell())) // if need to rebuild path
{ {
const auto halfExtents = world->getPathfindingHalfExtents(actor); const osg::Vec3f playerHalfExtents = world->getHalfExtents(getPlayer()); // Using player half extents for better performance
mPathFinder.buildPath(actor, position, dest, actor.getCell(), getPathGridGraph(actor.getCell()), mPathFinder.buildPath(actor, position, dest, actor.getCell(), getPathGridGraph(actor.getCell()),
halfExtents, getNavigatorFlags(actor)); playerHalfExtents, getNavigatorFlags(actor));
mRotateOnTheRunChecks = 3; mRotateOnTheRunChecks = 3;
// give priority to go directly on target if there is minimal opportunity // give priority to go directly on target if there is minimal opportunity

View file

@ -155,9 +155,9 @@ namespace MWMechanics
} }
else else
{ {
const osg::Vec3f halfExtents = MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(actor); const osg::Vec3f playerHalfExtents = MWBase::Environment::get().getWorld()->getHalfExtents(getPlayer()); // Using player half extents for better performance
mPathFinder.buildPath(actor, pos.asVec3(), mDestination, actor.getCell(), mPathFinder.buildPath(actor, pos.asVec3(), mDestination, actor.getCell(),
getPathGridGraph(actor.getCell()), halfExtents, getNavigatorFlags(actor)); getPathGridGraph(actor.getCell()), playerHalfExtents, getNavigatorFlags(actor));
} }
if (mPathFinder.isPathConstructed()) if (mPathFinder.isPathConstructed())
@ -312,9 +312,10 @@ namespace MWMechanics
if ((!isWaterCreature && !destinationIsAtWater(actor, mDestination)) || if ((!isWaterCreature && !destinationIsAtWater(actor, mDestination)) ||
(isWaterCreature && !destinationThroughGround(currentPosition, mDestination))) (isWaterCreature && !destinationThroughGround(currentPosition, mDestination)))
{ {
const osg::Vec3f halfExtents = MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(actor); // Using player half extents for better performance
const osg::Vec3f playerHalfExtents = MWBase::Environment::get().getWorld()->getHalfExtents(getPlayer());
mPathFinder.buildPath(actor, currentPosition, mDestination, actor.getCell(), mPathFinder.buildPath(actor, currentPosition, mDestination, actor.getCell(),
getPathGridGraph(actor.getCell()), halfExtents, getNavigatorFlags(actor)); getPathGridGraph(actor.getCell()), playerHalfExtents, getNavigatorFlags(actor));
mPathFinder.addPointToPath(mDestination); mPathFinder.addPointToPath(mDestination);
if (mPathFinder.isPathConstructed()) if (mPathFinder.isPathConstructed())

View file

@ -201,11 +201,6 @@ osg::Vec3f Actor::getHalfExtents() const
return osg::componentMultiply(mHalfExtents, mScale); return osg::componentMultiply(mHalfExtents, mScale);
} }
osg::Vec3f Actor::getOriginalHalfExtents() const
{
return mHalfExtents;
}
osg::Vec3f Actor::getRenderingHalfExtents() const osg::Vec3f Actor::getRenderingHalfExtents() const
{ {
return osg::componentMultiply(mHalfExtents, mRenderingScale); return osg::componentMultiply(mHalfExtents, mRenderingScale);

View file

@ -66,11 +66,6 @@ namespace MWPhysics
*/ */
osg::Vec3f getHalfExtents() const; osg::Vec3f getHalfExtents() const;
/**
* Returns the half extents of the collision body (not scaled)
*/
osg::Vec3f getOriginalHalfExtents() const;
/** /**
* Returns the position of the collision body * Returns the position of the collision body
* @note The collision shape's origin is in its center, so the position returned can be described as center of the actor collision box in world space. * @note The collision shape's origin is in its center, so the position returned can be described as center of the actor collision box in world space.

View file

@ -906,14 +906,6 @@ namespace MWPhysics
return osg::Vec3f(); return osg::Vec3f();
} }
osg::Vec3f PhysicsSystem::getOriginalHalfExtents(const MWWorld::ConstPtr &actor) const
{
if (const Actor* physactor = getActor(actor))
return physactor->getOriginalHalfExtents();
else
return osg::Vec3f();
}
osg::Vec3f PhysicsSystem::getRenderingHalfExtents(const MWWorld::ConstPtr &actor) const osg::Vec3f PhysicsSystem::getRenderingHalfExtents(const MWWorld::ConstPtr &actor) const
{ {
const Actor* physactor = getActor(actor); const Actor* physactor = getActor(actor);

View file

@ -136,9 +136,6 @@ namespace MWPhysics
/// Get physical half extents (scaled) of the given actor. /// Get physical half extents (scaled) of the given actor.
osg::Vec3f getHalfExtents(const MWWorld::ConstPtr& actor) const; osg::Vec3f getHalfExtents(const MWWorld::ConstPtr& actor) const;
/// Get physical half extents (not scaled) of the given actor.
osg::Vec3f getOriginalHalfExtents(const MWWorld::ConstPtr& actor) const;
/// @see MWPhysics::Actor::getRenderingHalfExtents /// @see MWPhysics::Actor::getRenderingHalfExtents
osg::Vec3f getRenderingHalfExtents(const MWWorld::ConstPtr& actor) const; osg::Vec3f getRenderingHalfExtents(const MWWorld::ConstPtr& actor) const;

View file

@ -122,12 +122,6 @@ namespace MWWorld
return ptr; return ptr;
} }
MWWorld::ConstPtr Player::getConstPlayer() const
{
MWWorld::ConstPtr ptr (&mPlayer, mCellStore);
return ptr;
}
void Player::setBirthSign (const std::string &sign) void Player::setBirthSign (const std::string &sign)
{ {
mSign = sign; mSign = sign;

View file

@ -27,7 +27,6 @@ namespace Loading
namespace MWWorld namespace MWWorld
{ {
class CellStore; class CellStore;
class ConstPtr;
/// \brief NPC object representing the player and additional player data /// \brief NPC object representing the player and additional player data
class Player class Player
@ -82,7 +81,6 @@ namespace MWWorld
void setCell (MWWorld::CellStore *cellStore); void setCell (MWWorld::CellStore *cellStore);
MWWorld::Ptr getPlayer(); MWWorld::Ptr getPlayer();
MWWorld::ConstPtr getConstPlayer() const;
void setBirthSign(const std::string &sign); void setBirthSign(const std::string &sign);
const std::string &getBirthSign() const; const std::string &getBirthSign() const;

View file

@ -172,9 +172,12 @@ namespace
); );
} }
} }
else if (physics.getActor(ptr)) else if (const auto actor = physics.getActor(ptr))
{ {
navigator.addAgent(MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(ptr)); const auto halfExtents = ptr.getCell()->isExterior()
? physics.getHalfExtents(MWBase::Environment::get().getWorld()->getPlayerPtr())
: actor->getHalfExtents();
navigator.addAgent(halfExtents);
} }
} }
@ -334,14 +337,15 @@ namespace MWWorld
ListAndResetObjectsVisitor visitor; ListAndResetObjectsVisitor visitor;
(*iter)->forEach<ListAndResetObjectsVisitor>(visitor); (*iter)->forEach<ListAndResetObjectsVisitor>(visitor);
const auto world = MWBase::Environment::get().getWorld(); const auto player = MWBase::Environment::get().getWorld()->getPlayerPtr();
const auto playerHalfExtents = mPhysics->getHalfExtents(player);
for (const auto& ptr : visitor.mObjects) for (const auto& ptr : visitor.mObjects)
{ {
if (const auto object = mPhysics->getObject(ptr)) if (const auto object = mPhysics->getObject(ptr))
navigator->removeObject(DetourNavigator::ObjectId(object)); navigator->removeObject(DetourNavigator::ObjectId(object));
else if (const auto actor = mPhysics->getActor(ptr)) else if (const auto actor = mPhysics->getActor(ptr))
{ {
navigator->removeAgent(world->getPathfindingHalfExtents(ptr)); navigator->removeAgent(ptr.getCell()->isExterior() ? playerHalfExtents : actor->getHalfExtents());
mRendering.removeActorPath(ptr); mRendering.removeActorPath(ptr);
} }
mPhysics->remove(ptr); mPhysics->remove(ptr);
@ -368,7 +372,6 @@ namespace MWWorld
if ((*iter)->getCell()->hasWater()) if ((*iter)->getCell()->hasWater())
navigator->removeWater(osg::Vec2i(cellX, cellY)); navigator->removeWater(osg::Vec2i(cellX, cellY));
const auto player = world->getPlayerPtr();
navigator->update(player.getRefData().getPosition().asVec3()); navigator->update(player.getRefData().getPosition().asVec3());
MWBase::Environment::get().getMechanicsManager()->drop (*iter); MWBase::Environment::get().getMechanicsManager()->drop (*iter);
@ -812,7 +815,10 @@ namespace MWWorld
} }
else if (const auto actor = mPhysics->getActor(ptr)) else if (const auto actor = mPhysics->getActor(ptr))
{ {
navigator->removeAgent(MWBase::Environment::get().getWorld()->getPathfindingHalfExtents(ptr)); const auto& halfExtents = ptr.getCell()->isExterior()
? mPhysics->getHalfExtents(MWBase::Environment::get().getWorld()->getPlayerPtr())
: actor->getHalfExtents();
navigator->removeAgent(halfExtents);
} }
mPhysics->remove(ptr); mPhysics->remove(ptr);
mRendering.removeObject (ptr); mRendering.removeObject (ptr);

View file

@ -1298,9 +1298,6 @@ namespace MWWorld
{ {
mPhysics->updatePosition(newPtr); mPhysics->updatePosition(newPtr);
mPhysics->updatePtr(ptr, newPtr); mPhysics->updatePtr(ptr, newPtr);
if (const auto object = mPhysics->getObject(newPtr))
updateNavigatorObject(object);
} }
} }
if (isPlayer) if (isPlayer)
@ -1331,17 +1328,9 @@ namespace MWWorld
void World::scaleObject (const Ptr& ptr, float scale) void World::scaleObject (const Ptr& ptr, float scale)
{ {
if (mPhysics->getActor(ptr))
mNavigator->removeAgent(getPathfindingHalfExtents(ptr));
ptr.getCellRef().setScale(scale); ptr.getCellRef().setScale(scale);
mWorldScene->updateObjectScale(ptr); mWorldScene->updateObjectScale(ptr);
if (mPhysics->getActor(ptr))
mNavigator->addAgent(getPathfindingHalfExtents(ptr));
else if (const auto object = mPhysics->getObject(ptr))
mShouldUpdateNavigator = updateNavigatorObject(object) || mShouldUpdateNavigator;
} }
void World::rotateObjectImp (const Ptr& ptr, const osg::Vec3f& rot, bool adjust) void World::rotateObjectImp (const Ptr& ptr, const osg::Vec3f& rot, bool adjust)
@ -1381,12 +1370,7 @@ namespace MWWorld
ptr.getRefData().setPosition(pos); ptr.getRefData().setPosition(pos);
if(ptr.getRefData().getBaseNode() != 0) if(ptr.getRefData().getBaseNode() != 0)
{
mWorldScene->updateObjectRotation(ptr, true); mWorldScene->updateObjectRotation(ptr, true);
if (const auto object = mPhysics->getObject(ptr))
updateNavigatorObject(object);
}
} }
void World::adjustPosition(const Ptr &ptr, bool force) void World::adjustPosition(const Ptr &ptr, bool force)
@ -1580,20 +1564,19 @@ namespace MWWorld
void World::updateNavigator() void World::updateNavigator()
{ {
bool updated = false;
mPhysics->forEachAnimatedObject([&] (const MWPhysics::Object* object) mPhysics->forEachAnimatedObject([&] (const MWPhysics::Object* object)
{ {
mShouldUpdateNavigator = updateNavigatorObject(object) || mShouldUpdateNavigator; updated = updateNavigatorObject(object) || updated;
}); });
for (const auto& door : mDoorStates) for (const auto& door : mDoorStates)
if (const auto object = mPhysics->getObject(door.first)) if (const auto object = mPhysics->getObject(door.first))
mShouldUpdateNavigator = updateNavigatorObject(object) || mShouldUpdateNavigator; updated = updateNavigatorObject(object) || updated;
if (mShouldUpdateNavigator) if (updated)
{
mNavigator->update(getPlayerPtr().getRefData().getPosition().asVec3()); mNavigator->update(getPlayerPtr().getRefData().getPosition().asVec3());
mShouldUpdateNavigator = false;
}
} }
bool World::updateNavigatorObject(const MWPhysics::Object* object) bool World::updateNavigatorObject(const MWPhysics::Object* object)
@ -2425,7 +2408,7 @@ namespace MWWorld
{ {
// Remove the old CharacterController // Remove the old CharacterController
MWBase::Environment::get().getMechanicsManager()->remove(getPlayerPtr()); MWBase::Environment::get().getMechanicsManager()->remove(getPlayerPtr());
mNavigator->removeAgent(getPathfindingHalfExtents(getPlayerConstPtr())); mNavigator->removeAgent(mPhysics->getHalfExtents(getPlayerPtr()));
mPhysics->remove(getPlayerPtr()); mPhysics->remove(getPlayerPtr());
mRendering->removePlayer(getPlayerPtr()); mRendering->removePlayer(getPlayerPtr());
@ -2460,8 +2443,7 @@ namespace MWWorld
applyLoopingParticles(player); applyLoopingParticles(player);
mDefaultHalfExtents = mPhysics->getOriginalHalfExtents(getPlayerPtr()); mNavigator->addAgent(mPhysics->getHalfExtents(getPlayerPtr()));
mNavigator->addAgent(getPathfindingHalfExtents(getPlayerConstPtr()));
} }
World::RestPermitted World::canRest () const World::RestPermitted World::canRest () const
@ -3436,11 +3418,6 @@ namespace MWWorld
return mPlayer->getPlayer(); return mPlayer->getPlayer();
} }
MWWorld::ConstPtr World::getPlayerConstPtr() const
{
return mPlayer->getConstPlayer();
}
void World::updateDialogueGlobals() void World::updateDialogueGlobals()
{ {
MWWorld::Ptr player = getPlayerPtr(); MWWorld::Ptr player = getPlayerPtr();
@ -3810,12 +3787,4 @@ namespace MWWorld
mRendering->setNavMeshNumber(value); mRendering->setNavMeshNumber(value);
} }
osg::Vec3f World::getPathfindingHalfExtents(const MWWorld::ConstPtr& actor) const
{
if (actor.getCell()->isExterior())
return mDefaultHalfExtents; // Using default half extents for better performance
else
return getHalfExtents(actor);
}
} }

View file

@ -111,9 +111,6 @@ namespace MWWorld
std::string mUserDataPath; std::string mUserDataPath;
osg::Vec3f mDefaultHalfExtents;
bool mShouldUpdateNavigator = false;
// not implemented // not implemented
World (const World&); World (const World&);
World& operator= (const World&); World& operator= (const World&);
@ -241,7 +238,6 @@ namespace MWWorld
Player& getPlayer() override; Player& getPlayer() override;
MWWorld::Ptr getPlayerPtr() override; MWWorld::Ptr getPlayerPtr() override;
MWWorld::ConstPtr getPlayerConstPtr() const override;
const MWWorld::ESMStore& getStore() const override; const MWWorld::ESMStore& getStore() const override;
@ -721,9 +717,6 @@ namespace MWWorld
void removeActorPath(const MWWorld::ConstPtr& actor) const override; void removeActorPath(const MWWorld::ConstPtr& actor) const override;
void setNavMeshNumberToRender(const std::size_t value) override; void setNavMeshNumberToRender(const std::size_t value) override;
/// Return physical half extents of the given actor to be used in pathfinding
osg::Vec3f getPathfindingHalfExtents(const MWWorld::ConstPtr& actor) const override;
}; };
} }

View file

@ -69,11 +69,4 @@ namespace
object.update(mTransform, AreaType_ground); object.update(mTransform, AreaType_ground);
EXPECT_FALSE(object.update(mTransform, AreaType_ground)); EXPECT_FALSE(object.update(mTransform, AreaType_ground));
} }
TEST_F(DetourNavigatorRecastMeshObjectTest, update_for_changed_local_scaling_should_return_true)
{
RecastMeshObject object(mBoxShape, mTransform, AreaType_ground);
mBoxShape.setLocalScaling(btVector3(2, 2, 2));
EXPECT_TRUE(object.update(mTransform, AreaType_ground));
}
} }

View file

@ -13,7 +13,6 @@ namespace DetourNavigator
: mShape(shape) : mShape(shape)
, mTransform(transform) , mTransform(transform)
, mAreaType(areaType) , mAreaType(areaType)
, mLocalScaling(shape.getLocalScaling())
, mChildren(makeChildrenObjects(shape, mAreaType)) , mChildren(makeChildrenObjects(shape, mAreaType))
{ {
} }
@ -31,11 +30,6 @@ namespace DetourNavigator
mAreaType = areaType; mAreaType = areaType;
result = true; result = true;
} }
if (!(mLocalScaling == mShape.get().getLocalScaling()))
{
mLocalScaling = mShape.get().getLocalScaling();
result = true;
}
if (mShape.get().isCompound()) if (mShape.get().isCompound())
result = updateCompoundObject(static_cast<const btCompoundShape&>(mShape.get()), mAreaType, mChildren) result = updateCompoundObject(static_cast<const btCompoundShape&>(mShape.get()), mAreaType, mChildren)
|| result; || result;

View file

@ -39,7 +39,6 @@ namespace DetourNavigator
std::reference_wrapper<const btCollisionShape> mShape; std::reference_wrapper<const btCollisionShape> mShape;
btTransform mTransform; btTransform mTransform;
AreaType mAreaType; AreaType mAreaType;
btVector3 mLocalScaling;
std::vector<RecastMeshObject> mChildren; std::vector<RecastMeshObject> mChildren;
static bool updateCompoundObject(const btCompoundShape& shape, const AreaType areaType, static bool updateCompoundObject(const btCompoundShape& shape, const AreaType areaType,