feat(topola-egui): Add checkbox to toggle fixing of step rate

This commit is contained in:
Mikolaj Wielgus 2025-10-29 15:57:33 +01:00
parent 04293d9e4a
commit c163980073
5 changed files with 31 additions and 20 deletions

View File

@ -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);
}
}

View File

@ -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,21 +169,14 @@ 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_enabled_ui(self.fix_step_rate, |ui| {
ui.label(tr.text("tr-menu-debug-update-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)
egui::widgets::Slider::new(&mut self.update_timestep, 0.01..=3.0)
.suffix(" s"),
);
});
});
ui.menu_button(tr.text("tr-menu-help"), |ui| {
actions.help.render_menu(ctx, ui, online_documentation_url)

View File

@ -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,
);

View File

@ -76,14 +76,21 @@ impl Workspace {
&mut self,
tr: &Translator,
error_dialog: &mut ErrorDialog,
frame_timestep: f32,
maybe_update_timestep: Option<f32>,
interactive_input: &InteractiveInput,
) -> bool {
let instant = Instant::now();
if maybe_update_timestep.is_some() {
self.update_counter += interactive_input.dt;
while self.update_counter >= frame_timestep {
self.update_counter -= frame_timestep;
}
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;

View File

@ -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