Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This provides a better estimate of a typical frametime in reactive mode.
Summary: when animating things, stop using
unstable_dt
and start usingstable_dt.min(0.1)
.From the docstring of
stable_dt
:Time since last frame (in seconds), but gracefully handles the first frame after sleeping in reactive mode.
In reactive mode (available in e.g.
eframe
),egui
only updates when there is new inputor something is animating.
This can lead to large gaps of time (sleep), leading to large [
Self::unstable_dt
].If
egui
requested a repaint the previous frame, thenegui
will usestable_dt = unstable_dt;
, but ifegui
did not not request a repaint last frame,then
egui
will assumeunstable_dt
is too large, and will usestable_dt = predicted_dt;
.This means that for the first frame after a sleep,
stable_dt
will be a prediction of the delta-time until the next frame,and in all other situations this will be an accurate measurement of time passed
since the previous frame.
Note that a frame can still stall for various reasons, so
stable_dt
canstill be unusually large in some situations.
When animating something, it is recommended that you use something like
stable_dt.min(0.1)
- this will give you smooth animations when the framerate is good(even in reactive mode), but will avoid large jumps when framerate is bad,
and will effectively slow down the animation when FPS drops below 10.