summaryrefslogtreecommitdiffhomepage
path: root/src/path-search-dijkstra.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-17 01:17:23 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-17 01:17:23 +0200
commit3907f9b7dd425b3886a9b156d157c324cbf6196d (patch)
treecd30fbfa8a6d5c9e1ba9672e22398c3a08995fe8 /src/path-search-dijkstra.cpp
parenta27ac8b71720d5e6340f5182d13d5eea528f8423 (diff)
a
Diffstat (limited to 'src/path-search-dijkstra.cpp')
-rw-r--r--src/path-search-dijkstra.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp
index 79f94e9d..b5f5355a 100644
--- a/src/path-search-dijkstra.cpp
+++ b/src/path-search-dijkstra.cpp
@@ -135,9 +135,6 @@ path_search_result astar::Dijkstra(world& w, const point from_, const point to_,
if (!path_search::is_passable(w, to, to_offset, own_size, own_id, p))
return {};
- path_search_result result;
- auto& path = result.path(); path.clear();
-
cache.allocate(from_, max_dist);
nodes.push_back({.dist = 0, .pt = from_, });
add_to_heap(0);
@@ -319,7 +316,23 @@ path_search_result astar::Dijkstra(world& w, const point from_, const point to_,
}
#endif
- // todo...
+ path_search_result result;
+ auto& path = result.path();
+ path.clear();
+
+ if (auto i = goal_idx; i != (uint32_t)-1)
+ {
+ do {
+ const auto& node = nodes[i];
+ path.push_back(node.pt);
+ i = node.prev;
+
+ } while(i !=(uint32_t)-1);
+
+ result.set_cost(nodes[goal_idx].dist);
+ std::reverse(path.begin(), path.end());
+ }
+
return result;
}