Selaa lähdekoodia

fixed range destroy - it's probably slightly slower now but it works also with views and groups (close #261)

Michele Caini 6 vuotta sitten
vanhempi
commit
c697e52c0c
2 muutettua tiedostoa jossa 4 lisäystä ja 29 poistoa
  1. 4 20
      src/entt/entity/registry.hpp
  2. 0 9
      test/entt/entity/registry.cpp

+ 4 - 20
src/entt/entity/registry.hpp

@@ -643,30 +643,14 @@ public:
 
     /**
      * @brief Destroys all the entities in a range.
-     * @tparam It Type of forward iterator.
+     * @tparam It Type of input iterator.
      * @param first An iterator to the first element of the range to generate.
      * @param last An iterator past the last element of the range to generate.
      */
     template<typename It>
     void destroy(It first, It last) {
-        ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); }));
-
-        for(auto pos = pools.size(); pos; --pos) {
-            if(auto &pdata = pools[pos-1]; pdata.pool) {
-                std::for_each(first, last, [&pdata, this](const auto entity) {
-                    if(pdata.pool->has(entity)) {
-                        pdata.remove(*this, entity);
-                    }
-                });
-            }
-        };
-
-        // just a way to protect users from listeners that attach components
-        ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return orphan(entity); }));
-
-        std::for_each(first, last, [this](const auto entity) {
-            release(entity);
-        });
+        // useless this-> used to suppress a warning with clang
+        std::for_each(first, last, [this](const auto entity) { this->destroy(entity); });
     }
 
     /**
@@ -1412,7 +1396,7 @@ public:
      * components.<br/>
      * This is particularly well suited to plugin systems and mods in general.
      *
-     * @tparam It Type of forward iterator.
+     * @tparam It Type of input iterator.
      * @param first An iterator to the first element of the range of components.
      * @param last An iterator past the last element of the range of components.
      * @return A newly created runtime view.

+ 0 - 9
test/entt/entity/registry.cpp

@@ -987,15 +987,6 @@ TEST(Registry, DestroyByComponents) {
     ASSERT_TRUE(registry.valid(e1));
     ASSERT_TRUE(registry.valid(e2));
 
-    {
-        const auto view = registry.view<int, char, double>();
-        registry.destroy(view.begin(), view.end());
-    }
-
-    ASSERT_FALSE(registry.valid(e0));
-    ASSERT_TRUE(registry.valid(e1));
-    ASSERT_TRUE(registry.valid(e2));
-
     {
         const auto view = registry.view<int, char>();
         registry.destroy(view.begin(), view.end());