diff --git a/src/framework/core/adaptativeframecounter.cpp b/src/framework/core/adaptativeframecounter.cpp index a349a3ec77..f4c09f357c 100644 --- a/src/framework/core/adaptativeframecounter.cpp +++ b/src/framework/core/adaptativeframecounter.cpp @@ -26,7 +26,7 @@ bool AdaptativeFrameCounter::update() { - const uint8_t maxFps = m_targetFps == 0 ? m_maxFps : std::clamp(m_targetFps, 1, std::max(m_maxFps, m_targetFps)); + const auto maxFps = m_targetFps == 0 ? m_maxFps : std::clamp(m_targetFps, 1, std::max(m_maxFps, m_targetFps)); if (maxFps > 0) { const int32_t sleepPeriod = (getMaxPeriod(maxFps) - 1000) - m_timer.elapsed_micros(); if (sleepPeriod > 0) stdext::microsleep(sleepPeriod); diff --git a/src/framework/core/adaptativeframecounter.h b/src/framework/core/adaptativeframecounter.h index 9f0638102d..97b584431f 100644 --- a/src/framework/core/adaptativeframecounter.h +++ b/src/framework/core/adaptativeframecounter.h @@ -36,8 +36,8 @@ class AdaptativeFrameCounter bool update(); uint16_t getFps() const { return m_fps; } - uint8_t getMaxFps() const { return m_maxFps; } - uint8_t getTargetFps() const { return m_targetFps; } + uint16_t getMaxFps() const { return m_maxFps; } + uint16_t getTargetFps() const { return m_targetFps; } void setMaxFps(const uint16_t max) { m_maxFps = max; } void setTargetFps(const uint16_t target) { m_targetFps = target; } @@ -45,8 +45,8 @@ class AdaptativeFrameCounter void resetTargetFps() { m_targetFps = 0; } float getPercent() const { - const auto maxFps = std::clamp(m_targetFps, 1, std::max(m_maxFps, m_targetFps)); - return ((maxFps - m_fps) * 100) / static_cast(m_fps); + const float maxFps = std::clamp(m_targetFps, 1, std::max(m_maxFps, m_targetFps)); + return ((maxFps - m_fps) / maxFps) * 100.f; } float getFpsPercent(float percent) const { diff --git a/src/framework/core/graphicalapplication.cpp b/src/framework/core/graphicalapplication.cpp index c915484365..64eb40cfbb 100644 --- a/src/framework/core/graphicalapplication.cpp +++ b/src/framework/core/graphicalapplication.cpp @@ -163,9 +163,9 @@ void GraphicalApplication::run() if (g_window.vsyncEnabled() || getMaxFps() || getTargetFps()) { // get min fps between the two threads return std::min(m_frameCounter.getFps(), frameCounter2.getFps()); - } else { - return std::max(10, getFps() - m_frameCounter.getFpsPercent(frameCounter2.getPercent())); } + + return std::max(10, getFps() - m_frameCounter.getFpsPercent(frameCounter2.getPercent())); }; g_asyncDispatcher.dispatch([&] { diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index f7b6a29a94..01edabfbf1 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -936,8 +936,11 @@ void WIN32Window::setFullscreen(bool fullscreen) void WIN32Window::setVerticalSync(bool enable) { - g_mainDispatcher.addEvent([&, enable] { - m_vsync = enable; + if (m_vsync == enable) + return; + + m_vsync = enable; + g_mainDispatcher.addEvent([this, enable] { #ifdef OPENGL_ES eglSwapInterval(m_eglDisplay, enable); #else @@ -950,7 +953,7 @@ void WIN32Window::setVerticalSync(bool enable) wglSwapInterval(enable); #endif - }); +}); } void WIN32Window::setIcon(const std::string& file)