Просмотр исходного кода

storage: make the entity storage perform a full clear rather than a fake one (still viable via erase)

skypjack 3 лет назад
Родитель
Сommit
b7d8e01867

+ 1 - 0
TODO

@@ -20,6 +20,7 @@ TODO (high prio):
 * doc: exclude only views, storage entity, bump entities
 * deprecate/remove registry reserve, capacity, empty, data, destroyed, release and so on
 * test exclude-only views
+* drop fast_compact, make clear do clear for real :)
 
 WIP:
 * get rid of observers, storage based views made them pointless - document alternatives

+ 2 - 1
src/entt/entity/registry.hpp

@@ -1114,7 +1114,8 @@ public:
                 pools.begin()[pos - 1u].second->clear();
             }
 
-            entities.clear();
+            auto iterable = entities.each();
+            entities.erase(iterable.begin().base(), iterable.end().base());
         } else {
             (assure<Type>().clear(), ...);
         }

+ 2 - 3
src/entt/entity/storage.hpp

@@ -958,9 +958,8 @@ protected:
 
     /*! @brief Erases all entities of a sparse set. */
     void pop_all() override {
-        for(; length; --length) {
-            base_type::bump(local_traits_type::next(base_type::operator[](length - 1u)));
-        }
+        length = 0u;
+        base_type::pop_all();
     }
 
     /**

+ 3 - 8
test/entt/entity/sigh_mixin.cpp

@@ -504,14 +504,11 @@ TEST(SighMixin, StorageEntity) {
 
     pool.clear();
 
-    ASSERT_TRUE(pool.contains(traits_type::construct(0, 3)));
-    ASSERT_TRUE(pool.contains(traits_type::construct(1, 1)));
-    ASSERT_TRUE(pool.contains(traits_type::construct(2, 2)));
+    ASSERT_EQ(pool.size(), 0u);
+    ASSERT_EQ(pool.in_use(), 0u);
 
     ASSERT_EQ(on_construct.value, 3);
     ASSERT_EQ(on_destroy.value, 3);
-    ASSERT_EQ(pool.size(), 3u);
-    ASSERT_EQ(pool.in_use(), 0u);
 
     pool.spawn();
     pool.spawn(entt::entity{0});
@@ -526,9 +523,7 @@ TEST(SighMixin, StorageEntity) {
 
     pool.clear();
 
-    ASSERT_EQ(on_construct.value, 6);
-    ASSERT_EQ(on_destroy.value, 6);
-    ASSERT_EQ(pool.size(), 3u);
+    ASSERT_EQ(pool.size(), 0u);
     ASSERT_EQ(pool.in_use(), 0u);
 }
 

+ 4 - 8
test/entt/entity/storage_entity.cpp

@@ -104,12 +104,10 @@ TEST(StorageEntity, Move) {
 
     other.clear();
 
-    ASSERT_EQ(other.size(), 2u);
+    ASSERT_EQ(other.size(), 0u);
     ASSERT_EQ(other.in_use(), 0u);
 
-    ASSERT_EQ(*other.push(entt::null), traits_type::construct(1, 1));
     ASSERT_EQ(*other.push(entt::null), entt::entity{0});
-    ASSERT_EQ(*other.push(entt::null), entt::entity{2});
 }
 
 TEST(StorageEntity, Swap) {
@@ -142,14 +140,12 @@ TEST(StorageEntity, Swap) {
     pool.clear();
     other.clear();
 
-    ASSERT_EQ(pool.size(), 3u);
-    ASSERT_EQ(other.size(), 2u);
+    ASSERT_EQ(pool.size(), 0u);
+    ASSERT_EQ(other.size(), 0u);
     ASSERT_EQ(pool.in_use(), 0u);
     ASSERT_EQ(other.in_use(), 0u);
 
-    ASSERT_EQ(*other.push(entt::null), traits_type::construct(1, 1));
     ASSERT_EQ(*other.push(entt::null), entt::entity{0});
-    ASSERT_EQ(*other.push(entt::null), entt::entity{2});
 }
 
 TEST(StorageEntity, Push) {
@@ -444,6 +440,6 @@ TEST(StorageEntity, CustomAllocator) {
 
     pool.clear();
 
-    ASSERT_EQ(pool.size(), 2u);
+    ASSERT_EQ(pool.size(), 0u);
     ASSERT_EQ(pool.in_use(), 0u);
 }