Clone the context instead of repeating the same code

This commit is contained in:
reo 2025-09-05 16:07:48 +03:00
parent b3b69756e6
commit 1a200e62ef
2 changed files with 13 additions and 8 deletions

View file

@ -1,7 +1,16 @@
use std::cell::RefCell;
use std::rc::Rc;
use winit::event::Event;
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 {
/// The latest winit event.
pub current_event: Event<()>,
pub asset_manager: ModelManagerRef,
pub frame_width: f32,

View file

@ -65,7 +65,7 @@ impl Platform for GliumPlatform {
frame_width: w as f32,
frame_height: h as f32,
};
self.engine.initialize(ctx);
self.engine.initialize(ctx.clone());
let _ = &self.event_loop.run(move |event, el| {
match event {
Event::WindowEvent { event, .. } => match event {
@ -91,13 +91,9 @@ impl Platform for GliumPlatform {
_ => {},
},
Event::AboutToWait => {
let ctx = PlatformContext {
current_event: event.clone(),
asset_manager: self.asset_manager.clone(),
frame_width: w as f32,
frame_height: h as f32,
};
self.engine.update(ctx);
let mut ctx2 = ctx.clone();
ctx2.current_event = event.clone();
self.engine.update(ctx2);
self.window.request_redraw();
}
_ => {},