Merge 948a929040 into c32a452f17
This commit is contained in:
commit
34d06c9eb7
5 changed files with 30 additions and 23 deletions
|
|
@ -8,6 +8,7 @@ pub trait EngineTrait {
|
|||
fn new() -> Self;
|
||||
fn initialize(&mut self, platform_context: PlatformContext);
|
||||
fn update(&mut self, platform_context: PlatformContext);
|
||||
fn handle_event(&mut self, platform_context: PlatformContext);
|
||||
fn current_scene_mut(&mut self) -> &mut Scene;
|
||||
fn get_debug_ui_buffer(&self) -> Rc<RefCell<DebugUIBuffer>>;
|
||||
fn reset_debug_ui_buffer(&mut self);
|
||||
|
|
|
|||
|
|
@ -56,6 +56,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.values_mut() {
|
||||
system.handle_event(&mut ctx);
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn build_system_context(&mut self) -> SystemContext {
|
||||
// SystemContext {
|
||||
// scene: self.scene_manager.current_mut(),
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ pub trait System {
|
|||
fn initialize(&mut self) {}
|
||||
/// Spawn the first entities of the world.
|
||||
fn load_world(&mut self, _ctx: &mut SystemContext) {}
|
||||
/// Handle events sent from the platform.
|
||||
fn handle_event(&mut self, _ctx: &mut SystemContext) {}
|
||||
fn update(&mut self, _ctx: &mut SystemContext) {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,15 +18,10 @@ const MAIN_SCENE_ID: &str = "main_scene";
|
|||
#[derive(Default)]
|
||||
struct UpdateAspectRatioSystem;
|
||||
impl System for UpdateAspectRatioSystem {
|
||||
fn initialize(&mut self) {}
|
||||
|
||||
fn load_world(&mut self, _ctx: &mut SystemContext) {}
|
||||
|
||||
fn update(&mut self, ctx: &mut SystemContext) {
|
||||
// FIXME: Need an event handler rework for systems.
|
||||
match &ctx.platform_context.current_event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::Resized(sz) => {
|
||||
fn handle_event(&mut self, ctx: &mut SystemContext) {
|
||||
if let Event::WindowEvent { event: WindowEvent::Resized(sz), .. } =
|
||||
&ctx.platform_context.current_event
|
||||
{
|
||||
let _ = ctx
|
||||
.scene
|
||||
.world
|
||||
|
|
@ -36,10 +31,6 @@ impl System for UpdateAspectRatioSystem {
|
|||
cam.aspect = sz.width as f32 / sz.height as f32;
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ impl<E: EngineTrait> Platform<E> for GliumPlatform<E> {
|
|||
.systems
|
||||
.values_mut()
|
||||
.for_each(|system| system.handle_event(&mut self.window, event.clone()));
|
||||
let mut ctx2 = ctx.clone();
|
||||
ctx2.current_event = event.clone();
|
||||
self.engine.handle_event(ctx2.clone());
|
||||
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
|
|
@ -94,8 +97,6 @@ impl<E: EngineTrait> Platform<E> for GliumPlatform<E> {
|
|||
_ => {},
|
||||
},
|
||||
Event::AboutToWait => {
|
||||
let mut ctx2 = ctx.clone();
|
||||
ctx2.current_event = event.clone();
|
||||
self.engine.update(ctx2);
|
||||
self.rendering_system_manager
|
||||
.systems
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue