diff options
-rw-r--r-- | floormat/main.hpp | 4 | ||||
-rw-r--r-- | main/draw.cpp | 20 | ||||
-rw-r--r-- | main/main-impl.hpp | 2 |
3 files changed, 15 insertions, 11 deletions
diff --git a/floormat/main.hpp b/floormat/main.hpp index b80ac289..1854010e 100644 --- a/floormat/main.hpp +++ b/floormat/main.hpp @@ -45,7 +45,7 @@ struct floormat_main virtual Magnum::Math::Vector2<int> window_size() const noexcept; virtual tile_shader& shader() noexcept = 0; virtual const tile_shader& shader() const noexcept = 0; - constexpr float smoothed_dt() const noexcept { return _frame_time1; } + constexpr float smoothed_dt() const noexcept { return _frame_time; } virtual fm_settings& settings() noexcept = 0; virtual const fm_settings& settings() const noexcept = 0; @@ -75,7 +75,7 @@ struct floormat_main [[maybe_unused]] static void debug_break(); protected: - float _frame_time1 = 0, _frame_time2 = 0; + float _frame_time = 0; Vector2 _dpi_scale{1, 1}, _virtual_scale{1, 1}; Vector2i _framebuffer_size; }; diff --git a/main/draw.cpp b/main/draw.cpp index f388b60e..56f4b61e 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -62,6 +62,8 @@ void main_impl::recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept // -- user-- app.on_viewport_event(fb_size); + + fps_sample_timeline.start(); } global_coords main_impl::pixel_to_tile(Vector2d position) const noexcept @@ -189,15 +191,15 @@ void main_impl::do_update() float dt = timeline.previousFrameDuration(); if (dt > 0) { - const float RC1 = dt_expected.do_sleep ? 1.f : 1.f/5, RC2 = 1.f/10; - const float alpha1 = dt/(dt + RC1); - const float alpha2 = dt/(dt + RC2); - - _frame_time1 = _frame_time1*(1-alpha1) + alpha1*dt; - _frame_time2 = _frame_time1*(1-alpha2) + alpha2*dt; - constexpr float max_deviation = 5 * 1e-3f; - if (std::fabs(_frame_time1 - _frame_time2) > max_deviation) - _frame_time1 = _frame_time2; + if (fps_sample_timeline.currentFrameDuration() > 1.f/15) + { + fps_sample_timeline.nextFrame(); + constexpr float RC = 10; + const float alpha = 1/(1 + RC); + _frame_time = _frame_time*(1-alpha) + alpha*dt; + } + if (dt >= 1.f/55 && dt_expected.value < 1e-1f) + fm_debug("frame took %.1f milliseconds", dt*1e3f); } else { diff --git a/main/main-impl.hpp b/main/main-impl.hpp index 20b1aa41..fc20c947 100644 --- a/main/main-impl.hpp +++ b/main/main-impl.hpp @@ -112,6 +112,8 @@ private: bool do_sleep = false; } dt_expected; + Timeline fps_sample_timeline; + void recalc_viewport(Vector2i fb_size, Vector2i win_size) noexcept; void draw_world() noexcept; |