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

Add Has query parameter #3088

Closed
alice-i-cecile opened this issue Nov 9, 2021 · 4 comments
Closed

Add Has query parameter #3088

alice-i-cecile opened this issue Nov 9, 2021 · 4 comments
Assignees
Labels
A-ECS Entities, components, systems, and events C-Enhancement A new feature

Comments

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Nov 9, 2021

What problem does this solve or what need does it fill?

A common pattern is to use Option<&C> query parameters, then check if it's .is_some.

Unfortunately, this is slightly more verbose than needed (and the intent is less clear). More critically, it pointlessly locks the resource to a higher permissions level than needed.

What solution would you like?

Add a Has<C: Component> query parameter, which returns true if the entity has the particular component. This does not require any read permissions, as components cannot be changed during the execution of a parallel stage.

What alternative(s) have you considered?

Use the existing strategy.

Additional context

Idea blatantly borrowed from @Ralith's HECS, where it is called Satisfies, and can also be used to check whether an entity matches a given query. We don't need that particular bit of functionality: if anything, a simple Query::contains(entity) method would work well (but should be a seperate PR). See #3089 for that issue.

A Not query parameter, used for this and query filters, might be helpful for clarity but is not essential.

@alice-i-cecile alice-i-cecile added C-Enhancement A new feature A-ECS Entities, components, systems, and events labels Nov 9, 2021
@TheRawMeatball TheRawMeatball self-assigned this Nov 9, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 9, 2021

Option<With<T>> and then calling .is_some() is the same behaviour as Has<T> isnt it?

@alice-i-cecile
Copy link
Member Author

alice-i-cecile commented Nov 9, 2021

Option<With> and then calling .is_some() is the same behaviour as Has isnt it?

Yes, but the intent to the reader is dramatically less clear. I don't think I've ever seen With<T> being used in a non-filtering position (and had to verify that this in fact works).

@MinerSebas
Copy link
Contributor

Another "problem" with Option<With<T>> is, that the Some(false) will never occur, because either the Entity has it (Some(true)) or it doesn't (None). #2665 (comment)

@alice-i-cecile
Copy link
Member Author

Closing this out; I don't think it's useful enough to be worth expanding the API.

If we can only have one, I think it needs to be With because of the symmetry with Without. Has and DoesNotHave is a no-go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Enhancement A new feature
Projects
None yet
Development

No branches or pull requests

4 participants