entt
entt copied to clipboard
Get a view of components with a certain trait
As the title suggest, is there anyway to get a view with different types of components, but that they match a certain compile time predicate?
For example, lets say I have a trait IsEnergy
template <typename T>
struct IsEnergy : public std::false_type{};
template <>
struct IsEnergy<A> : public std::true_type{};
template <>
struct IsEnergy<B> : public std::true_type{};
Is there anyway I can get all the entities that have components A or B?
is there anyway to get a view with different types of components, but that they match a certain compile time predicate?
No, there isn't.
Is there anyway I can get all the entities that have components A or B?
The simplest solution is to redesign your component and turn the template parameter into a member, so as to have a single type to filter later on.
Another option is that of using listeners for IsEnergy<T> pools that fill a storage<void> pool somewhere else with the entities of interest. Then you can use the latter to construct your view.
You can also refine the last approach with a mixin to make it transparent/automatic. All mixins receive the registry after all and they know when an element is emplaced or erased, so 🤷♂️ the sigh mixin is an example to take inspiration from eventually.
I assume this was answered. Feel free to continue the discussion here if this isn't the case. Thanks.