فهرست منبع

no longer _each (it was too ugly for me)

Michele Caini 6 سال پیش
والد
کامیت
0dec05fd70
3فایلهای تغییر یافته به همراه17 افزوده شده و 16 حذف شده
  1. 6 6
      docs/md/entity.md
  2. 6 5
      src/entt/entity/registry.hpp
  3. 5 5
      test/entt/entity/registry.cpp

+ 6 - 6
docs/md/entity.md

@@ -186,13 +186,13 @@ registry.destroy(entity);
 
 
 The `create` member function has also an overload that accepts two iterators and
 The `create` member function has also an overload that accepts two iterators and
 can be used to generate multiple entities at once efficiently. Similarly, the
 can be used to generate multiple entities at once efficiently. Similarly, the
-`destroy_each` member function works with a range of entities and destroys them
+`destroy` member function works also with a range of entities and destroys them
 all:
 all:
 
 
 ```cpp
 ```cpp
 // destroys all the entities in a range
 // destroys all the entities in a range
 auto view = registry.view<a_component, another_component>();
 auto view = registry.view<a_component, another_component>();
-registry.destroy_each(view.begin(), view.end());
+registry.destroy(view.begin(), view.end());
 ```
 ```
 
 
 In both cases, the `create` member function accepts also a list of default
 In both cases, the `create` member function accepts also a list of default
@@ -236,8 +236,8 @@ vel.dx = 0.;
 vel.dy = 0.;
 vel.dy = 0.;
 ```
 ```
 
 
-Similarly, the `assign_each` member function template accepts two iterators,
-that is a range of entities to which to assign a component.
+This function is overloaded and can receive also a couple of iterators to be
+used to assign the same component to multiple entities at once.
 
 
 If an entity already has the given component, the `replace` member function
 If an entity already has the given component, the `replace` member function
 template can be used to replace it:
 template can be used to replace it:
@@ -689,8 +689,8 @@ applied to different containers.
 
 
 Once there are multiple registries available, however, one or more methods are
 Once there are multiple registries available, however, one or more methods are
 needed to transfer information from one container to another. This results in
 needed to transfer information from one container to another. This results in
-the `stomp` and `stomp_each` member functions, other than a couple of overloads
-of the `create` member function for the `registry` class .<br/>
+the `stomp` member functions and a couple of overloads of the `create` member
+function for the `registry` class .<br/>
 These functions allow to take one entity from a registry and use it to _stomp_
 These functions allow to take one entity from a registry and use it to _stomp_
 one or more entities in another registry (or even the same, actually making
 one or more entities in another registry (or even the same, actually making
 local copies). On the other hand, the overloads of the `create` member function
 local copies). On the other hand, the overloads of the `create` member function

+ 6 - 5
src/entt/entity/registry.hpp

@@ -650,7 +650,7 @@ public:
         create(first, last);
         create(first, last);
 
 
         if constexpr(sizeof...(Component) == 0) {
         if constexpr(sizeof...(Component) == 0) {
-            stomp_each<Component...>(first, last, src, other, exclude<Exclude...>);
+            stomp<Component...>(first, last, src, other, exclude<Exclude...>);
         } else {
         } else {
             static_assert(sizeof...(Exclude) == 0);
             static_assert(sizeof...(Exclude) == 0);
             (assure<Component>()->batch(*this, first, last, other.get<Component>(src)), ...);
             (assure<Component>()->batch(*this, first, last, other.get<Component>(src)), ...);
@@ -703,7 +703,7 @@ public:
      * @param last An iterator past the last element of the range to destroy.
      * @param last An iterator past the last element of the range to destroy.
      */
      */
     template<typename It>
     template<typename It>
-    void destroy_each(It first, It last) {
+    void destroy(It first, It last) {
         // useless this-> used to suppress a warning with clang
         // useless this-> used to suppress a warning with clang
         std::for_each(first, last, [this](const auto entity) { this->destroy(entity); });
         std::for_each(first, last, [this](const auto entity) { this->destroy(entity); });
     }
     }
@@ -748,7 +748,8 @@ public:
      * @return An iterator to the list of components just created.
      * @return An iterator to the list of components just created.
      */
      */
     template<typename Component, typename It, typename... Args>
     template<typename Component, typename It, typename... Args>
-    auto assign_each(It first, It last, Args &&... args) {
+    std::enable_if_t<!std::is_same_v<It, entity_type>, std::reverse_iterator<typename pool_type<Component>::iterator_type>>
+    assign(It first, It last, Args &&... args) {
         ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); }));
         ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); }));
         return std::make_reverse_iterator(assure<Component>()->batch(*this, first, last, std::forward<Args>(args)...) + std::distance(first, last));
         return std::make_reverse_iterator(assure<Component>()->batch(*this, first, last, std::forward<Args>(args)...) + std::distance(first, last));
     }
     }
@@ -1639,7 +1640,7 @@ public:
     template<typename... Component, typename... Exclude>
     template<typename... Component, typename... Exclude>
     void stomp(const entity_type dst, const entity_type src, const basic_registry &other, exclude_t<Exclude...> = {}) {
     void stomp(const entity_type dst, const entity_type src, const basic_registry &other, exclude_t<Exclude...> = {}) {
         const entity_type entt[1]{dst};
         const entity_type entt[1]{dst};
-        stomp_each<Component...>(std::begin(entt), std::end(entt), src, other, exclude<Exclude...>);
+        stomp<Component...>(std::begin(entt), std::end(entt), src, other, exclude<Exclude...>);
     }
     }
 
 
     /**
     /**
@@ -1656,7 +1657,7 @@ public:
      * @param other The registry that owns the source entity.
      * @param other The registry that owns the source entity.
      */
      */
     template<typename... Component, typename It, typename... Exclude>
     template<typename... Component, typename It, typename... Exclude>
-    void stomp_each(It first, It last, const entity_type src, const basic_registry &other, exclude_t<Exclude...> = {}) {
+    void stomp(It first, It last, const entity_type src, const basic_registry &other, exclude_t<Exclude...> = {}) {
         static_assert(sizeof...(Component) == 0 || sizeof...(Exclude) == 0);
         static_assert(sizeof...(Component) == 0 || sizeof...(Exclude) == 0);
 
 
         for(auto pos = other.pools.size(); pos; --pos) {
         for(auto pos = other.pools.size(); pos; --pos) {

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

@@ -1046,7 +1046,7 @@ TEST(Registry, RangeDestroy) {
 
 
     {
     {
         const auto view = registry.view<int, char>();
         const auto view = registry.view<int, char>();
-        registry.destroy_each(view.begin(), view.end());
+        registry.destroy(view.begin(), view.end());
     }
     }
 
 
     ASSERT_FALSE(registry.valid(e0));
     ASSERT_FALSE(registry.valid(e0));
@@ -1055,7 +1055,7 @@ TEST(Registry, RangeDestroy) {
 
 
     {
     {
         const auto view = registry.view<int>();
         const auto view = registry.view<int>();
-        registry.destroy_each(view.begin(), view.end());
+        registry.destroy(view.begin(), view.end());
     }
     }
 
 
     ASSERT_FALSE(registry.valid(e0));
     ASSERT_FALSE(registry.valid(e0));
@@ -1084,7 +1084,7 @@ TEST(Registry, RangeAssign) {
     ASSERT_FALSE(registry.has<float>(e2));
     ASSERT_FALSE(registry.has<float>(e2));
 
 
     const auto view = registry.view<int, char>();
     const auto view = registry.view<int, char>();
-    auto it = registry.assign_each<float>(view.begin(), view.end());
+    auto it = registry.assign<float>(view.begin(), view.end());
 
 
     ASSERT_TRUE(registry.has<float>(e0));
     ASSERT_TRUE(registry.has<float>(e0));
     ASSERT_TRUE(registry.has<float>(e1));
     ASSERT_TRUE(registry.has<float>(e1));
@@ -1571,7 +1571,7 @@ TEST(Registry, StompMulti) {
 
 
     entt::entity entities[2];
     entt::entity entities[2];
     registry.create(std::begin(entities), std::end(entities));
     registry.create(std::begin(entities), std::end(entities));
-    registry.stomp_each<int, char, double>(std::begin(entities), std::end(entities), prototype, registry);
+    registry.stomp<int, char, double>(std::begin(entities), std::end(entities), prototype, registry);
 
 
     ASSERT_TRUE((registry.has<int, char>(entities[0])));
     ASSERT_TRUE((registry.has<int, char>(entities[0])));
     ASSERT_TRUE((registry.has<int, char>(entities[1])));
     ASSERT_TRUE((registry.has<int, char>(entities[1])));
@@ -1588,7 +1588,7 @@ TEST(Registry, StompExcludeMulti) {
 
 
     entt::entity entities[2];
     entt::entity entities[2];
     registry.create(std::begin(entities), std::end(entities));
     registry.create(std::begin(entities), std::end(entities));
-    registry.stomp_each(std::begin(entities), std::end(entities), prototype, registry, entt::exclude<char>);
+    registry.stomp(std::begin(entities), std::end(entities), prototype, registry, entt::exclude<char>);
 
 
     ASSERT_TRUE((registry.has<int>(entities[0])));
     ASSERT_TRUE((registry.has<int>(entities[0])));
     ASSERT_TRUE((registry.has<int>(entities[1])));
     ASSERT_TRUE((registry.has<int>(entities[1])));