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

@ -6,6 +6,7 @@ use std::any::TypeId;
use std::cell::RefCell;
use std::rc::Rc;
use crate::input::InputState;
use crate::resources::EngineResources;
pub struct SystemContext<'a> {
pub scene: &'a mut Scene,
@ -18,10 +19,10 @@ pub trait System {
/// Initialize the system.
fn initialize(&mut self) {}
/// Spawn the first entities of the world.
fn load_world(&mut self, _ctx: &mut SystemContext) {}
fn handle_event(&mut self, _ctx: &mut SystemContext) {}
fn fixed_update(&mut self, _ctx: &mut SystemContext) {}
fn frame_update(&mut self, _ctx: &mut SystemContext) {}
fn load_world(&mut self, res: &mut EngineResources, scene: &mut Scene) {}
fn handle_event(&mut self, res: &mut EngineResources, scene: &mut Scene) {}
fn fixed_update(&mut self, res: &mut EngineResources, scene: &mut Scene) {}
fn frame_update(&mut self, res: &mut EngineResources, scene: &mut Scene) {}
}
pub struct SystemManager {