Minor pathfinding cleanup

This commit is contained in:
Chris Robinson 2013-08-29 19:17:27 -07:00
parent 8f23b330d3
commit 82a09a988b
2 changed files with 14 additions and 21 deletions

View file

@ -147,13 +147,13 @@ namespace MWMechanics
mIsPathConstructed = false; mIsPathConstructed = false;
} }
void PathFinder::buildPath(ESM::Pathgrid::Point startPoint, ESM::Pathgrid::Point endPoint, void PathFinder::buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const ESM::Pathgrid* pathGrid, float xCell, float yCell, bool allowShortcuts) const ESM::Pathgrid *pathGrid, float xCell, float yCell, bool allowShortcuts)
{ {
if(allowShortcuts) if(allowShortcuts)
{ {
if(MWBase::Environment::get().getWorld()->castRay(startPoint.mX, startPoint.mY, startPoint.mZ, endPoint.mX, endPoint.mY, if(MWBase::Environment::get().getWorld()->castRay(startPoint.mX, startPoint.mY, startPoint.mZ,
endPoint.mZ)) endPoint.mX, endPoint.mY, endPoint.mZ))
allowShortcuts = false; allowShortcuts = false;
} }
@ -184,14 +184,14 @@ namespace MWMechanics
mIsPathConstructed = false; mIsPathConstructed = false;
} }
float PathFinder::getZAngleToNext(float x, float y) float PathFinder::getZAngleToNext(float x, float y) const
{ {
// This should never happen (programmers should have an if statement checking mIsPathConstructed that prevents this call // This should never happen (programmers should have an if statement checking mIsPathConstructed that prevents this call
// if otherwise). // if otherwise).
if(mPath.empty()) if(mPath.empty())
return 0; return 0;
ESM::Pathgrid::Point nextPoint = *mPath.begin(); const ESM::Pathgrid::Point &nextPoint = *mPath.begin();
float directionX = nextPoint.mX - x; float directionX = nextPoint.mX - x;
float directionY = nextPoint.mY - y; float directionY = nextPoint.mY - y;
float directionResult = sqrt(directionX * directionX + directionY * directionY); float directionResult = sqrt(directionX * directionX + directionY * directionY);
@ -217,15 +217,5 @@ namespace MWMechanics
return false; return false;
} }
std::list<ESM::Pathgrid::Point> PathFinder::getPath()
{
return mPath;
}
bool PathFinder::isPathConstructed()
{
return mIsPathConstructed;
}
} }

View file

@ -12,15 +12,18 @@ namespace MWMechanics
PathFinder(); PathFinder();
void clearPath(); void clearPath();
void buildPath(ESM::Pathgrid::Point startPoint, ESM::Pathgrid::Point endPoint, void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const ESM::Pathgrid* pathGrid, float xCell = 0, float yCell = 0, bool allowShortcuts = 1); const ESM::Pathgrid* pathGrid, float xCell = 0, float yCell = 0,
bool allowShortcuts = true);
bool checkPathCompleted(float x, float y, float z); bool checkPathCompleted(float x, float y, float z);
///< \Returns true if the last point of the path has been reached. ///< \Returns true if the last point of the path has been reached.
float getZAngleToNext(float x, float y); float getZAngleToNext(float x, float y) const;
std::list<ESM::Pathgrid::Point> getPath(); bool isPathConstructed() const
bool isPathConstructed(); {
return mIsPathConstructed;
}
private: private:
std::list<ESM::Pathgrid::Point> mPath; std::list<ESM::Pathgrid::Point> mPath;