1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-23 17:39:43 +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:
gus 2013-04-18 18:35:01 +01:00
parent 905cff2a94
commit c753eb4c28

View file

@ -1,5 +1,5 @@
#include "pathfinding.hpp" #include "pathfinding.hpp"
#include <boost/graph/astar_search.hpp> #include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/adjacency_list.hpp> #include <boost/graph/adjacency_list.hpp>
#include "boost/tuple/tuple.hpp" #include "boost/tuple/tuple.hpp"
#include "OgreMath.h" #include "OgreMath.h"
@ -55,7 +55,7 @@ namespace
struct found_path {}; struct found_path {};
class goalVisited : public boost::default_astar_visitor /*class goalVisited : public boost::default_astar_visitor
{ {
public: public:
goalVisited(PointID goal) : mGoal(goal) {} goalVisited(PointID goal) : mGoal(goal) {}
@ -69,7 +69,7 @@ namespace
PointID mGoal; PointID mGoal;
}; };
class DistanceHeuristic : public boost::astar_heuristic <PathGridGraph, float> class DistanceHeuristic : public boost::atasr_heuristic <PathGridGraph, float>
{ {
public: public:
DistanceHeuristic(const PathGridGraph & l, PointID goal) DistanceHeuristic(const PathGridGraph & l, PointID goal)
@ -87,11 +87,23 @@ namespace
private: private:
const PathGridGraph & mGraph; const PathGridGraph & mGraph;
PointID mGoal; 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 buildGraph(const ESM::Pathgrid* pathgrid,float xCell = 0,float yCell = 0)
{ {
PathGridGraph graph; PathGridGraph graph;
@ -126,11 +138,10 @@ namespace MWMechanics
std::list<ESM::Pathgrid::Point> shortest_path; std::list<ESM::Pathgrid::Point> shortest_path;
try { try {
boost::astar_search boost::dijkstra_shortest_paths
( (
graph, graph,
start, start,
DistanceHeuristic(graph,end),
boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(goalVisited(end))//.weight_map(boost::get(&Edge::distance, graph)) boost::predecessor_map(&p[0]).distance_map(&d[0]).visitor(goalVisited(end))//.weight_map(boost::get(&Edge::distance, graph))
); );
@ -146,6 +157,10 @@ namespace MWMechanics
//end of helpers functions //end of helpers functions
}
namespace MWMechanics
{
PathFinder::PathFinder() PathFinder::PathFinder()
{ {
mIsPathConstructed = false; mIsPathConstructed = false;