mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-08-03 15:27:13 -04:00
Remove isAreaOccupiedByOtherActor from obstacle.*
It uses functions only from World anyway.
This commit is contained in:
parent
c79b39cf0d
commit
ae909d7685
@ -574,8 +574,7 @@ namespace MWBase
|
||||
virtual bool hasCollisionWithDoor(
|
||||
const MWWorld::ConstPtr& door, const osg::Vec3f& position, const osg::Vec3f& destination) const = 0;
|
||||
|
||||
virtual bool isAreaOccupiedByOtherActor(
|
||||
const osg::Vec3f& position, float radius, std::span<const MWWorld::ConstPtr> ignore) const = 0;
|
||||
virtual bool isAreaOccupiedByOtherActor(const MWWorld::ConstPtr& actor, const osg::Vec3f& position) const = 0;
|
||||
|
||||
virtual void reportStats(unsigned int frameNumber, osg::Stats& stats) const = 0;
|
||||
|
||||
|
@ -279,7 +279,9 @@ namespace MWMechanics
|
||||
getAllowedNodes(actor, storage);
|
||||
}
|
||||
|
||||
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
||||
MWBase::World& world = *MWBase::Environment::get().getWorld();
|
||||
|
||||
auto& prng = world.getPrng();
|
||||
if (canActorMoveByZAxis(actor) && mDistance > 0)
|
||||
{
|
||||
// Typically want to idle for a short time before the next wander
|
||||
@ -333,7 +335,7 @@ namespace MWMechanics
|
||||
|
||||
if (storage.mIsWanderingManually && storage.mState == AiWanderStorage::Wander_Walking
|
||||
&& (mPathFinder.getPathSize() == 0 || isDestinationHidden(actor, mPathFinder.getPath().back())
|
||||
|| isAreaOccupiedByOtherActor(actor, mPathFinder.getPath().back())))
|
||||
|| world.isAreaOccupiedByOtherActor(actor, mPathFinder.getPath().back())))
|
||||
completeManualWalking(actor, storage);
|
||||
|
||||
return false; // AiWander package not yet completed
|
||||
@ -363,12 +365,12 @@ namespace MWMechanics
|
||||
std::size_t attempts = 10; // If a unit can't wander out of water, don't want to hang here
|
||||
const bool isWaterCreature = actor.getClass().isPureWaterCreature(actor);
|
||||
const bool isFlyingCreature = actor.getClass().isPureFlyingCreature(actor);
|
||||
const auto world = MWBase::Environment::get().getWorld();
|
||||
const auto agentBounds = world->getPathfindingAgentBounds(actor);
|
||||
const auto navigator = world->getNavigator();
|
||||
MWBase::World& world = *MWBase::Environment::get().getWorld();
|
||||
const auto agentBounds = world.getPathfindingAgentBounds(actor);
|
||||
const auto navigator = world.getNavigator();
|
||||
const DetourNavigator::Flags navigatorFlags = getNavigatorFlags(actor);
|
||||
const DetourNavigator::AreaCosts areaCosts = getAreaCosts(actor, navigatorFlags);
|
||||
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
||||
Misc::Rng::Generator& prng = world.getPrng();
|
||||
|
||||
do
|
||||
{
|
||||
@ -408,7 +410,7 @@ namespace MWMechanics
|
||||
if (isDestinationHidden(actor, mDestination))
|
||||
continue;
|
||||
|
||||
if (isAreaOccupiedByOtherActor(actor, mDestination))
|
||||
if (world.isAreaOccupiedByOtherActor(actor, mDestination))
|
||||
continue;
|
||||
|
||||
constexpr float endTolerance = 0;
|
||||
|
@ -106,15 +106,6 @@ namespace MWMechanics
|
||||
return visitor.mResult;
|
||||
}
|
||||
|
||||
bool isAreaOccupiedByOtherActor(const MWWorld::ConstPtr& actor, const osg::Vec3f& destination)
|
||||
{
|
||||
const auto world = MWBase::Environment::get().getWorld();
|
||||
const osg::Vec3f halfExtents = world->getPathfindingAgentBounds(actor).mHalfExtents;
|
||||
const auto maxHalfExtent = std::max(halfExtents.x(), std::max(halfExtents.y(), halfExtents.z()));
|
||||
const std::array ignore{ actor };
|
||||
return world->isAreaOccupiedByOtherActor(destination, 2 * maxHalfExtent, ignore);
|
||||
}
|
||||
|
||||
ObstacleCheck::ObstacleCheck()
|
||||
: mEvadeDirectionIndex(std::size(evadeDirections) - 1)
|
||||
{
|
||||
|
@ -22,8 +22,6 @@ namespace MWMechanics
|
||||
/** \return Pointer to the door, or empty pointer if none exists **/
|
||||
const MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor, float minDist);
|
||||
|
||||
bool isAreaOccupiedByOtherActor(const MWWorld::ConstPtr& actor, const osg::Vec3f& destination);
|
||||
|
||||
class ObstacleCheck
|
||||
{
|
||||
public:
|
||||
|
@ -18,12 +18,11 @@ namespace MWPhysics
|
||||
return nearest.distance(position) < radius;
|
||||
}
|
||||
|
||||
template <class Ignore>
|
||||
class HasSphereCollisionCallback final : public btBroadphaseAabbCallback
|
||||
{
|
||||
public:
|
||||
explicit HasSphereCollisionCallback(
|
||||
const btVector3& position, const btScalar radius, const int mask, const int group, const Ignore& ignore)
|
||||
explicit HasSphereCollisionCallback(const btVector3& position, const btScalar radius, const int mask,
|
||||
const int group, const btCollisionObject* ignore)
|
||||
: mPosition(position)
|
||||
, mRadius(radius)
|
||||
, mIgnore(ignore)
|
||||
@ -37,7 +36,7 @@ namespace MWPhysics
|
||||
if (mResult)
|
||||
return false;
|
||||
const auto collisionObject = static_cast<btCollisionObject*>(proxy->m_clientObject);
|
||||
if (mIgnore(collisionObject) || !needsCollision(*proxy)
|
||||
if (mIgnore == collisionObject || !needsCollision(*proxy)
|
||||
|| !testAabbAgainstSphere(proxy->m_aabbMin, proxy->m_aabbMax, mPosition, mRadius))
|
||||
return true;
|
||||
mResult = true;
|
||||
@ -49,7 +48,7 @@ namespace MWPhysics
|
||||
private:
|
||||
btVector3 mPosition;
|
||||
btScalar mRadius;
|
||||
Ignore mIgnore;
|
||||
const btCollisionObject* mIgnore;
|
||||
int mCollisionFilterMask;
|
||||
int mCollisionFilterGroup;
|
||||
bool mResult = false;
|
||||
|
@ -850,24 +850,17 @@ namespace MWPhysics
|
||||
}
|
||||
|
||||
bool PhysicsSystem::isAreaOccupiedByOtherActor(
|
||||
const osg::Vec3f& position, const float radius, std::span<const MWWorld::ConstPtr> ignore) const
|
||||
const MWWorld::LiveCellRefBase* actor, const osg::Vec3f& position, const float radius) const
|
||||
{
|
||||
std::vector<const btCollisionObject*> ignoredObjects;
|
||||
ignoredObjects.reserve(ignore.size());
|
||||
for (const auto& v : ignore)
|
||||
if (const auto it = mActors.find(v.mRef); it != mActors.end())
|
||||
ignoredObjects.push_back(it->second->getCollisionObject());
|
||||
std::sort(ignoredObjects.begin(), ignoredObjects.end());
|
||||
ignoredObjects.erase(std::unique(ignoredObjects.begin(), ignoredObjects.end()), ignoredObjects.end());
|
||||
const auto ignoreFilter = [&](const btCollisionObject* v) {
|
||||
return std::binary_search(ignoredObjects.begin(), ignoredObjects.end(), v);
|
||||
};
|
||||
const auto bulletPosition = Misc::Convert::toBullet(position);
|
||||
const auto aabbMin = bulletPosition - btVector3(radius, radius, radius);
|
||||
const auto aabbMax = bulletPosition + btVector3(radius, radius, radius);
|
||||
const btCollisionObject* ignoredObject = nullptr;
|
||||
if (const auto it = mActors.find(actor); it != mActors.end())
|
||||
ignoredObject = it->second->getCollisionObject();
|
||||
const btVector3 bulletPosition = Misc::Convert::toBullet(position);
|
||||
const btVector3 aabbMin = bulletPosition - btVector3(radius, radius, radius);
|
||||
const btVector3 aabbMax = bulletPosition + btVector3(radius, radius, radius);
|
||||
const int mask = MWPhysics::CollisionType_Actor;
|
||||
const int group = MWPhysics::CollisionType_AnyPhysical;
|
||||
HasSphereCollisionCallback callback(bulletPosition, radius, mask, group, ignoreFilter);
|
||||
HasSphereCollisionCallback callback(bulletPosition, radius, mask, group, ignoredObject);
|
||||
mTaskScheduler->aabbTest(aabbMin, aabbMax, callback);
|
||||
return callback.getResult();
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ namespace MWPhysics
|
||||
}
|
||||
|
||||
bool isAreaOccupiedByOtherActor(
|
||||
const osg::Vec3f& position, float radius, std::span<const MWWorld::ConstPtr> ignore) const;
|
||||
const MWWorld::LiveCellRefBase* actor, const osg::Vec3f& position, float radius) const;
|
||||
|
||||
void reportStats(unsigned int frameNumber, osg::Stats& stats) const;
|
||||
void reportCollision(const btVector3& position, const btVector3& normal);
|
||||
|
@ -3832,10 +3832,11 @@ namespace MWWorld
|
||||
return btRayAabb(localFrom, localTo, aabbMin, aabbMax, hitDistance, hitNormal);
|
||||
}
|
||||
|
||||
bool World::isAreaOccupiedByOtherActor(
|
||||
const osg::Vec3f& position, const float radius, std::span<const MWWorld::ConstPtr> ignore) const
|
||||
bool World::isAreaOccupiedByOtherActor(const MWWorld::ConstPtr& actor, const osg::Vec3f& position) const
|
||||
{
|
||||
return mPhysics->isAreaOccupiedByOtherActor(position, radius, ignore);
|
||||
const osg::Vec3f halfExtents = getPathfindingAgentBounds(actor).mHalfExtents;
|
||||
const float maxHalfExtent = std::max(halfExtents.x(), std::max(halfExtents.y(), halfExtents.z()));
|
||||
return mPhysics->isAreaOccupiedByOtherActor(actor.mRef, position, 2 * maxHalfExtent);
|
||||
}
|
||||
|
||||
void World::reportStats(unsigned int frameNumber, osg::Stats& stats) const
|
||||
|
@ -656,8 +656,7 @@ namespace MWWorld
|
||||
bool hasCollisionWithDoor(
|
||||
const MWWorld::ConstPtr& door, const osg::Vec3f& position, const osg::Vec3f& destination) const override;
|
||||
|
||||
bool isAreaOccupiedByOtherActor(
|
||||
const osg::Vec3f& position, float radius, std::span<const MWWorld::ConstPtr> ignore) const override;
|
||||
bool isAreaOccupiedByOtherActor(const MWWorld::ConstPtr& actor, const osg::Vec3f& position) const override;
|
||||
|
||||
void reportStats(unsigned int frameNumber, osg::Stats& stats) const override;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user