From 6737ffb2eb9f88b8f13c60f44b58a30ec7659df6 Mon Sep 17 00:00:00 2001 From: NukeBird Date: Sat, 15 Feb 2025 00:36:15 +0300 Subject: [PATCH] Addresses of removed components should be reused --- tests/zecsy.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/zecsy.cpp b/tests/zecsy.cpp index 5aa7360..9f654cb 100644 --- a/tests/zecsy.cpp +++ b/tests/zecsy.cpp @@ -129,3 +129,42 @@ TEST_CASE("Remove a component from an entity and verify it is no longer attached REQUIRE_FALSE(w.has(e)); } + +TEST_CASE("Addresses of removed components should be reused") +{ + world w; + std::vector entities; + std::vector addr; + + const int N = 4; + + for(int i = 0; i < 2; ++i) + { + for(int j = 0; j < N; ++j) + { + entities.emplace_back(w.make_entity()); + entities.back().set(); + } + + if(addr.empty()) + { + for(int j = 0; j < N; ++j) + { + addr.emplace_back(&entities[j].get()); + } + } + else + { + for(int j = 0; j < N; ++j) + { + REQUIRE(&entities[j].get() == addr[j]); + } + } + + for(auto e: entities) + { + e.remove(); + } + entities.clear(); + } +}