From 4f068467c4954fb79e6ce297ae1ac0fdd2bdf16a Mon Sep 17 00:00:00 2001 From: tcmal Date: Sun, 25 Aug 2024 17:44:24 +0100 Subject: WIP refactor(skeleton): type state for context also some api improvements closes #2 related: #7 --- examples/render-quad/src/main.rs | 50 ++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'examples') diff --git a/examples/render-quad/src/main.rs b/examples/render-quad/src/main.rs index 618779e..45c469a 100644 --- a/examples/render-quad/src/main.rs +++ b/examples/render-quad/src/main.rs @@ -19,7 +19,6 @@ use stockton_levels::{ types::Rgba, }; use stockton_render::{ - camera::calc_vp_matrix_system, level::{LevelDrawPass, LevelDrawPassConfig}, ui::UiDrawPass, window::{process_window_events_system, UiState, WindowEvent, WindowFlow}, @@ -28,7 +27,7 @@ use stockton_skeleton::{ draw_passes::ConsDrawPass, error::full_error_display, texture::resolver::FsResolver, Renderer, }; use stockton_types::{ - components::{CameraSettings, CameraVPMatrix, Transform}, + components::{CameraSettings, Transform}, Session, Vector2, Vector3, }; @@ -162,15 +161,10 @@ fn try_main() -> Result<()> { let mut session = Session::new(move |schedule| { schedule .add_system(update_deltatime_system()) - .add_system(process_window_events_system::< - MovementInputsManager, - Dp<'static>, - >()) + .add_system(process_window_events_system::()) .flush() .add_system(hello_world_system()) - .add_system(flycam_move_system::()) - .flush() - .add_thread_local(calc_vp_matrix_system::>()); + .add_system(flycam_move_system::()); }); session.resources.insert(map.clone()); @@ -190,7 +184,6 @@ fn try_main() -> Result<()> { fov: 90.0, near: 0.1, }, - CameraVPMatrix::default(), FlycamControlled::new(512.0, 400.0), )); @@ -217,7 +210,7 @@ fn try_main() -> Result<()> { ui.populate_initial_state(&renderer); } - session.resources.insert(renderer); + let mut renderer = Some(renderer); // Done loading - This is our main loop. // It just communicates events to the session and continuously ticks @@ -228,15 +221,38 @@ fn try_main() -> Result<()> { } Event::RedrawRequested(_) => { session.do_update(); - let mut renderer = session - .resources - .get_mut::>>() - .unwrap(); - renderer.render(&session).unwrap(); + let r = renderer.take().unwrap(); + match r.render(&session) { + Ok(r) => { + renderer = Some(r); + } + Err(e) => { + println!("Error drawing: {}", full_error_display(e)); + + // TODO: Not really sound + *(new_control_flow.write().unwrap()) = ControlFlow::Exit; + } + } } _ => { if let Some(we) = WindowEvent::from(&event) { - tx.send(we).unwrap() + tx.send(we).unwrap(); + + println!("{:?}", we); + if let WindowEvent::SizeChanged(_, _) = we { + let r = renderer.take().unwrap(); + match r.recreate_surface(&session) { + Ok(r) => { + renderer = Some(r); + } + Err(e) => { + println!("Error resizing: {}", full_error_display(e)); + + // TODO: Not really sound + *(new_control_flow.write().unwrap()) = ControlFlow::Exit; + } + } + } } } } -- cgit v1.2.3