use std::any::TypeId; use std::cell::RefCell; use std::rc::Rc; use std::sync::{Arc, Mutex}; use indexmap::IndexMap; use glium::{Display, Frame}; use glium::glutin::surface::WindowSurface; use raidillon_assets::ModelManagerRef; use raidillon_core::{define_typemap, EguiQueue}; use raidillon_core::scene::Scene; use glam::Vec3; use winit::event_loop::EventLoop; use std::cell::Cell; pub struct RenderingContext<'a> { pub scene: &'a Scene, pub target: &'a mut Frame, pub window: Arc>, pub display: &'a Display, pub asset_manager: ModelManagerRef, pub egui_queue: Rc>, pub env_light_dir: Vec3, pub should_egui_receive_input_events: Rc> } /// The internal "rendering system" trait of glium_platform. /// This is unrelated to the main System trait in core. pub trait RenderingSystem { fn handle_event( &mut self, _window: Arc>, _event: winit::event::Event<()>, ) { } fn prepare_frame(&mut self, _window: Arc>) {} fn render(&mut self, ctx: &mut RenderingContext); fn initialize(display: &Display, window: Arc>, event_loop: &EventLoop<()>) -> Self where Self: Sized; } // define_typemap!(RenderingSystemManager, RenderingSystem); pub struct RenderingSystemManager { pub systems: IndexMap>, } impl RenderingSystemManager { pub fn new() -> Self { Self { systems: IndexMap::default(), } } pub fn add(&mut self, display: &Display, window: Arc>, event_loop: &EventLoop<()>) where R: RenderingSystem + 'static, { let system = R::initialize(display, window, event_loop); self.systems.insert(TypeId::of::(), Box::new(system)); } pub fn remove(&mut self) { self.systems.shift_remove(&TypeId::of::()); } }