diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-01 21:24:25 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-01 21:33:19 +0100 |
commit | fd9f2776417e62c4ca4061f540a7d3afde114c3e (patch) | |
tree | 748615f442594587d6702594f317e0f283d56f1a /main | |
parent | 52b8ef97891061fcf4e57a7f07b6e1b4e1898f2b (diff) |
start implementing renderer window state again
Diffstat (limited to 'main')
-rw-r--r-- | main/main-impl.hpp | 19 | ||||
-rw-r--r-- | main/setup.cpp | 36 |
2 files changed, 44 insertions, 11 deletions
diff --git a/main/main-impl.hpp b/main/main-impl.hpp index 12169d6a..f87bd5fc 100644 --- a/main/main-impl.hpp +++ b/main/main-impl.hpp @@ -107,11 +107,19 @@ private: { static constexpr unsigned min_refresh_rate = 20; - unsigned refresh_rate = min_refresh_rate; - float smoothed_frame_time = 0; - bool vsync : 1 = false; - bool minimized : 1 = false; - bool focused : 1 = true; + unsigned refresh_rate; + float smoothed_frame_time; + bool vsync : 1; + bool minimized : 1; + bool focused : 1; + }; + + frame_timings_s _frame_timings = { + .refresh_rate = frame_timings_s::min_refresh_rate, + .smoothed_frame_time = 0, + .vsync = false, + .minimized = false, + .focused = true, }; Time timeline; @@ -125,7 +133,6 @@ private: Array<clickable> _clickable_scenery; class world _world{}; uint32_t _mouse_cursor = (uint32_t)-1; - frame_timings_s _frame_timings; ground_mesh _ground_mesh; wall_mesh _wall_mesh; anim_mesh _anim_mesh; diff --git a/main/setup.cpp b/main/setup.cpp index 82fbb9b0..b61e411b 100644 --- a/main/setup.cpp +++ b/main/setup.cpp @@ -112,19 +112,45 @@ unsigned get_window_refresh_rate(SDL_Window* window, unsigned min, unsigned max) fm_warn_once("SDL_GetCurrentDisplayMode: %s", SDL_GetError()); else { - fm_assert(dpymode.refresh_rate > 0 && dpymode.refresh_rate < max); - return (unsigned)dpymode.refresh_rate; + auto hz = (unsigned)dpymode.refresh_rate; + fm_assert(dpymode.refresh_rate > 0); + fm_assert(hz < max); + return hz; } return min; } void main_impl::update_window_state() // todo window minimized, out of focus, fake vsync etc { - auto refresh_rate = get_window_refresh_rate(window(), _frame_timings.min_refresh_rate, 10000); - fm_assert(refresh_rate > 0 && refresh_rate < 1000); + constexpr auto b = [](bool x) { return x ? "1" : "0"; }; + const auto flags = (SDL_WindowFlags)SDL_GetWindowFlags(window()); + + int interval = std::abs(SDL_GL_GetSwapInterval()); + bool vsync = interval != 0; + //bool vsync = s.vsync ? interval != 0 : false; + if (interval < 0) [[unlikely]] + fm_warn_once("bad swap interval %d", interval); + + auto hz = get_window_refresh_rate(window(), _frame_timings.min_refresh_rate, 10000); + bool hidden = flags & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED); + bool focused = flags & SDL_WINDOW_INPUT_FOCUS; + focused &= !hidden; + + fm_assert(hz > 0 && hz < 1000); _frame_timings = { - .refresh_rate = refresh_rate, + .refresh_rate = hz, + .smoothed_frame_time = 0, + .vsync = vsync, + .minimized = hidden, + .focused = focused, }; + +#if 0 + DBG_nospace << "window:" + << " " << _framebuffer_size.x() << "x" << _framebuffer_size.y() + << " hz:" << hz << " vsync:" << b(vsync) + << " focused:" << b(focused) << " hidden:" << b(hidden); +#endif } auto main_impl::meshes() noexcept -> struct meshes |