From be600cd122abfdbd608a7a84a69e68e136269211 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 8 Jun 2024 04:44:10 +0200 Subject: tests: oops, fix naming conflict --- test/app.cpp | 4 +-- test/app.hpp | 2 +- test/collisions.cpp | 99 ----------------------------------------------------- test/rtree.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 102 deletions(-) delete mode 100644 test/collisions.cpp create mode 100644 test/rtree.cpp diff --git a/test/app.cpp b/test/app.cpp index 26ecac74..f7adebcb 100644 --- a/test/app.cpp +++ b/test/app.cpp @@ -65,6 +65,7 @@ int App::exec() FM_TEST(test_bptr), FM_TEST(test_iptr), FM_TEST(test_entity), + FM_TEST(test_hash), // normal FM_TEST(test_bitmask), FM_TEST(test_json), @@ -72,13 +73,12 @@ int App::exec() FM_TEST(test_json3), FM_TEST(test_loader), FM_TEST(test_region), - FM_TEST(test_collisions), + FM_TEST(test_rtree), FM_TEST(test_raycast), FM_TEST(test_wall_atlas), FM_TEST(test_wall_atlas2), // the rest are slow FM_TEST(test_astar), - FM_TEST(test_hash), FM_TEST(test_critter), FM_TEST(test_dijkstra), FM_TEST(test_loader2), diff --git a/test/app.hpp b/test/app.hpp index b358d896..b1995e77 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -19,7 +19,6 @@ void test_astar(); void test_astar_pool(); void test_bitmask(); void test_bptr(); -void test_collisions(); void test_coords(); void test_critter(); void test_dijkstra(); @@ -38,6 +37,7 @@ void test_magnum_math(); void test_math(); void test_raycast(); void test_region(); +void test_rtree(); void test_save(); void test_saves(); void test_script(); diff --git a/test/collisions.cpp b/test/collisions.cpp deleted file mode 100644 index 5a535a44..00000000 --- a/test/collisions.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "app.hpp" -#include "src/world.hpp" -#include "src/critter.hpp" -#include "src/RTree.hpp" -#include "src/nanosecond.inl" -#include "loader/loader.hpp" - -namespace floormat { - -namespace { - -critter_proto make_critter_proto() -{ - critter_proto proto; - proto.atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH); - proto.name = "critter"_s; - proto.speed = 1; - proto.playable = true; - proto.offset = {}; - proto.bbox_offset = {}; - proto.bbox_size = Vector2ub(tile_size_xy/2); - return proto; -} - -void test1() -{ - auto w = world(); - constexpr auto ch = chunk_coords_{0, 0, 0}; - constexpr auto ch2 = chunk_coords_{2, 2, 0}; - constexpr auto pos = global_coords{ch, {0, 0}}; - constexpr auto pos2 = global_coords{ch2, {0, 0}}; - auto& c = w[ch]; - auto& c2 = w[ch2]; - - fm_assert(c.rtree()->Count() == 0); - auto C = w.make_object(w.make_id(), pos, make_critter_proto()); - fm_assert(C->offset == Vector2b{}); - fm_assert(c.objects().size() == 1); - fm_assert(c.rtree()->Count() == 1); - fm_assert(c2.rtree()->Count() == 0); - auto index = C->index(); - C->teleport_to(index, pos, {1, 2}, rotation::N); - fm_assert(C->offset == Vector2b{1, 2}); - fm_assert(c.rtree()->Count() == 1); - fm_assert(c2.rtree()->Count() == 0); - C->teleport_to(index, pos2, {}, rotation::N); - fm_assert(c.objects().size() == 0); - fm_assert(c.rtree()->Count() == 0); - fm_assert(c2.rtree()->Count() == 1); - (void)index; -} - -void test2() -{ - auto w = world(); - constexpr auto ch = chunk_coords_{0, 0, 0}; - constexpr auto pos = global_coords{ch, {0, 0}}; - constexpr auto ch2 = chunk_coords_{-1, 0, 0}; - auto& c = w[ch]; - auto& c2 = w[ch2]; - - fm_assert(c.rtree()->Count() == 0); - auto C = w.make_object(w.make_id(), pos, make_critter_proto()); - fm_assert(C->offset == Vector2b{}); - fm_assert(c.objects().size() == 1); - fm_assert(c.rtree()->Count() == 1); - auto index = C->index(); - bool moved = false; - c.ensure_passability(); - for (int i = 0; i < 60*2; i++) - { - constexpr auto dt = Ns{Seconds / 60}; - auto dtʹ = dt; - auto result = C->move_toward(index, dtʹ, {{-10, 0, 0}, {}, {}}); - fm_assert(!result.blocked); - moved |= result.moved; - fm_assert(!c.is_passability_modified()); - - auto cnt = c.rtree()->Count(), cnt2 = c2.rtree()->Count(); - fm_assert(cnt <= 1); - fm_assert(cnt2 <= 1); - fm_assert_not_equal(cnt, cnt2); - } - fm_assert(moved); - fm_assert_equal(ch2, C->coord.chunk3()); - fm_assert_equal(0, c.rtree()->Count()); - fm_assert_equal(1, c2.rtree()->Count()); -} - -} // namespace - - -void Test::test_collisions() -{ - test1(); - test2(); -} - -} // namespace floormat diff --git a/test/rtree.cpp b/test/rtree.cpp new file mode 100644 index 00000000..16e89659 --- /dev/null +++ b/test/rtree.cpp @@ -0,0 +1,99 @@ +#include "app.hpp" +#include "src/world.hpp" +#include "src/critter.hpp" +#include "src/RTree.hpp" +#include "src/nanosecond.inl" +#include "loader/loader.hpp" + +namespace floormat { + +namespace { + +critter_proto make_critter_proto() +{ + critter_proto proto; + proto.atlas = loader.anim_atlas("npc-walk", loader.ANIM_PATH); + proto.name = "critter"_s; + proto.speed = 1; + proto.playable = true; + proto.offset = {}; + proto.bbox_offset = {}; + proto.bbox_size = Vector2ub(tile_size_xy/2); + return proto; +} + +void test1() +{ + auto w = world(); + constexpr auto ch = chunk_coords_{0, 0, 0}; + constexpr auto ch2 = chunk_coords_{2, 2, 0}; + constexpr auto pos = global_coords{ch, {0, 0}}; + constexpr auto pos2 = global_coords{ch2, {0, 0}}; + auto& c = w[ch]; + auto& c2 = w[ch2]; + + fm_assert(c.rtree()->Count() == 0); + auto C = w.make_object(w.make_id(), pos, make_critter_proto()); + fm_assert(C->offset == Vector2b{}); + fm_assert(c.objects().size() == 1); + fm_assert(c.rtree()->Count() == 1); + fm_assert(c2.rtree()->Count() == 0); + auto index = C->index(); + C->teleport_to(index, pos, {1, 2}, rotation::N); + fm_assert(C->offset == Vector2b{1, 2}); + fm_assert(c.rtree()->Count() == 1); + fm_assert(c2.rtree()->Count() == 0); + C->teleport_to(index, pos2, {}, rotation::N); + fm_assert(c.objects().size() == 0); + fm_assert(c.rtree()->Count() == 0); + fm_assert(c2.rtree()->Count() == 1); + (void)index; +} + +void test2() +{ + auto w = world(); + constexpr auto ch = chunk_coords_{0, 0, 0}; + constexpr auto pos = global_coords{ch, {0, 0}}; + constexpr auto ch2 = chunk_coords_{-1, 0, 0}; + auto& c = w[ch]; + auto& c2 = w[ch2]; + + fm_assert(c.rtree()->Count() == 0); + auto C = w.make_object(w.make_id(), pos, make_critter_proto()); + fm_assert(C->offset == Vector2b{}); + fm_assert(c.objects().size() == 1); + fm_assert(c.rtree()->Count() == 1); + auto index = C->index(); + bool moved = false; + c.ensure_passability(); + for (int i = 0; i < 60*2; i++) + { + constexpr auto dt = Ns{Seconds / 60}; + auto dtʹ = dt; + auto result = C->move_toward(index, dtʹ, {{-10, 0, 0}, {}, {}}); + fm_assert(!result.blocked); + moved |= result.moved; + fm_assert(!c.is_passability_modified()); + + auto cnt = c.rtree()->Count(), cnt2 = c2.rtree()->Count(); + fm_assert(cnt <= 1); + fm_assert(cnt2 <= 1); + fm_assert_not_equal(cnt, cnt2); + } + fm_assert(moved); + fm_assert_equal(ch2, C->coord.chunk3()); + fm_assert_equal(0, c.rtree()->Count()); + fm_assert_equal(1, c2.rtree()->Count()); +} + +} // namespace + + +void Test::test_rtree() +{ + test1(); + test2(); +} + +} // namespace floormat -- cgit v1.2.3