summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorYuri Rubinsky <chaosus89@gmail.com>2023-01-22 12:00:54 +0300
committerYuri Rubinsky <chaosus89@gmail.com>2023-01-22 12:04:41 +0300
commit078600a3c41426c070fd9af2f528727bf4a22658 (patch)
treece44c2771ae6cb0e8914dc66c0eedc5247ca0cf8 /core/math
parentc3539b4561f9b4d7dc4ba1c5859217e7fbf9c6fe (diff)
Enchance the performance of `AStar` by using a `LocalVector`
Diffstat (limited to 'core/math')
-rw-r--r--core/math/a_star.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index a54804c5dc..9bfe46727b 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -794,7 +794,7 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) {
bool found_route = false;
- Vector<AStar3D::Point *> open_list;
+ LocalVector<AStar3D::Point *> open_list;
SortArray<AStar3D::Point *, AStar3D::SortPoints> sorter;
begin_point->g_score = 0;
@@ -802,19 +802,19 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) {
open_list.push_back(begin_point);
while (!open_list.is_empty()) {
- AStar3D::Point *p = open_list[0]; // The currently processed point
+ AStar3D::Point *p = open_list[0]; // The currently processed point.
if (p == end_point) {
found_route = true;
break;
}
- sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list
+ sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list.
open_list.remove_at(open_list.size() - 1);
- p->closed_pass = astar.pass; // Mark the point as closed
+ p->closed_pass = astar.pass; // Mark the point as closed.
for (OAHashMap<int64_t, AStar3D::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
- AStar3D::Point *e = *(it.value); // The neighbour point
+ AStar3D::Point *e = *(it.value); // The neighbour point.
if (!e->enabled || e->closed_pass == astar.pass) {
continue;
@@ -837,9 +837,9 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) {
e->f_score = e->g_score + _estimate_cost(e->id, end_point->id);
if (new_point) { // The position of the new points is already known.
- sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr());
} else {
- sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw());
+ sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr());
}
}
}