diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-09 05:25:16 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-09 05:25:16 +0200 |
commit | 0e9ecb5c33e35a9adceea97de637db133ffa9dbf (patch) | |
tree | c376a086ad0d268e9ab1a8ad8c14009fefc7d4d3 | |
parent | e93021bccd1f6c3d3019f8108cb2471ed926d7a6 (diff) |
a
-rw-r--r-- | src/path-search-dijkstra.cpp | 12 | ||||
-rw-r--r-- | src/path-search.hpp | 2 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp index 417b1b55..cec44225 100644 --- a/src/path-search-dijkstra.cpp +++ b/src/path-search-dijkstra.cpp @@ -264,17 +264,23 @@ path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id o if (dist >= max_dist) continue; - #ifdef FM_ASTAR_NO_EDGE_CACHE + const auto new_pt = point{.coord = new_coord, .offset = new_offset}; + + if (auto it = indexes.find(new_pt); it != indexes.end()) + if (nodes[it->second].dist >= dist) + continue; + +#ifdef FM_ASTAR_NO_EDGE_CACHE { auto vec_ = Vector2(vec); auto bb1 = bbox<float>{ bb0.min + vec_, bb0.max + vec_ }; auto bb = bbox_union(bb1, bb0); if (!path_search::is_passable(w, chunk_coords_(new_coord), bb, own_id, p)) continue; } - #endif +#endif const auto sz = nodes.size(); - auto [it, fresh] = indexes.try_emplace({.coord = new_coord, .offset = new_offset}, sz); + auto [it, fresh] = indexes.try_emplace(new_pt, sz); const auto new_idx = it.value(); if (new_idx == sz) diff --git a/src/path-search.hpp b/src/path-search.hpp index ce739ea4..733f5374 100644 --- a/src/path-search.hpp +++ b/src/path-search.hpp @@ -81,7 +81,7 @@ struct astar object_id own_id, uint32_t max_dist, Vector2ub own_size, int debug = 0, const pred& p = path_search::never_continue()); -//#define FM_ASTAR_NO_EDGE_CACHE +#define FM_ASTAR_NO_EDGE_CACHE private: static constexpr auto div_factor = (int8_t)path_search::div_factor; |