summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-12-06 17:27:44 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-12-06 17:29:25 +0100
commit646f9d9774d72e9459f50726b200a586d7e07614 (patch)
treeb3f0357c62e252298cbe6c5a8ed314373ac2d5cd /test
parentd73d869bc195bf8dbb7525ce12acf2c2fde56084 (diff)
src/chunk: stick bboxes into the pointer on 64-bit
Diffstat (limited to 'test')
-rw-r--r--test/bbox.cpp42
-rw-r--r--test/quadtree.cpp34
2 files changed, 22 insertions, 54 deletions
diff --git a/test/bbox.cpp b/test/bbox.cpp
index 87921271..9ffd6122 100644
--- a/test/bbox.cpp
+++ b/test/bbox.cpp
@@ -2,48 +2,24 @@
#include "src/chunk.hpp"
#include "src/collision.hpp"
#include <Magnum/Math/Vector2.h>
+#include <Magnum/Math/Vector4.h>
namespace floormat {
-static void test_simple(chunk c)
+void test_app::test_bbox()
{
- auto& qt = c.ensure_passability();
- fm_assert(qt.GetSize() >= 2);
+ auto c = make_test_chunk();
- using namespace loose_quadtree;
- using bbox = BoundingBox<std::int16_t>;
constexpr auto pos1 = sTILE_SIZE2 * (TILE_MAX_DIM/2) - Vector2s(0, sTILE_SIZE2[1]/2);
- constexpr auto b1 = bbox{pos1[0], pos1[1], usTILE_SIZE2[0], usTILE_SIZE2[1]};
- auto q1 = qt.QueryIntersectsRegion(b1);
- fm_assert(!q1.EndOfQuery());
- auto x1 = *q1.GetCurrent();
- fm_assert(x1.pass_mode == pass_mode::blocked);
- do q1.Next(); while (!q1.EndOfQuery());
+ constexpr auto b1 = Vector4s{pos1[0], pos1[1], sTILE_SIZE2[0], sTILE_SIZE2[1]};
constexpr auto pos2 = Vector2s(iTILE_SIZE2 * (Vector2i(TILE_MAX_DIM/2) - Vector2i(-1, -1)) - Vector2i(0, iTILE_SIZE[1]/2));
- constexpr auto b2 = bbox{pos2[0], pos2[1], usTILE_SIZE2[0], usTILE_SIZE2[1]};
- auto q2 = qt.QueryIntersectsRegion(b2);
- fm_assert(q2.EndOfQuery());
-}
-
-static void test_wrapper(chunk c)
-{
+ constexpr auto b2 = Vector4s{pos2[0], pos2[1], usTILE_SIZE2[0], usTILE_SIZE2[1]};
{
- int i = 0;
- for (auto b : c.query_collisions(local_coords{TILE_MAX_DIM/2, TILE_MAX_DIM/2},
- usTILE_SIZE2,
- Vector2s(sTILE_SIZE2[0]/2, 0)))
- {
- fm_assert(b.pass_mode == pass_mode::blocked);
- i++;
- }
- fm_assert(i > 0);
+ auto q1 = c.query_collisions(b1, collision::move);
+ fm_assert(q1);
+ auto q2 = c.query_collisions(b2, collision::move);
+ fm_assert(!q2);
}
}
-void test_app::test_bbox()
-{
- test_simple(make_test_chunk());
- test_wrapper(make_test_chunk());
-}
-
} // namespace floormat
diff --git a/test/quadtree.cpp b/test/quadtree.cpp
index 20e270d0..4ad90acc 100644
--- a/test/quadtree.cpp
+++ b/test/quadtree.cpp
@@ -9,6 +9,7 @@
#include "compat/LooseQuadtree.h"
#include "compat/LooseQuadtree-impl.h"
#include "compat/assert.hpp"
+#include "src/collision.hpp"
#include "test/app.hpp"
#include <chrono>
@@ -22,19 +23,6 @@ using namespace loose_quadtree;
namespace {
template <typename NumberT>
-class TrivialBBExtractor {
-public:
- static void ExtractBoundingBox(const BoundingBox<NumberT> *object, BoundingBox<NumberT> *bbox) {
- bbox->left = object->left;
- bbox->top = object->top;
- bbox->width = object->width;
- bbox->height = object->height;
- }
-};
-
-
-
-template <typename NumberT>
void TestBoundingBox() {
BoundingBox<NumberT> big(100, 100, 200, 50);
BoundingBox<NumberT> small_inside(200, 125, 5, 5);
@@ -592,13 +580,11 @@ void TestQueries() {
TestQueryContains<NumberT>(objects, lqt);
}
-
-
template <typename NumberT>
-void StressTest() {
-#ifndef NDEBUG
- const int objects_generated = 10000;
- const int object_fluctuation = 1000;
+[[maybe_unused]] void StressTest() {
+#if 0
+ const int objects_generated = 100;
+ const int object_fluctuation = 10;
#else
const int objects_generated = 200000;
const int object_fluctuation = 20000;
@@ -697,22 +683,28 @@ void StressTest() {
lqt.ForceCleanup();
}
-
+#define FM_NO_QUADTREE_BENCHMARK
template <typename NumberT>
-void RunTests(const char* type_str) {
+void RunTests(const char* type_str)
+{
+ (void)type_str;
+#ifndef FM_NO_QUADTREE_BENCHMARK
printf("quadtree test %13s", type_str);
fflush(stdout);
auto start = std::chrono::high_resolution_clock::now();
+#endif
TestBoundingBox<NumberT>();
TestTraversals<NumberT>();
TestContainer<NumberT>();
TestQueries<NumberT>();
+#ifndef FM_NO_QUADTREE_BENCHMARK
StressTest<NumberT>();
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> time = end - start;
printf(": %.1f ms\n", time.count());
fflush(stdout);
+#endif
}
} // namespace