summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main/main-impl.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/main/main-impl.cpp b/main/main-impl.cpp
index f4593344..d2ea74cc 100644
--- a/main/main-impl.cpp
+++ b/main/main-impl.cpp
@@ -244,17 +244,20 @@ void main_impl::drawEvent()
#ifdef _WIN32
constexpr float eps = 1e-3f;
#else
- constexpr float eps = 2e-4f;
+ constexpr float eps = 1e-4f;
#endif
- const float dt0 = timeline.currentFrameDuration(), sleep_secs = dt_expected.value - dt0 - dt_expected.jitter;
+ const float Δt൦ = timeline.currentFrameDuration(), sleep_secs = dt_expected.value - Δt൦ - dt_expected.jitter;
if (sleep_secs > eps)
{
//fm_debug("sleeping for %.1f <- %.1f\n", sleep_secs*1000, dt0*1000);
std::this_thread::sleep_for(std::chrono::nanoseconds((long long)(sleep_secs * 1e9f)));
}
//fm_debug("jitter:%.1f sleep:%.0f", dt_expected.jitter*1000, sleep_secs*1000);
- dt_expected.jitter += 0.1f * (timeline.currentFrameDuration() - dt_expected.value);
+ const float Δt = (timeline.currentFrameDuration() - dt_expected.value);
+ constexpr float α = .1f;
+ dt_expected.jitter = std::fmax(dt_expected.jitter + Δt * α,
+ dt_expected.jitter * (1-α) + Δt * α);
dt_expected.jitter = std::copysignf(std::fminf(dt_expected.value, std::fabsf(dt_expected.jitter)), dt_expected.jitter);
}
else