1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 02:15:32 +00:00

Pathfinding Overhaul - Cleanup, removed unnecessary include, fixed spacing, added a function for clearing a path, overall preperation to begin working on fixing pathfinding.

This commit is contained in:
Torben Carrington 2013-05-29 15:59:23 -07:00
parent dc17fa1636
commit 4838678944
2 changed files with 87 additions and 78 deletions

View file

@ -3,10 +3,10 @@
#include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp"
#include "OgreMath.h"
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/adjacency_list.hpp>
#include "boost/tuple/tuple.hpp"
#include "OgreMath.h"
namespace
{
@ -28,14 +28,16 @@ namespace
static float sgn(float a)
{
if(a>0) return 1.;
else return -1.;
if(a > 0) return 1.0;
else return -1.0;
}
int getClosestPoint(const ESM::Pathgrid* grid,float x,float y,float z)
{
if(!grid) return -1;
if(grid->mPoints.empty()) return -1;
if(!grid)
return -1;
if(grid->mPoints.empty())
return -1;
float m = distance(grid->mPoints[0],x,y,z);
int i0 = 0;
@ -130,7 +132,6 @@ namespace
boost::tie(edge,done) = boost::add_edge(u,v,graph);
WeightMap weightmap = boost::get(boost::edge_weight, graph);
weightmap[edge] = distance(graph[u],graph[v]);
}
return graph;
@ -170,6 +171,13 @@ namespace MWMechanics
mIsPathConstructed = false;
}
void PathFinder::clearPath()
{
if(!mPath.empty())
mPath.clear();
mIsPathConstructed = false;
}
void PathFinder::buildPath(ESM::Pathgrid::Point startPoint,ESM::Pathgrid::Point endPoint,
const ESM::Pathgrid* pathGrid,float xCell,float yCell)
{
@ -193,9 +201,8 @@ namespace MWMechanics
float PathFinder::getZAngleToNext(float x,float y,float z)
{
if(mPath.empty())
{
return 0; /// shouldn't happen!
}
ESM::Pathgrid::Point nextPoint = *mPath.begin();
float dX = nextPoint.mX - x;
float dY = nextPoint.mY - y;
@ -206,17 +213,16 @@ namespace MWMechanics
bool PathFinder::checkIfNextPointReached(float x,float y,float z)
{
if(mPath.empty())
{
return true;
}
ESM::Pathgrid::Point nextPoint = *mPath.begin();
if(distanceZCorrected(nextPoint,x,y,z) < 20)
{
mPath.pop_front();
if(mPath.empty())
{
return true;
}
nextPoint = *mPath.begin();
}
return false;
@ -226,8 +232,10 @@ namespace MWMechanics
{
return mPath;
}
bool PathFinder::isPathConstructed()
{
return mIsPathConstructed;
}
}

View file

@ -11,6 +11,7 @@ namespace MWMechanics
public:
PathFinder();
void clearPath();
void buildPath(ESM::Pathgrid::Point startPoint,ESM::Pathgrid::Point endPoint,
const ESM::Pathgrid* pathGrid,float xCell = 0,float yCell = 0);