Use IndexMap in glium rendering systems

- Improve RenderingContext
- Improve RenderingSystem trait
This commit is contained in:
reo 2025-08-10 13:36:25 +03:00
parent 147a9d3a85
commit 379d54b048

View file

@ -1,39 +1,38 @@
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use raidillon_core::Scene; use raidillon_core::Scene;
use glium::Surface; use glium::Frame;
use crate::GliumAssetManager; use crate::GliumAssetManager;
use indexmap::IndexMap;
pub struct RenderingContext<'a, S: Surface> { pub struct RenderingContext<'a> {
pub scene: &'a mut Scene, pub scene: &'a Scene,
pub target: &'a mut S, pub target: &'a mut Frame,
pub asset_manager: Arc<RwLock<GliumAssetManager>>, pub asset_manager: &'a mut 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(&mut self, ctx: &mut RenderingContext);
fn compile_shaders() {} fn compile_shaders(&mut self) {}
} }
type SystemID = String; type SystemID = String;
pub struct RenderingSystemManager<T: RenderingSystem> { pub struct RenderingSystemManager {
pub systems: HashMap<SystemID, Box<T>>, pub systems: IndexMap<SystemID, Box<dyn RenderingSystem>>,
} }
impl<T: RenderingSystem> RenderingSystemManager<T> { impl RenderingSystemManager {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
systems: HashMap::new(), systems: IndexMap::default(),
} }
} }
pub fn add_system(&mut self, id: SystemID, system: T) { pub fn add_system(&mut self, id: SystemID, system: Box<dyn RenderingSystem>) {
self.systems.insert(id, Box::new(system)); self.systems.insert(id, system);
} }
pub fn remove_system(&mut self, id: SystemID) { pub fn remove_system(&mut self, id: SystemID) {
self.systems.remove(&id); self.systems.shift_remove(&id);
} }
} }