sparse_set: ::clear honors the modality of the set

This commit is contained in:
Michele Caini
2021-08-19 17:36:16 +02:00
parent 7fd1858db0
commit cf9522bd3b
4 changed files with 21 additions and 8 deletions

1
TODO
View File

@@ -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), ...

View File

@@ -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:

View File

@@ -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);

View File

@@ -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});