Replace contexts with resources

- Implements a new macro to generate code for a new structure: TypeMap
- TypeMaps are wrappers for HashMaps that use TypeIDs as keys.
- Refactor the entire codebase to use the new resource structures.
- This commit is the first step towards getting rid of "god context objects everywhere".
This commit is contained in:
reo 2025-10-15 22:33:04 +03:00
parent 6e42d94b44
commit ef055a1bda
16 changed files with 287 additions and 93 deletions

View file

@ -98,9 +98,12 @@ impl<E: EngineTrait<PlatformCtx = PlatformContext>> Platform<E> for GliumPlatfor
WindowEvent::RedrawRequested => {
let mut target = self.display.draw();
target.clear_color_and_depth((0.1, 0.1, 0.15, 1.0), 1.0);
let (scene_mut, debug_ui_buffer) = self.engine.scene_and_debug_ui_buffer_mut();
let (scene, debug_ui_buffer) = (
self.engine.current_scene(),
self.engine.get_debug_ui_buffer(),
);
let mut context = RenderingContext {
scene: scene_mut,
scene,
target: &mut target,
asset_manager: self.asset_manager.clone(),
window: self.window.clone(),

View file

@ -41,7 +41,7 @@ impl RenderingSystem for ImguiBridge {
self.rendered_this_frame = true;
let ui = self.imgui.frame();
ctx.debug_ui_buffer.borrow().write_buffer(&ui);
ctx.debug_ui_buffer.write_buffer(&ui);
{
let window = ctx.window.lock().unwrap();

View file

@ -6,7 +6,7 @@ use indexmap::IndexMap;
use glium::{Display, Frame};
use glium::glutin::surface::WindowSurface;
use raidillon_assets::ModelManagerRef;
use raidillon_core::DebugUIBuffer;
use raidillon_core::{define_typemap, DebugUIBuffer};
use raidillon_core::scene::Scene;
use glam::Vec3;
@ -15,7 +15,7 @@ pub struct RenderingContext<'a> {
pub target: &'a mut Frame,
pub window: Arc<Mutex<glium::winit::window::Window>>,
pub asset_manager: ModelManagerRef,
pub debug_ui_buffer: Rc<RefCell<DebugUIBuffer>>,
pub debug_ui_buffer: &'a DebugUIBuffer,
pub env_light_dir: Vec3,
}
@ -35,6 +35,8 @@ pub trait RenderingSystem {
Self: Sized;
}
// define_typemap!(RenderingSystemManager, RenderingSystem);
pub struct RenderingSystemManager {
pub systems: IndexMap<TypeId, Box<dyn RenderingSystem>>,
}