diff --git a/source/Pathfinder.cpp b/source/Pathfinder.cpp index c9f872b..ce52e69 100644 --- a/source/Pathfinder.cpp +++ b/source/Pathfinder.cpp @@ -8,8 +8,8 @@ #include "Pathfinder.h" #include -#include -#include +#include +#include #include @@ -31,19 +31,21 @@ std::vector Pathfinder::astarArea(Area* start, Area* end) const { assert(start); assert(end); + auto heuristic_cost_estimate = [](Area* start, Area* end) { + return thor::length(sf::Vector2f(end->center - start->center)); + }; - std::unordered_set closed; - std::unordered_map openAreasEstimatedCost; + std::set closed; + std::map openAreasEstimatedCost; // Navigated areas with previous area/portal. - std::unordered_map> previousAreaAndPortal; - std::unordered_map bestPathCost; + std::map> previousAreaAndPortal; + std::map bestPathCost; openAreasEstimatedCost[start] = heuristic_cost_estimate(start, end); bestPathCost[start] = 0; while (!openAreasEstimatedCost.empty()) { - Area* current = std::min_element(openAreasEstimatedCost.begin(), - openAreasEstimatedCost.end())->first; + Area* current = openAreasEstimatedCost.begin()->first; if (current == end) { std::vector path; auto previous = current; @@ -134,18 +136,6 @@ Pathfinder::getPath(const sf::Vector2f& start, const sf::Vector2f& end, return path; } -/** - * Returns the linear distance between two areas (using their center). - */ -float -Pathfinder::heuristic_cost_estimate(Area* start, Area* end) const { - return thor::length(sf::Vector2f(end->center - start->center)); -} - -bool Pathfinder::Portal::operator==(const Portal& p) { - return start == p.start && end == p.end && area == p.area; -} - /** * Inserts an area used for path finding. * diff --git a/source/Pathfinder.h b/source/Pathfinder.h index 972a30c..456a951 100644 --- a/source/Pathfinder.h +++ b/source/Pathfinder.h @@ -24,7 +24,6 @@ public: private: Area* getArea(const sf::Vector2f& point) const; - float heuristic_cost_estimate(Area* start, Area* end) const; std::vector astarArea(Area* start, Area* end) const; private: @@ -38,7 +37,6 @@ private: * Redundant data as portals are saved twice. */ struct Pathfinder::Portal { - bool operator==(const Portal& p); sf::Vector2i start; sf::Vector2i end; Area* area;