mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Use system type name as default system name
This commit is contained in:
parent
45a1f0515f
commit
a1cbf36b0c
5 changed files with 28 additions and 8 deletions
|
@ -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<String, Vec<System>>,
|
||||
stage_order: Vec<String>,
|
||||
system_names: HashSet<Cow<'static, str>>,
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
use legion::prelude::{Resources, Runnable, Schedulable, World};
|
||||
use std::borrow::Cow;
|
||||
pub enum System {
|
||||
Schedulable(Box<dyn Schedulable>),
|
||||
ThreadLocal(Box<dyn Runnable>),
|
||||
ThreadLocalFn(Box<dyn FnMut(&mut World, &mut Resources)>),
|
||||
ThreadLocalFn((&'static str, Box<dyn FnMut(&mut World, &mut Resources)>)),
|
||||
}
|
||||
|
||||
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<Box<dyn Schedulable>> 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::<T>(), Box::new(system)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -771,6 +771,10 @@ impl SystemId {
|
|||
type_id: TypeId::of::<T>(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(&self) -> Cow<'static, str> {
|
||||
self.name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SystemId {
|
||||
|
|
|
@ -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<dyn Schedulable>;
|
||||
|
@ -59,8 +58,7 @@ macro_rules! impl_system {
|
|||
}
|
||||
|
||||
fn system(self) -> Box<dyn Schedulable> {
|
||||
let uuid = Uuid::new_v4();
|
||||
self.system_id(uuid.to_simple().to_string().into())
|
||||
self.system_id(std::any::type_name::<Self>().to_string().into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -325,7 +325,7 @@ pub fn mesh_batcher_system() -> Box<dyn Schedulable> {
|
|||
}
|
||||
|
||||
pub fn mesh_specializer_system() -> Box<dyn Schedulable> {
|
||||
SystemBuilder::new("mesh_batcher")
|
||||
SystemBuilder::new("mesh_specializer")
|
||||
.read_resource::<AssetStorage<Mesh>>()
|
||||
.with_query(
|
||||
<(Read<Handle<Mesh>>, Write<Renderable>)>::query()
|
||||
|
|
Loading…
Reference in a new issue