entt
entt copied to clipboard
View on all entities except some with specific component
Hi, It there a way to grap all entities that do not have some component like:
registry.view(exclude<someComponent>) ?
At the moment, you can only iterate all entities (registry::each) and if them explicitly.
However, what you're asking for is on the roadmap. This is the final interface fyi:
auto view = registry.view<void>(entt::exclude<T, U>);
Great to know. From a performance perspective, is it more efficient to create a BaseComponent to all entity and query it with my exclude, or the each + if on any_of ?
If you create a base component and exlude it, it doesn't mean that all derived classes are also excluded as a consequence. I guess this answers your question.
I meaned a struct BaseComponent that ensure that every entities have one (each time i create an entiti, I add this BaseComponent to it)
then, I can:
auto view = Registry.view<BaseComponent>(exclude<ComponentToExclue>);
I would use this BaseComponent as a workaround to get a view to all my entities
Oh, sorry, didn't get it. Then I would go with the BaseComponent since it will be easier to update later on (just replace BaseComponent with void and you're done).
Great. BTW, that lead to a feature request : is there any way to get a signal on a new entity creation (and destruction) as we have with components instance:
It would be useful for my case of course, but I also use the hierarchy pattern you suggested. So during an entity destruction, i would like to ensure that the destroyed entity is get rid off any hierarchy
The answer is exactly the same: the plan is to put all entities in their own storage. Then on_construct<void> is the answer.
Available upstream on the wip branch. The way it works is:
for(auto entt: registry.view<entt::entity>(entt::exclude<T>)) { ... }
Signals on entity construction/deletion are also available as in:
registry.on_construct<entt::entity>().connect<&my_func>();
Available on master. :+1:
I've just noticed that the size() of this kind of view is not available:
auto myview = registry.viewentt::entity();
myview.size() returns the total number of entities
auto myview = registry.viewentt::entity(entt::exclude<MyComponent>);
myview.size() -> ERROR : size() not a member of ...
Is there any workaround ?
size_hint @christopheseyler it tells you the maximum number of elements returned by the view.
It's not guaranteed to return exactly N elements but it never returns more than them.