Compare commits

..

2 commits

Author SHA1 Message Date
72f635400a 📦More tests for archetypes📦 2025-02-20 02:55:04 +03:00
bcd5a8135d 📦Remove empty archetypes📦 2025-02-20 02:54:40 +03:00
2 changed files with 39 additions and 4 deletions

View file

@ -473,12 +473,40 @@ TEST_CASE("Archetype signature management")
// Initial state: empty archetype
REQUIRE(w.archetype_count() == 0);
auto e = w.make_entity();
REQUIRE(w.archetype_count() == 1);
auto e0 = w.make_entity();
REQUIRE(w.archetype_count() == 1); //<>
// Add first component
w.set<A>(e);
REQUIRE(w.archetype_count() == 1);
w.set<A>(e0);
REQUIRE(w.archetype_count() == 1); //<A>
w.set<B>(e0);
REQUIRE(w.archetype_count() == 1); //<A, B>
w.set<C>(e0);
REQUIRE(w.archetype_count() == 1); //<A, B, C>
w.remove<A, B>(e0);
REQUIRE(w.archetype_count() == 1); //<C>
auto e1 = w.make_entity();
w.set<A, B>(e1);
REQUIRE(w.archetype_count() == 2); //<C>, <A, B>
w.remove<C>(e0);
REQUIRE(w.archetype_count() == 2); //<>, <A, B>
w.set<A>(e0);
REQUIRE(w.archetype_count() == 2); //<A>, <A, B>
w.set<B>(e0);
REQUIRE(w.archetype_count() == 1); //<A, B>
w.destroy_entity(e0);
REQUIRE(w.archetype_count() == 1); //<A, B>
w.destroy_entity(e1);
REQUIRE(w.archetype_count() == 0);
}
TEST_CASE("Component distribution across archetypes")
@ -499,11 +527,13 @@ TEST_CASE("Component distribution across archetypes")
auto e = w.make_entity();
w.set<A>(e);
}
for(int i = 0; i < 3; ++i)
{
auto e = w.make_entity();
w.set<A, B>(e);
}
for(int i = 0; i < 2; ++i)
{
auto e = w.make_entity();

View file

@ -319,6 +319,11 @@ namespace zecsy
archetypes[new_key].emplace_back(e);
if(archetypes[old_key].empty())
{
archetypes.erase(old_key);
}
auto& pool = pools[id];
auto index = pool.entity_to_index[e];
pool.free_list.push_back(index);