Add per-event handling to systems

This commit is contained in:
Emre Osmanoğlu 2025-09-10 15:03:49 +03:00
parent 0c0d5cdb2a
commit ee2999a0d5
5 changed files with 95 additions and 78 deletions

View file

@ -1,12 +1,11 @@
use std::cell::RefCell;
use std::rc::Rc;
use winit::event::Event;
use raidillon_core::scene::{Scene, SceneManager};
use crate::system::{SystemContext, SystemManager};
use raidillon_assets::{ModelManager, ModelManagerRef};
use raidillon_core::context::PlatformContext;
use raidillon_core::DebugUIBuffer;
use raidillon_core::engine::{EngineTrait};
use raidillon_core::context::PlatformContext;
use raidillon_core::engine::EngineTrait;
use raidillon_core::scene::{Scene, SceneManager};
use std::cell::RefCell;
use std::rc::Rc;
pub struct Engine {
pub scene_manager: SceneManager,
@ -58,6 +57,18 @@ impl EngineTrait for Engine {
}
}
fn handle_event(&mut self, platform_context: PlatformContext) {
let mut ctx = SystemContext {
scene: self.scene_manager.current_mut(),
platform_context,
debug_ui_buffer: self.debug_ui_buffer.clone(),
};
for (_, system) in self.system_manager.systems.iter_mut() {
system.handle_event(&mut ctx);
}
}
// pub fn build_system_context(&mut self) -> SystemContext {
// SystemContext {
// scene: self.scene_manager.current_mut(),
@ -68,7 +79,7 @@ impl EngineTrait for Engine {
self.scene_manager.current_mut()
}
fn get_debug_ui_buffer(&self) -> Rc<RefCell<DebugUIBuffer>> {
fn get_debug_ui_buffer(&self) -> Rc<RefCell<DebugUIBuffer>> {
self.debug_ui_buffer.clone()
}

View file

@ -1,10 +1,9 @@
use indexmap::IndexMap;
use raidillon_core::DebugUIBuffer;
use raidillon_core::context::PlatformContext;
use raidillon_core::scene::Scene;
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.
@ -19,6 +18,7 @@ pub trait System {
/// Spawn the first entities of the world.
fn load_world(&mut self, ctx: &mut SystemContext) {}
fn update(&mut self, ctx: &mut SystemContext) {}
fn handle_event(&mut self, ctx: &mut SystemContext) {}
}
pub type SystemID = &'static str;
@ -39,4 +39,4 @@ impl SystemManager {
pub fn remove_system(&mut self, id: SystemID) {
self.systems.shift_remove(&id);
}
}
}