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

Remove impl ScheduleLabel for Box<dyn ScheduleLabel> #7556

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ impl App {
let mut schedules = self.world.resource_mut::<Schedules>();

if schedules.get(&label).is_none() {
schedules.insert(label.dyn_clone(), Schedule::new());
schedules.insert_boxed(label.dyn_clone(), Schedule::new());
}

let schedule = schedules.get_mut(&label).unwrap();
Expand Down
15 changes: 15 additions & 0 deletions crates/bevy_ecs/src/schedule/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ impl Schedules {
/// and the old schedule is returned. Otherwise, `None` is returned.
pub fn insert(&mut self, label: impl ScheduleLabel, schedule: Schedule) -> Option<Schedule> {
let label = label.dyn_clone();
self.insert_boxed(label, schedule)
}

/// Inserts a labeled schedule into the map.
///
/// Unlike `insert`, this method takes a [`BoxedScheduleLabel`]. This is useful when you
/// do not have a concrete schedule label and only a boxed version of it.
///
/// 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_boxed(
&mut self,
label: BoxedScheduleLabel,
schedule: Schedule,
) -> Option<Schedule> {
if self.inner.contains_key(&label) {
warn!("schedule with label {:?} already exists", label);
}
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,8 @@ impl World {

/// Runs the [`Schedule`] associated with the `label` a single time.
///
/// Unlike the `run_schedule` method, this method takes the label by reference, which can save a clone.
/// Unlike the `run_schedule` method, this method takes the label by reference. This is useful
/// when you have the schedule label behind a pointer, such as a `Box`.
///
/// The [`Schedule`] is fetched from the [`Schedules`] resource of the world by its label,
/// and system state is cached.
Expand All @@ -1747,7 +1748,7 @@ impl World {
let _span = bevy_utils::tracing::info_span!("schedule", name = ?extracted_label).entered();
schedule.run(self);
self.resource_mut::<Schedules>()
.insert(extracted_label, schedule);
.insert_boxed(extracted_label, schedule);
}
}

Expand Down
8 changes: 0 additions & 8 deletions crates/bevy_utils/src/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ macro_rules! define_boxed_label {
self.dyn_clone()
}
}

impl $label_trait_name for Box<dyn $label_trait_name> {
fn dyn_clone(&self) -> Box<dyn $label_trait_name> {
// Be explicit that we want to use the inner value
// to avoid infinite recursion.
(**self).dyn_clone()
}
}
};
}

Expand Down