summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-06-08 04:31:26 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-06-08 05:00:37 +0200
commit0b1e606551926d5058e920b9ab62bffbf2d6b9fc (patch)
treef8df37a12fa4747642ff5646aeb8423c69762579
parent221f0db1a89b1f3f16ed96da44540edfb219826a (diff)
tests: improve collision/rtree test
-rw-r--r--test/collisions.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/test/collisions.cpp b/test/collisions.cpp
index 958676d0..5a535a44 100644
--- a/test/collisions.cpp
+++ b/test/collisions.cpp
@@ -26,21 +26,27 @@ 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<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);
+ 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);
- C->teleport_to(index, point{{2, 2, 0}, {}, {0, 0}}, rotation::N);
+ 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;
}
@@ -49,7 +55,10 @@ 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<critter>(w.make_id(), pos, make_critter_proto());
fm_assert(C->offset == Vector2b{});
@@ -58,16 +67,24 @@ void test2()
auto index = C->index();
bool moved = false;
c.ensure_passability();
- for (int i = 0; i < tile_size_xy*2; i++)
+ for (int i = 0; i < 60*2; i++)
{
- auto dt = Ns{Seconds / 60};
- auto result = C->move_toward(index, dt, {{-10, 0, 0}, {}, {}});
+ 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());
- fm_assert(c.rtree()->Count() < 2);
+
+ 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