1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 11:23:51 +00:00

simplified pathfinding code.

remove mIsPathConstructed.  Instead call !mPath.empty().
This commit is contained in:
dteviot 2015-06-14 15:14:02 +12:00
parent bfff84ba8f
commit 520fbd63c4
2 changed files with 3 additions and 18 deletions

View file

@ -114,8 +114,7 @@ namespace MWMechanics
} }
PathFinder::PathFinder() PathFinder::PathFinder()
: mIsPathConstructed(false), : mPathgrid(NULL),
mPathgrid(NULL),
mCell(NULL) mCell(NULL)
{ {
} }
@ -124,7 +123,6 @@ namespace MWMechanics
{ {
if(!mPath.empty()) if(!mPath.empty())
mPath.clear(); mPath.clear();
mIsPathConstructed = false;
} }
/* /*
@ -180,7 +178,6 @@ namespace MWMechanics
static_cast<float>(endPoint.mX), static_cast<float>(endPoint.mY), static_cast<float>(endPoint.mZ))) static_cast<float>(endPoint.mX), static_cast<float>(endPoint.mY), static_cast<float>(endPoint.mZ)))
{ {
mPath.push_back(endPoint); mPath.push_back(endPoint);
mIsPathConstructed = true;
return; return;
} }
} }
@ -197,7 +194,6 @@ namespace MWMechanics
if(!mPathgrid || mPathgrid->mPoints.empty()) if(!mPathgrid || mPathgrid->mPoints.empty())
{ {
mPath.push_back(endPoint); mPath.push_back(endPoint);
mIsPathConstructed = true;
return; return;
} }
@ -235,7 +231,6 @@ namespace MWMechanics
if(startNode == endNode.first) if(startNode == endNode.first)
{ {
mPath.push_back(endPoint); mPath.push_back(endPoint);
mIsPathConstructed = true;
return; return;
} }
@ -243,7 +238,6 @@ namespace MWMechanics
if(!mPath.empty()) if(!mPath.empty())
{ {
mIsPathConstructed = true;
// Add the destination (which may be different to the closest // Add the destination (which may be different to the closest
// pathgrid point). However only add if endNode was the closest // pathgrid point). However only add if endNode was the closest
// point to endPoint. // point to endPoint.
@ -256,14 +250,8 @@ namespace MWMechanics
if(endNode.second) if(endNode.second)
mPath.push_back(endPoint); mPath.push_back(endPoint);
} }
else
mIsPathConstructed = false;
} }
else
mIsPathConstructed = false;
} }
else
mIsPathConstructed = false;
return; return;
} }
@ -271,7 +259,7 @@ namespace MWMechanics
float PathFinder::getZAngleToNext(float x, float y) const float PathFinder::getZAngleToNext(float x, float y) const
{ {
// This should never happen (programmers should have an if statement checking // This should never happen (programmers should have an if statement checking
// mIsPathConstructed that prevents this call if otherwise). // isPathConstructed that prevents this call if otherwise).
if(mPath.empty()) if(mPath.empty())
return 0.; return 0.;
@ -293,7 +281,6 @@ namespace MWMechanics
mPath.pop_front(); mPath.pop_front();
if(mPath.empty()) if(mPath.empty())
{ {
mIsPathConstructed = false;
return true; return true;
} }
} }

View file

@ -48,7 +48,7 @@ namespace MWMechanics
bool isPathConstructed() const bool isPathConstructed() const
{ {
return mIsPathConstructed; return !mPath.empty();
} }
int getPathSize() const int getPathSize() const
@ -96,8 +96,6 @@ namespace MWMechanics
private: private:
bool mIsPathConstructed;
std::list<ESM::Pathgrid::Point> mPath; std::list<ESM::Pathgrid::Point> mPath;
const ESM::Pathgrid *mPathgrid; const ESM::Pathgrid *mPathgrid;