mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-01 22:45:33 +00:00
another way to do pathfinding. Slightly less powerfull algorithme in theory, but morrowind pathgrids are so simple it shouldn't be a problem. Hope it solves the bug for KittyCat
This commit is contained in:
parent
905cff2a94
commit
c753eb4c28
1 changed files with 25 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
|||
#include "pathfinding.hpp"
|
||||
#include <boost/graph/astar_search.hpp>
|
||||
#include <boost/graph/dijkstra_shortest_paths.hpp>
|
||||
#include <boost/graph/adjacency_list.hpp>
|
||||
#include "boost/tuple/tuple.hpp"
|
||||
#include "OgreMath.h"
|
||||
|
@ -55,7 +55,7 @@ namespace
|
|||
|
||||
struct found_path {};
|
||||
|
||||
class goalVisited : public boost::default_astar_visitor
|
||||
/*class goalVisited : public boost::default_astar_visitor
|
||||
{
|
||||
public:
|
||||
goalVisited(PointID goal) : mGoal(goal) {}
|
||||
|
@ -69,7 +69,7 @@ namespace
|
|||
PointID mGoal;
|
||||
};
|
||||
|
||||
class DistanceHeuristic : public boost::astar_heuristic <PathGridGraph, float>
|
||||
class DistanceHeuristic : public boost::atasr_heuristic <PathGridGraph, float>
|
||||
{
|
||||
public:
|
||||
DistanceHeuristic(const PathGridGraph & l, PointID goal)
|
||||
|
@ -87,11 +87,23 @@ namespace
|
|||
private:
|
||||
const PathGridGraph & mGraph;
|
||||
PointID mGoal;
|
||||
};
|
||||
}
|
||||
};*/
|
||||
|
||||
class goalVisited : public boost::default_dijkstra_visitor
|
||||
{
|
||||
public:
|
||||
goalVisited(PointID goal) : mGoal(goal) {}
|
||||
|
||||
void examine_vertex(PointID u, const PathGridGraph g)
|
||||
{
|
||||
if(u == mGoal)
|
||||
throw found_path();
|
||||
}
|
||||
private:
|
||||
PointID mGoal;
|
||||
};
|
||||
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
PathGridGraph buildGraph(const ESM::Pathgrid* pathgrid,float xCell = 0,float yCell = 0)
|
||||
{
|
||||
PathGridGraph graph;
|
||||
|
@ -126,13 +138,12 @@ namespace MWMechanics
|
|||
std::list<ESM::Pathgrid::Point> shortest_path;
|
||||
|
||||
try {
|
||||
boost::astar_search
|
||||
boost::dijkstra_shortest_paths
|
||||
(
|
||||
graph,
|
||||
start,
|
||||
DistanceHeuristic(graph,end),
|
||||
boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(goalVisited(end))//.weight_map(boost::get(&Edge::distance, graph))
|
||||
);
|
||||
);
|
||||
|
||||
} catch(found_path fg) {
|
||||
for(PointID v = end;; v = p[v]) {
|
||||
|
@ -146,6 +157,10 @@ namespace MWMechanics
|
|||
|
||||
//end of helpers functions
|
||||
|
||||
}
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
PathFinder::PathFinder()
|
||||
{
|
||||
mIsPathConstructed = false;
|
||||
|
|
Loading…
Reference in a new issue