mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-11 15:40:39 +00:00
Minor pathfinding cleanup
This commit is contained in:
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…
x
Reference in New Issue
Block a user