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

Improve system schedules #584

Merged
merged 10 commits into from
Sep 20, 2024
55 changes: 33 additions & 22 deletions src/plugin/plugin.rs
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -99,38 +99,46 @@ where
match set {
PhysicsSet::SyncBackend => (
// Run the character controller before the manual transform propagation.
systems::update_character_controls,
systems::update_character_controls.in_set(PhysicsSet::SyncBackend),
// Run Bevy transform propagation additionally to sync [`GlobalTransform`]
(
bevy::transform::systems::sync_simple_transforms,
bevy::transform::systems::propagate_transforms,
)
.chain()
.in_set(RapierTransformPropagateSet),
systems::on_add_entity_with_parent,
systems::on_change_world,
systems::sync_removals,
#[cfg(all(feature = "dim3", feature = "async-collider"))]
systems::init_async_scene_colliders,
#[cfg(all(feature = "dim3", feature = "async-collider"))]
systems::init_async_colliders,
systems::init_rigid_bodies,
systems::init_colliders,
systems::init_joints,
systems::apply_scale,
systems::apply_collider_user_changes,
systems::apply_rigid_body_user_changes,
systems::apply_joint_user_changes,
systems::apply_initial_rigid_body_impulses,
(
systems::on_add_entity_with_parent,
systems::on_change_world,
systems::sync_removals,
#[cfg(all(feature = "dim3", feature = "async-collider"))]
systems::init_async_scene_colliders,
#[cfg(all(feature = "dim3", feature = "async-collider"))]
systems::init_async_colliders,
systems::init_rigid_bodies,
systems::init_colliders,
systems::init_joints,
systems::apply_scale,
systems::apply_collider_user_changes,
systems::apply_rigid_body_user_changes,
systems::apply_joint_user_changes,
systems::apply_initial_rigid_body_impulses,
)
.chain()
.in_set(PhysicsSet::SyncBackend),
)
.chain()
.into_configs(),
PhysicsSet::StepSimulation => (systems::step_simulation::<PhysicsHooks>).into_configs(),
PhysicsSet::StepSimulation => (systems::step_simulation::<PhysicsHooks>)
.in_set(PhysicsSet::StepSimulation)
.into_configs(),
PhysicsSet::Writeback => (
systems::update_colliding_entities,
systems::writeback_rigid_bodies,
systems::writeback_mass_properties,
// Each writeback write to different properties.
systems::writeback_mass_properties.ambiguous_with(systems::writeback_rigid_bodies),
)
.in_set(PhysicsSet::Writeback)
.into_configs(),
}
}
Expand Down Expand Up @@ -244,14 +252,17 @@ where
.chain()
.before(TransformSystem::TransformPropagate),
);
app.configure_sets(
self.schedule,
RapierTransformPropagateSet.in_set(PhysicsSet::SyncBackend),
);

app.add_systems(
self.schedule,
(
Self::get_systems(PhysicsSet::SyncBackend).in_set(PhysicsSet::SyncBackend),
Self::get_systems(PhysicsSet::StepSimulation)
.in_set(PhysicsSet::StepSimulation),
Self::get_systems(PhysicsSet::Writeback).in_set(PhysicsSet::Writeback),
Self::get_systems(PhysicsSet::SyncBackend),
Self::get_systems(PhysicsSet::StepSimulation),
Self::get_systems(PhysicsSet::Writeback),
),
);
app.init_resource::<TimestepMode>();
Expand Down