Refactor and speed up transform propagation and hierarchies further #380
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
#377 refactored collider hierarchy logic and extracted it into a
ColliderHierarchyPlugin<C: ScalableCollider>
, along with significantly speeding upColliderTransform
propagation using aColliderAncestor
marker component to ignore trees that don't have colliders.However, a similar marker component approach can also be used to speed up the many copies of transform propagation that the engine has. By limiting the propagation runs to physics entities, we could drastically reduce the overhead for scenes with lots of non-physics entities, further addressing #356.
Solution
ColliderHierarchyPlugin
into anAncestorMarkerPlugin<C: Component>
that adds anAncestorMarker<C>
component for all ancestors of entities with the given componentC
. The logic was also refactored to be more robust and fix some edge cases and fully support hierarchy changes, along with adding more tests.SyncPlugin
to mark rigid body ancestors.sync.rs
above the propagation systems to see how this works.ColliderBackendPlugin
now adds a general, automatically managedColliderMarker
component for all colliders, which allows filtering collider entities without knowing the collider type. This lets us get rid of the generics onColliderHierarchyPlugin
!PrepareSet
to account for some changes and to be more logical.Results
Test scene: 12 substeps, 1 root entity, 100,000 child entities. All entities have just a
SpatialBundle
, and one child entity also has aCollider
.Of course, this scene is not very representative of an actual game scene, but it does show just how much of an impact the transform propagation was having. A lot of games (probably most of them) do have many more non-physics entities than physics entities, and the overhead added by the marker components and new checks should be very minimal in comparison.
Migration Guide
Some
PrepareSet
system sets have changed order.Before:
PreInit
PropagateTransforms
InitRigidBodies
InitMassProperties
InitColliders
InitTransforms
Finalize
After:
PreInit
InitRigidBodies
InitColliders
PropagateTransforms
InitMassProperties
InitTransforms
Finalize
Additionally, the
ColliderHierarchyPlugin
added in #377 no longer needs generics. The plugin is new anyway however, so this isn't really a breaking change.