Use IndexMap in glium rendering systems
- Improve RenderingContext - Improve RenderingSystem trait
This commit is contained in:
parent
147a9d3a85
commit
379d54b048
1 changed files with 15 additions and 16 deletions
|
|
@ -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<RwLock<GliumAssetManager>>,
|
||||
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<S: Surface>(ctx: &mut RenderingContext<S>);
|
||||
fn compile_shaders() {}
|
||||
fn render(&mut self, ctx: &mut RenderingContext);
|
||||
fn compile_shaders(&mut self) {}
|
||||
}
|
||||
|
||||
type SystemID = String;
|
||||
|
||||
pub struct RenderingSystemManager<T: RenderingSystem> {
|
||||
pub systems: HashMap<SystemID, Box<T>>,
|
||||
pub struct RenderingSystemManager {
|
||||
pub systems: IndexMap<SystemID, Box<dyn RenderingSystem>>,
|
||||
}
|
||||
|
||||
impl<T: RenderingSystem> RenderingSystemManager<T> {
|
||||
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<dyn RenderingSystem>) {
|
||||
self.systems.insert(id, system);
|
||||
}
|
||||
|
||||
pub fn remove_system(&mut self, id: SystemID) {
|
||||
self.systems.remove(&id);
|
||||
self.systems.shift_remove(&id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue