diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-07 23:48:21 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-07 23:48:21 +0200 |
| commit | ef47c7d8bcf5c60d086ab24b5d2f9c31a65c57c0 (patch) | |
| tree | 02d3ff558f1a92a99fef12dab83b69079d509a7e /src/path-search-dijkstra.cpp | |
| parent | 823aeb462cd46114ac290c0a415879f96d69c18e (diff) | |
a
Diffstat (limited to 'src/path-search-dijkstra.cpp')
| -rw-r--r-- | src/path-search-dijkstra.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp index beb87ddd..2fbc11e0 100644 --- a/src/path-search-dijkstra.cpp +++ b/src/path-search-dijkstra.cpp @@ -124,6 +124,14 @@ size_t astar::edge_hash::operator()(const edge& e) const #endif } +constexpr astar::edge make_edge(const point& a, const point& b) +{ + if (a < b) + return { a.coord, b.coord, a.offset, b.offset }; + else + return { b.coord, a.coord, b.offset, a.offset }; +} + path_search_result path_search::Dijkstra(world& w, Vector2ub own_size, const object_id own_id, const point from_, const point to_, const pred& p) { @@ -201,6 +209,10 @@ path_search_result path_search::Dijkstra(world& w, Vector2ub own_size, const obj continue; auto [new_coord, new_offset] = object::normalize_coords(node.coord, node.offset, vec); + + if (!astar.edges.insert(make_edge({node.coord, node.offset}, {new_coord, new_offset})).second) + continue; + auto [it, found] = astar.indexes.try_emplace({.coord = new_coord, .offset = new_offset}, (uint32_t)-1); if (!found) { |
