Minor pathfinding cleanup

actorid
Chris Robinson 12 years ago
parent 8f23b330d3
commit 82a09a988b

@ -147,13 +147,13 @@ namespace MWMechanics
mIsPathConstructed = false;
}
void PathFinder::buildPath(ESM::Pathgrid::Point startPoint, ESM::Pathgrid::Point endPoint,
const ESM::Pathgrid* pathGrid, float xCell, float yCell, bool allowShortcuts)
void PathFinder::buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const ESM::Pathgrid *pathGrid, float xCell, float yCell, bool allowShortcuts)
{
if(allowShortcuts)
{
if(MWBase::Environment::get().getWorld()->castRay(startPoint.mX, startPoint.mY, startPoint.mZ, endPoint.mX, endPoint.mY,
endPoint.mZ))
if(MWBase::Environment::get().getWorld()->castRay(startPoint.mX, startPoint.mY, startPoint.mZ,
endPoint.mX, endPoint.mY, endPoint.mZ))
allowShortcuts = false;
}
@ -184,14 +184,14 @@ namespace MWMechanics
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
// if otherwise).
if(mPath.empty())
return 0;
ESM::Pathgrid::Point nextPoint = *mPath.begin();
const ESM::Pathgrid::Point &nextPoint = *mPath.begin();
float directionX = nextPoint.mX - x;
float directionY = nextPoint.mY - y;
float directionResult = sqrt(directionX * directionX + directionY * directionY);
@ -217,15 +217,5 @@ namespace MWMechanics
return false;
}
std::list<ESM::Pathgrid::Point> PathFinder::getPath()
{
return mPath;
}
bool PathFinder::isPathConstructed()
{
return mIsPathConstructed;
}
}

@ -12,15 +12,18 @@ namespace MWMechanics
PathFinder();
void clearPath();
void buildPath(ESM::Pathgrid::Point startPoint, ESM::Pathgrid::Point endPoint,
const ESM::Pathgrid* pathGrid, float xCell = 0, float yCell = 0, bool allowShortcuts = 1);
void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const ESM::Pathgrid* pathGrid, float xCell = 0, float yCell = 0,
bool allowShortcuts = true);
bool checkPathCompleted(float x, float y, float z);
///< \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();
bool isPathConstructed() const
{
return mIsPathConstructed;
}
private:
std::list<ESM::Pathgrid::Point> mPath;

Loading…
Cancel
Save