diff --git a/benches/benches/bevy_ecs/components/archetype_updates.rs b/benches/benches/bevy_ecs/components/archetype_updates.rs index 30f8ca6fccb97..ec7703a0b1d49 100644 --- a/benches/benches/bevy_ecs/components/archetype_updates.rs +++ b/benches/benches/bevy_ecs/components/archetype_updates.rs @@ -7,7 +7,7 @@ struct A(f32); fn setup(system_count: usize) -> (World, Schedule) { let mut world = World::new(); fn empty() {} - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); for _ in 0..system_count { schedule.add_systems(empty); } diff --git a/benches/benches/bevy_ecs/empty_archetypes.rs b/benches/benches/bevy_ecs/empty_archetypes.rs index 315a2d2ce2b68..d6521303f6fc0 100644 --- a/benches/benches/bevy_ecs/empty_archetypes.rs +++ b/benches/benches/bevy_ecs/empty_archetypes.rs @@ -77,7 +77,7 @@ fn par_for_each( fn setup(parallel: bool, setup: impl FnOnce(&mut Schedule)) -> (World, Schedule) { let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); if parallel { world.insert_resource(ComputeTaskPool(TaskPool::default())); } diff --git a/benches/benches/bevy_ecs/scheduling/run_condition.rs b/benches/benches/bevy_ecs/scheduling/run_condition.rs index a18bdd8c97f40..7f0100633d8f5 100644 --- a/benches/benches/bevy_ecs/scheduling/run_condition.rs +++ b/benches/benches/bevy_ecs/scheduling/run_condition.rs @@ -18,7 +18,7 @@ pub fn run_condition_yes(criterion: &mut Criterion) { group.measurement_time(std::time::Duration::from_secs(3)); fn empty() {} for amount in 0..21 { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems(empty.run_if(yes)); for _ in 0..amount { schedule.add_systems((empty, empty, empty, empty, empty).distributive_run_if(yes)); @@ -41,7 +41,7 @@ pub fn run_condition_no(criterion: &mut Criterion) { group.measurement_time(std::time::Duration::from_secs(3)); fn empty() {} for amount in 0..21 { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems(empty.run_if(no)); for _ in 0..amount { schedule.add_systems((empty, empty, empty, empty, empty).distributive_run_if(no)); @@ -71,7 +71,7 @@ pub fn run_condition_yes_with_query(criterion: &mut Criterion) { query.single().0 } for amount in 0..21 { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems(empty.run_if(yes_with_query)); for _ in 0..amount { schedule.add_systems( @@ -100,7 +100,7 @@ pub fn run_condition_yes_with_resource(criterion: &mut Criterion) { res.0 } for amount in 0..21 { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems(empty.run_if(yes_with_resource)); for _ in 0..amount { schedule.add_systems( diff --git a/benches/benches/bevy_ecs/scheduling/running_systems.rs b/benches/benches/bevy_ecs/scheduling/running_systems.rs index 151b96d4a6af4..00c5b3ec0ee27 100644 --- a/benches/benches/bevy_ecs/scheduling/running_systems.rs +++ b/benches/benches/bevy_ecs/scheduling/running_systems.rs @@ -21,7 +21,7 @@ pub fn empty_systems(criterion: &mut Criterion) { group.measurement_time(std::time::Duration::from_secs(3)); fn empty() {} for amount in 0..5 { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); for _ in 0..amount { schedule.add_systems(empty); } @@ -33,7 +33,7 @@ pub fn empty_systems(criterion: &mut Criterion) { }); } for amount in 1..21 { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); for _ in 0..amount { schedule.add_systems((empty, empty, empty, empty, empty)); } @@ -73,7 +73,7 @@ pub fn busy_systems(criterion: &mut Criterion) { world.spawn_batch((0..ENTITY_BUNCH).map(|_| (A(0.0), B(0.0), C(0.0), D(0.0)))); world.spawn_batch((0..ENTITY_BUNCH).map(|_| (A(0.0), B(0.0), C(0.0), E(0.0)))); for system_amount in 0..5 { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems((ab, cd, ce)); for _ in 0..system_amount { schedule.add_systems((ab, cd, ce)); @@ -124,7 +124,7 @@ pub fn contrived(criterion: &mut Criterion) { world.spawn_batch((0..ENTITY_BUNCH).map(|_| (A(0.0), B(0.0)))); world.spawn_batch((0..ENTITY_BUNCH).map(|_| (C(0.0), D(0.0)))); for system_amount in 0..5 { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems((s_0, s_1, s_2)); for _ in 0..system_amount { schedule.add_systems((s_0, s_1, s_2)); diff --git a/benches/benches/bevy_ecs/scheduling/schedule.rs b/benches/benches/bevy_ecs/scheduling/schedule.rs index e670c23d74b37..99f8b20f2bc05 100644 --- a/benches/benches/bevy_ecs/scheduling/schedule.rs +++ b/benches/benches/bevy_ecs/scheduling/schedule.rs @@ -46,7 +46,7 @@ pub fn schedule(c: &mut Criterion) { world.spawn_batch((0..10000).map(|_| (A(0.0), B(0.0), C(0.0), E(0.0)))); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems((ab, cd, ce)); schedule.run(&mut world); diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index eadbdaad13f29..426c045dce28e 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -384,9 +384,9 @@ impl App { if let Some(schedule) = schedules.get_mut(&schedule) { schedule.add_systems(systems); } else { - let mut new_schedule = Schedule::new(); + let mut new_schedule = Schedule::new(schedule); new_schedule.add_systems(systems); - schedules.insert(schedule, new_schedule); + schedules.insert(new_schedule); } self @@ -403,9 +403,9 @@ impl App { if let Some(schedule) = schedules.get_mut(&schedule) { schedule.configure_set(set); } else { - let mut new_schedule = Schedule::new(); + let mut new_schedule = Schedule::new(schedule); new_schedule.configure_set(set); - schedules.insert(schedule, new_schedule); + schedules.insert(new_schedule); } self } @@ -421,9 +421,9 @@ impl App { if let Some(schedule) = schedules.get_mut(&schedule) { schedule.configure_sets(sets); } else { - let mut new_schedule = Schedule::new(); + let mut new_schedule = Schedule::new(schedule); new_schedule.configure_sets(sets); - schedules.insert(schedule, new_schedule); + schedules.insert(new_schedule); } self } @@ -798,9 +798,9 @@ impl App { /// # Warning /// This method will overwrite any existing schedule at that label. /// To avoid this behavior, use the `init_schedule` method instead. - pub fn add_schedule(&mut self, label: impl ScheduleLabel, schedule: Schedule) -> &mut Self { + pub fn add_schedule(&mut self, schedule: Schedule) -> &mut Self { let mut schedules = self.world.resource_mut::(); - schedules.insert(label, schedule); + schedules.insert(schedule); self } @@ -811,7 +811,7 @@ impl App { pub fn init_schedule(&mut self, label: impl ScheduleLabel) -> &mut Self { let mut schedules = self.world.resource_mut::(); if !schedules.contains(&label) { - schedules.insert(label, Schedule::new()); + schedules.insert(Schedule::new(label)); } self } @@ -841,7 +841,7 @@ impl App { let mut schedules = self.world.resource_mut::(); if schedules.get(&label).is_none() { - schedules.insert(label.dyn_clone(), Schedule::new()); + schedules.insert(Schedule::new(label.dyn_clone())); } let schedule = schedules.get_mut(&label).unwrap(); diff --git a/crates/bevy_app/src/main_schedule.rs b/crates/bevy_app/src/main_schedule.rs index f72ac80fb00cc..004aba0a6fc0a 100644 --- a/crates/bevy_app/src/main_schedule.rs +++ b/crates/bevy_app/src/main_schedule.rs @@ -161,13 +161,13 @@ pub struct MainSchedulePlugin; impl Plugin for MainSchedulePlugin { fn build(&self, app: &mut App) { // simple "facilitator" schedules benefit from simpler single threaded scheduling - let mut main_schedule = Schedule::new(); + let mut main_schedule = Schedule::new(Main); main_schedule.set_executor_kind(ExecutorKind::SingleThreaded); - let mut fixed_update_loop_schedule = Schedule::new(); + let mut fixed_update_loop_schedule = Schedule::new(RunFixedUpdateLoop); fixed_update_loop_schedule.set_executor_kind(ExecutorKind::SingleThreaded); - app.add_schedule(Main, main_schedule) - .add_schedule(RunFixedUpdateLoop, fixed_update_loop_schedule) + app.add_schedule(main_schedule) + .add_schedule(fixed_update_loop_schedule) .init_resource::() .add_systems(Main, Main::run_main); } diff --git a/crates/bevy_ecs/src/change_detection.rs b/crates/bevy_ecs/src/change_detection.rs index ff5f9bf3958c1..a00a5cd6bb66b 100644 --- a/crates/bevy_ecs/src/change_detection.rs +++ b/crates/bevy_ecs/src/change_detection.rs @@ -149,7 +149,7 @@ pub trait DetectChangesMut: DetectChanges { /// # score_changed.initialize(&mut world); /// # score_changed.run((), &mut world); /// # - /// # let mut schedule = Schedule::new(); + /// # let mut schedule = Schedule::default(); /// # schedule.add_systems(reset_score); /// # /// # // first time `reset_score` runs, the score is changed. @@ -214,7 +214,7 @@ pub trait DetectChangesMut: DetectChanges { /// # score_changed_event.initialize(&mut world); /// # score_changed_event.run((), &mut world); /// # - /// # let mut schedule = Schedule::new(); + /// # let mut schedule = Schedule::default(); /// # schedule.add_systems(reset_score); /// # /// # // first time `reset_score` runs, the score is changed. diff --git a/crates/bevy_ecs/src/event.rs b/crates/bevy_ecs/src/event.rs index 25ae9ebb7275e..7f0887eb4cc90 100644 --- a/crates/bevy_ecs/src/event.rs +++ b/crates/bevy_ecs/src/event.rs @@ -1034,7 +1034,7 @@ mod tests { world.send_event(TestEvent { i: 3 }); world.send_event(TestEvent { i: 4 }); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems(|mut events: EventReader| { let mut iter = events.iter(); diff --git a/crates/bevy_ecs/src/query/mod.rs b/crates/bevy_ecs/src/query/mod.rs index 0c4106d189ff9..863122d90a8b6 100644 --- a/crates/bevy_ecs/src/query/mod.rs +++ b/crates/bevy_ecs/src/query/mod.rs @@ -789,7 +789,7 @@ mod tests { } } - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems((propagate_system, modify_system).chain()); schedule.run(&mut world); world.clear_trackers(); diff --git a/crates/bevy_ecs/src/schedule/condition.rs b/crates/bevy_ecs/src/schedule/condition.rs index 8186819ccdb63..f8ad50a5bbf71 100644 --- a/crates/bevy_ecs/src/schedule/condition.rs +++ b/crates/bevy_ecs/src/schedule/condition.rs @@ -26,7 +26,7 @@ pub type BoxedCondition = Box>; /// /// # #[derive(Resource)] struct DidRun(bool); /// # fn my_system(mut did_run: ResMut) { did_run.0 = true; } -/// # let mut schedule = Schedule::new(); +/// # let mut schedule = Schedule::default(); /// schedule.add_systems(my_system.run_if(every_other_time())); /// # let mut world = World::new(); /// # world.insert_resource(DidRun(false)); @@ -46,13 +46,13 @@ pub type BoxedCondition = Box>; /// } /// /// # fn always_true() -> bool { true } -/// # let mut schedule = Schedule::new(); +/// # let mut app = Schedule::default(); /// # #[derive(Resource)] struct DidRun(bool); /// # fn my_system(mut did_run: ResMut) { did_run.0 = true; } -/// schedule.add_systems(my_system.run_if(always_true.pipe(identity()))); +/// app.add_systems(my_system.run_if(always_true.pipe(identity()))); /// # let mut world = World::new(); /// # world.insert_resource(DidRun(false)); -/// # schedule.run(&mut world); +/// # app.run(&mut world); /// # assert!(world.resource::().0); pub trait Condition: sealed::Condition { /// Returns a new run condition that only returns `true` @@ -69,7 +69,7 @@ pub trait Condition: sealed::Condition { /// #[derive(Resource, PartialEq)] /// struct R(u32); /// - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # fn my_system() {} /// app.add_systems( @@ -86,7 +86,7 @@ pub trait Condition: sealed::Condition { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, PartialEq)] /// # struct R(u32); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # fn my_system() {} /// app.add_systems( @@ -123,7 +123,7 @@ pub trait Condition: sealed::Condition { /// #[derive(Resource, PartialEq)] /// struct B(u32); /// - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # #[derive(Resource)] struct C(bool); /// # fn my_system(mut c: ResMut) { c.0 = true; } @@ -197,7 +197,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// app.add_systems( @@ -238,7 +238,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// app.add_systems( /// // `resource_exists` will only return true if the given resource exists in the world @@ -277,7 +277,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default, PartialEq)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// app.add_systems( @@ -315,7 +315,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default, PartialEq)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// app.add_systems( /// // `resource_exists_and_equals` will only return true @@ -358,7 +358,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// app.add_systems( /// // `resource_added` will only return true if the @@ -408,7 +408,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// app.add_systems( @@ -462,7 +462,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// app.add_systems( /// // `resource_exists_and_changed` will only return true if the @@ -523,7 +523,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// app.add_systems( @@ -593,7 +593,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// app.add_systems( @@ -648,7 +648,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// #[derive(States, Clone, Copy, Default, Eq, PartialEq, Hash, Debug)] @@ -695,7 +695,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// #[derive(States, Clone, Copy, Default, Eq, PartialEq, Hash, Debug)] @@ -747,7 +747,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// #[derive(States, Clone, Copy, Default, Eq, PartialEq, Hash, Debug)] @@ -813,7 +813,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// #[derive(States, Clone, Copy, Default, Eq, PartialEq, Hash, Debug)] @@ -863,7 +863,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// # world.init_resource::>(); @@ -907,7 +907,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// app.add_systems( @@ -954,7 +954,7 @@ pub mod common_conditions { /// # use bevy_ecs::prelude::*; /// # #[derive(Resource, Default)] /// # struct Counter(u8); - /// # let mut app = Schedule::new(); + /// # let mut app = Schedule::default(); /// # let mut world = World::new(); /// # world.init_resource::(); /// app.add_systems( @@ -1084,7 +1084,7 @@ mod tests { fn run_condition() { let mut world = World::new(); world.init_resource::(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); // Run every other cycle schedule.add_systems(increment_counter.run_if(every_other_time)); @@ -1111,7 +1111,7 @@ mod tests { fn run_condition_combinators() { let mut world = World::new(); world.init_resource::(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); // Always run schedule.add_systems(increment_counter.run_if(every_other_time.or_else(|| true))); @@ -1128,7 +1128,7 @@ mod tests { fn multiple_run_conditions() { let mut world = World::new(); world.init_resource::(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); // Run every other cycle schedule.add_systems(increment_counter.run_if(every_other_time).run_if(|| true)); @@ -1146,7 +1146,7 @@ mod tests { let mut world = World::new(); world.init_resource::(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); // This should never run, if multiple run conditions worked // like an OR condition then it would always run diff --git a/crates/bevy_ecs/src/schedule/config.rs b/crates/bevy_ecs/src/schedule/config.rs index 9817feec6d4ca..5ef4428ecc948 100644 --- a/crates/bevy_ecs/src/schedule/config.rs +++ b/crates/bevy_ecs/src/schedule/config.rs @@ -225,7 +225,7 @@ where /// /// ``` /// # use bevy_ecs::prelude::*; - /// # let mut schedule = Schedule::new(); + /// # let mut schedule = Schedule::default(); /// # fn a() {} /// # fn b() {} /// # fn condition() -> bool { true } @@ -258,7 +258,7 @@ where /// /// ``` /// # use bevy_ecs::prelude::*; - /// # let mut schedule = Schedule::new(); + /// # let mut schedule = Schedule::default(); /// # fn a() {} /// # fn b() {} /// # fn condition() -> bool { true } diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index 1982ce03dae3d..faba4851e95c9 100644 --- a/crates/bevy_ecs/src/schedule/mod.rs +++ b/crates/bevy_ecs/src/schedule/mod.rs @@ -180,7 +180,7 @@ mod tests { #[test] fn add_systems_correct_order() { let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); world.init_resource::(); @@ -201,7 +201,7 @@ mod tests { #[test] fn add_systems_correct_order_nested() { let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); world.init_resource::(); @@ -528,14 +528,14 @@ mod tests { #[test] #[should_panic] fn dependency_loop() { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.configure_set(TestSet::X.after(TestSet::X)); } #[test] fn dependency_cycle() { let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.configure_set(TestSet::A.after(TestSet::B)); schedule.configure_set(TestSet::B.after(TestSet::A)); @@ -550,7 +550,7 @@ mod tests { fn bar() {} let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems((foo.after(bar), bar.after(foo))); let result = schedule.initialize(&mut world); @@ -563,14 +563,14 @@ mod tests { #[test] #[should_panic] fn hierarchy_loop() { - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.configure_set(TestSet::X.in_set(TestSet::X)); } #[test] fn hierarchy_cycle() { let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.configure_set(TestSet::A.in_set(TestSet::B)); schedule.configure_set(TestSet::B.in_set(TestSet::A)); @@ -586,7 +586,7 @@ mod tests { fn bar() {} let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); // Schedule `bar` to run after `foo`. schedule.add_systems((foo, bar.after(foo))); @@ -607,7 +607,7 @@ mod tests { )); // same goes for `ambiguous_with` - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems(foo); schedule.add_systems(bar.ambiguous_with(foo)); let result = schedule.initialize(&mut world); @@ -624,14 +624,14 @@ mod tests { #[should_panic] fn configure_system_type_set() { fn foo() {} - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.configure_set(foo.into_system_set()); } #[test] fn hierarchy_redundancy() { let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.set_build_settings(ScheduleBuildSettings { hierarchy_detection: LogLevel::Error, @@ -658,7 +658,7 @@ mod tests { #[test] fn cross_dependency() { let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); // Add `B` and give it both kinds of relationships with `A`. schedule.configure_set(TestSet::B.in_set(TestSet::A)); @@ -673,7 +673,7 @@ mod tests { #[test] fn sets_have_order_but_intersect() { let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); fn foo() {} @@ -704,7 +704,7 @@ mod tests { fn res_mut(_x: ResMut) {} let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.set_build_settings(ScheduleBuildSettings { ambiguity_detection: LogLevel::Error, diff --git a/crates/bevy_ecs/src/schedule/schedule.rs b/crates/bevy_ecs/src/schedule/schedule.rs index b45504b77998f..33d5c5647f936 100644 --- a/crates/bevy_ecs/src/schedule/schedule.rs +++ b/crates/bevy_ecs/src/schedule/schedule.rs @@ -41,8 +41,8 @@ impl Schedules { /// /// If the map already had an entry for `label`, `schedule` is inserted, /// and the old schedule is returned. Otherwise, `None` is returned. - pub fn insert(&mut self, label: impl ScheduleLabel, schedule: Schedule) -> Option { - let label = label.dyn_clone(); + pub fn insert(&mut self, schedule: Schedule) -> Option { + let label = schedule.name.dyn_clone(); self.inner.insert(label, schedule) } @@ -158,22 +158,31 @@ fn make_executor(kind: ExecutorKind) -> Box { /// } /// ``` pub struct Schedule { + name: BoxedScheduleLabel, graph: ScheduleGraph, executable: SystemSchedule, executor: Box, executor_initialized: bool, } +#[derive(ScheduleLabel, Hash, PartialEq, Eq, Debug, Clone)] +struct DefaultSchedule; + +/// Creates a schedule with a default label. Only use in situations where +/// where you don't care about the [`ScheduleLabel`]. Inserting a default schedule +/// into the world risks overwriting another schedule. For most situations you should use +/// [`Schedule::new`]. impl Default for Schedule { fn default() -> Self { - Self::new() + Self::new(DefaultSchedule) } } impl Schedule { /// Constructs an empty `Schedule`. - pub fn new() -> Self { + pub fn new(label: impl ScheduleLabel) -> Self { Self { + name: label.dyn_clone(), graph: ScheduleGraph::new(), executable: SystemSchedule::new(), executor: make_executor(ExecutorKind::default()), @@ -237,8 +246,12 @@ impl Schedule { /// Runs all systems in this schedule on the `world`, using its current execution strategy. pub fn run(&mut self, world: &mut World) { + #[cfg(feature = "trace")] + let _span = bevy_utils::tracing::info_span!("schedule", name = ?self.name).entered(); + world.check_change_ticks(); - self.initialize(world).unwrap_or_else(|e| panic!("{e}")); + self.initialize(world) + .unwrap_or_else(|e| panic!("Error when intializing schedule {:?}: {e}", self.name)); self.executor.run(&mut self.executable, world); } @@ -250,7 +263,7 @@ impl Schedule { if self.graph.changed { self.graph.initialize(world); self.graph - .update_schedule(&mut self.executable, world.components())?; + .update_schedule(&mut self.executable, world.components(), &self.name)?; self.graph.changed = false; self.executor_initialized = false; } @@ -882,13 +895,14 @@ impl ScheduleGraph { pub fn build_schedule( &mut self, components: &Components, + schedule_label: &BoxedScheduleLabel, ) -> Result { // check hierarchy for cycles self.hierarchy.topsort = self.topsort_graph(&self.hierarchy.graph, ReportCycles::Hierarchy)?; let hier_results = check_graph(&self.hierarchy.graph, &self.hierarchy.topsort); - self.optionally_check_hierarchy_conflicts(&hier_results.transitive_edges)?; + self.optionally_check_hierarchy_conflicts(&hier_results.transitive_edges, schedule_label)?; // remove redundant edges self.hierarchy.graph = hier_results.transitive_reduction; @@ -932,7 +946,7 @@ impl ScheduleGraph { // check for conflicts let conflicting_systems = self.get_conflicting_systems(&flat_results.disconnected, &ambiguous_with_flattened); - self.optionally_check_conflicts(&conflicting_systems, components)?; + self.optionally_check_conflicts(&conflicting_systems, components, schedule_label)?; self.conflicting_systems = conflicting_systems; // build the schedule @@ -1182,6 +1196,7 @@ impl ScheduleGraph { &mut self, schedule: &mut SystemSchedule, components: &Components, + schedule_label: &BoxedScheduleLabel, ) -> Result<(), ScheduleBuildError> { if !self.uninit.is_empty() { return Err(ScheduleBuildError::Uninitialized); @@ -1206,7 +1221,7 @@ impl ScheduleGraph { self.system_set_conditions[id.index()] = conditions; } - *schedule = self.build_schedule(components)?; + *schedule = self.build_schedule(components, schedule_label)?; // move systems into new schedule for &id in &schedule.system_ids { @@ -1297,6 +1312,7 @@ impl ScheduleGraph { fn optionally_check_hierarchy_conflicts( &self, transitive_edges: &[(NodeId, NodeId)], + schedule_label: &BoxedScheduleLabel, ) -> Result<(), ScheduleBuildError> { if self.settings.hierarchy_detection == LogLevel::Ignore || transitive_edges.is_empty() { return Ok(()); @@ -1306,7 +1322,10 @@ impl ScheduleGraph { match self.settings.hierarchy_detection { LogLevel::Ignore => unreachable!(), LogLevel::Warn => { - error!("{}", message); + error!( + "Schedule {schedule_label:?} has redundant edges:\n {}", + message + ); Ok(()) } LogLevel::Error => Err(ScheduleBuildError::HierarchyRedundancy(message)), @@ -1505,6 +1524,7 @@ impl ScheduleGraph { &self, conflicts: &[(NodeId, NodeId, Vec)], components: &Components, + schedule_label: &BoxedScheduleLabel, ) -> Result<(), ScheduleBuildError> { if self.settings.ambiguity_detection == LogLevel::Ignore || conflicts.is_empty() { return Ok(()); @@ -1514,7 +1534,7 @@ impl ScheduleGraph { match self.settings.ambiguity_detection { LogLevel::Ignore => Ok(()), LogLevel::Warn => { - warn!("{}", message); + warn!("Schedule {schedule_label:?} has ambiguities.\n{}", message); Ok(()) } LogLevel::Error => Err(ScheduleBuildError::Ambiguity(message)), @@ -1689,7 +1709,7 @@ mod tests { struct Set; let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.configure_set(Set.run_if(|| false)); schedule.add_systems( diff --git a/crates/bevy_ecs/src/schedule/set.rs b/crates/bevy_ecs/src/schedule/set.rs index 1277f4b54dc2b..bdbc16ff7d905 100644 --- a/crates/bevy_ecs/src/schedule/set.rs +++ b/crates/bevy_ecs/src/schedule/set.rs @@ -198,9 +198,9 @@ mod tests { let mut world = World::new(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::new(A); schedule.add_systems(|mut flag: ResMut| flag.0 = true); - world.add_schedule(schedule, A); + world.add_schedule(schedule); let boxed: Box = Box::new(A); diff --git a/crates/bevy_ecs/src/system/combinator.rs b/crates/bevy_ecs/src/system/combinator.rs index 13c2b7869303d..1d20927ef995b 100644 --- a/crates/bevy_ecs/src/system/combinator.rs +++ b/crates/bevy_ecs/src/system/combinator.rs @@ -50,7 +50,7 @@ use super::{ReadOnlySystem, System}; /// # let mut world = World::new(); /// # world.init_resource::(); /// # -/// # let mut app = Schedule::new(); +/// # let mut app = Schedule::default(); /// app.add_systems(my_system.run_if(Xor::new( /// IntoSystem::into_system(resource_equals(A(1))), /// IntoSystem::into_system(resource_equals(B(1))), diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index 3c404a551c97e..927b608cd35cb 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -596,9 +596,9 @@ impl<'w, 's> Commands<'w, 's> { /// # let mut world = World::new(); /// # world.init_resource::(); /// # -/// # let mut setup_schedule = Schedule::new(); +/// # let mut setup_schedule = Schedule::default(); /// # setup_schedule.add_systems(setup); -/// # let mut assert_schedule = Schedule::new(); +/// # let mut assert_schedule = Schedule::default(); /// # assert_schedule.add_systems(assert_names); /// # /// # setup_schedule.run(&mut world); diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index 051795fd566eb..fd4b3027c4b90 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -55,7 +55,7 @@ //! //! ``` //! # use bevy_ecs::prelude::*; -//! # let mut schedule = Schedule::new(); +//! # let mut schedule = Schedule::default(); //! # let mut world = World::new(); //! // Configure these systems to run in order using `chain()`. //! schedule.add_systems((print_first, print_last).chain()); @@ -170,7 +170,7 @@ pub trait IntoSystem: Sized { /// /// ``` /// # use bevy_ecs::prelude::*; - /// # let mut schedule = Schedule::new(); + /// # let mut schedule = Schedule::default(); /// // Ignores the output of a system that may fail. /// schedule.add_systems(my_system.map(std::mem::drop)); /// # let mut world = World::new(); @@ -1916,7 +1916,7 @@ mod tests { world.insert_resource(A); world.insert_resource(C(0)); - let mut sched = Schedule::new(); + let mut sched = Schedule::default(); sched.add_systems( ( (|mut res: ResMut| { diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index ef7a8252bf153..e5343002df95a 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -353,7 +353,7 @@ impl_param_set!(); /// /// ``` /// # let mut world = World::default(); -/// # let mut schedule = Schedule::new(); +/// # let mut schedule = Schedule::default(); /// # use bevy_ecs::prelude::*; /// #[derive(Resource)] /// struct MyResource { value: u32 } @@ -854,7 +854,7 @@ pub trait SystemBuffer: FromWorld + Send + 'static { /// // ... /// }); /// -/// let mut schedule = Schedule::new(); +/// let mut schedule = Schedule::default(); /// // These two systems have no conflicts and will run in parallel. /// schedule.add_systems((alert_criminal, alert_monster)); /// @@ -1735,7 +1735,7 @@ mod tests { } let mut world = World::new(); - let mut schedule = crate::schedule::Schedule::new(); + let mut schedule = crate::schedule::Schedule::default(); schedule.add_systems(non_sync_system); schedule.run(&mut world); } diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 0e79b19ce8568..93217aca5ebf9 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -1748,9 +1748,9 @@ impl World { /// accessing the [`Schedules`] resource. /// /// The `Schedules` resource will be initialized if it does not already exist. - pub fn add_schedule(&mut self, schedule: Schedule, label: impl ScheduleLabel) { + pub fn add_schedule(&mut self, schedule: Schedule) { let mut schedules = self.get_resource_or_insert_with(Schedules::default); - schedules.insert(label, schedule); + schedules.insert(schedule); } /// Temporarily removes the schedule associated with `label` from the world, @@ -1770,21 +1770,16 @@ impl World { f: impl FnOnce(&mut World, &mut Schedule) -> R, ) -> Result { let label = label.as_ref(); - let Some((extracted_label, mut schedule)) = self + let Some(mut schedule) = self .get_resource_mut::() - .and_then(|mut s| s.remove_entry(label)) + .and_then(|mut s| s.remove(label)) else { return Err(TryRunScheduleError(label.dyn_clone())); }; - // TODO: move this span to Schedule::run - #[cfg(feature = "trace")] - let _span = bevy_utils::tracing::info_span!("schedule", name = ?extracted_label).entered(); let value = f(self, &mut schedule); - let old = self - .resource_mut::() - .insert(extracted_label, schedule); + let old = self.resource_mut::().insert(schedule); if old.is_some() { warn!("Schedule `{label:?}` was inserted during a call to `World::schedule_scope`: its value has been overwritten"); } @@ -1809,10 +1804,10 @@ impl World { /// # /// # let mut world = World::new(); /// # world.insert_resource(Counter(0)); - /// # let mut schedule = Schedule::new(); + /// # let mut schedule = Schedule::new(MySchedule); /// # schedule.add_systems(tick_counter); /// # world.init_resource::(); - /// # world.add_schedule(schedule, MySchedule); + /// # world.add_schedule(schedule); /// # fn tick_counter(mut counter: ResMut) { counter.0 += 1; } /// // Run the schedule five times. /// world.schedule_scope(MySchedule, |world, schedule| { diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index c467a8623726b..473f75fc3aba4 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -132,7 +132,7 @@ impl Render { pub fn base_schedule() -> Schedule { use RenderSet::*; - let mut schedule = Schedule::new(); + let mut schedule = Schedule::new(Self); // Create "stage-like" structure using buffer flushes + ordering schedule.add_systems(( @@ -295,12 +295,12 @@ impl Plugin for RenderPlugin { let mut render_app = App::empty(); render_app.main_schedule_label = Box::new(Render); - let mut extract_schedule = Schedule::new(); + let mut extract_schedule = Schedule::new(ExtractSchedule); extract_schedule.set_apply_final_deferred(false); render_app - .add_schedule(ExtractSchedule, extract_schedule) - .add_schedule(Render, Render::base_schedule()) + .add_schedule(extract_schedule) + .add_schedule(Render::base_schedule()) .init_resource::() .insert_resource(app.world.resource::().clone()) .add_systems(ExtractSchedule, PipelineCache::extract_shaders) diff --git a/crates/bevy_time/src/time.rs b/crates/bevy_time/src/time.rs index 0602e141dda16..260910c46bde8 100644 --- a/crates/bevy_time/src/time.rs +++ b/crates/bevy_time/src/time.rs @@ -124,7 +124,7 @@ impl Time { /// world.insert_resource(time); /// world.insert_resource(Health { health_value: 0.2 }); /// - /// let mut schedule = Schedule::new(); + /// let mut schedule = Schedule::default(); /// schedule.add_systems(health_system); /// /// // Simulate that 30 ms have passed diff --git a/crates/bevy_transform/src/systems.rs b/crates/bevy_transform/src/systems.rs index 48d76fa14e1ab..76ba509f6743b 100644 --- a/crates/bevy_transform/src/systems.rs +++ b/crates/bevy_transform/src/systems.rs @@ -200,7 +200,7 @@ mod test { let offset_transform = |offset| TransformBundle::from_transform(Transform::from_xyz(offset, offset, offset)); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems((sync_simple_transforms, propagate_transforms)); let mut command_queue = CommandQueue::default(); @@ -251,7 +251,7 @@ mod test { ComputeTaskPool::init(TaskPool::default); let mut world = World::default(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems((sync_simple_transforms, propagate_transforms)); // Root entity @@ -289,7 +289,7 @@ mod test { fn did_propagate_command_buffer() { let mut world = World::default(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems((sync_simple_transforms, propagate_transforms)); // Root entity @@ -329,7 +329,7 @@ mod test { ComputeTaskPool::init(TaskPool::default); let mut world = World::default(); - let mut schedule = Schedule::new(); + let mut schedule = Schedule::default(); schedule.add_systems((sync_simple_transforms, propagate_transforms)); // Add parent entities