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

Query Joins #11535

Merged
merged 21 commits into from
Mar 11, 2024
Merged

Query Joins #11535

merged 21 commits into from
Mar 11, 2024

Conversation

hymm
Copy link
Contributor

@hymm hymm commented Jan 26, 2024

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
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
crates/bevy_ecs/src/query/state.rs Outdated Show resolved Hide resolved
crates/bevy_ecs/src/query/state.rs Outdated Show resolved Hide resolved
world: &World,
other: &QueryState<OtherD, OtherF>,
) -> QueryState<NewD, NewF> {
let mut component_access = FilteredAccess::default();
Copy link
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
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
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

crates/bevy_ecs/src/query/state.rs Outdated Show resolved Hide resolved
crates/bevy_ecs/src/query/state.rs Outdated Show resolved Hide resolved

QueryState {
world_id: self.world_id,
archetype_generation: self.archetype_generation,
Copy link
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
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
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.

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

crates/bevy_ecs/src/query/state.rs Show resolved Hide 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
Copy link
Member

@alice-i-cecile alice-i-cecile 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 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-Needs-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
27 checks passed
@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-Needs-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
Status: Merged PR
Development

Successfully merging this pull request may close these issues.

Tools for joining Query objects
4 participants