diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/draw.cpp | 20 | ||||
-rw-r--r-- | main/main-impl.hpp | 1 | ||||
-rw-r--r-- | main/setup.cpp | 7 |
3 files changed, 28 insertions, 0 deletions
diff --git a/main/draw.cpp b/main/draw.cpp index 8d7f9ab7..1de1bd50 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -215,8 +215,13 @@ bool floormat_main::check_chunk_visible(const Vector2d& offset, const Vector2i& return X + W > 0 && X < size[x] && Y + H > 0 && Y < size[y]; } +#ifndef FM_NO_DEBUG +static size_t good_frames, bad_frames; +#endif + void main_impl::do_update() { + float dt = timeline.previousFrameDuration(); if (dt > 0) { @@ -238,7 +243,22 @@ void main_impl::do_update() } if (auto d = Math::abs(dt - dt_expected.value); d <= 4e-3f) + { dt = dt_expected.value + 1e-6f; +#ifndef FM_NO_DEBUG + ++good_frames; +#endif + } +#ifndef FM_NO_DEBUG + else if (dt_expected.has_focus && dt_expected.do_sleep) [[unlikely]] + { + if (good_frames) + { + DBG_nospace << ++bad_frames << " bad frame " << d << ", expected:" << dt_expected.value << " good-frames:" << good_frames; + good_frames = 0; + } + } +#endif dt = Math::clamp(dt, 1e-5f, Math::max(.2f, dt_expected.value)); diff --git a/main/main-impl.hpp b/main/main-impl.hpp index ecfa17f7..0f1bae35 100644 --- a/main/main-impl.hpp +++ b/main/main-impl.hpp @@ -125,6 +125,7 @@ private: float value = 0; float jitter = 0; bool do_sleep = false; + bool has_focus = true; } dt_expected; Timeline fps_sample_timeline; diff --git a/main/setup.cpp b/main/setup.cpp index a413d8b6..a16165ba 100644 --- a/main/setup.cpp +++ b/main/setup.cpp @@ -61,13 +61,20 @@ void main_impl::update_window_state() dt_expected.do_sleep = true; dt_expected.jitter = 0; + dt_expected.has_focus = true; if (flags & SDL_WINDOW_HIDDEN) + { + dt_expected.has_focus = false; dt_expected.value = 1; + } else if (int interval = std::abs(SDL_GL_GetSwapInterval()); s.vsync && interval > 0) { int hz = get_window_refresh_rate(window()) / interval; if (!(flags & SDL_WINDOW_INPUT_FOCUS)) + { dt_expected.value = 2.f / hz; + dt_expected.has_focus = false; + } else dt_expected.value = 1.f/hz; } |