-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Split EntityClonerBuilder
in AllowAll
and DenyAll
variants
#19649
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
Draft
urben1680
wants to merge
26
commits into
bevyengine:main
Choose a base branch
from
urben1680:EntityClonerBuilder-split
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,171
−516
Conversation
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
Labels
A-ECS
Entities, components, systems, and events
C-Feature
A new feature, making something new possible
S-Waiting-on-Author
The author needs to make changes or address concerns before this can be merged
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
Further tests after #19326 showed that configuring
EntityCloner
with required components is bug prone and the current design has several weaknesses in it's API:EntityClonerBuilder::allow
andEntityClonerBuilder::deny
requires extra care how to support that which has an impact on surrounding code that has to keep edge cases in mind. This is especially true for attempts to fix the following issues. There is no use-case known (to me) why someone would mix those.EntityClonerBuilder::allow_all
configuration tries to support required components likeEntityClonerBuilder::deny_all
does, but the meaning of that is conflicting with how you'd expect things to work:A
, do you also want to exclude required components ofA
too? Or are these also valid withoutA
at the target entity?EntityClonerBuilder::allow_all
should ignore required components and not add them to be filtered away, which purpose hasEntityClonerBuilder::without_required_components
for this cloner?A
also denies required components ofA
even whenA
does not exist at the source entityA
also allows required components ofA
even whenA
does not exist at the source entityallow_if_new
filters to the cloner faces the same issues and require a common solution to dealing with source-archetype sensitive cloningAlternative to #19632 and #19635.
Solution
EntityClonerBuilder
is made generic and split intoEntityClonerBuilder<AllowAll>
andEntityClonerBuilder<DenyAll>
EntityBuilder::build
has been split up inbuild_allow_all
andbuild_deny_all
AllowAll
only offersdeny
filtersDenyAll
only offersallow
filtersDenyAll
considers required components and can opt out of them viawithout_required_components
allow_if_new
filter toDenyAll
variant_by_bundle_id
for bothEntityWorldMut
andEntityCommands
that exposeEntityClonerBuilder
are split up tooAlgorithm
The generic of
EntityClonerBuilder
contains the filter data that is needed to build and clone the entity components.As the filter needs to be borrowed mutably for the duration of the clone, the borrow checker forced me to separate the filter value and all other fields in
EntityCloner
. The latter are not in theEntityClonerConfig
struct. This caused many changed LOC.To make reviewing easier:
(TODO, point to interesting parts)
AllowAll
This is trivial, just a
ComponentId
set containing the components not to clone. This variant simplified compared to how it is in main since it does not regard required components.DenyAll
This is the new complexity, reviewers should focus on this struct and it's methods. I put in effort to explaining how it works, might be a bit too excessive for internal code?
Todo
deny_all
benchmarks