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

entity/*: stop using deprecated functions internally

Michele Caini 6 лет назад
Родитель
Сommit
0f42827047

+ 0 - 1
TODO

@@ -20,7 +20,6 @@ Next:
 * replace observer class with observer functions
 * get(cmp, entity) -> void *, set(cmp, entity, void *)
 * review multi component views to reduce instantiations once empty types are gone...
-* avoid using deprecated functions all around
 * accept fixed type iterators like std::container<T> does rather than all possible types
 
 * WIP:

+ 1 - 1
src/entt/entity/actor.hpp

@@ -111,7 +111,7 @@ struct basic_actor {
      */
     template<typename Component, typename... Args>
     decltype(auto) assign(Args &&... args) {
-        return reg->template assign_or_replace<Component>(entt, std::forward<Args>(args)...);
+        return reg->template emplace_or_replace<Component>(entt, std::forward<Args>(args)...);
     }
 
     /**

+ 2 - 2
src/entt/entity/observer.hpp

@@ -180,7 +180,7 @@ class basic_observer {
         static void maybe_valid_if(basic_observer &obs, const basic_registry<Entity> &reg, const Entity entt) {
             if(reg.template has<Require...>(entt) && !reg.template any<Reject...>(entt)) {
                 if(auto *comp = obs.view.try_get(entt); !comp) {
-                    obs.view.construct(entt);
+                    obs.view.emplace(entt);
                 }
 
                 obs.view.get(entt) |= (1 << Index);
@@ -216,7 +216,7 @@ class basic_observer {
         static void maybe_valid_if(basic_observer &obs, const basic_registry<Entity> &reg, const Entity entt) {
             if(reg.template has<AllOf..., Require...>(entt) && !reg.template any<NoneOf..., Reject...>(entt)) {
                 if(auto *comp = obs.view.try_get(entt); !comp) {
-                    obs.view.construct(entt);
+                    obs.view.emplace(entt);
                 }
 
                 obs.view.get(entt) |= (1 << Index);

+ 7 - 7
src/entt/entity/registry.hpp

@@ -63,7 +63,7 @@ class basic_registry {
 
         template<typename... Args>
         decltype(auto) emplace(basic_registry &owner, const Entity entt, Args &&... args) {
-            this->construct(entt, std::forward<Args>(args)...);
+            storage<entity_type, Component>::emplace(entt, std::forward<Args>(args)...);
             construction.publish(owner, entt);
 
             if constexpr(!ENTT_IS_EMPTY(Component)) {
@@ -73,7 +73,7 @@ class basic_registry {
 
         template<typename It, typename Value>
         void insert(basic_registry &owner, It first, It last, Value &&value) {
-            this->construct(first, last, std::forward<Value>(value));
+            storage<entity_type, Component>::insert(first, last, std::forward<Value>(value));
 
             if(!construction.empty()) {
                 while(first != last) { construction.publish(owner, *(first++)); }
@@ -147,7 +147,7 @@ class basic_registry {
 
             if constexpr(sizeof...(Owned) == 0) {
                 if(is_valid && !current.has(entt)) {
-                    current.construct(entt);
+                    current.emplace(entt);
                 }
             } else {
                 if(is_valid && !(std::get<0>(cpools).index(entt) < current)) {
@@ -648,14 +648,14 @@ public:
      *
      * @sa emplace
      *
-     * @tparam Component Type of component to create.
      * @tparam It Type of input iterator.
+     * @tparam Component Type of component to create.
      * @param first An iterator to the first element of the range of entities.
      * @param last An iterator past the last element of the range of entities.
      * @param value An instance of the component to assign.
      */
     template<typename It, typename Component>
-    void insert(It first, It last, const Component &value = {}) {
+    void insert(It first, It last, const Component &value) {
         ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); }));
         assure<Component>().insert(*this, first, last, value);
     }
@@ -664,7 +664,7 @@ public:
     template<typename Component, typename It>
     [[deprecated("use ::insert instead")]]
     std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
-    assign(It first, It last, const Component &value = {}) {
+    assign(It first, It last, const Component &value) {
         return insert(std::move(first), std::move(last), value);
     }
 
@@ -1434,7 +1434,7 @@ public:
 
             if constexpr(sizeof...(Owned) == 0) {
                 for(const auto entity: view<Owned..., Get...>(entt::exclude<Exclude...>)) {
-                    handler->current.construct(entity);
+                    handler->current.emplace(entity);
                 }
             } else {
                 // we cannot iterate backwards because we want to leave behind valid entities in case of owned types

+ 4 - 4
src/entt/entity/snapshot.hpp

@@ -216,12 +216,12 @@ class basic_snapshot_loader {
             if constexpr(std::is_empty_v<Type>) {
                 archive(entt);
                 force(*reg, entt, discard);
-                reg->template assign<Type>(args..., entt);
+                reg->template emplace<Type>(args..., entt);
             } else {
                 Type instance{};
                 archive(entt, instance);
                 force(*reg, entt, discard);
-                reg->template assign<Type>(args..., entt, std::as_const(instance));
+                reg->template emplace<Type>(args..., entt, std::as_const(instance));
             }
         }
     }
@@ -433,13 +433,13 @@ class basic_continuous_loader {
             if constexpr(std::is_empty_v<Other>) {
                 archive(entt);
                 restore(entt);
-                reg->template assign_or_replace<Other>(map(entt));
+                reg->template emplace_or_replace<Other>(map(entt));
             } else {
                 Other instance{};
                 archive(entt, instance);
                 (update(instance, member), ...);
                 restore(entt);
-                reg->template assign_or_replace<Other>(map(entt), std::as_const(instance));
+                reg->template emplace_or_replace<Other>(map(entt), std::as_const(instance));
             }
         }
     }

+ 9 - 9
src/entt/entity/storage.hpp

@@ -324,7 +324,7 @@ public:
         }
 
         // entity goes after component in case constructor throws
-        underlying_type::construct(entt);
+        underlying_type::emplace(entt);
     }
 
     /*! @copydoc emplace */
@@ -350,17 +350,17 @@ public:
      * @param value An instance of the object to construct.
      */
     template<typename It>
-    void insert(It first, It last, const object_type &value = {}) {
+    void insert(It first, It last, const object_type &value) {
         instances.insert(instances.end(), std::distance(first, last), value);
         // entities go after components in case constructors throw
-        underlying_type::construct(first, last);
+        underlying_type::insert(first, last);
     }
 
     /*! @copydoc insert */
     template<typename It>
     [[deprecated("use ::insert instead")]]
     std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
-    construct(It first, It last, const object_type &value = {}) {
+    construct(It first, It last, const object_type &value) {
         insert(std::move(first), std::move(last), value);
     }
 
@@ -380,7 +380,7 @@ public:
     void insert(EIt first, EIt last, CIt value) {
         instances.insert(instances.end(), value, value + std::distance(first, last));
         // entities go after components in case constructors throw
-        underlying_type::construct(first, last);
+        underlying_type::insert(first, last);
     }
 
     /*! @copydoc insert */
@@ -533,7 +533,7 @@ public:
     template<typename... Args>
     void emplace(const entity_type entt, Args &&... args) {
         [[maybe_unused]] object_type instance{std::forward<Args>(args)...};
-        underlying_type::construct(entt);
+        underlying_type::emplace(entt);
     }
 
     /*! @copydoc emplace */
@@ -557,8 +557,8 @@ public:
      * @param last An iterator past the last element of the range of entities.
      */
     template<typename It>
-    void insert(It first, It last, const object_type & = {}) {
-        underlying_type::construct(first, last);
+    void insert(It first, It last, const object_type &) {
+        underlying_type::insert(first, last);
     }
 
     /**
@@ -568,7 +568,7 @@ public:
     template<typename It>
     [[deprecated("use ::insert instead")]]
     std::enable_if_t<std::is_same_v<typename std::iterator_traits<It>::value_type, entity_type>, void>
-    construct(It first, It last, const object_type &value = {}) {
+    construct(It first, It last, const object_type &value) {
         insert(std::move(first), std::move(last), value);
     }
 };

+ 2 - 2
test/benchmark/benchmark.cpp

@@ -115,8 +115,8 @@ TEST(Benchmark, ConstructManyWithComponents) {
 
     timer timer;
     registry.create(entities.begin(), entities.end());
-    registry.assign<position>(entities.begin(), entities.end());
-    registry.assign<velocity>(entities.begin(), entities.end());
+    registry.assign(entities.begin(), entities.end(), position{});
+    registry.assign(entities.begin(), entities.end(), velocity{});
     timer.elapsed();
 }
 

+ 3 - 3
test/entt/entity/registry.cpp

@@ -362,7 +362,7 @@ TEST(Registry, CreateManyEntitiesAtOnceWithListener) {
     registry.on_construct<empty_type>().connect<&listener::incr<empty_type>>(listener);
     registry.create(std::begin(entities), std::end(entities));
     registry.assign(std::begin(entities), std::end(entities), 'a');
-    registry.assign<empty_type>(std::begin(entities), std::end(entities));
+    registry.assign(std::begin(entities), std::end(entities), empty_type{});
 
     ASSERT_TRUE(registry.has<empty_type>(entities[0]));
     ASSERT_EQ(registry.get<char>(entities[2]), 'a');
@@ -815,8 +815,8 @@ TEST(Registry, NestedGroups) {
     entt::entity entities[10];
 
     registry.create(std::begin(entities), std::end(entities));
-    registry.assign<int>(std::begin(entities), std::end(entities));
-    registry.assign<char>(std::begin(entities), std::end(entities));
+    registry.assign(std::begin(entities), std::end(entities), int{});
+    registry.assign(std::begin(entities), std::end(entities), char{});
     const auto g1 = registry.group<int>(entt::get<char>, entt::exclude<double>);
 
     ASSERT_TRUE(g1.sortable());

+ 1 - 1
test/entt/entity/storage.cpp

@@ -111,7 +111,7 @@ TEST(Storage, BatchAddEmptyType) {
     entities[0] = entt::entity{3};
     entities[1] = entt::entity{42};
 
-    pool.construct(std::begin(entities), std::end(entities));
+    pool.construct(std::begin(entities), std::end(entities), {});
 
     ASSERT_TRUE(pool.has(entities[0]));
     ASSERT_TRUE(pool.has(entities[1]));