summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-06-07 22:20:07 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-06-07 23:22:53 +0200
commitb59abcd07e8c9bd2c79061f8cfc827a43c9408ef (patch)
treeaca1c3c6e5637c456c32c2a2f482370783c551a6
parent8cecac2948cd0101ad76cbce8e32224f66002b8a (diff)
add failing test
-rw-r--r--test/app.cpp1
-rw-r--r--test/app.hpp1
-rw-r--r--test/collisions.cpp54
3 files changed, 56 insertions, 0 deletions
diff --git a/test/app.cpp b/test/app.cpp
index 91c56b29..bc02a952 100644
--- a/test/app.cpp
+++ b/test/app.cpp
@@ -72,6 +72,7 @@ int App::exec()
FM_TEST(test_json2),
FM_TEST(test_json3),
FM_TEST(test_loader),
+ FM_TEST(test_collisions),
FM_TEST(test_raycast),
FM_TEST(test_region),
FM_TEST(test_wall_atlas),
diff --git a/test/app.hpp b/test/app.hpp
index 989b72be..b358d896 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -19,6 +19,7 @@ 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();
diff --git a/test/collisions.cpp b/test/collisions.cpp
new file mode 100644
index 00000000..c675546d
--- /dev/null
+++ b/test/collisions.cpp
@@ -0,0 +1,54 @@
+#include "app.hpp"
+#include "src/world.hpp"
+#include "src/critter.hpp"
+#include "src/RTree.hpp"
+#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 pos = global_coords{ch, {0, 0}};
+ auto& c = w[ch];
+
+ fm_assert(c.rtree()->Count() == 0);
+ auto C = w.make_object<critter>(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();
+ C->teleport_to(index, pos, {1, 2}, rotation::N);
+ fm_assert(C->offset == Vector2b{1, 2});
+ fm_assert(c.rtree()->Count() == 1);
+ C->teleport_to(index, point{{2, 2, 0}, {}, {0, 0}}, rotation::N);
+ fm_assert(c.objects().size() == 0);
+ fm_assert(c.rtree()->Count() == 0);
+ (void)index;
+}
+
+} // namespace
+
+
+void Test::test_collisions()
+{
+ test1();
+}
+
+} // namespace floormat