diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-22 18:36:42 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-22 19:43:03 +0100 |
commit | 3b8fe52e0f801978f9e0b1a7174155c8686c61bd (patch) | |
tree | 6b617db4f6de82baa0cfca6c588c6b79a0441261 | |
parent | 96c9743e65ac95706be3f49da3254d8db4c3afba (diff) |
editor: region test stub
-rw-r--r-- | editor/tests-private.hpp | 4 | ||||
-rw-r--r-- | editor/tests/region.cpp | 73 |
2 files changed, 76 insertions, 1 deletions
diff --git a/editor/tests-private.hpp b/editor/tests-private.hpp index c4acc80d..5e44879c 100644 --- a/editor/tests-private.hpp +++ b/editor/tests-private.hpp @@ -31,7 +31,7 @@ protected: }; enum class Test : uint32_t { - none, path, raycast, COUNT, + none, path, raycast, /*region,*/ COUNT, }; struct tests_data final : tests_data_ @@ -43,6 +43,7 @@ struct tests_data final : tests_data_ static Pointer<base_test> make_test_none(); static Pointer<base_test> make_test_path(); static Pointer<base_test> make_test_raycast(); + static Pointer<base_test> make_test_region(); Pointer<base_test> current_test; Test current_index = Test::none; @@ -58,6 +59,7 @@ struct tests_data final : tests_data_ { "None"_s, Test::none, &tests_data::make_test_none, }, { "Path"_s, Test::path, &tests_data::make_test_path, }, { "Raycasting"_s, Test::raycast, &tests_data::make_test_raycast }, + //{ "Region extraction"_s, Test::region, &tests_data::make_test_region }, }; }; diff --git a/editor/tests/region.cpp b/editor/tests/region.cpp new file mode 100644 index 00000000..74a4523f --- /dev/null +++ b/editor/tests/region.cpp @@ -0,0 +1,73 @@ +#include "../tests-private.hpp" +#include "src/tile-constants.hpp" +#include <bitset> + +namespace floormat::tests { + +namespace { + +constexpr int div_factor = 4; // from path-search.hpp +constexpr auto div_size = iTILE_SIZE2 / div_factor; +constexpr uint32_t chunk_nbits = TILE_MAX_DIM*TILE_MAX_DIM*uint32_t{div_factor*div_factor}; + +template<typename T> constexpr inline auto tile_size = Math::Vector2<T>{iTILE_SIZE2}; +template<typename T> constexpr inline auto chunk_size = Math::Vector2<T>{TILE_MAX_DIM} * tile_size<T>; + +constexpr Vector2i chunk_offsets[3][3] = { // from src/raycast.cpp + { + { -chunk_size<int>.x(), -chunk_size<int>.y() }, + { -chunk_size<int>.x(), 0 }, + { -chunk_size<int>.x(), chunk_size<int>.y() }, + }, + { + { 0, -chunk_size<int>.y() }, + { 0, 0 }, + { 0, chunk_size<int>.y() }, + }, + { + { chunk_size<int>.x(), -chunk_size<int>.y() }, + { chunk_size<int>.x(), 0 }, + { chunk_size<int>.x(), chunk_size<int>.y() }, + }, +}; +//static_assert(chunk_offsets[0][0] == Vector2i(-1024, -1024)); +//static_assert(chunk_offsets[2][0] == Vector2i(1024, -1024)); + +constexpr int8_t div_min = -div_factor*2, div_max = div_factor*2; // from src/dijkstra.cpp +//for (int8_t y = div_min; y <= div_max; y++) +// for (int8_t x = div_min; x <= div_max; x++) + +struct pending_s +{ + chunk_coords_ c; +}; + +struct result_s +{ + chunk_coords_ c; + std::bitset<chunk_nbits> is_passable; +}; + +#if 0 +struct region_test : base_test +{ + result_s result; + pending_s pending; + + ~region_test() noexcept override; + + bool handle_key(app&, const key_event&, bool) override; + bool handle_mouse_click(app& a, const mouse_button_event& e, bool is_down) override; + bool handle_mouse_move(app& a, const mouse_move_event& e) override; + void draw_overlay(app& a) override; + void draw_ui(app&, float) override; + void update_pre(app&) override; + void update_post(app& a) override; +}; +#endif + +} // namespace + +//Pointer<base_test> tests_data::make_test_region() { return Pointer<region_test>{InPlaceInit}; } + +} // namespace floormat::tests |