From 67a9004bd076a6e875eb0f88d93518a4b91f03b5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 21 Oct 2023 15:52:25 +0200 Subject: a --- src/dijkstra.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/dijkstra.cpp') diff --git a/src/dijkstra.cpp b/src/dijkstra.cpp index ab654660..1adc021a 100644 --- a/src/dijkstra.cpp +++ b/src/dijkstra.cpp @@ -151,8 +151,7 @@ path_search_result astar::Dijkstra(world& w, const point from_, const point to_, add_to_heap(0); { const auto bb0 = bbox_from_pos(Vector2(from.local()), {}, own_size); - uint32_t idx = 0; - constexpr int8_t div_min = div_factor*-2, div_max = div_factor*2+1; + constexpr int8_t div_min = -div_factor, div_max = div_factor; for (int8_t y = div_min; y <= div_max; y++) for (int8_t x = div_min; x <= div_max; x++) @@ -161,14 +160,15 @@ path_search_result astar::Dijkstra(world& w, const point from_, const point to_, auto off = Vector2(off_); auto bb1 = bbox{ bb0.min + off, bb0.max + off}; auto bb = bbox_union(bb0, bb1); - auto dist = (uint32_t)off.length(); + auto pt = object::normalize_coords({from, {}}, off_); + auto dist = distance(from_, pt); if (path_search::is_passable(w, from.chunk3(), bb, own_id, p)) { - auto pt = object::normalize_coords({from, {}}, off_); + auto idx = (uint32_t)nodes.size(); cache.add_index(pt, idx); nodes.push_back({.dist = dist, .prev = (uint32_t)-1, .pt = pt, }); - add_to_heap(idx++); + add_to_heap(idx); } } } -- cgit v1.2.3