pub mod handler;
pub mod param;
pub mod schedule;
use std::{any::TypeId, collections::HashMap};
use super::world::UnsafeWorldCell;
use handler::{into::IntoSystemHandler, SystemHandler};
#[derive(Default)]
pub struct Systems {
systems: HashMap<TypeId, Vec<Box<dyn SystemHandler>>>,
}
impl Systems {
pub fn add<S, H, P>(&mut self, _: S, handler: H)
where
S: 'static,
H: IntoSystemHandler<P> + 'static,
P: 'static,
{
let id = TypeId::of::<S>();
self.systems
.entry(id)
.or_insert(vec![])
.push(Box::new(handler.into_handler()));
}
pub fn run<S>(&self, _: S, cell: &UnsafeWorldCell)
where
S: 'static,
{
let id = TypeId::of::<S>();
self.systems
.get(&id)
.map(|s| s.iter().for_each(|s| s.run(cell)));
}
}