mirror of https://codeberg.org/topola/topola.git
feat(topola-egui): Add checkbox to toggle fixing of step rate
This commit is contained in:
parent
04293d9e4a
commit
c163980073
|
|
@ -373,6 +373,7 @@ pub struct DebugActions {
|
||||||
pub show_topo_navmesh: Switch,
|
pub show_topo_navmesh: Switch,
|
||||||
pub show_bboxes: Switch,
|
pub show_bboxes: Switch,
|
||||||
pub show_primitive_indices: Switch,
|
pub show_primitive_indices: Switch,
|
||||||
|
pub fix_update_timestep: Switch,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DebugActions {
|
impl DebugActions {
|
||||||
|
|
@ -402,6 +403,8 @@ impl DebugActions {
|
||||||
tr.text("tr-menu-debug-show-primitive-indices"),
|
tr.text("tr-menu-debug-show-primitive-indices"),
|
||||||
)
|
)
|
||||||
.into_switch(),
|
.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_bboxes.checkbox(ui, &mut menu_bar.show_bboxes);
|
||||||
self.show_primitive_indices
|
self.show_primitive_indices
|
||||||
.checkbox(ui, &mut menu_bar.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ pub struct MenuBar {
|
||||||
pub show_origin_destination: bool,
|
pub show_origin_destination: bool,
|
||||||
pub show_primitive_indices: bool,
|
pub show_primitive_indices: bool,
|
||||||
pub show_appearance_panel: bool,
|
pub show_appearance_panel: bool,
|
||||||
|
pub fix_step_rate: bool,
|
||||||
pub update_timestep: f32,
|
pub update_timestep: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +75,8 @@ impl MenuBar {
|
||||||
show_origin_destination: false,
|
show_origin_destination: false,
|
||||||
show_primitive_indices: false,
|
show_primitive_indices: false,
|
||||||
show_appearance_panel: true,
|
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| {
|
ui.menu_button(tr.text("tr-menu-debug"), |ui| {
|
||||||
actions.debug.render_menu(ctx, ui, self);
|
actions.debug.render_menu(ctx, ui, self);
|
||||||
|
|
||||||
ui.separator();
|
ui.add_enabled_ui(self.fix_step_rate, |ui| {
|
||||||
|
ui.label(tr.text("tr-menu-debug-update-timestep"));
|
||||||
ui.label(tr.text("tr-menu-debug-frame-timestep"));
|
ui.add(
|
||||||
ui.add(
|
egui::widgets::Slider::new(&mut self.update_timestep, 0.01..=3.0)
|
||||||
// NOTE: Frame timestep slider's minimal value
|
.suffix(" s"),
|
||||||
// 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.menu_button(tr.text("tr-menu-help"), |ui| {
|
ui.menu_button(tr.text("tr-menu-help"), |ui| {
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ impl Viewport {
|
||||||
workspace.advance_state_by_dt(
|
workspace.advance_state_by_dt(
|
||||||
tr,
|
tr,
|
||||||
error_dialog,
|
error_dialog,
|
||||||
menu_bar.update_timestep,
|
menu_bar.fix_step_rate.then_some(menu_bar.update_timestep),
|
||||||
&interactive_input,
|
&interactive_input,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,14 +76,21 @@ impl Workspace {
|
||||||
&mut self,
|
&mut self,
|
||||||
tr: &Translator,
|
tr: &Translator,
|
||||||
error_dialog: &mut ErrorDialog,
|
error_dialog: &mut ErrorDialog,
|
||||||
frame_timestep: f32,
|
maybe_update_timestep: Option<f32>,
|
||||||
interactive_input: &InteractiveInput,
|
interactive_input: &InteractiveInput,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let instant = Instant::now();
|
let instant = Instant::now();
|
||||||
|
|
||||||
self.update_counter += interactive_input.dt;
|
if maybe_update_timestep.is_some() {
|
||||||
while self.update_counter >= frame_timestep {
|
self.update_counter += interactive_input.dt;
|
||||||
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) {
|
if let ControlFlow::Break(()) = self.update_state(tr, error_dialog, interactive_input) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -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-topo-navmesh = Show Topological Navmesh
|
||||||
tr-menu-debug-show-bboxes = Show BBoxes
|
tr-menu-debug-show-bboxes = Show BBoxes
|
||||||
tr-menu-debug-show-primitive-indices = Show Primitive Indices
|
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-debug-update-timestep = Update Timestep
|
||||||
|
|
||||||
tr-menu-help = Help
|
tr-menu-help = Help
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue