From fbeb3ab03a876724e83626347fabd93ce8c87f84 Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 31 Jul 2023 21:37:32 +0200 Subject: [PATCH] Do not build path to next path point via navmesh To void a situation when next path point continuously changing making actor go in circles. This is unnecessary but also creates problems since pathgrid is used to build path for AiWander. --- apps/openmw/mwmechanics/aiwander.cpp | 7 ---- apps/openmw/mwmechanics/pathfinding.cpp | 48 ------------------------- apps/openmw/mwmechanics/pathfinding.hpp | 4 --- 3 files changed, 59 deletions(-) diff --git a/apps/openmw/mwmechanics/aiwander.cpp b/apps/openmw/mwmechanics/aiwander.cpp index f9e0ec1358..4e3e29c4fb 100644 --- a/apps/openmw/mwmechanics/aiwander.cpp +++ b/apps/openmw/mwmechanics/aiwander.cpp @@ -314,13 +314,6 @@ namespace MWMechanics completeManualWalking(actor, storage); } - if (storage.mState == AiWanderStorage::Wander_Walking && mUsePathgrid) - { - const auto agentBounds = MWBase::Environment::get().getWorld()->getPathfindingAgentBounds(actor); - mPathFinder.buildPathByNavMeshToNextPoint( - actor, agentBounds, getNavigatorFlags(actor), getAreaCosts(actor)); - } - if (storage.mState == AiWanderStorage::Wander_MoveNow && storage.mCanWanderAlongPathGrid) { // Construct a new path if there isn't one diff --git a/apps/openmw/mwmechanics/pathfinding.cpp b/apps/openmw/mwmechanics/pathfinding.cpp index cabfa5e7a1..417a238f15 100644 --- a/apps/openmw/mwmechanics/pathfinding.cpp +++ b/apps/openmw/mwmechanics/pathfinding.cpp @@ -75,13 +75,6 @@ namespace return sqrDistance(osg::Vec2f(lhs.x(), lhs.y()), osg::Vec2f(rhs.x(), rhs.y())); } - float getPathStepSize(const MWWorld::ConstPtr& actor) - { - const auto world = MWBase::Environment::get().getWorld(); - const auto realHalfExtents = world->getHalfExtents(actor); - return 2 * std::max(realHalfExtents.x(), realHalfExtents.y()); - } - float getHeight(const MWWorld::ConstPtr& actor) { const auto world = MWBase::Environment::get().getWorld(); @@ -457,47 +450,6 @@ namespace MWMechanics return status; } - void PathFinder::buildPathByNavMeshToNextPoint(const MWWorld::ConstPtr& actor, - const DetourNavigator::AgentBounds& agentBounds, const DetourNavigator::Flags flags, - const DetourNavigator::AreaCosts& areaCosts) - { - if (mPath.empty()) - return; - - const auto stepSize = getPathStepSize(actor); - const auto startPoint = actor.getRefData().getPosition().asVec3(); - - if (sqrDistanceIgnoreZ(mPath.front(), startPoint) <= 4 * stepSize * stepSize) - return; - - const auto navigator = MWBase::Environment::get().getWorld()->getNavigator(); - std::deque prePath; - auto prePathInserter = std::back_inserter(prePath); - const float endTolerance = 0; - const auto status = DetourNavigator::findPath( - *navigator, agentBounds, startPoint, mPath.front(), flags, areaCosts, endTolerance, prePathInserter); - - if (status == DetourNavigator::Status::NavMeshNotFound) - return; - - if (status != DetourNavigator::Status::Success) - { - Log(Debug::Debug) << "Build path by navigator error: \"" << DetourNavigator::getMessage(status) - << "\" for \"" << actor.getClass().getName(actor) << "\" (" << actor.getBase() - << ") from " << startPoint << " to " << mPath.front() << " with flags (" - << DetourNavigator::WriteFlags{ flags } << ")"; - return; - } - - while (!prePath.empty() && sqrDistanceIgnoreZ(prePath.front(), startPoint) < stepSize * stepSize) - prePath.pop_front(); - - while (!prePath.empty() && sqrDistanceIgnoreZ(prePath.back(), mPath.front()) < stepSize * stepSize) - prePath.pop_back(); - - std::copy(prePath.rbegin(), prePath.rend(), std::front_inserter(mPath)); - } - void PathFinder::buildLimitedPath(const MWWorld::ConstPtr& actor, const osg::Vec3f& startPoint, const osg::Vec3f& endPoint, const MWWorld::CellStore* cell, const PathgridGraph& pathgridGraph, const DetourNavigator::AgentBounds& agentBounds, const DetourNavigator::Flags flags, diff --git a/apps/openmw/mwmechanics/pathfinding.hpp b/apps/openmw/mwmechanics/pathfinding.hpp index c23cf04ade..44566d3b45 100644 --- a/apps/openmw/mwmechanics/pathfinding.hpp +++ b/apps/openmw/mwmechanics/pathfinding.hpp @@ -115,10 +115,6 @@ namespace MWMechanics const DetourNavigator::AgentBounds& agentBounds, const DetourNavigator::Flags flags, const DetourNavigator::AreaCosts& areaCosts, float endTolerance, PathType pathType); - void buildPathByNavMeshToNextPoint(const MWWorld::ConstPtr& actor, - const DetourNavigator::AgentBounds& agentBounds, const DetourNavigator::Flags flags, - const DetourNavigator::AreaCosts& areaCosts); - void buildLimitedPath(const MWWorld::ConstPtr& actor, const osg::Vec3f& startPoint, const osg::Vec3f& endPoint, const MWWorld::CellStore* cell, const PathgridGraph& pathgridGraph, const DetourNavigator::AgentBounds& agentBounds, const DetourNavigator::Flags flags,