raidillon/engine/src/system.rs
reo 84ab3a26b1 Timing Module Update
- Implement a new timing module
- Utilize the new timing module in glium platform implementation for frame limiting and fixed engine updates timing.
2025-09-24 23:20:51 +03:00

45 lines
1.2 KiB
Rust

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<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 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<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>());
}
}