Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get a view of components with a certain trait #1144

Open
jjcasmar opened this issue May 11, 2024 · 1 comment
Open

Get a view of components with a certain trait #1144

jjcasmar opened this issue May 11, 2024 · 1 comment
Assignees
Labels
question open question

Comments

@jjcasmar
Copy link

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?

@skypjack skypjack self-assigned this May 13, 2024
@skypjack skypjack added the question open question label May 13, 2024
@skypjack
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question open question
Projects
None yet
Development

No branches or pull requests

2 participants