From 379d54b04871612a35bf3cf49dd2e68ed7d00d07 Mon Sep 17 00:00:00 2001 From: reo Date: Sun, 10 Aug 2025 13:36:25 +0300 Subject: [PATCH] Use IndexMap in glium rendering systems - Improve RenderingContext - Improve RenderingSystem trait --- raidillon_glium/src/system.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/raidillon_glium/src/system.rs b/raidillon_glium/src/system.rs index 8fd8a9e..60c3527 100644 --- a/raidillon_glium/src/system.rs +++ b/raidillon_glium/src/system.rs @@ -1,39 +1,38 @@ -use std::collections::HashMap; -use std::sync::{Arc, RwLock}; use raidillon_core::Scene; -use glium::Surface; +use glium::Frame; use crate::GliumAssetManager; +use indexmap::IndexMap; -pub struct RenderingContext<'a, S: Surface> { - pub scene: &'a mut Scene, - pub target: &'a mut S, - pub asset_manager: Arc>, +pub struct RenderingContext<'a> { + pub scene: &'a Scene, + pub target: &'a mut Frame, + pub asset_manager: &'a mut GliumAssetManager, } /// 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() {} + fn render(&mut self, ctx: &mut RenderingContext); + fn compile_shaders(&mut self) {} } type SystemID = String; -pub struct RenderingSystemManager { - pub systems: HashMap>, +pub struct RenderingSystemManager { + pub systems: IndexMap>, } -impl RenderingSystemManager { +impl RenderingSystemManager { pub fn new() -> Self { Self { - systems: HashMap::new(), + systems: IndexMap::default(), } } - pub fn add_system(&mut self, id: SystemID, system: T) { - self.systems.insert(id, Box::new(system)); + pub fn add_system(&mut self, id: SystemID, system: Box) { + self.systems.insert(id, system); } pub fn remove_system(&mut self, id: SystemID) { - self.systems.remove(&id); + self.systems.shift_remove(&id); } }