From ecf1c762647f870a994a2fc32960f2539ae8b4f0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Oct 2022 12:30:52 +0200 Subject: [PATCH 1/4] Add comment --- crates/fj-window/src/run.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 31194880f5..ca708f799d 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -171,6 +171,8 @@ pub fn run( window.window().request_redraw(); } Event::RedrawRequested(_) => { + // Only do a screen resize once per frame. This protects against + // spurious resize events that cause issues with the renderer. if let Some(size) = new_size.take() { viewer.handle_screen_resize(size); } From 5da542da3d91f0b6e830b21e46869c12323a70c9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Oct 2022 13:13:03 +0200 Subject: [PATCH 2/4] Always require watcher in `fj_window::run` --- crates/fj-app/src/main.rs | 2 +- crates/fj-window/src/run.rs | 66 ++++++++++++++++++------------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/crates/fj-app/src/main.rs b/crates/fj-app/src/main.rs index 3dca6df06b..283efecc7d 100644 --- a/crates/fj-app/src/main.rs +++ b/crates/fj-app/src/main.rs @@ -91,7 +91,7 @@ fn main() -> anyhow::Result<()> { let invert_zoom = config.invert_zoom.unwrap_or(false); let watcher = model.load_and_watch(parameters)?; - run(Some(watcher), shape_processor, status, invert_zoom)?; + run(watcher, shape_processor, status, invert_zoom)?; Ok(()) } diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index ca708f799d..cdf8053e38 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -27,7 +27,7 @@ use crate::window::{self, Window}; /// Initializes a model viewer for a given model and enters its process loop. pub fn run( - watcher: Option, + watcher: Watcher, shape_processor: ShapeProcessor, mut status: StatusReport, invert_zoom: bool, @@ -49,50 +49,48 @@ pub fn run( event_loop.run(move |event, _, control_flow| { trace!("Handling event: {:?}", event); - if let Some(watcher) = &watcher { - match watcher.receive_shape(&mut status) { - Ok(shape) => { - if let Some(shape) = shape { - match shape_processor.process(&shape) { - Ok(shape) => { - viewer.handle_shape_update(shape); - } - Err(err) => { - // Can be cleaned up, once `Report` is stable: - // https://doc.rust-lang.org/std/error/struct.Report.html + match watcher.receive_shape(&mut status) { + Ok(shape) => { + if let Some(shape) = shape { + match shape_processor.process(&shape) { + Ok(shape) => { + viewer.handle_shape_update(shape); + } + Err(err) => { + // Can be cleaned up, once `Report` is stable: + // https://doc.rust-lang.org/std/error/struct.Report.html - println!("Shape processing error: {}", err); + println!("Shape processing error: {}", err); - let mut current_err = &err as &dyn error::Error; - while let Some(err) = current_err.source() { - println!(); - println!("Caused by:"); - println!(" {}", err); + let mut current_err = &err as &dyn error::Error; + while let Some(err) = current_err.source() { + println!(); + println!("Caused by:"); + println!(" {}", err); - current_err = err; - } + current_err = err; } } } } - Err(err) => { - // Can be cleaned up, once `Report` is stable: - // https://doc.rust-lang.org/std/error/struct.Report.html + } + Err(err) => { + // Can be cleaned up, once `Report` is stable: + // https://doc.rust-lang.org/std/error/struct.Report.html - println!("Error receiving updated shape: {}", err); + println!("Error receiving updated shape: {}", err); - let mut current_err = &err as &dyn error::Error; - while let Some(err) = current_err.source() { - println!(); - println!("Caused by:"); - println!(" {}", err); + let mut current_err = &err as &dyn error::Error; + while let Some(err) = current_err.source() { + println!(); + println!("Caused by:"); + println!(" {}", err); - current_err = err; - } - - *control_flow = ControlFlow::Exit; - return; + current_err = err; } + + *control_flow = ControlFlow::Exit; + return; } } From 70952bdbf183cbcaa2436e041acfe965a3d66477 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Oct 2022 13:18:22 +0200 Subject: [PATCH 3/4] Refactor --- crates/fj-interop/src/status_report.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/fj-interop/src/status_report.rs b/crates/fj-interop/src/status_report.rs index 23f74b802d..f5c645da2b 100644 --- a/crates/fj-interop/src/status_report.rs +++ b/crates/fj-interop/src/status_report.rs @@ -3,6 +3,7 @@ use std::collections::VecDeque; /// Struct to store and update status messages +#[derive(Default)] pub struct StatusReport { status: VecDeque, } @@ -10,9 +11,7 @@ pub struct StatusReport { impl StatusReport { /// Create a new ``StatusReport`` instance with a blank status pub fn new() -> Self { - Self { - status: VecDeque::new(), - } + Self::default() } /// Update the status @@ -39,9 +38,3 @@ impl StatusReport { self.status.clear(); } } - -impl Default for StatusReport { - fn default() -> Self { - Self::new() - } -} From 541150a716d5dfc5227368ecb60ab262f2463010 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 20 Oct 2022 13:26:04 +0200 Subject: [PATCH 4/4] Don't refer to `Event` in an overly specific way --- crates/fj-window/src/run.rs | 4 ++-- crates/fj-window/src/window.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index cdf8053e38..000fc9b672 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -200,8 +200,8 @@ pub fn run( }); } -fn input_event( - event: &Event<()>, +fn input_event( + event: &Event, window: &Window, held_mouse_button: &Option, previous_cursor: &mut Option, diff --git a/crates/fj-window/src/window.rs b/crates/fj-window/src/window.rs index db1c57a841..25d709d39a 100644 --- a/crates/fj-window/src/window.rs +++ b/crates/fj-window/src/window.rs @@ -8,7 +8,7 @@ pub struct Window(winit::window::Window); impl Window { /// Returns a new window with the given `EventLoop`. - pub fn new(event_loop: &EventLoop<()>) -> Result { + pub fn new(event_loop: &EventLoop) -> Result { let window = WindowBuilder::new() .with_title("Fornjot") .with_maximized(true)