Implement core "system" system
This commit is contained in:
parent
379d54b048
commit
84f8a495b7
2 changed files with 38 additions and 1 deletions
|
|
@ -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};
|
||||
|
|
|
|||
35
raidillon_core/src/system.rs
Normal file
35
raidillon_core/src/system.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue