summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-12-05 21:32:57 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-12-06 01:35:11 +0100
commit0a6612286bfa8c2503c757da2b39da37aa05deaf (patch)
tree3606dbe2ee59026f0fcdba7377034dfcab13da0d /test
parent2679d49a53a3f9825ce855f6ed25b3b045ec5aa1 (diff)
src/chunk: plug in lqt for collision detection
Diffstat (limited to 'test')
-rw-r--r--test/app.hpp5
-rw-r--r--test/bbox.cpp28
-rw-r--r--test/main.cpp1
-rw-r--r--test/serializer.cpp2
4 files changed, 35 insertions, 1 deletions
diff --git a/test/app.hpp b/test/app.hpp
index 17ca2b6e..46ea3fc0 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -13,12 +13,16 @@
#endif
namespace floormat {
+
+struct chunk;
+
struct test_app final : private FM_APPLICATION
{
using Application = FM_APPLICATION;
explicit test_app(const Arguments& arguments);
~test_app();
int exec() override;
+ static chunk make_test_chunk();
static void test_json();
static void test_tile_iter();
static void test_const_math();
@@ -26,5 +30,6 @@ struct test_app final : private FM_APPLICATION
static void test_entity();
static void test_quadtree();
static void test_loader();
+ static void test_bbox();
};
} // namespace floormat
diff --git a/test/bbox.cpp b/test/bbox.cpp
new file mode 100644
index 00000000..c045d858
--- /dev/null
+++ b/test/bbox.cpp
@@ -0,0 +1,28 @@
+#include "app.hpp"
+#include "src/chunk.hpp"
+#include "compat/LooseQuadtree-impl.h"
+#include <Magnum/Math/Vector2.h>
+
+namespace floormat {
+
+void test_app::test_bbox()
+{
+ auto c = make_test_chunk();
+ auto& qt = c.ensure_passability();
+ fm_assert(qt.GetSize() >= 2);
+
+ using namespace loose_quadtree;
+ using bbox = BoundingBox<std::int16_t>;
+ constexpr auto pos1 = Vector2s(iTILE_SIZE2 * (TILE_MAX_DIM/2) - Vector2i(0, iTILE_SIZE[1]/2)),
+ size = Vector2s(iTILE_SIZE2);
+ constexpr auto b1 = bbox{pos1[0], pos1[1], size[0], size[1]};
+ constexpr auto pos2 = Vector2s(iTILE_SIZE2 * (Vector2i(TILE_MAX_DIM/2) - Vector2i(-1, -1)) - Vector2i(0, iTILE_SIZE[1]/2));
+ auto q1 = qt.QueryIntersectsRegion(b1);
+ fm_assert(!q1.EndOfQuery());
+ do q1.Next(); while (!q1.EndOfQuery());
+ constexpr auto b2 = bbox{pos2[0], pos2[1], size[0], size[1]};
+ auto q2 = qt.QueryIntersectsRegion(b2);
+ fm_assert(q2.EndOfQuery());
+}
+
+} // namespace floormat
diff --git a/test/main.cpp b/test/main.cpp
index ec09f55f..305c4926 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -25,6 +25,7 @@ int test_app::exec()
test_serializer();
test_entity();
test_loader();
+ test_bbox();
test_quadtree();
return 0;
}
diff --git a/test/serializer.cpp b/test/serializer.cpp
index 9f382602..69b45575 100644
--- a/test/serializer.cpp
+++ b/test/serializer.cpp
@@ -9,7 +9,7 @@ namespace floormat {
namespace Path = Corrade::Utility::Path;
-static chunk make_test_chunk()
+chunk test_app::make_test_chunk()
{
auto metal1 = loader.tile_atlas("metal1", {2, 2}, pass_mode::pass),
metal2 = loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked),