diff --git a/TODO b/TODO index ede3c824c..826d8beb7 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,7 @@ * custom pools example (multi instance, tables, enable/disable, and so on...) WIP: +* review pop_at/push_at to avoid multiple calls to page/offset * make sparse_set/storage adhere to AllocatorAwareContainer requirements * fast-contains for sparse sets (low prio but nice-to-have) * runtime components (registry), runtime events (dispatcher/emitter), ... diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index f30b4f11a..329d8f985 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -920,13 +920,9 @@ public: */ void clear(void *ud = nullptr) { for(auto &&entity: *this) { - if(entity != tombstone) { - in_place_pop(entity, ud); - } + // honor the modality and filter all tombstones + remove(entity, ud); } - - free_list = tombstone; - count = {}; } private: diff --git a/test/entt/entity/sparse_set.cpp b/test/entt/entity/sparse_set.cpp index 48cbd5d5d..924c91976 100644 --- a/test/entt/entity/sparse_set.cpp +++ b/test/entt/entity/sparse_set.cpp @@ -454,10 +454,14 @@ TEST(SparseSet, StableErase) { set.clear(); - ASSERT_EQ(set.size(), 0u); + ASSERT_EQ(set.size(), 1u); ASSERT_EQ(set.current(entities[2u]), traits_type::to_version(entt::tombstone)); ASSERT_EQ(set.slot(), 0u); + set.compact(); + + ASSERT_EQ(set.size(), 0u); + set.insert(std::begin(entities), std::end(entities)); set.erase(entities[2u]); @@ -645,10 +649,14 @@ TEST(SparseSet, StableRemove) { set.clear(); - ASSERT_EQ(set.size(), 0u); + ASSERT_EQ(set.size(), 1u); ASSERT_EQ(set.current(entities[2u]), traits_type::to_version(entt::tombstone)); ASSERT_EQ(set.slot(), 0u); + set.compact(); + + ASSERT_EQ(set.size(), 0u); + set.insert(std::begin(entities), std::end(entities)); ASSERT_EQ(set.remove(entities[2u]), 1u); diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index 0d150fb14..4ae44a915 100644 --- a/test/entt/entity/storage.cpp +++ b/test/entt/entity/storage.cpp @@ -306,6 +306,10 @@ TEST(Storage, StableErase) { pool.clear(); + ASSERT_EQ(pool.size(), 1u); + + pool.compact(); + ASSERT_EQ(pool.size(), 0u); pool.emplace(entities[0u], stable_type{0}); @@ -440,6 +444,10 @@ TEST(Storage, StableRemove) { pool.clear(); + ASSERT_EQ(pool.size(), 1u); + + pool.compact(); + ASSERT_EQ(pool.size(), 0u); pool.emplace(entities[0u], stable_type{0});