Clone the context instead of repeating the same code
This commit is contained in:
parent
b3b69756e6
commit
1a200e62ef
2 changed files with 13 additions and 8 deletions
|
|
@ -1,7 +1,16 @@
|
||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
use winit::event::Event;
|
use winit::event::Event;
|
||||||
use raidillon_assets::{ModelManagerRef, ModelManager};
|
use raidillon_assets::{ModelManagerRef, ModelManager};
|
||||||
|
|
||||||
|
// TODO: Find a way to move this to raidillon_platform as it belongs there.
|
||||||
|
// TODO: The name "Context" doesn't imply the wide role of this structure.
|
||||||
|
|
||||||
|
/// This provides a bridge between the game logic systems (raidillon_core::System) and
|
||||||
|
/// platform-related data/utilities.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct PlatformContext {
|
pub struct PlatformContext {
|
||||||
|
/// The latest winit event.
|
||||||
pub current_event: Event<()>,
|
pub current_event: Event<()>,
|
||||||
pub asset_manager: ModelManagerRef,
|
pub asset_manager: ModelManagerRef,
|
||||||
pub frame_width: f32,
|
pub frame_width: f32,
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ impl Platform for GliumPlatform {
|
||||||
frame_width: w as f32,
|
frame_width: w as f32,
|
||||||
frame_height: h as f32,
|
frame_height: h as f32,
|
||||||
};
|
};
|
||||||
self.engine.initialize(ctx);
|
self.engine.initialize(ctx.clone());
|
||||||
let _ = &self.event_loop.run(move |event, el| {
|
let _ = &self.event_loop.run(move |event, el| {
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
|
|
@ -91,13 +91,9 @@ impl Platform for GliumPlatform {
|
||||||
_ => {},
|
_ => {},
|
||||||
},
|
},
|
||||||
Event::AboutToWait => {
|
Event::AboutToWait => {
|
||||||
let ctx = PlatformContext {
|
let mut ctx2 = ctx.clone();
|
||||||
current_event: event.clone(),
|
ctx2.current_event = event.clone();
|
||||||
asset_manager: self.asset_manager.clone(),
|
self.engine.update(ctx2);
|
||||||
frame_width: w as f32,
|
|
||||||
frame_height: h as f32,
|
|
||||||
};
|
|
||||||
self.engine.update(ctx);
|
|
||||||
self.window.request_redraw();
|
self.window.request_redraw();
|
||||||
}
|
}
|
||||||
_ => {},
|
_ => {},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue