As-needed change detection#17629
Closed
SpecificProtagonist wants to merge 10 commits intobevyengine:mainfrom
Closed
As-needed change detection#17629SpecificProtagonist wants to merge 10 commits intobevyengine:mainfrom
SpecificProtagonist wants to merge 10 commits intobevyengine:mainfrom
Conversation
Member
I would prefer this flavor of design: the "nice" name should be the one returned by default. |
Contributor
Author
|
I'll need to do some experimenting on how to avoid API duplication and then split this into multiple PRs. Closing for now :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Make change detection optional in a runtime-configurable way.
See #4882.
For prior art, also see #6659, which statically determined whether query items would be change-detection-enabled based on the type of the component.
Solution
Querying for
&mut Tnow gives you aMut<T>(newly introduced type) instead of aRefMut<T>(previously calledMut). This still writes change ticks, but doesn't let you read them. Resources are unchanged.By default, change detection is disabled for all components. It can be manually enabled via
World::enable_change_detection::<T>(). Using a query with aRef<T>,Mut<T>,Added<T>orChanged<T>term also enables change detection forTif not yet enabled, but prints a warning if entities with this component exist (as their change ticks were missed).Updating change ticks via
MutMarkChangesdoes not branch: When change detection forTis disabled, they're instead written to a dummy sink.This PR doesn't turn change ticks into components of their own, which can happen in a followup if desired.
Many methods that previously worked with
Mut/MutUntypednow have both a version with and without read access to change ticks (this is responsible for much of the line count; if you review this PR, going commit by commit helps). There's likely some opportunity for deduplication there, but I wanted to go with the simple solution for the initial PR.This design should be easy to expand to coarse-grained (per-table) ticks, but doesn't make multi-level or equality based change detection easier.
Status
This is in draft. I haven't pushed quite all the changes described above, but because of several ecs changes that have been merged since, it will be easier to recreate the changes than to rebase them.
Most of the diff (and growth in line count) is because many
_mutmethods have been split into a_mutand_mut_with_ticksvariant. Can and should we prevent this duplication by making them generic over this – e.g. instead ofget_mut<T: Component<Mutability = Mutable>>(…andget_mut_with_ticks<T: Component<Mutability = Mutable>>(…we would haveget_mut<T: Component<Mutability = Mutable>, const TICKS: bool>(?Besides this, there is more important work to do:
SystemRegistry), bad edge cases, or unwieldiness?Testing
(todo)
Showcase
Migration Guide
(todo)