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
Showing only changes of commit b86bbdd237 - Show all commits

View file

@ -65,8 +65,9 @@ impl System for RenderingTestSystem {
} }
fn frame_update(&mut self, res: &mut EngineResources, scene: &mut Scene) { fn frame_update(&mut self, res: &mut EngineResources, scene: &mut Scene) {
let pctx = res.get::<PlatformContext>().unwrap().clone(); let pctx = res.get::<PlatformContext>().unwrap();
let dbg_ui = scene.resources.get_mut::<DebugUIBuffer>().unwrap(); let dbg_ui = scene.resources.get_mut::<DebugUIBuffer>().unwrap();
reo marked this conversation as resolved

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.

Solved by implementing get_many

Solved by implementing [`get_many`](https://git.reoco.de/reo/raidillon/commit/1a48e58a1cfca6baea4cd60437abfca69fe0d6dd)
dbg_ui.text("Hello World!".to_owned()); dbg_ui.text("Hello World!".to_owned());
dbg_ui.text(format!("Frame Delta: {}", pctx.time_ctx.frame_dt)); dbg_ui.text(format!("Frame Delta: {}", pctx.time_ctx.frame_dt));
dbg_ui.text(format!("Fixed Delta: {}", pctx.time_ctx.fixed_dt)); dbg_ui.text(format!("Fixed Delta: {}", pctx.time_ctx.fixed_dt));
@ -75,6 +76,7 @@ impl System for RenderingTestSystem {
fn fixed_update(&mut self, res: &mut EngineResources, scene: &mut Scene) { fn fixed_update(&mut self, res: &mut EngineResources, scene: &mut Scene) {
let pctx = res.get::<PlatformContext>().unwrap(); let pctx = res.get::<PlatformContext>().unwrap();
scene.world.query_mut::<(&mut Transform, &ModelHandle)>().into_iter().for_each(|(_, (t, _))| { scene.world.query_mut::<(&mut Transform, &ModelHandle)>().into_iter().for_each(|(_, (t, _))| {
t.rotation *= Quat::from_rotation_y(*self.rotation_speed.borrow() * pctx.time_ctx.fixed_dt); t.rotation *= Quat::from_rotation_y(*self.rotation_speed.borrow() * pctx.time_ctx.fixed_dt);
}); });