Skip to content

Query Joins - #11535

Merged
alice-i-cecile merged 21 commits into
bevyengine:mainfrom
hymm:query-join
Mar 11, 2024
Merged

alice-i-cecile merged 21 commits into
bevyengine:mainfrom
hymm:query-join

Conversation

@hymm

@hymm hymm commented Jan 26, 2024 •

Copy link
Copy Markdown
Contributor

Objective

Solution

  • Use a similar method to query transmute, but take the intersection of matched archetypes between the 2 queries and the union of the accesses to create the new underlying QueryState.

Changelog

  • Add query joins

@Kanabenki Kanabenki added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events labels Jan 26, 2024
@alice-i-cecile

Copy link
Copy Markdown
Member

This counts as fixing #1658. We can make more detailed issues for more complex and specific needs as they arise.

@alice-i-cecile alice-i-cecile added the D-Complex Quite challenging from either a design or technical perspective. Ask for help! label Jan 27, 2024
Comment thread crates/bevy_ecs/src/system/query.rs Resolved
Comment thread crates/bevy_ecs/src/system/query.rs Resolved
Comment thread crates/bevy_ecs/src/system/query.rs Resolved
Comment thread crates/bevy_ecs/src/system/query.rs Resolved
Comment thread crates/bevy_ecs/src/query/state.rs Resolved
Comment thread crates/bevy_ecs/src/query/state.rs Resolved
world: &World,
other: &QueryState<OtherD, OtherF>,
) -> QueryState<NewD, NewF> {
let mut component_access = FilteredAccess::default();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not necessary in this PR, but pre-allocating here might be a good idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, I think there should be a way for this method and transmutes to reuse an existing query state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

wrote up an issue for this here #12271

Comment thread crates/bevy_ecs/src/query/state.rs Resolved
Comment thread crates/bevy_ecs/src/query/state.rs Resolved

QueryState {
world_id: self.world_id,
archetype_generation: self.archetype_generation,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We may need to validate that our archetype generation here is identical to that of both the World and the other query.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a warning for when the queries don't have matching id's. I didn't make it a panic as there shouldn't be any safety issues with it and there are probably some niche cases that it would still be valid to do this with mismatching.

I didn't do this for the world. First because it's not available here, but also it's not really valid to call update_archetypes on a QueryState generated from joins or transmutes.

@hymm hymm added this to the 0.14 milestone Mar 4, 2024

@james7132 james7132 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me! Not the biggest fan of hiding QueryState construction, but this is definitely cheaper than calling QueryState::new with the intersection.

Comment thread crates/bevy_ecs/src/query/state.rs Resolved
@james7132
james7132 requested a review from alice-i-cecile March 5, 2024 04:36
@hymm
hymm force-pushed the query-join branch 2 times, most recently from f21bc09 to 2c0c481 Compare March 10, 2024 00:01

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm happy with this. I'd like to see more user-facing docs about how to use this (probably an example), but I'll punt that to a new issue.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it M-Release-Note Work that should be called out in the blog due to impact labels Mar 11, 2024
@alice-i-cecile
alice-i-cecile added this pull request to the merge queue Mar 11, 2024
Merged via the queue into bevyengine:main with commit 9cd3165 Mar 11, 2024
@hymm
hymm deleted the query-join branch August 12, 2024 03:30
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 D-Complex Quite challenging from either a design or technical perspective. Ask for help! M-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

No open projects
Status: Merged PR

Development

Successfully merging this pull request may close these issues.

Tools for joining Query objects

4 participants