diff --git a/docs/md/entity.md b/docs/md/entity.md index 52f354fa9..f27bfebb9 100644 --- a/docs/md/entity.md +++ b/docs/md/entity.md @@ -186,13 +186,13 @@ registry.destroy(entity); 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 -`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: ```cpp // destroys all the entities in a range auto view = registry.view(); -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 @@ -236,8 +236,8 @@ vel.dx = 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 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 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 .
+the `stomp` member functions and a couple of overloads of the `create` member +function for the `registry` class .
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 local copies). On the other hand, the overloads of the `create` member function diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index a9431c164..c75a2cb92 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -650,7 +650,7 @@ public: create(first, last); if constexpr(sizeof...(Component) == 0) { - stomp_each(first, last, src, other, exclude); + stomp(first, last, src, other, exclude); } else { static_assert(sizeof...(Exclude) == 0); (assure()->batch(*this, first, last, other.get(src)), ...); @@ -703,7 +703,7 @@ public: * @param last An iterator past the last element of the range to destroy. */ template - void destroy_each(It first, It last) { + void destroy(It first, It last) { // useless this-> used to suppress a warning with clang 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. */ template - auto assign_each(It first, It last, Args &&... args) { + std::enable_if_t, std::reverse_iterator::iterator_type>> + assign(It first, It last, Args &&... args) { ENTT_ASSERT(std::all_of(first, last, [this](const auto entity) { return valid(entity); })); return std::make_reverse_iterator(assure()->batch(*this, first, last, std::forward(args)...) + std::distance(first, last)); } @@ -1639,7 +1640,7 @@ public: template void stomp(const entity_type dst, const entity_type src, const basic_registry &other, exclude_t = {}) { const entity_type entt[1]{dst}; - stomp_each(std::begin(entt), std::end(entt), src, other, exclude); + stomp(std::begin(entt), std::end(entt), src, other, exclude); } /** @@ -1656,7 +1657,7 @@ public: * @param other The registry that owns the source entity. */ template - void stomp_each(It first, It last, const entity_type src, const basic_registry &other, exclude_t = {}) { + void stomp(It first, It last, const entity_type src, const basic_registry &other, exclude_t = {}) { static_assert(sizeof...(Component) == 0 || sizeof...(Exclude) == 0); for(auto pos = other.pools.size(); pos; --pos) { diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index 2fdf2f020..51912bb70 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -1046,7 +1046,7 @@ TEST(Registry, RangeDestroy) { { const auto view = registry.view(); - registry.destroy_each(view.begin(), view.end()); + registry.destroy(view.begin(), view.end()); } ASSERT_FALSE(registry.valid(e0)); @@ -1055,7 +1055,7 @@ TEST(Registry, RangeDestroy) { { const auto view = registry.view(); - registry.destroy_each(view.begin(), view.end()); + registry.destroy(view.begin(), view.end()); } ASSERT_FALSE(registry.valid(e0)); @@ -1084,7 +1084,7 @@ TEST(Registry, RangeAssign) { ASSERT_FALSE(registry.has(e2)); const auto view = registry.view(); - auto it = registry.assign_each(view.begin(), view.end()); + auto it = registry.assign(view.begin(), view.end()); ASSERT_TRUE(registry.has(e0)); ASSERT_TRUE(registry.has(e1)); @@ -1571,7 +1571,7 @@ TEST(Registry, StompMulti) { entt::entity entities[2]; registry.create(std::begin(entities), std::end(entities)); - registry.stomp_each(std::begin(entities), std::end(entities), prototype, registry); + registry.stomp(std::begin(entities), std::end(entities), prototype, registry); ASSERT_TRUE((registry.has(entities[0]))); ASSERT_TRUE((registry.has(entities[1]))); @@ -1588,7 +1588,7 @@ TEST(Registry, StompExcludeMulti) { entt::entity entities[2]; registry.create(std::begin(entities), std::end(entities)); - registry.stomp_each(std::begin(entities), std::end(entities), prototype, registry, entt::exclude); + registry.stomp(std::begin(entities), std::end(entities), prototype, registry, entt::exclude); ASSERT_TRUE((registry.has(entities[0]))); ASSERT_TRUE((registry.has(entities[1])));