Replace Contexts with Resources #7

Merged
reo merged 5 commits from 2025-10-15-resources into master 2025-10-19 14:24:22 +00:00
Owner
  • 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.
- 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.
reo added 1 commit 2025-10-15 19:38:13 +00:00
- 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".
reo self-assigned this 2025-10-15 19:38:32 +00:00
Author
Owner

THREAD: Reminder to clean up unused code

**THREAD**: Reminder to clean up unused code
reo reviewed 2025-10-15 19:55:38 +00:00
reo reviewed 2025-10-15 20:01:27 +00:00
@ -22,3 +22,1 @@
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) {}
Author
Owner

I'm wondering if I should put scene inside EngineResources instead 🤔

I'm wondering if I should put scene inside EngineResources instead 🤔
@ -63,1 +67,3 @@
let mut dbg_ui = ctx.debug_ui_buffer.borrow_mut();
fn frame_update(&mut self, res: &mut EngineResources, scene: &mut Scene) {
let pctx = res.get::<PlatformContext>().unwrap().clone();
let dbg_ui = scene.resources.get_mut::<DebugUIBuffer>().unwrap();
Author
Owner

Looking at this mess makes me want to invent a simple domain-specific language to specify which resources a system needs, and then make a macro to generate this code.

res!("pctx = PlatformContext, dbg_ui = DebugUIBuffer");
// generates:
// let pctx = res.get::<PlatformContext>().unwrap().clone();
// let dbg_ui = scene.resources.get_mut::<DebugUIBuffer>().unwrap();

I've never made a list of the most over-engineered things I've created. If I were to start now I wouldn't have trouble deciding which one gets the top spot.

Looking at this mess makes me want to invent a simple domain-specific language to specify which resources a system needs, and then make a macro to generate this code. ```rust res!("pctx = PlatformContext, dbg_ui = DebugUIBuffer"); // generates: // let pctx = res.get::<PlatformContext>().unwrap().clone(); // let dbg_ui = scene.resources.get_mut::<DebugUIBuffer>().unwrap(); ``` I've never made a list of the most over-engineered things I've created. If I were to start now I wouldn't have trouble deciding which one gets the top spot.
Author
Owner

Solved by implementing get_many

Solved by implementing [`get_many`](https://git.reoco.de/reo/raidillon/commit/1a48e58a1cfca6baea4cd60437abfca69fe0d6dd)
reo marked this conversation as resolved
reo added 2 commits 2025-10-16 13:13:17 +00:00
I believe the repeated code can be generated with procedural macros, but
I don't need that right now. I'll do it if I ever end up needing this.
Right now I need to start making the game itself more than anything.
reo added 1 commit 2025-10-16 14:01:33 +00:00
reo reviewed 2025-10-16 16:02:37 +00:00
reo added 1 commit 2025-10-17 20:18:20 +00:00
Author
Owner

The nasty repetition in define_typemap! can probably be eliminated with a procedural macro, but I don't think it's worth my time. I'd rather do physics right now and think about procedural macros if I ever need to look up 10 resources in a single query or something.

The nasty repetition in `define_typemap!` can probably be eliminated with a procedural macro, but I don't think it's worth my time. I'd rather do physics right now and think about procedural macros if I ever need to look up 10 resources in a single query or something.
Author
Owner

I probably should've written a test for TypeMap, get_many is alright but get_many_mut returns None for existing resources.

I probably should've written a test for `TypeMap`, `get_many` is alright but `get_many_mut` returns `None` for existing resources.
reo merged commit d280a0b9a5 into master 2025-10-19 14:24:22 +00:00
Sign in to join this conversation.
No description provided.