From 0e9ecb5c33e35a9adceea97de637db133ffa9dbf Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 9 Oct 2023 05:25:16 +0200 Subject: a --- src/path-search-dijkstra.cpp | 12 +++++++++--- 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{ 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; -- cgit v1.2.3