summaryrefslogtreecommitdiffhomepage
path: root/main
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-26 01:43:32 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-26 01:43:32 +0200
commit12f48dc702f3cb6a1ed8d8e1c51b00154667d372 (patch)
treea726ef5e5e25f9a70083ffa4d6ed01cdb8f37f62 /main
parentc8c70f05d00ef85c3e95e6d9f28756c85db785ba (diff)
fix underflow
Diffstat (limited to 'main')
-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