use indexmap::IndexMap; use raidillon_core::scene::Scene; use raidillon_core::DebugUIBuffer; use raidillon_platform::PlatformContext; use std::any::TypeId; use std::cell::RefCell; use std::rc::Rc; pub struct SystemContext<'a> { // TODO: time delta etc. pub scene: &'a mut Scene, pub platform_context: PlatformContext, pub debug_ui_buffer: Rc>, } pub trait System { /// Initialize the system. fn initialize(&mut self) {} /// Spawn the first entities of the world. fn load_world(&mut self, _ctx: &mut SystemContext) {} fn handle_event(&mut self, _ctx: &mut SystemContext) {} fn fixed_update(&mut self, _ctx: &mut SystemContext) {} fn frame_update(&mut self, _ctx: &mut SystemContext) {} } pub struct SystemManager { pub systems: IndexMap>, } impl SystemManager { pub fn new() -> Self { Self { systems: IndexMap::default(), } } pub fn add(&mut self) { self.systems .insert(TypeId::of::(), Box::new(S::default())); } pub fn remove(&mut self) { self.systems.shift_remove(&TypeId::of::()); } }