Browse Source

registry: removed deprecated functions

Michele Caini 6 years ago
parent
commit
b5e411d251
2 changed files with 3 additions and 291 deletions
  1. 3 109
      src/entt/entity/registry.hpp
  2. 0 182
      test/entt/entity/registry.cpp

+ 3 - 109
src/entt/entity/registry.hpp

@@ -66,10 +66,10 @@ class basic_registry {
             return this->get(entt);
         }
 
-        template<typename It, typename... Value>
+        template<typename It, typename Value>
         std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, Entity>, void>
-        assign(basic_registry &owner, It first, It last, Value &&... value) {
-            this->construct(first, last, std::forward<Value>(value)...);
+        assign(basic_registry &owner, It first, It last, Value &&value) {
+            this->construct(first, last, std::forward<Value>(value));
 
             if(!construction.empty()) {
                 std::for_each(first, last, [this, &owner](const auto entt) { construction.publish(owner, entt); });
@@ -110,9 +110,7 @@ class basic_registry {
     struct pool_data {
         ENTT_ID_TYPE type_id{};
         std::unique_ptr<sparse_set<Entity>> pool{};
-        void(* assure)(basic_registry &, const sparse_set<Entity> &){};
         void(* remove)(sparse_set<Entity> &, basic_registry &, const Entity){};
-        void(* stamp)(basic_registry &, const Entity, const sparse_set<Entity> &, const Entity){};
     };
 
     template<typename...>
@@ -202,20 +200,6 @@ class basic_registry {
                 pdata.remove = [](sparse_set<entity_type> &cpool, basic_registry &owner, const entity_type entt) {
                     static_cast<pool_handler<Component> &>(cpool).remove(owner, entt);
                 };
-
-                if constexpr(std::is_copy_constructible_v<std::decay_t<Component>>) {
-                    pdata.assure = [](basic_registry &other, const sparse_set<entity_type> &cpool) {
-                        if constexpr(ENTT_ENABLE_ETO(Component)) {
-                            other.assure<Component>().assign(other, cpool.begin(), cpool.end());
-                        } else {
-                            other.assure<Component>().assign(other, cpool.begin(), cpool.end(), static_cast<const pool_handler<Component> &>(cpool).cbegin());
-                        }
-                    };
-
-                    pdata.stamp = [](basic_registry &other, const entity_type dst, const sparse_set<entity_type> &cpool, const entity_type src) {
-                        other.assign_or_replace<Component>(dst, static_cast<const pool_handler<Component> &>(cpool).get(src));
-                    };
-                }
             }
         }
 
@@ -1463,96 +1447,6 @@ public:
         return { std::move(selected) };
     }
 
-    /**
-     * @brief Returns a full or partial copy of a registry.
-     *
-     * The components must be copyable for obvious reasons. The entities
-     * maintain their versions once copied.<br/>
-     * If no components are provided, the registry will try to clone all the
-     * existing pools. The ones for non-copyable types won't be cloned.
-     *
-     * This feature supports exclusion lists. The excluded types have higher
-     * priority than those indicated for cloning. An excluded type will never be
-     * cloned.
-     *
-     * @note
-     * There isn't an efficient way to know if all the entities are assigned at
-     * least one component once copied. Therefore, there may be orphans. It is
-     * up to the caller to clean up the registry if necessary.
-     *
-     * @note
-     * Listeners and groups aren't copied. It is up to the caller to connect the
-     * listeners of interest to the new registry and to set up groups.
-     *
-     * @warning
-     * Attempting to clone components that aren't copyable results in unexpected
-     * behaviors.<br/>
-     * A static assertion will abort the compilation when the components
-     * provided aren't copy constructible. Otherwise, an assertion will abort
-     * the execution at runtime in debug mode in case one or more pools cannot
-     * be cloned.
-     *
-     * @tparam Component Types of components to clone.
-     * @tparam Exclude Types of components not to be cloned.
-     * @return A fresh copy of the registry.
-     */
-    template<typename... Component, typename... Exclude>
-    [[deprecated("use ::visit and custom (eventually erased) functions instead")]]
-    basic_registry clone(exclude_t<Exclude...> = {}) const {
-        basic_registry other;
-
-        other.destroyed = destroyed;
-        other.entities = entities;
-
-        std::for_each(pools.cbegin(), pools.cend(), [&other](auto &&pdata) {
-            if constexpr(sizeof...(Component) == 0) {
-                if(pdata.assure && ((pdata.type_id != type_info<Exclude>::id()) && ...)) {
-                    pdata.assure(other, *pdata.pool);
-                }
-            } else {
-                static_assert(sizeof...(Exclude) == 0 && std::conjunction_v<std::is_copy_constructible<Component>...>);
-                if(pdata.assure && ((pdata.type_id == type_info<Component>::id()) || ...)) {
-                    pdata.assure(other, *pdata.pool);
-                }
-            }
-        });
-
-        return other;
-    }
-
-    /**
-     * @brief Stamps an entity onto another entity.
-     *
-     * This function supports exclusion lists. An excluded type will never be
-     * copied.
-     *
-     * @warning
-     * Attempting to copy components that aren't copyable results in unexpected
-     * behaviors.<br/>
-     * An assertion will abort the execution at runtime in debug mode in case
-     * one or more types cannot be copied.
-     *
-     * @warning
-     * Attempting to use invalid entities results in undefined behavior.<br/>
-     * An assertion will abort the execution at runtime in debug mode in case of
-     * invalid entities.
-     *
-     * @tparam Exclude Types of components not to be copied.
-     * @param dst A valid entity identifier to copy to.
-     * @param other The registry that owns the source entity.
-     * @param src A valid entity identifier to be copied.
-     */
-    template<typename... Exclude>
-    [[deprecated("use ::visit and custom (eventually erased) functions instead")]]
-    void stamp(const entity_type dst, const basic_registry &other, const entity_type src, exclude_t<Exclude...> = {}) {
-        std::for_each(other.pools.cbegin(), other.pools.cend(), [this, dst, src](auto &&pdata) {
-            if(((pdata.type_id != type_info<Exclude>::id()) && ...) && pdata.pool->has(src)) {
-                ENTT_ASSERT(pdata.stamp);
-                pdata.stamp(*this, dst, *pdata.pool, src);
-            }
-        });
-    }
-
     /**
      * @brief Returns a temporary object to use to create snapshots.
      *

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

@@ -1297,188 +1297,6 @@ TEST(Registry, NonOwningGroupSortInterleaved) {
     });
 }
 
-TEST(Registry, Clone) {
-    entt::registry registry;
-    entt::registry other;
-
-    registry.destroy(registry.create());
-
-    const auto e0 = registry.create();
-    registry.assign<int>(e0, 0);
-    registry.assign<empty_type>(e0);
-
-    const auto e1 = registry.create();
-    registry.assign<int>(e1, 1);
-    registry.assign<char>(e1, '1');
-    registry.assign<empty_type>(e1);
-
-    const auto e2 = registry.create();
-    registry.assign<int>(e2, 2);
-    registry.assign<char>(e2, '2');
-
-    registry.destroy(e1);
-
-    ASSERT_EQ((other.group<int, char>().size()), entt::registry::size_type{0});
-
-    other = registry.clone<int, char, float>();
-
-    ASSERT_EQ((other.group<int, char>().size()), entt::registry::size_type{1});
-    ASSERT_EQ(other.size(), registry.size());
-    ASSERT_EQ(other.alive(), registry.alive());
-
-    ASSERT_TRUE(other.valid(e0));
-    ASSERT_FALSE(other.valid(e1));
-    ASSERT_TRUE(other.valid(e2));
-
-    ASSERT_TRUE((other.any<int, empty_type>(e0)));
-    ASSERT_FALSE((other.has<empty_type>(e0)));
-    ASSERT_TRUE((other.has<int, char>(e2)));
-
-    ASSERT_EQ(other.get<int>(e0), 0);
-    ASSERT_EQ(other.get<int>(e2), 2);
-    ASSERT_EQ(other.get<char>(e2), '2');
-
-    const auto e3 = other.create();
-
-    ASSERT_NE(e1, e3);
-    ASSERT_EQ(registry.entity(e1), registry.entity(e3));
-    ASSERT_EQ(other.entity(e1), other.entity(e3));
-
-    other.assign<int>(e3, 3);
-    other.assign<char>(e3, '3');
-
-    ASSERT_EQ((registry.group<int, char>().size()), entt::registry::size_type{1});
-    ASSERT_EQ((other.group<int, char>().size()), entt::registry::size_type{2});
-
-    other = registry.clone();
-
-    ASSERT_EQ(other.size(), registry.size());
-    ASSERT_EQ(other.alive(), registry.alive());
-
-    ASSERT_TRUE(other.valid(e0));
-    ASSERT_FALSE(other.valid(e1));
-    ASSERT_TRUE(other.valid(e2));
-    ASSERT_FALSE(other.valid(e3));
-
-    ASSERT_TRUE((other.has<int, empty_type>(e0)));
-    ASSERT_TRUE((other.has<int, char>(e2)));
-
-    ASSERT_EQ(other.get<int>(e0), 0);
-    ASSERT_TRUE(other.has<empty_type>(e0));
-    ASSERT_EQ(other.get<int>(e2), 2);
-    ASSERT_EQ(other.get<char>(e2), '2');
-
-    other = other.clone<char>();
-
-    ASSERT_EQ(other.size(), registry.size());
-    ASSERT_EQ(other.alive(), registry.alive());
-
-    ASSERT_TRUE(other.valid(e0));
-    ASSERT_FALSE(other.valid(e1));
-    ASSERT_TRUE(other.valid(e2));
-    ASSERT_FALSE(other.valid(e3));
-
-    ASSERT_FALSE((other.any<int, empty_type>(e0)));
-    ASSERT_FALSE((other.has<int>(e2)));
-    ASSERT_TRUE((other.has<char>(e2)));
-
-    ASSERT_TRUE(other.orphan(e0));
-    ASSERT_EQ(other.get<char>(e2), '2');
-
-    // the remove erased function must be available after cloning
-    other.clear();
-}
-
-TEST(Registry, CloneExclude) {
-    entt::registry registry;
-    entt::registry other;
-
-    const auto entity = registry.create();
-    registry.assign<int>(entity);
-    registry.assign<char>(entity);
-
-    other = registry.clone<int>();
-
-    ASSERT_TRUE(other.has(entity));
-    ASSERT_TRUE(other.has<int>(entity));
-    ASSERT_FALSE(other.has<char>(entity));
-
-    other = registry.clone(entt::exclude<int>);
-
-    ASSERT_TRUE(other.has(entity));
-    ASSERT_FALSE(other.has<int>(entity));
-    ASSERT_TRUE(other.has<char>(entity));
-
-    other = registry.clone(entt::exclude<int, char>);
-
-    ASSERT_TRUE(other.has(entity));
-    ASSERT_TRUE(other.orphan(entity));
-}
-
-TEST(Registry, CloneMoveOnlyComponent) {
-    entt::registry registry;
-    const auto entity = registry.create();
-
-    registry.assign<std::unique_ptr<int>>(entity);
-    registry.assign<char>(entity);
-
-    auto other = registry.clone();
-
-    ASSERT_TRUE(other.valid(entity));
-    ASSERT_TRUE(other.has<char>(entity));
-    ASSERT_FALSE(other.has<std::unique_ptr<int>>(entity));
-}
-
-TEST(Registry, Stamp) {
-    entt::registry registry;
-
-    const auto prototype = registry.create();
-    registry.assign<int>(prototype, 3);
-    registry.assign<char>(prototype, 'c');
-
-    auto entity = registry.create();
-    registry.stamp(entity, registry, prototype);
-
-    ASSERT_TRUE((registry.has<int, char>(entity)));
-    ASSERT_EQ(registry.get<int>(entity), 3);
-    ASSERT_EQ(registry.get<char>(entity), 'c');
-
-    registry.replace<int>(prototype, [](auto &instance) { instance = 42; });
-    registry.replace<char>(prototype, [](auto &instance) { instance = 'a'; });
-    registry.stamp(entity, registry, prototype);
-
-    ASSERT_EQ(registry.get<int>(entity), 42);
-    ASSERT_EQ(registry.get<char>(entity), 'a');
-}
-
-TEST(Registry, StampExclude) {
-    entt::registry registry;
-
-    const auto prototype = registry.create();
-    registry.assign<int>(prototype, 3);
-    registry.assign<char>(prototype, 'c');
-    registry.assign<empty_type>(prototype);
-
-    const auto entity = registry.create();
-    registry.stamp(entity, registry, prototype, entt::exclude<char>);
-
-    ASSERT_TRUE((registry.has<int, empty_type>(entity)));
-    ASSERT_FALSE(registry.has<char>(entity));
-    ASSERT_EQ(registry.get<int>(entity), 3);
-
-    registry.replace<int>(prototype, [](auto &instance) { instance = 42; });
-    registry.stamp(entity, registry, prototype, entt::exclude<int>);
-
-    ASSERT_TRUE((registry.has<int, char, empty_type>(entity)));
-    ASSERT_EQ(registry.get<int>(entity), 3);
-    ASSERT_EQ(registry.get<char>(entity), 'c');
-
-    registry.remove<int, char, empty_type>(entity);
-    registry.stamp(entity, registry, prototype, entt::exclude<int, char, empty_type>);
-
-    ASSERT_TRUE(registry.orphan(entity));
-}
-
 TEST(Registry, GetOrAssign) {
     entt::registry registry;
     const auto entity = registry.create();