From 1a200e62ef5f5719c2588c8a81359eefd349c271 Mon Sep 17 00:00:00 2001 From: reo Date: Fri, 5 Sep 2025 16:07:48 +0300 Subject: [PATCH] Clone the context instead of repeating the same code --- core/src/context.rs | 9 +++++++++ glium_platform/src/platform.rs | 12 ++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/src/context.rs b/core/src/context.rs index 01db2f9..a89d46c 100644 --- a/core/src/context.rs +++ b/core/src/context.rs @@ -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, diff --git a/glium_platform/src/platform.rs b/glium_platform/src/platform.rs index 9a491c2..478974f 100644 --- a/glium_platform/src/platform.rs +++ b/glium_platform/src/platform.rs @@ -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(); } _ => {},