summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-04-11 22:35:52 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-04-11 22:35:52 +0200
commitf09cc7eb5e5f936292d002d5060c1e5354492953 (patch)
treefaf8115a91cdfa73431d1045dff157e3286b1086
parent7ff663338f2c5b26134abb8d7061514154716dcd (diff)
fff
-rw-r--r--main/draw.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/main/draw.cpp b/main/draw.cpp
index 6894973e..732c9cee 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -199,7 +199,7 @@ void main_impl::do_update()
_frame_time = _frame_time*(1-alpha) + alpha*dt;
}
static size_t ctr = 0;
- if (dt >= 1.f/55 && dt_expected.value < 1e-1f)
+ if (dt >= 1.f/55 && !dt_expected.do_sleep)
fm_debug("%zu frame took %.1f milliseconds", ctr++, dt*1e3f);
}
else
@@ -239,15 +239,16 @@ void main_impl::drawEvent()
swapBuffers();
redraw();
+ timeline.nextFrame();
if (dt_expected.do_sleep)
{
constexpr float ε = 1e-3f;
- const float Δt൦ = timeline.currentFrameDuration(), sleep_secs = dt_expected.value - Δt൦ - dt_expected.jitter;
+ const float Δt൦ = timeline.previousFrameDuration(), sleep_secs = dt_expected.value - Δt൦ - dt_expected.jitter;
if (sleep_secs > ε)
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);
- const float Δt = timeline.currentFrameDuration() - dt_expected.value;
+ const float Δt = timeline.previousFrameDuration() - dt_expected.value;
constexpr float α = .1f;
dt_expected.jitter = std::fmax(dt_expected.jitter + Δt * α,
dt_expected.jitter * (1-α) + Δt * α);
@@ -255,8 +256,6 @@ void main_impl::drawEvent()
}
else
dt_expected.jitter = 0;
-
- timeline.nextFrame();
}
ArrayView<const clickable> main_impl::clickable_scenery() const noexcept