wip: Changes of the week

- Move engine to a different crate
- Add engine trait
- Refactor the rest of the codebase to work with these changes
- Add debug ui buffer, use it to finish imgui support
This commit is contained in:
reo 2025-09-07 17:00:04 +03:00
parent 3fd5b09a94
commit 15122b8ebd
20 changed files with 344 additions and 117 deletions

42
engine/src/system.rs Normal file
View file

@ -0,0 +1,42 @@
use std::cell::RefCell;
use std::rc::Rc;
use raidillon_core::scene::Scene;
use indexmap::IndexMap;
use winit::event::Event;
use raidillon_core::context::PlatformContext;
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 type SystemID = &'static str;
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);
}
}