Skip to content

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
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

urben1680
Copy link
Contributor

@urben1680 urben1680 commented Jun 15, 2025

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:

  • Mixing EntityClonerBuilder::allow and EntityClonerBuilder::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.
  • A builder with EntityClonerBuilder::allow_all configuration tries to support required components like EntityClonerBuilder::deny_all does, but the meaning of that is conflicting with how you'd expect things to work:
    • If all components should be cloned except component A, do you also want to exclude required components of A too? Or are these also valid without A at the target entity?
    • If EntityClonerBuilder::allow_all should ignore required components and not add them to be filtered away, which purpose has EntityClonerBuilder::without_required_components for this cloner?
  • Other bugs found with the linked PR are:
    • Denying A also denies required components of A even when A does not exist at the source entity
    • Allowing A also allows required components of A even when A does not exist at the source entity
  • Adding allow_if_new filters to the cloner faces the same issues and require a common solution to dealing with source-archetype sensitive cloning

Alternative to #19632 and #19635.

Solution

EntityClonerBuilder is made generic and split into EntityClonerBuilder<AllowAll> and EntityClonerBuilder<DenyAll>

  • EntityBuilder::build has been split up in build_allow_all and build_deny_all
  • AllowAll only offers deny filters
  • DenyAll only offers allow filters
  • Only DenyAll considers required components and can opt out of them via without_required_components
  • Added allow_if_new filter to DenyAll variant
  • Added _by_bundle_id for both
  • Methods in the ecs, like EntityWorldMut and EntityCommands that expose EntityClonerBuilder are split up too

Algorithm

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 the EntityClonerConfig 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

  • Fix CI
  • Write deny_all benchmarks
  • Explain algorith in PR
  • Compare cloner benchmarks of main (except new one)
  • Document new methods, types and behaviors
  • Migration Guide
  • Add many tests and see if the three removed tests need to be replaced
  • work on remaining todos

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 15, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants