43 lines
No EOL
1.1 KiB
Rust
43 lines
No EOL
1.1 KiB
Rust
use std::any::TypeId;
|
|
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
use indexmap::IndexMap;
|
|
use raidillon_core::context::PlatformContext;
|
|
use raidillon_core::scene::Scene;
|
|
use raidillon_core::DebugUIBuffer;
|
|
|
|
pub struct SystemContext<'a> {
|
|
// TODO: time delta etc.
|
|
pub scene: &'a mut Scene,
|
|
pub platform_context: PlatformContext,
|
|
pub debug_ui_buffer: Rc<RefCell<DebugUIBuffer>>,
|
|
}
|
|
|
|
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 struct SystemManager {
|
|
pub systems: IndexMap<TypeId, Box<dyn System>>,
|
|
}
|
|
|
|
impl SystemManager {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
systems: IndexMap::default(),
|
|
}
|
|
}
|
|
|
|
pub fn add<S: System + Default + 'static>(&mut self) {
|
|
self.systems
|
|
.insert(TypeId::of::<S>(), Box::new(S::default()));
|
|
}
|
|
|
|
pub fn remove<S: 'static>(&mut self) {
|
|
self.systems.shift_remove(&TypeId::of::<S>());
|
|
}
|
|
} |