updated registry::destroy for ranges
This commit is contained in:
3
TODO
3
TODO
@@ -17,9 +17,6 @@
|
||||
TODO
|
||||
* add and burst add with components (sort of registry.create<A, B>(first, last) and registry.create<A, B>())
|
||||
|
||||
TODO
|
||||
* update doc dispatcher (it's outdated) or rollback changes to add extra parameters (is that really useful at the end of the day?)
|
||||
|
||||
TODO
|
||||
* events on replace, so that one can track updated components? indagate impact
|
||||
* define basic reactive systems (track entities to which component is attached, track entities from which component is removed, and so on)
|
||||
|
||||
@@ -139,15 +139,14 @@ auto entity = registry.create();
|
||||
registry.destroy(entity);
|
||||
```
|
||||
|
||||
There exists another overload of the `create` member function that accepts two
|
||||
iterators, that is a range to assign. It can be used to create multiple entities
|
||||
at once.<br/>
|
||||
Entities can also be destroyed _by type_, that is by specifying the types of the
|
||||
components that identify them:
|
||||
There exist also overloads of the `create` and `destroy` member functions that
|
||||
accept two iterators, that is a range to assign or to destroy. It can be used to
|
||||
create or destroy multiple entities at once:
|
||||
|
||||
```cpp
|
||||
// destroys the entities that own the given components, if any
|
||||
registry.destroy<a_component, another_component>();
|
||||
// destroys all the entities in a range
|
||||
auto view = registry.view<a_component, another_component>();
|
||||
registry.destroy(view.begin(), view.end());
|
||||
```
|
||||
|
||||
When an entity is destroyed, the registry can freely reuse it internally with a
|
||||
|
||||
@@ -561,24 +561,16 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroys the entities that own the given components, if any.
|
||||
*
|
||||
* Convenient shortcut to destroy a set of entities at once.<br/>
|
||||
* Syntactic sugar for the following snippet:
|
||||
*
|
||||
* @code{.cpp}
|
||||
* for(const auto entity: registry.view<Component...>()) {
|
||||
* registry.destroy(entity);
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @tparam Component Types of components to use to search for the entities.
|
||||
* @brief Destroys all the entities in a range.
|
||||
* @tparam It Type of forward 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... Component>
|
||||
void destroy() {
|
||||
for(const auto entity: view<Component...>()) {
|
||||
template<typename It>
|
||||
void destroy(It first, It last) {
|
||||
std::for_each(first, last, [this](const auto entity) {
|
||||
destroy(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -874,19 +874,28 @@ TEST(Registry, DestroyByComponents) {
|
||||
ASSERT_TRUE(registry.valid(e1));
|
||||
ASSERT_TRUE(registry.valid(e2));
|
||||
|
||||
registry.destroy<int, char, double>();
|
||||
{
|
||||
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));
|
||||
|
||||
registry.destroy<int, char>();
|
||||
{
|
||||
const auto view = registry.view<int, char>();
|
||||
registry.destroy(view.begin(), view.end());
|
||||
}
|
||||
|
||||
ASSERT_FALSE(registry.valid(e0));
|
||||
ASSERT_FALSE(registry.valid(e1));
|
||||
ASSERT_TRUE(registry.valid(e2));
|
||||
|
||||
registry.destroy<int>();
|
||||
{
|
||||
const auto view = registry.view<int>();
|
||||
registry.destroy(view.begin(), view.end());
|
||||
}
|
||||
|
||||
ASSERT_FALSE(registry.valid(e0));
|
||||
ASSERT_FALSE(registry.valid(e1));
|
||||
|
||||
Reference in New Issue
Block a user