diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-06 23:11:21 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-06 23:49:50 +0200 |
commit | 7ed03e01ac8913a90cae827bc656969e09fc7455 (patch) | |
tree | be3f87d4bbae74806aa45f72f5069ee82f8fc9ac | |
parent | d26b3630c7248bc367d6e45faacc5ff0d734c66e (diff) |
mark tiles reachable around player in region bitmask
-rw-r--r-- | editor/tests/region-test.cpp | 19 | ||||
-rw-r--r-- | src/chunk-region.cpp | 15 | ||||
-rw-r--r-- | src/chunk.hpp | 4 |
3 files changed, 26 insertions, 12 deletions
diff --git a/editor/tests/region-test.cpp b/editor/tests/region-test.cpp index 46255eb4..9826845f 100644 --- a/editor/tests/region-test.cpp +++ b/editor/tests/region-test.cpp @@ -1,4 +1,5 @@ #include "../tests-private.hpp" +#include "compat/shared-ptr-wrapper.hpp" #include "src/tile-constants.hpp" #include "src/chunk-region.hpp" #include "src/object.hpp" @@ -6,7 +7,7 @@ #include "../app.hpp" #include "../imgui-raii.hpp" #include "floormat/main.hpp" -#include <mg/Vector2.h> +#include "src/critter.hpp" namespace floormat::tests { @@ -44,7 +45,7 @@ struct region_test final : base_test result_s result; pending_s pending; - void do_region_extraction(world& w, chunk_coords_ coord); + void do_region_extraction(app& a, chunk_coords_ coord); ~region_test() noexcept override = default; bool handle_key(app&, const key_event&, bool) override { return {}; } @@ -144,20 +145,24 @@ void region_test::update_post(app& a, const Ns&) if (pending.exists) { pending.exists = false; - auto& M = a.main(); - auto& w = M.world(); - do_region_extraction(w, pending.c); + do_region_extraction(a, pending.c); } } -void region_test::do_region_extraction(world& w, chunk_coords_ coord) +void region_test::do_region_extraction(app& a, chunk_coords_ coord) { + auto& M = a.main(); + auto& w = M.world(); + auto C = a.ensure_player_character(w).ptr; if (auto* c = w.at(coord)) + { + Vector2i C_coord[] = { Vector2i(C->coord.local()) * iTILE_SIZE2 + Vector2i(C->offset) }; result = { - .region = c->make_pass_region(true), + .region = c->make_pass_region(true, C_coord), .c = coord, .exists = true, }; + } } } // namespace diff --git a/src/chunk-region.cpp b/src/chunk-region.cpp index 57d09ab4..e28cc041 100644 --- a/src/chunk-region.cpp +++ b/src/chunk-region.cpp @@ -19,6 +19,7 @@ namespace { using Search::bbox; using Search::div_size; using Search::div_count; +using Search::div_factor; using Search::pred; static_assert(div_count.x() == div_count.y()); @@ -131,12 +132,12 @@ auto default_region_predicate(chunk& c) noexcept } // namespace -auto chunk::make_pass_region(bool debug) -> pass_region +auto chunk::make_pass_region(bool debug, ArrayView<Vector2i> positions) -> pass_region { - return make_pass_region(default_region_predicate(*this), debug); + return make_pass_region(default_region_predicate(*this), debug, positions); } -auto chunk::make_pass_region(const pred& f, bool debug) -> pass_region +auto chunk::make_pass_region(const pred& f, bool debug, ArrayView<Vector2i> positions) -> pass_region { Timeline timeline; timeline.start(); @@ -172,6 +173,14 @@ auto chunk::make_pass_region(const pred& f, bool debug) -> pass_region do_pixel.operator()<D, true>(Vector2i(i, -1)); } + for (auto pos : positions) + { + const auto posʹ = (pos + iTILE_SIZE2)*div_factor / iTILE_SIZE2; + fm_debug_assert(posʹ >= Vector2i{}); + fm_debug_assert(posʹ < div_count); + tmp.append(ret.bits, posʹ); + } + while (!tmp.stack.isEmpty()) { auto p = tmp.stack.back().pos; diff --git a/src/chunk.hpp b/src/chunk.hpp index 266d01e5..2eccef14 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -117,8 +117,8 @@ public: static constexpr size_t max_wall_quad_count = TILE_COUNT*Wall::Direction_COUNT*(Wall::Group_COUNT+4); - pass_region make_pass_region(bool debug = false); - pass_region make_pass_region(const Search::pred& f, bool debug = false); + pass_region make_pass_region(bool debug = false, ArrayView<Vector2i> positions = {}); + pass_region make_pass_region(const Search::pred& f, bool debug = false, ArrayView<Vector2i> positions = {}); private: struct ground_stuff |