diff --git a/crates/topola-egui/src/actions.rs b/crates/topola-egui/src/actions.rs index 0fd3cc4..bd5a680 100644 --- a/crates/topola-egui/src/actions.rs +++ b/crates/topola-egui/src/actions.rs @@ -373,6 +373,7 @@ pub struct DebugActions { pub show_topo_navmesh: Switch, pub show_bboxes: Switch, pub show_primitive_indices: Switch, + pub fix_update_timestep: Switch, } impl DebugActions { @@ -402,6 +403,8 @@ impl DebugActions { tr.text("tr-menu-debug-show-primitive-indices"), ) .into_switch(), + fix_update_timestep: Action::new_keyless(tr.text("tr-menu-debug-fix-step-rate")) + .into_switch(), } } @@ -422,6 +425,11 @@ impl DebugActions { self.show_bboxes.checkbox(ui, &mut menu_bar.show_bboxes); self.show_primitive_indices .checkbox(ui, &mut menu_bar.show_primitive_indices); + + ui.separator(); + + self.fix_update_timestep + .checkbox(ui, &mut menu_bar.fix_step_rate); } } diff --git a/crates/topola-egui/src/menu_bar.rs b/crates/topola-egui/src/menu_bar.rs index 160fbf2..5021cae 100644 --- a/crates/topola-egui/src/menu_bar.rs +++ b/crates/topola-egui/src/menu_bar.rs @@ -40,6 +40,7 @@ pub struct MenuBar { pub show_origin_destination: bool, pub show_primitive_indices: bool, pub show_appearance_panel: bool, + pub fix_step_rate: bool, pub update_timestep: f32, } @@ -74,7 +75,8 @@ impl MenuBar { show_origin_destination: false, show_primitive_indices: false, show_appearance_panel: true, - update_timestep: 0.1, + fix_step_rate: false, + update_timestep: 0.25, } } @@ -167,20 +169,13 @@ impl MenuBar { ui.menu_button(tr.text("tr-menu-debug"), |ui| { actions.debug.render_menu(ctx, ui, self); - ui.separator(); - - ui.label(tr.text("tr-menu-debug-frame-timestep")); - ui.add( - // NOTE: Frame timestep slider's minimal value - // should not go down to zero seconds because this - // will leave no time for the GUI to update until - // the currently performed action finishes, which - // may leave the GUI unresponsive during that time, - // or even freeze the application if the action - // fails to end in reasonable time. - egui::widgets::Slider::new(&mut self.update_timestep, 0.001..=3.0) - .suffix(" s"), - ); + ui.add_enabled_ui(self.fix_step_rate, |ui| { + ui.label(tr.text("tr-menu-debug-update-timestep")); + ui.add( + egui::widgets::Slider::new(&mut self.update_timestep, 0.01..=3.0) + .suffix(" s"), + ); + }); }); ui.menu_button(tr.text("tr-menu-help"), |ui| { diff --git a/crates/topola-egui/src/viewport.rs b/crates/topola-egui/src/viewport.rs index 8656768..f941bd7 100644 --- a/crates/topola-egui/src/viewport.rs +++ b/crates/topola-egui/src/viewport.rs @@ -69,7 +69,7 @@ impl Viewport { workspace.advance_state_by_dt( tr, error_dialog, - menu_bar.update_timestep, + menu_bar.fix_step_rate.then_some(menu_bar.update_timestep), &interactive_input, ); diff --git a/crates/topola-egui/src/workspace.rs b/crates/topola-egui/src/workspace.rs index 0948b05..7d20621 100644 --- a/crates/topola-egui/src/workspace.rs +++ b/crates/topola-egui/src/workspace.rs @@ -76,14 +76,21 @@ impl Workspace { &mut self, tr: &Translator, error_dialog: &mut ErrorDialog, - frame_timestep: f32, + maybe_update_timestep: Option, interactive_input: &InteractiveInput, ) -> bool { let instant = Instant::now(); - self.update_counter += interactive_input.dt; - while self.update_counter >= frame_timestep { - self.update_counter -= frame_timestep; + if maybe_update_timestep.is_some() { + self.update_counter += interactive_input.dt; + } + + while maybe_update_timestep + .is_none_or(|update_timestep| self.update_counter >= update_timestep) + { + if let Some(update_timestep) = maybe_update_timestep { + self.update_counter -= update_timestep; + } if let ControlFlow::Break(()) = self.update_state(tr, error_dialog, interactive_input) { return true; diff --git a/locales/en-US/main.ftl b/locales/en-US/main.ftl index b75ddf4..c324455 100644 --- a/locales/en-US/main.ftl +++ b/locales/en-US/main.ftl @@ -46,6 +46,7 @@ tr-menu-debug-show-pathfinding-scores = Show Pathfinding Scores tr-menu-debug-show-topo-navmesh = Show Topological Navmesh tr-menu-debug-show-bboxes = Show BBoxes tr-menu-debug-show-primitive-indices = Show Primitive Indices +tr-menu-debug-fix-step-rate = Fix Step Rate tr-menu-debug-update-timestep = Update Timestep tr-menu-help = Help