mirror of https://codeberg.org/topola/topola.git
fix(topola-egui): Add another condition to prevent stuttering
This commit is contained in:
parent
ba5a254e11
commit
b9f7d4ec4f
|
|
@ -59,6 +59,8 @@ impl Viewport {
|
||||||
if i.stable_dt <= i.predicted_dt {
|
if i.stable_dt <= i.predicted_dt {
|
||||||
i.stable_dt
|
i.stable_dt
|
||||||
} else {
|
} else {
|
||||||
|
// Clamp dt to egui's predicted dt to
|
||||||
|
// additionally safeguard against stuttering.
|
||||||
i.predicted_dt
|
i.predicted_dt
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
ops::ControlFlow,
|
ops::ControlFlow,
|
||||||
sync::mpsc::{channel, Receiver, Sender},
|
sync::mpsc::{channel, Receiver, Sender},
|
||||||
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use topola::{
|
use topola::{
|
||||||
|
|
@ -77,14 +78,26 @@ impl Workspace {
|
||||||
error_dialog: &mut ErrorDialog,
|
error_dialog: &mut ErrorDialog,
|
||||||
frame_timestep: f32,
|
frame_timestep: f32,
|
||||||
interactive_input: &InteractiveInput,
|
interactive_input: &InteractiveInput,
|
||||||
) {
|
) -> bool {
|
||||||
|
let instant = Instant::now();
|
||||||
|
|
||||||
self.update_counter += interactive_input.dt;
|
self.update_counter += interactive_input.dt;
|
||||||
while self.update_counter >= frame_timestep {
|
while self.update_counter >= frame_timestep {
|
||||||
self.update_counter -= frame_timestep;
|
self.update_counter -= frame_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) {
|
||||||
break;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hard limit: never spend more time on advancing state than the
|
||||||
|
// duration of last frame to prevent stuttering.
|
||||||
|
// Of course, this does not safeguard against infinite loops.
|
||||||
|
if instant.elapsed().as_secs_f32() >= interactive_input.dt {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_state_for_event(
|
pub fn update_state_for_event(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue