Addresses of removed components should be reused

This commit is contained in:
NukeBird 2025-02-15 00:36:15 +03:00
parent 84b132f853
commit 6737ffb2eb

View file

@ -129,3 +129,42 @@ TEST_CASE("Remove a component from an entity and verify it is no longer attached
REQUIRE_FALSE(w.has<ChoosenOne>(e)); REQUIRE_FALSE(w.has<ChoosenOne>(e));
} }
TEST_CASE("Addresses of removed components should be reused")
{
world w;
std::vector<entity> entities;
std::vector<ChoosenOne*> 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<ChoosenOne>();
}
if(addr.empty())
{
for(int j = 0; j < N; ++j)
{
addr.emplace_back(&entities[j].get<ChoosenOne>());
}
}
else
{
for(int j = 0; j < N; ++j)
{
REQUIRE(&entities[j].get<ChoosenOne>() == addr[j]);
}
}
for(auto e: entities)
{
e.remove<ChoosenOne>();
}
entities.clear();
}
}