mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-18 13:12:50 +00:00
Update and check for complete Pathfinder path by different methods
This commit is contained in:
parent
b6dd2119a6
commit
4fe764c3a5
@ -171,7 +171,9 @@ bool MWMechanics::AiPackage::pathTo(const MWWorld::Ptr& actor, const osg::Vec3f&
|
||||
mTimer = 0;
|
||||
}
|
||||
|
||||
if (isDestReached || mPathFinder.checkPathCompleted(pos.asVec3())) // if path is finished
|
||||
mPathFinder.update(pos.asVec3(), std::max(destTolerance, DEFAULT_TOLERANCE));
|
||||
|
||||
if (isDestReached || mPathFinder.checkPathCompleted()) // if path is finished
|
||||
{
|
||||
// turn to destination point
|
||||
zTurn(actor, getZAngleToPoint(start, dest));
|
||||
|
@ -250,7 +250,7 @@ namespace MWMechanics
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (storage.mIsWanderingManually && mPathFinder.checkPathCompleted(pos.asVec3(), DESTINATION_TOLERANCE))
|
||||
else if (storage.mIsWanderingManually && mPathFinder.checkPathCompleted())
|
||||
{
|
||||
completeManualWalking(actor, storage);
|
||||
}
|
||||
|
@ -121,6 +121,7 @@ namespace MWMechanics
|
||||
void PathFinder::buildPath(const osg::Vec3f& startPoint, const osg::Vec3f& endPoint,
|
||||
const MWWorld::CellStore* cell, const PathgridGraph& pathgridGraph)
|
||||
{
|
||||
mConstructed = true;
|
||||
mPath.clear();
|
||||
mCell = cell;
|
||||
|
||||
@ -250,12 +251,10 @@ namespace MWMechanics
|
||||
return getXAngleToDir(dir);
|
||||
}
|
||||
|
||||
bool PathFinder::checkPathCompleted(const osg::Vec3f& position, const float tolerance)
|
||||
void PathFinder::update(const osg::Vec3f& position, const float tolerance)
|
||||
{
|
||||
if (!mPath.empty() && sqrDistanceIgnoreZ(mPath.front(), position) < tolerance*tolerance)
|
||||
mPath.pop_front();
|
||||
|
||||
return mPath.empty();
|
||||
}
|
||||
|
||||
// see header for the rationale
|
||||
|
@ -57,12 +57,14 @@ namespace MWMechanics
|
||||
{
|
||||
public:
|
||||
PathFinder()
|
||||
: mCell(nullptr)
|
||||
: mConstructed(false)
|
||||
, mCell(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void clearPath()
|
||||
{
|
||||
mConstructed = false;
|
||||
mPath.clear();
|
||||
mCell = nullptr;
|
||||
}
|
||||
@ -70,8 +72,13 @@ namespace MWMechanics
|
||||
void buildPath(const osg::Vec3f& startPoint, const osg::Vec3f& endPoint,
|
||||
const MWWorld::CellStore* cell, const PathgridGraph& pathgridGraph);
|
||||
|
||||
bool checkPathCompleted(const osg::Vec3f& position, const float tolerance = DEFAULT_TOLERANCE);
|
||||
///< \Returns true if we are within \a tolerance units of the last path point.
|
||||
/// Remove front point if exist and within tolerance
|
||||
void update(const osg::Vec3f& position, const float tolerance = DEFAULT_TOLERANCE);
|
||||
|
||||
bool checkPathCompleted() const
|
||||
{
|
||||
return mConstructed && mPath.empty();
|
||||
}
|
||||
|
||||
/// In radians
|
||||
float getZAngleToNext(float x, float y) const;
|
||||
@ -80,7 +87,7 @@ namespace MWMechanics
|
||||
|
||||
bool isPathConstructed() const
|
||||
{
|
||||
return !mPath.empty();
|
||||
return mConstructed && !mPath.empty();
|
||||
}
|
||||
|
||||
std::size_t getPathSize() const
|
||||
@ -110,6 +117,7 @@ namespace MWMechanics
|
||||
|
||||
void addPointToPath(const osg::Vec3f& point)
|
||||
{
|
||||
mConstructed = true;
|
||||
mPath.push_back(point);
|
||||
}
|
||||
|
||||
@ -168,6 +176,7 @@ namespace MWMechanics
|
||||
}
|
||||
|
||||
private:
|
||||
bool mConstructed;
|
||||
std::deque<osg::Vec3f> mPath;
|
||||
|
||||
const MWWorld::CellStore* mCell;
|
||||
|
Loading…
x
Reference in New Issue
Block a user