bevy
bevy copied to clipboard
Run fixed time-step in an exclusive system
Objective
- Allow combining fixed time-steps with run criteria.
- Lets us yeet looping run criteria in the future.
Solution
SubSchedule-- a schedule that does not necessarily run along with the main schedule.- Gets stored in a public resource, and then extracted and run in an exclusive system.
- Useful not just for fixed time-steps -- they could be used to invoke a collection of systems as a sort of callback, at any time. Example:
OnEnterorOnExitfor states. - Analogous to the system sets on #4391 -- only
SubScheduleis worse since it's split into stages.- Eventually this API should be fully replaced in stageless. The primary motivation of this API is to ease migration.
Changelog
todo
Migration Guide
Before:
App::new()
.add_system_set(
SystemSet::new()
.with_run_criteria(FixedTimestep::step(1.0 / 60.0))
.with_system(my_system),
);
After:
App::new()
.add_fixed_schedule(
FixedTimestep::step(1.0 / 60.0),
SystemStage::single_threaded().with_system(my_system),
);
More complex schedules:
#[derive(ScheduleLabel)]
struct FixedUpdate;
#[derive(StageLabel)]
struct FixedStage {
A,
B,
}
App::new()
.add_fixed_schedule_to_stage(
CoreStage::PreUpdate,
FixedTimestep::steps_per_second(60.0).with_label(FixedUpdate),
Schedule::default()
.with_stage(FixedStage::A, SystemStage::parallel())
.with_stage(FixedStage::B, SystemStage::parallel()),
)
.sub_schedule(FixedUpdate, |s: &mut Schedule| {
s.add_system_to_stage(FixedStage::A, foo);
s.add_system_to_stage(FixedStage::B, bar);
});
Notes
This PR adds thiserror as a direct dependency for bevy_app, but it was already in the dependency tree.