From ff05d860c453c85cf1078162c9e3c2a7f97884ff Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 10 Dec 2024 01:49:20 -0600 Subject: [PATCH] [turbine/glfw] Replace uninterruptedRefreshes with mandatoryRefreshPeriodEnd --- src/olympic/turbine/src/glfw/context.hpp | 2 +- src/olympic/turbine/src/glfw/gfx.cpp | 6 ++++-- src/olympic/turbine/src/glfw/turbine.cpp | 8 ++------ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/olympic/turbine/src/glfw/context.hpp b/src/olympic/turbine/src/glfw/context.hpp index 522e3c13..de760dad 100644 --- a/src/olympic/turbine/src/glfw/context.hpp +++ b/src/olympic/turbine/src/glfw/context.hpp @@ -20,7 +20,7 @@ class Context { ox::AnyPtr applicationData; // GLFW impl data //////////////////////////////////////////////////////// - int uninterruptedRefreshes = 3; + TimeMs mandatoryRefreshPeriodEnd{}; ox::UPtr clipboard; struct GLFWwindow *window = nullptr; int refreshWithinMs = 0; diff --git a/src/olympic/turbine/src/glfw/gfx.cpp b/src/olympic/turbine/src/glfw/gfx.cpp index 0b345165..89b937c0 100644 --- a/src/olympic/turbine/src/glfw/gfx.cpp +++ b/src/olympic/turbine/src/glfw/gfx.cpp @@ -72,14 +72,16 @@ static void handleKeyPress(Context &ctx, int key, bool down) noexcept { static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept { } +static constexpr TimeMs MandatoryRefreshPeriod = 168; + static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept { auto const ctx = static_cast(glfwGetWindowUserPointer(window)); - ctx->uninterruptedRefreshes = 25; + ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod; } static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept { auto const ctx = static_cast(glfwGetWindowUserPointer(window)); - ctx->uninterruptedRefreshes = 25; + ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod; if (action == GLFW_PRESS) { handleKeyPress(*ctx, key, true); } else if (action == GLFW_RELEASE) { diff --git a/src/olympic/turbine/src/glfw/turbine.cpp b/src/olympic/turbine/src/glfw/turbine.cpp index d8446064..4e4b540b 100644 --- a/src/olympic/turbine/src/glfw/turbine.cpp +++ b/src/olympic/turbine/src/glfw/turbine.cpp @@ -88,12 +88,8 @@ ox::Error run(Context &ctx) noexcept { tickFps(ctx, ticks); draw(ctx); auto const realSleepTime = ox::min(static_cast(ctx.refreshWithinMs), sleepTime); - if (realSleepTime) { - if (ctx.uninterruptedRefreshes) { - --ctx.uninterruptedRefreshes; - } else { - glfwWaitEventsTimeout(static_cast(realSleepTime) / 1000); - } + if (realSleepTime && ctx.mandatoryRefreshPeriodEnd >= ticks) { + glfwWaitEventsTimeout(static_cast(realSleepTime) / 1000); } } shutdown(ctx);