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

Isolate component registration #17671

Merged

Conversation

ElliottjPierce
Copy link
Contributor

Objective

Progresses #17569. The end goal here is to synchronize component registration. See the other PR for details for the motivation behind that.

For this PR specifically, the objective is to decouple Components from Storages. What components are registered etc should have nothing to do with what Storages looks like. Storages should only care about what entity archetypes have been spawned.

Solution

Previously, this was used to create sparse sets for relevant components when those components were registered. Now, we do that when the component is inserted/spawned.

This PR proposes doing that in BundleInfo::new, but there may be a better place.

Testing

In theory, this shouldn't have changed any functionality, so no new tests were created. I'm not aware of any examples that make heavy use of sparse set components either.

Migration Guide

  • Remove storages from functions where it is no longer needed.
  • Note that SparseSets are no longer present for all registered sparse set components, only those that have been spawned.

Copy link
Contributor

@SpecificProtagonist SpecificProtagonist left a comment

Choose a reason for hiding this comment

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

Makes sense to me, and the unsafe code is still sound (as far as I can tell).

Note that SparseSets are no longer present for all registered sparse set components, only those that have been spawned.

Maybe also add a comment to that effect on Storages.sparse_sets?

crates/bevy_ecs/src/query/fetch.rs Show resolved Hide resolved
crates/bevy_ecs/src/query/fetch.rs Show resolved Hide resolved
crates/bevy_ecs/src/query/filter.rs Show resolved Hide resolved
crates/bevy_ecs/src/query/filter.rs Show resolved Hide resolved
crates/bevy_ecs/src/world/entity_ref.rs Outdated Show resolved Hide resolved
crates/bevy_ecs/src/world/entity_ref.rs Outdated Show resolved Hide resolved
@ElliottjPierce
Copy link
Contributor Author

Maybe also add a comment to that effect on Storages.sparse_sets?

Done! Thanks @SpecificProtagonist for the review and suggestions.

Github doesn't run fmt or course for commits from a review.
Copy link
Contributor

@chescock chescock 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! Thanks for pulling this out of the larger PR!

crates/bevy_ecs/src/bundle.rs Outdated Show resolved Hide resolved
crates/bevy_ecs/src/query/fetch.rs Show resolved Hide resolved
@chescock chescock added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Feb 4, 2025
crates/bevy_ecs/src/bundle.rs Outdated Show resolved Hide resolved
@alice-i-cecile
Copy link
Member

Good stuff; I think this is a worthwhile cleanup regardless of the final design choice.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 5, 2025
Merged via the queue into bevyengine:main with commit 1b2cf7d Feb 5, 2025
28 checks passed
@ElliottjPierce ElliottjPierce deleted the isolate-component-registration branch February 5, 2025 20:16
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-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants