diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-24 18:58:49 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-24 18:58:49 +0100 |
commit | 7d02953f5338fc60d0a3941ab6a144b1a0e5bc96 (patch) | |
tree | 009575e536f8ffb2c05fe418d87ed7c2814c76d0 | |
parent | 849d73f22ad89e04137006704d2fd6d6fdbb4969 (diff) |
test: add region test
-rw-r--r-- | test/app.cpp | 1 | ||||
-rw-r--r-- | test/app.hpp | 1 | ||||
-rw-r--r-- | test/region.cpp | 115 |
3 files changed, 117 insertions, 0 deletions
diff --git a/test/app.cpp b/test/app.cpp index 5e343bdc..0cacfe45 100644 --- a/test/app.cpp +++ b/test/app.cpp @@ -54,6 +54,7 @@ int test_app::exec() FM_TEST(test_raycast), FM_TEST(test_json), FM_TEST(test_loader), + FM_TEST(test_region), FM_TEST(test_wall_atlas), FM_TEST(test_json2), FM_TEST(test_wall_atlas2), diff --git a/test/app.hpp b/test/app.hpp index 7c736a95..e4b77614 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -38,6 +38,7 @@ struct test_app final : private FM_APPLICATION static void test_magnum_math(); static void test_math(); static void test_raycast(); + static void test_region(); static void test_saves(); static void test_serializer1(); static void test_tile_iter(); diff --git a/test/region.cpp b/test/region.cpp new file mode 100644 index 00000000..9b09cdf9 --- /dev/null +++ b/test/region.cpp @@ -0,0 +1,115 @@ +#include "app.hpp" +#include "src/world.hpp" +#include "src/chunk-region.hpp" +#include "loader/loader.hpp" + +namespace floormat { + +namespace { + +chunk& make_chunk1(chunk& c, bool val, bool flipped) +{ + auto floor = tile_image_proto { loader.ground_atlas("texel"), 0 }; + auto empty = tile_image_proto{}; + + constexpr uint8_t mat[TILE_MAX_DIM][TILE_MAX_DIM] = { + { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, + { 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, }, + { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, }, + { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, + }; + + if (!flipped) + for (auto j = 0u; j < TILE_MAX_DIM; j++) + for (auto i = 0u; i < TILE_MAX_DIM; i++) + c[{i, j}].ground() = !!mat[i][j] == val ? floor : empty; + else + for (auto j = 0u; j < TILE_MAX_DIM; j++) + for (auto i = 0u; i < TILE_MAX_DIM; i++) + c[{i, j}].ground() = !!mat[j][i] == val ? floor : empty; + + return c; +} + +constexpr auto COORD = chunk_coords_{2, 1, 0}; + +void test1() +{ + auto w = world(); + auto& c = make_chunk1(w[COORD], true, false); + auto p = chunk::pass_region{}; + c.make_pass_region(p); + const auto count = p.bits.count(); + fm_assert(count > 1000); + fm_assert(p.bits.size() - count > 2000); + fm_assert(c.get_pass_region()->bits == p.bits); + { auto w = world(); + auto& c = make_chunk1(w[COORD], true, true); + auto p2 = chunk::pass_region{}; + c.make_pass_region(p2); + fm_assert(p2.bits.count() == count); + } +} + +void test2() +{ + auto w = world(); + auto& c = make_chunk1(w[COORD], false, false); + auto p = chunk::pass_region{}; + c.make_pass_region(p); + const auto count = p.bits.count(); + fm_assert(count > 1000); + fm_assert(p.bits.size() - count > 2000); + { auto w = world(); + auto& c = make_chunk1(w[COORD], false, true); + auto p2 = chunk::pass_region{}; + c.make_pass_region(p2); + fm_assert(p2.bits.count() == count); + } +} + +void test3() +{ + auto w = world(); + auto& c = make_chunk1(w[COORD], true, false); + const auto bits = c.get_pass_region()->bits; + fm_assert(bits.count() > 1000); + + { auto p2 = chunk::pass_region{}; + c.make_pass_region(p2); + fm_assert(p2.bits == bits); + } + + { const auto empty = tile_image_proto{}; + fm_assert(c[{0, 0}].ground() != empty); + + c[{0, 0}].ground() = empty; + fm_assert(c.get_pass_region()->bits == bits); + + c.mark_passability_modified(); + fm_assert(c.get_pass_region()->bits != bits); + } +} + +} // namespace + +void test_app::test_region() +{ + test1(); + test2(); + test3(); +} + +} // namespace floormat |