summaryrefslogtreecommitdiffhomepage
path: root/src/dijkstra.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-21 15:52:25 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-21 15:52:25 +0200
commit67a9004bd076a6e875eb0f88d93518a4b91f03b5 (patch)
tree2cdc4d0e374a96c6e99b35f186619f58f17de2ee /src/dijkstra.cpp
parent1bfb21734d9511a1fca1870818f645c994b0e8a3 (diff)
a
Diffstat (limited to 'src/dijkstra.cpp')
-rw-r--r--src/dijkstra.cpp10
1 files changed, 5 insertions, 5 deletions
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<float>{ 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);
}
}
}