Implement core "system" system

This commit is contained in:
reo 2025-08-10 13:36:58 +03:00
parent 379d54b048
commit 84f8a495b7
2 changed files with 38 additions and 1 deletions

View file

@ -1,5 +1,7 @@
mod scene;
mod engine;
pub mod system;
pub use scene::{Scene, SceneManager};
pub use engine::Engine;
pub use engine::Engine;
pub use system::{System, SystemManager};

View file

@ -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<SystemID, Box<dyn System>>,
}
impl SystemManager {
pub fn new() -> Self {
let systems = IndexMap::default();
Self { systems }
}
pub fn add_system(&mut self, id: SystemID, system: Box<dyn System>) {
self.systems.insert(id, system);
}
pub fn remove_system(&mut self, id: SystemID) {
self.systems.shift_remove(&id);
}
}