From 646f9d9774d72e9459f50726b200a586d7e07614 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 6 Dec 2022 17:27:44 +0100 Subject: src/chunk: stick bboxes into the pointer on 64-bit --- test/bbox.cpp | 42 +++++++++--------------------------------- test/quadtree.cpp | 34 +++++++++++++--------------------- 2 files changed, 22 insertions(+), 54 deletions(-) (limited to 'test') 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 +#include 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; 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 @@ -21,19 +22,6 @@ using namespace loose_quadtree; namespace { -template -class TrivialBBExtractor { -public: - static void ExtractBoundingBox(const BoundingBox *object, BoundingBox *bbox) { - bbox->left = object->left; - bbox->top = object->top; - bbox->width = object->width; - bbox->height = object->height; - } -}; - - - template void TestBoundingBox() { BoundingBox big(100, 100, 200, 50); @@ -592,13 +580,11 @@ void TestQueries() { TestQueryContains(objects, lqt); } - - template -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 -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(); TestTraversals(); TestContainer(); TestQueries(); +#ifndef FM_NO_QUADTREE_BENCHMARK StressTest(); auto end = std::chrono::high_resolution_clock::now(); std::chrono::duration time = end - start; printf(": %.1f ms\n", time.count()); fflush(stdout); +#endif } } // namespace -- cgit v1.2.3