Skip to content

Component groups and get_many/get_many_mut for EntityRef/EntityMut. #11584

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

mintlu8
Copy link
Contributor

@mintlu8 mintlu8 commented Jan 28, 2024

Objective

Give a generic group of components similar functionality as if they were a single component. This is achieved with access to ergonomic filter queries and with get function support for EntityRef/EntityMut.

Use case:

trait SomeBehavior {
    type Read: ComponentGroup;
    type Modify: ComponentGroup;
    type Require: ComponentGroup;
    
    fn modify_behavior(
        write: &mut <Self::Modify as ComponentGroup>::WriteQuery, 
        read: &<Self::Read as ComponentGroup>::ReadQuery
    );
}

fn behavior_system<B: SomeBehavior>(query: Query<
    (Entity, <B::Read as ComponentGroup>::ReadQuery, <B::Modify as ComponentGroup>::WriteQuery), 
    (<B::Read as ComponentGroup>::Changed, <B::Require as ComponentGroup>::With),
>) {
     for (r, mut w) in query.iter() {
         SomeBehavior::modify_behavior(&mut w, r);
     }
}

Solution

Added trait ComponentGroup implemented on components and tuple Bundles. The trait has GATs that converts the tuple into queries, With queries, Has queries, Added queries, Changed queries, etc.

Or and its new counterpart And can now be used on the data side as boolean combinators to support this change.


Changelog

  • Added aforementioned ComponentGroup.
  • Added the capability of And and Or to function on the data side.
    And and Or can be used with filter-only queries on the data side. This currently causes no issue but do keep this in mind.
  • Since Changed and Added recently got removed from the data side due to their confusing nature, defined Is<T> = And<(T,)> as a way to use these queries on the data side.
  • Added primitives Always and Never as default cases for some queries.
  • Implemented get_many and get_many_mut on component groups.

Migration Guide

I don't think there is a breaking change here.

Added ComponentGroup that allow tuple of components to function similar to `Component` at the type level. Added data side support for `Or` and its counterpart `And`. Added `Is` that replaces the previous functionality of `Changed` and `Added` on the data side.
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events labels Jan 28, 2024
@mintlu8 mintlu8 marked this pull request as ready for review January 28, 2024 21:23
@mintlu8 mintlu8 changed the title Component Groups and data position boolean combinators. Component groups and data side boolean combinators. Jan 29, 2024
Copy link
Member

@james7132 james7132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing the clear benefit of having this when the QueryData and QueryFilter macros exist. They seem to do the same thing.

@mintlu8
Copy link
Contributor Author

mintlu8 commented Jan 30, 2024

I'm not seeing the clear benefit of having this when the QueryData and QueryFilter macros exist. They seem to do the same thing.

It is designed for generic type projection in traits, specifically for library authors, as shown in the example. The macros only work for specific components.

What this trait means is 'Any number of components that act as a single component'. The analogues to ComponentGroup in bevy right now are WorldQuery and Bundle, but none of them support type projection, and both of them have quirks that makes type projection an awkward fit to implement on them.

Edit: Updated PR to show more intent.

@mintlu8 mintlu8 changed the title Component groups and data side boolean combinators. Component groups and get_many/get_many_mut for EntityRef/EntityMut. Jan 31, 2024
@mintlu8
Copy link
Contributor Author

mintlu8 commented Jan 31, 2024

Edit: Added new major functionality of get_many/get_many_mut for EntityRef/EntityMut.

@alice-i-cecile alice-i-cecile added the X-Controversial There is active debate or serious implications around merging this PR label Feb 3, 2024
@janhohenheim
Copy link
Member

Triage: has merge conflicts
@mintlu8 do you want to update this PR or should I tag it S-Needs-Adoption? :)

@janhohenheim janhohenheim added the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label May 17, 2025
@mintlu8
Copy link
Contributor Author

mintlu8 commented May 18, 2025

Triage: has merge conflicts @mintlu8 do you want to update this PR or should I tag it S-Needs-Adoption? :)

This PR is designed with ideas before the QueryData/QueryFilter split. I'd imagine starting a new PR would be better. That being said categorizing it asS-Needs-Adoption is fine.

@janhohenheim janhohenheim added S-Nominated-To-Close A triage team member thinks this PR or issue should be closed out. and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels May 18, 2025
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-Feature A new feature, making something new possible S-Nominated-To-Close A triage team member thinks this PR or issue should be closed out. X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants