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.
This commit is contained in:
reo 2025-08-07 20:07:29 +03:00
parent e817abf8ab
commit 1cc63a0dab
7 changed files with 32 additions and 6 deletions

1
Cargo.lock generated
View file

@ -1268,6 +1268,7 @@ dependencies = [
name = "raidillon_platform" name = "raidillon_platform"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"raidillon_core",
"winit", "winit",
] ]

View file

@ -0,0 +1,6 @@
use crate::SceneManager;
pub struct Engine {
scene_manager: SceneManager,
// TODO: Systems
}

View file

@ -1,2 +1,5 @@
mod scene; mod scene;
pub use scene::{Scene, SceneManager}; mod engine;
pub use scene::{Scene, SceneManager};
pub use engine::Engine;

View file

@ -1,14 +1,16 @@
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use glium::backend::Facade;
use raidillon_platform::Platform; use raidillon_platform::Platform;
use glium::winit::event_loop::EventLoop; use glium::winit::event_loop::EventLoop;
use glium::winit::window::Window; use glium::winit::window::Window;
use glium::backend::glutin::Display; use glium::backend::glutin::Display;
use glium::glutin::surface::WindowSurface; use glium::glutin::surface::WindowSurface;
use glium::backend::glutin::SimpleWindowBuilder; 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 winit::event::{Event, WindowEvent};
use raidillon_core::Engine;
use crate::GliumAssetManager; use crate::GliumAssetManager;
use crate::render::BasicRenderingSystem;
pub struct GliumPlatform<RS: RenderingSystem> { pub struct GliumPlatform<RS: RenderingSystem> {
event_loop: EventLoop<()>, event_loop: EventLoop<()>,
@ -29,8 +31,8 @@ impl<RS: RenderingSystem> Platform for GliumPlatform<RS> {
.with_inner_size(width, height) .with_inner_size(width, height)
.build(&event_loop); .build(&event_loop);
let rendering_system_manager = RenderingSystemManager::new();
let asset_manager = Arc::new(RwLock::new(GliumAssetManager::new(Box::new(display.clone())))); let asset_manager = Arc::new(RwLock::new(GliumAssetManager::new(Box::new(display.clone()))));
let rendering_system_manager = RenderingSystemManager::new();
Self { Self {
event_loop, event_loop,
window, window,
@ -40,17 +42,24 @@ impl<RS: RenderingSystem> Platform for GliumPlatform<RS> {
} }
} }
fn run(self) { fn run(mut self, engine: Engine) {
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 {
WindowEvent::CloseRequested => {}, WindowEvent::CloseRequested => {},
WindowEvent::RedrawRequested => { 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 => { Event::AboutToWait => {
// TODO: Run <engine: Engine> systems here
self.window.request_redraw(); self.window.request_redraw();
} }
_ => {}, _ => {},

View file

@ -1,16 +1,20 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use raidillon_core::Scene; use raidillon_core::Scene;
use glium::Surface; use glium::Surface;
use crate::GliumAssetManager;
pub struct RenderingContext<'a, S: Surface> { pub struct RenderingContext<'a, S: Surface> {
pub scene: &'a mut Scene, pub scene: &'a mut Scene,
pub target: &'a mut S, pub target: &'a mut S,
pub asset_manager: Arc<RwLock<GliumAssetManager>>,
} }
/// The internal "rendering system" trait of raidillon_glium. /// The internal "rendering system" trait of raidillon_glium.
/// This is unrelated to the main System trait in raidillon_core. /// This is unrelated to the main System trait in raidillon_core.
pub trait RenderingSystem { pub trait RenderingSystem {
fn render<S: Surface>(ctx: &mut RenderingContext<S>); fn render<S: Surface>(ctx: &mut RenderingContext<S>);
fn compile_shaders() {}
} }
type SystemID = String; type SystemID = String;

View file

@ -5,3 +5,4 @@ edition = "2024"
[dependencies] [dependencies]
winit = "0.30.12" winit = "0.30.12"
raidillon_core = { path = "../raidillon_core" }

View file

@ -1,5 +1,7 @@
use raidillon_core::Engine;
pub trait Platform { pub trait Platform {
/// Initialize platform. /// Initialize platform.
fn initialize(title: String, width: u32, height: u32) -> Self; fn initialize(title: String, width: u32, height: u32) -> Self;
fn run(self); fn run(self, engine: Engine);
} }