From 369bbd19c7329bc624f12e02acabbfa1b166d622 Mon Sep 17 00:00:00 2001 From: reo Date: Mon, 22 Sep 2025 19:45:30 +0300 Subject: [PATCH] Move PlatformContext to the raidillon_platform crate --- core/src/engine.rs | 8 ++++---- core/src/lib.rs | 1 - engine/src/engine.rs | 3 ++- engine/src/system.rs | 2 +- glium_platform/src/platform.rs | 4 ++-- {core => platform}/src/context.rs | 7 ++----- platform/src/lib.rs | 4 +++- platform/src/platform.rs | 2 +- 8 files changed, 15 insertions(+), 16 deletions(-) rename {core => platform}/src/context.rs (62%) diff --git a/core/src/engine.rs b/core/src/engine.rs index 53aeef1..9aafdf5 100644 --- a/core/src/engine.rs +++ b/core/src/engine.rs @@ -1,14 +1,14 @@ use std::cell::RefCell; use std::rc::Rc; -use crate::context::PlatformContext; use crate::DebugUIBuffer; use crate::scene::Scene; pub trait EngineTrait { + type PlatformCtx: Clone; 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 initialize(&mut self, platform_context: Self::PlatformCtx); + fn update(&mut self, platform_context: Self::PlatformCtx); + fn handle_event(&mut self, platform_context: Self::PlatformCtx); fn current_scene_mut(&mut self) -> &mut Scene; fn get_debug_ui_buffer(&self) -> Rc>; fn reset_debug_ui_buffer(&mut self); diff --git a/core/src/lib.rs b/core/src/lib.rs index b6fc074..ee279f9 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,5 +1,4 @@ pub mod engine; pub mod scene; -pub mod context; pub mod debug_ui; pub use debug_ui::*; \ No newline at end of file diff --git a/engine/src/engine.rs b/engine/src/engine.rs index bf3b692..38b6657 100644 --- a/engine/src/engine.rs +++ b/engine/src/engine.rs @@ -2,7 +2,7 @@ use std::cell::RefCell; use std::rc::Rc; use raidillon_core::scene::{Scene, SceneManager}; use crate::system::{SystemContext, SystemManager}; -use raidillon_core::context::PlatformContext; +use raidillon_platform::PlatformContext; use raidillon_core::DebugUIBuffer; use raidillon_core::engine::EngineTrait; @@ -13,6 +13,7 @@ pub struct Engine { } impl EngineTrait for Engine { + type PlatformCtx = PlatformContext; fn new() -> Self { let scene_manager = SceneManager::new(); let system_manager = SystemManager::new(); diff --git a/engine/src/system.rs b/engine/src/system.rs index b11d8fd..49b6c44 100644 --- a/engine/src/system.rs +++ b/engine/src/system.rs @@ -2,7 +2,7 @@ use std::any::TypeId; use std::cell::RefCell; use std::rc::Rc; use indexmap::IndexMap; -use raidillon_core::context::PlatformContext; +use raidillon_platform::PlatformContext; use raidillon_core::scene::Scene; use raidillon_core::DebugUIBuffer; diff --git a/glium_platform/src/platform.rs b/glium_platform/src/platform.rs index 4848c7c..97a94a1 100644 --- a/glium_platform/src/platform.rs +++ b/glium_platform/src/platform.rs @@ -15,7 +15,7 @@ use crate::render::debug_ui::ImguiBridge; use crate::render::BasicMeshRenderingSystem; use crate::GliumAssetManager; -pub struct GliumPlatform { +pub struct GliumPlatform> { event_loop: EventLoop<()>, window: Window, display: Display, @@ -24,7 +24,7 @@ pub struct GliumPlatform { engine: E, } -impl Platform for GliumPlatform { +impl> Platform for GliumPlatform { fn initialize(mut engine: E, title: String, width: u32, height: u32) -> Self { let event_loop = glium::winit::event_loop::EventLoop::builder() .build() diff --git a/core/src/context.rs b/platform/src/context.rs similarity index 62% rename from core/src/context.rs rename to platform/src/context.rs index f1cdffe..fb5ec65 100644 --- a/core/src/context.rs +++ b/platform/src/context.rs @@ -1,8 +1,5 @@ -use std::cell::RefCell; -use std::rc::Rc; -use std::sync::Arc; use winit::event::Event; -use raidillon_assets::{ModelManagerRef, ModelManager}; +use raidillon_assets::ModelManagerRef; #[derive(Clone)] pub struct PlatformContext { @@ -10,4 +7,4 @@ pub struct PlatformContext { pub asset_manager: ModelManagerRef, pub frame_width: f32, pub frame_height: f32, -} +} \ No newline at end of file diff --git a/platform/src/lib.rs b/platform/src/lib.rs index 3ff1a65..962c05f 100644 --- a/platform/src/lib.rs +++ b/platform/src/lib.rs @@ -1,6 +1,8 @@ pub mod platform; mod camera; +mod event; +pub mod context; pub use platform::Platform; pub use camera::Camera; -pub use raidillon_core::context::PlatformContext; +pub use context::PlatformContext; diff --git a/platform/src/platform.rs b/platform/src/platform.rs index 44b799f..d840723 100644 --- a/platform/src/platform.rs +++ b/platform/src/platform.rs @@ -2,7 +2,7 @@ use raidillon_assets::ModelManager; use raidillon_core::engine::EngineTrait; use crate::PlatformContext; -pub trait Platform { +pub trait Platform> { /// Initialize platform. fn initialize(engine: E, title: String, width: u32, height: u32) -> Self; fn run(self);