Browse Source

mixin: rework pop_all to make it work without component traits

Michele Caini 2 years ago
parent
commit
af059b5e21
2 changed files with 5 additions and 43 deletions
  1. 5 5
      src/entt/entity/mixin.hpp
  2. 0 38
      test/entt/entity/sigh_mixin.cpp

+ 5 - 5
src/entt/entity/mixin.hpp

@@ -51,13 +51,13 @@ class sigh_mixin final: public Type {
 
 
     void pop_all() final {
     void pop_all() final {
         if(auto &reg = owner_or_assert(); !destruction.empty()) {
         if(auto &reg = owner_or_assert(); !destruction.empty()) {
-            for(auto pos = underlying_type::each().begin().base().index(); !(pos < 0); --pos) {
-                if constexpr(underlying_type::traits_type::in_place_delete) {
-                    if(const auto entt = underlying_type::operator[](static_cast<typename underlying_type::size_type>(pos)); entt != tombstone) {
+            for(auto it = underlying_type::base_type::begin(0), last = underlying_type::base_type::end(0); it != last; ++it) {
+                if constexpr(std::is_same_v<typename underlying_type::value_type, typename underlying_type::entity_type>) {
+                    destruction.publish(reg, *it);
+                } else {
+                    if(const auto entt = *it; !underlying_type::traits_type::in_place_delete || entt != tombstone) {
                         destruction.publish(reg, entt);
                         destruction.publish(reg, entt);
                     }
                     }
-                } else {
-                    destruction.publish(reg, underlying_type::operator[](static_cast<typename underlying_type::size_type>(pos)));
                 }
                 }
             }
             }
         }
         }

+ 0 - 38
test/entt/entity/sigh_mixin.cpp

@@ -33,15 +33,6 @@ void listener(counter &counter, Registry &, typename Registry::entity_type) {
 
 
 struct empty_each_tag final {};
 struct empty_each_tag final {};
 
 
-template<>
-struct entt::basic_storage<empty_each_tag, entt::entity, std::allocator<empty_each_tag>>: entt::basic_storage<void, entt::entity, std::allocator<void>> {
-    basic_storage(const std::allocator<empty_each_tag> &) {}
-
-    [[nodiscard]] iterable each() noexcept {
-        return {internal::extended_storage_iterator{base_type::end()}, internal::extended_storage_iterator{base_type::end()}};
-    }
-};
-
 TEST(SighMixin, GenericType) {
 TEST(SighMixin, GenericType) {
     entt::entity entity[2u]{entt::entity{3}, entt::entity{42}};
     entt::entity entity[2u]{entt::entity{3}, entt::entity{42}};
     entt::sigh_mixin<entt::storage<int>> pool;
     entt::sigh_mixin<entt::storage<int>> pool;
@@ -434,35 +425,6 @@ TEST(SighMixin, Swap) {
     ASSERT_EQ(on_destroy.value, 3);
     ASSERT_EQ(on_destroy.value, 3);
 }
 }
 
 
-TEST(SighMixin, EmptyEachStorage) {
-    entt::sigh_mixin<entt::storage<empty_each_tag>> pool;
-    entt::registry registry;
-
-    counter on_destroy{};
-
-    pool.bind(entt::forward_as_any(registry));
-    pool.on_destroy().connect<&listener<entt::registry>>(on_destroy);
-
-    ASSERT_TRUE(pool.empty());
-    ASSERT_EQ(on_destroy.value, 0);
-
-    pool.push(entt::entity{42});
-
-    ASSERT_FALSE(pool.empty());
-    ASSERT_EQ(on_destroy.value, 0);
-
-    ASSERT_NE(pool.begin(), pool.end());
-    ASSERT_EQ(pool.each().begin(), pool.each().end());
-    ASSERT_EQ(on_destroy.value, 0);
-
-    pool.clear();
-
-    ASSERT_EQ(pool.begin(), pool.end());
-    ASSERT_EQ(pool.each().begin(), pool.each().end());
-    // no signal at all because of the (fake) empty iterable
-    ASSERT_EQ(on_destroy.value, 0);
-}
-
 TEST(SighMixin, StorageEntity) {
 TEST(SighMixin, StorageEntity) {
     using traits_type = entt::entt_traits<entt::entity>;
     using traits_type = entt::entt_traits<entt::entity>;