From 1cc63a0dab4eaa537fbce0794150493106d24344 Mon Sep 17 00:00:00 2001 From: reo Date: Thu, 7 Aug 2025 20:07:29 +0300 Subject: [PATCH] Implement Engine, add compile_shader to rendering systems - Implement the initial version of the run method of the glium platform - Add asset manager to the context of the renderer. I will probably move that to either the engine or somewhere else later. - Other unimportant stuff that I'm too lazy to include here. Early stage commit messages don't really matter anyways. --- Cargo.lock | 1 + raidillon_core/src/engine.rs | 6 ++++++ raidillon_core/src/lib.rs | 5 ++++- raidillon_glium/src/platform.rs | 17 +++++++++++++---- raidillon_glium/src/system.rs | 4 ++++ raidillon_platform/Cargo.toml | 1 + raidillon_platform/src/platform.rs | 4 +++- 7 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 raidillon_core/src/engine.rs diff --git a/Cargo.lock b/Cargo.lock index 8dd4c8f..d778047 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1268,6 +1268,7 @@ dependencies = [ name = "raidillon_platform" version = "0.1.0" dependencies = [ + "raidillon_core", "winit", ] diff --git a/raidillon_core/src/engine.rs b/raidillon_core/src/engine.rs new file mode 100644 index 0000000..91fd6de --- /dev/null +++ b/raidillon_core/src/engine.rs @@ -0,0 +1,6 @@ +use crate::SceneManager; + +pub struct Engine { + scene_manager: SceneManager, + // TODO: Systems +} diff --git a/raidillon_core/src/lib.rs b/raidillon_core/src/lib.rs index 82e3bb3..7f2750e 100644 --- a/raidillon_core/src/lib.rs +++ b/raidillon_core/src/lib.rs @@ -1,2 +1,5 @@ mod scene; -pub use scene::{Scene, SceneManager}; \ No newline at end of file +mod engine; + +pub use scene::{Scene, SceneManager}; +pub use engine::Engine; \ No newline at end of file diff --git a/raidillon_glium/src/platform.rs b/raidillon_glium/src/platform.rs index ff1e023..7e7d776 100644 --- a/raidillon_glium/src/platform.rs +++ b/raidillon_glium/src/platform.rs @@ -1,14 +1,16 @@ use std::sync::{Arc, RwLock}; -use glium::backend::Facade; use raidillon_platform::Platform; use glium::winit::event_loop::EventLoop; use glium::winit::window::Window; use glium::backend::glutin::Display; use glium::glutin::surface::WindowSurface; use glium::backend::glutin::SimpleWindowBuilder; -use crate::system::{RenderingSystemManager, RenderingSystem}; +use glium::Surface; +use crate::system::{RenderingSystemManager, RenderingSystem, RenderingContext}; use winit::event::{Event, WindowEvent}; +use raidillon_core::Engine; use crate::GliumAssetManager; +use crate::render::BasicRenderingSystem; pub struct GliumPlatform { event_loop: EventLoop<()>, @@ -29,8 +31,8 @@ impl Platform for GliumPlatform { .with_inner_size(width, height) .build(&event_loop); - let rendering_system_manager = RenderingSystemManager::new(); let asset_manager = Arc::new(RwLock::new(GliumAssetManager::new(Box::new(display.clone())))); + let rendering_system_manager = RenderingSystemManager::new(); Self { event_loop, window, @@ -40,17 +42,24 @@ impl Platform for GliumPlatform { } } - fn run(self) { + fn run(mut self, engine: Engine) { let _ = &self.event_loop.run(move |event, el| { match event { Event::WindowEvent { event, .. } => match event { WindowEvent::CloseRequested => {}, WindowEvent::RedrawRequested => { + let mut target = self.display.draw(); + target.clear_color(0.0, 0.0, 0.0, 1.0); + // TODO: let mut context; + for (system_id, system) in self.rendering_system_manager.systems.iter_mut() { + todo!(); + } } _ => {}, }, Event::AboutToWait => { + // TODO: Run systems here self.window.request_redraw(); } _ => {}, diff --git a/raidillon_glium/src/system.rs b/raidillon_glium/src/system.rs index 9e6fe3d..8fd8a9e 100644 --- a/raidillon_glium/src/system.rs +++ b/raidillon_glium/src/system.rs @@ -1,16 +1,20 @@ use std::collections::HashMap; +use std::sync::{Arc, RwLock}; use raidillon_core::Scene; use glium::Surface; +use crate::GliumAssetManager; pub struct RenderingContext<'a, S: Surface> { pub scene: &'a mut Scene, pub target: &'a mut S, + pub asset_manager: Arc>, } /// The internal "rendering system" trait of raidillon_glium. /// This is unrelated to the main System trait in raidillon_core. pub trait RenderingSystem { fn render(ctx: &mut RenderingContext); + fn compile_shaders() {} } type SystemID = String; diff --git a/raidillon_platform/Cargo.toml b/raidillon_platform/Cargo.toml index 92e8df0..f411ead 100644 --- a/raidillon_platform/Cargo.toml +++ b/raidillon_platform/Cargo.toml @@ -5,3 +5,4 @@ edition = "2024" [dependencies] winit = "0.30.12" +raidillon_core = { path = "../raidillon_core" } diff --git a/raidillon_platform/src/platform.rs b/raidillon_platform/src/platform.rs index 2db5a54..4042982 100644 --- a/raidillon_platform/src/platform.rs +++ b/raidillon_platform/src/platform.rs @@ -1,5 +1,7 @@ +use raidillon_core::Engine; + pub trait Platform { /// Initialize platform. fn initialize(title: String, width: u32, height: u32) -> Self; - fn run(self); + fn run(self, engine: Engine); }