diff --git a/crates/bevy_app/src/schedule_plan.rs b/crates/bevy_app/src/schedule_plan.rs index f5a00f25eb..ff3d3a65ff 100644 --- a/crates/bevy_app/src/schedule_plan.rs +++ b/crates/bevy_app/src/schedule_plan.rs @@ -1,11 +1,12 @@ use crate::System; use legion::prelude::Schedule; -use std::{cmp::Ordering, collections::HashMap}; +use std::{cmp::Ordering, collections::{HashSet, HashMap}, borrow::Cow}; #[derive(Default)] pub struct SchedulePlan { stages: HashMap>, stage_order: Vec, + system_names: HashSet>, } impl SchedulePlan { @@ -23,7 +24,7 @@ impl SchedulePlan { System::ThreadLocal(runnable) => { schedule_builder = schedule_builder.add_thread_local(runnable); } - System::ThreadLocalFn(thread_local) => { + System::ThreadLocalFn((_name, thread_local)) => { schedule_builder = schedule_builder.add_thread_local_fn(thread_local); } } @@ -90,6 +91,12 @@ impl SchedulePlan { .stages .get_mut(stage_name) .unwrap_or_else(|| panic!("Stage does not exist: {}", stage_name)); + let system = system.into(); + let system_name = system.name(); + if self.system_names.contains(&system_name) { + panic!("System with name {} already exists", system_name); + } + self.system_names.insert(system_name); systems.push(system.into()); self diff --git a/crates/bevy_app/src/system.rs b/crates/bevy_app/src/system.rs index 47875aa12a..f01be32412 100644 --- a/crates/bevy_app/src/system.rs +++ b/crates/bevy_app/src/system.rs @@ -1,8 +1,19 @@ use legion::prelude::{Resources, Runnable, Schedulable, World}; +use std::borrow::Cow; pub enum System { Schedulable(Box), ThreadLocal(Box), - ThreadLocalFn(Box), + ThreadLocalFn((&'static str, Box)), +} + +impl System { + pub fn name(&self) -> Cow<'static, str> { + match *self { + System::Schedulable(ref schedulable) => schedulable.name().name(), + System::ThreadLocal(ref runnable) => runnable.name().name(), + System::ThreadLocalFn((ref name, ref _thread_local_fn)) => Cow::Borrowed(name), + } + } } impl From> for System { @@ -22,6 +33,6 @@ where T: FnMut(&mut World, &mut Resources) + 'static, { fn from(system: T) -> Self { - System::ThreadLocalFn(Box::new(system)) + System::ThreadLocalFn((std::any::type_name::(), Box::new(system))) } } diff --git a/crates/bevy_legion/legion_systems/src/system.rs b/crates/bevy_legion/legion_systems/src/system.rs index 574481af4e..265d03ee0e 100644 --- a/crates/bevy_legion/legion_systems/src/system.rs +++ b/crates/bevy_legion/legion_systems/src/system.rs @@ -771,6 +771,10 @@ impl SystemId { type_id: TypeId::of::(), } } + + pub fn name(&self) -> Cow<'static, str> { + self.name.clone() + } } impl std::fmt::Display for SystemId { diff --git a/crates/bevy_legion/legion_systems/src/system_fn.rs b/crates/bevy_legion/legion_systems/src/system_fn.rs index 0d72c43e97..45ba0b13fb 100644 --- a/crates/bevy_legion/legion_systems/src/system_fn.rs +++ b/crates/bevy_legion/legion_systems/src/system_fn.rs @@ -14,7 +14,6 @@ use legion_core::{ storage::ComponentTypeId, }; use std::marker::PhantomData; -use uuid::Uuid; pub trait IntoSystem<'a, CommandBuffer, Resources, Components> { fn system_id(self, id: SystemId) -> Box; @@ -59,8 +58,7 @@ macro_rules! impl_system { } fn system(self) -> Box { - let uuid = Uuid::new_v4(); - self.system_id(uuid.to_simple().to_string().into()) + self.system_id(std::any::type_name::().to_string().into()) } } } diff --git a/crates/bevy_render/src/mesh.rs b/crates/bevy_render/src/mesh.rs index cd63f53cf4..1a25fa4930 100644 --- a/crates/bevy_render/src/mesh.rs +++ b/crates/bevy_render/src/mesh.rs @@ -325,7 +325,7 @@ pub fn mesh_batcher_system() -> Box { } pub fn mesh_specializer_system() -> Box { - SystemBuilder::new("mesh_batcher") + SystemBuilder::new("mesh_specializer") .read_resource::>() .with_query( <(Read>, Write)>::query()