summaryrefslogtreecommitdiffhomepage
path: root/src/path-search-dijkstra.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-10-07 02:18:34 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-10-07 02:19:11 +0200
commit70d32f586ad17872809ca13f24d9fb36fb9ad213 (patch)
tree311a98fa4d17fc59bade9bea838138202e1bb7f2 /src/path-search-dijkstra.cpp
parent072827b3cb04c29ba23c3db7ba1f9a94f0bc39e4 (diff)
a
Diffstat (limited to 'src/path-search-dijkstra.cpp')
-rw-r--r--src/path-search-dijkstra.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp
index eee01a47..404eb852 100644
--- a/src/path-search-dijkstra.cpp
+++ b/src/path-search-dijkstra.cpp
@@ -82,9 +82,36 @@ path_search_result path_search::Dijkstra(world& w, Vector2ub own_size, object_id
if (from_offset_len >= eps && is_passable(w, ch0, bb0, own_id, p))
astar.push({from, from_offset, from, from_offset}, from_offset_len);
+ constexpr auto dirs = [] constexpr -> std::array<Vector2i, 8> {
+ constexpr auto sqrt_2 = math::sqrt(2.f);
+ std::array<Vector2i, 8> array = {{
+ { -1, -1 },
+ { 1, 1 },
+ { -1, 1 },
+ { 1, -1 },
+ { -1, 0 },
+ { 0, -1 },
+ { 1, 0 },
+ { 0, 1 },
+ }};
+ for (auto i = 0uz; i < array.size(); i++)
+ for (auto j = 0uz; j < i; j++)
+ fm_assert(array[i] != array[j]);
+ for (auto& vec : array)
+ {
+ if (vec.product() != 0)
+ vec = Vector2i(Vector2(vec) * path_search::div_size * sqrt_2);
+ else
+ vec *= path_search::div_size;
+ }
+ return array;
+ }();
+
while (!astar.empty())
{
- auto [prev, dist0] = astar.pop();
+ auto [cur, dist0] = astar.pop();
+ if (!astar.add_visited(cur))
+ continue;
}
// todo...