diff --git a/raidillon_core/src/lib.rs b/raidillon_core/src/lib.rs index 7f2750e..0527964 100644 --- a/raidillon_core/src/lib.rs +++ b/raidillon_core/src/lib.rs @@ -1,5 +1,7 @@ mod scene; mod engine; +pub mod system; pub use scene::{Scene, SceneManager}; -pub use engine::Engine; \ No newline at end of file +pub use engine::Engine; +pub use system::{System, SystemManager}; diff --git a/raidillon_core/src/system.rs b/raidillon_core/src/system.rs new file mode 100644 index 0000000..fc2b600 --- /dev/null +++ b/raidillon_core/src/system.rs @@ -0,0 +1,35 @@ +use crate::Scene; +use indexmap::IndexMap; + +pub struct SystemContext<'a> { + // TODO: time delta etc. + pub scene: &'a mut Scene, +} + +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 update(&mut self, ctx: &mut SystemContext); +} + +pub type SystemID = String; +pub struct SystemManager { + pub systems: IndexMap>, +} + +impl SystemManager { + pub fn new() -> Self { + let systems = IndexMap::default(); + Self { systems } + } + + pub fn add_system(&mut self, id: SystemID, system: Box) { + self.systems.insert(id, system); + } + + pub fn remove_system(&mut self, id: SystemID) { + self.systems.shift_remove(&id); + } +} \ No newline at end of file