diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-26 16:36:14 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-26 16:36:14 +0200 |
commit | b1351006462e817e221ff9bdbfc2ad7122a79f1f (patch) | |
tree | ceef9eaebdc99eff03c100c4bc5808a4668c3fb8 | |
parent | 3e51922e2cfd9430c1a45074107d467f6c1e5e0e (diff) |
wip
-rw-r--r-- | src/path-search.hpp | 6 | ||||
-rw-r--r-- | test/path-search.cpp | 40 |
2 files changed, 42 insertions, 4 deletions
diff --git a/src/path-search.hpp b/src/path-search.hpp index f3601a26..04c20302 100644 --- a/src/path-search.hpp +++ b/src/path-search.hpp @@ -71,13 +71,13 @@ class path_search final struct obj_position { Vector2 center, size; }; - chunk_cache cache; - Array<global_coords> output; - // todo bucketize by array length path_search_result* pool = nullptr; public: + chunk_cache cache; + Array<global_coords> output; + struct bbox { Vector2 min, max; }; void ensure_allocated(chunk_coords a, chunk_coords b); diff --git a/test/path-search.cpp b/test/path-search.cpp index 2ed78530..d08af0dc 100644 --- a/test/path-search.cpp +++ b/test/path-search.cpp @@ -75,7 +75,7 @@ void test_bbox() c[{8, 8}].wall_north() = {metal2,0}; c.mark_passability_modified(); - fm_assert( is_passable_1(c, bbox({8, 8}, C))); + fm_assert( is_passable_1(c, bbox({8, 8}, C)) ); fm_assert( !is_passable_1(c, bbox({8, 7}, S)) ); fm_assert( !is_passable_1(c, bbox({8, 8}, N)) ); @@ -109,6 +109,44 @@ void test_bbox() fm_assert(neighbor_tiles(w, ch, {2, 4}).size == 3); fm_assert(neighbor_tiles(w, ch, {4, 4}).size == 3); } + { + constexpr auto ch = chunk_coords_{}; + auto w = world(); + auto& c = w[ch]; + constexpr size_t K = 8; + const auto wall = tile_image_proto{metal2, 0}; + c[{0, 0}].wall_north() = wall; + c[{0, 0}].wall_west() = wall; + + c[{K, K }].wall_north() = { metal2, 0 }; + c[{K, K }].wall_west() = { metal2, 0 }; + c[{K, K+1}].wall_north() = { metal2, 0 }; + c[{K+1, K }].wall_west() = { metal2, 0 }; + + path_search search; + search.ensure_allocated({-1, -1}, {0, 0}); + search.fill_cache_(w, {0, 0, 0}, {}, {}); + + const auto c_idx = [&](chunk_coords ch) + { + auto ch_ = Vector2i(ch) - search.cache.start; + return ch_.y()*search.cache.size.x() + ch_.x(); + }; + constexpr auto t_idx = [](local_coords tile) { + return (size_t)tile.y * TILE_MAX_DIM + (size_t)tile.x; + }; + const auto check_north = [&](chunk_coords ch, local_coords tile) { + return search.cache.array[c_idx(ch)].can_go_north[t_idx(tile)]; + }; + const auto check_west = [&](chunk_coords ch, local_coords tile) { + return search.cache.array[c_idx(ch)].can_go_west[t_idx(tile)]; + }; + + fm_assert( check_west ({}, {0, 0}) ); + fm_assert( check_north({}, {0, 0}) ); + fm_assert( !check_north({}, {K, K}) ); + fm_assert( !check_west ({}, {K, K}) ); + } } } // namespace |