Skip to content

Commit

Permalink
doc: update the give me everything section (close #1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Jul 27, 2023
1 parent 1a8a86c commit 5cca818
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions docs/md/entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -2105,28 +2105,27 @@ The same concepts apply to groups as well.
Views and groups are narrow windows on the entire list of entities. They work by
filtering entities according to their components.<br/>
In some cases there may be the need to iterate all the entities still in use
regardless of their components. The registry offers a specific member function
to do that:
regardless of their components. This is done by accessing entity storage:

```cpp
registry.each([](auto entity) {
for(auto entity: registry.view<entt::entity>()) {
// ...
});
}
```

As a rule of thumb, consider using a view or a group if the goal is to iterate
entities that have a determinate set of components. These tools are usually much
faster than combining the `each` function with a bunch of custom tests.<br/>
faster than filtering entities with a bunch of custom tests.<br/>
In all the other cases, this is the way to go. For example, it's possible to
combine `each` with the `orphan` member function to clean up orphan entities
combine this view with the `orphan` member function to clean up orphan entities
(that is, entities that are still in use and have no assigned components):

```cpp
registry.each([&registry](auto entity) {
for(auto entity: registry.view<entt::entity>()) {
if(registry.orphan(entity)) {
registry.release(entity);
}
});
}
```

In general, iterating all entities can result in poor performance. It should not
Expand Down

0 comments on commit 5cca818

Please sign in to comment.