diff options
author | Max Hilbrunner <mhilbrunner@users.noreply.github.com> | 2019-05-18 23:20:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-18 23:20:02 +0200 |
commit | 33897d9b5844aa0147d55841845427ed599d069f (patch) | |
tree | dae9f89fb334814da2cccb4469e1d7a18e3e4cea /core/math/a_star.h | |
parent | 6bfb9ed05475e081bf7059c94f9299cd8d7e5dd7 (diff) | |
parent | cc7be6c64316e72bfdbb523f52b479394b3bff76 (diff) |
Merge pull request #28925 from Daw11/astar-sorted-array
Improve the performance of AStar
Diffstat (limited to 'core/math/a_star.h')
-rw-r--r-- | core/math/a_star.h | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/core/math/a_star.h b/core/math/a_star.h index c63e1aa4dc..fac8a9d312 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -48,26 +48,34 @@ class AStar : public Reference { struct Point { - SelfList<Point> list; - int id; Vector3 pos; real_t weight_scale; - uint64_t last_pass; bool enabled; Set<Point *> neighbours; // Used for pathfinding Point *prev_point; - real_t distance; - - Point() : - list(this) {} + real_t g_score; + real_t f_score; + uint64_t open_pass; + uint64_t closed_pass; }; Map<int, Point *> points; + struct SortPoints { + _FORCE_INLINE_ bool operator()(const Point *A, const Point *B) const { // Returns true when the Point A is worse than Point B + if (A->f_score > B->f_score) + return true; + else if (A->f_score < B->f_score) + return false; + else + return A->g_score < B->g_score; // If the f_costs are the same then prioritize the points that are further away from the start + } + }; + struct Segment { union { struct { |