From 3b874c6e6aa0b80783fc9d712c31bc837326337c Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 17 Jun 2024 22:37:36 -0500 Subject: [PATCH] [turbine] Fix refresh logic to handle default refresh within value --- src/olympic/turbine/src/glfw/context.hpp | 2 +- src/olympic/turbine/src/glfw/turbine.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/olympic/turbine/src/glfw/context.hpp b/src/olympic/turbine/src/glfw/context.hpp index 8e208960..522e3c13 100644 --- a/src/olympic/turbine/src/glfw/context.hpp +++ b/src/olympic/turbine/src/glfw/context.hpp @@ -14,7 +14,7 @@ namespace turbine { class Context { public: - UpdateHandler updateHandler = [](Context&) -> int {return 0;}; + UpdateHandler updateHandler = [](Context&) -> int {return -1;}; keel::Context keelCtx; KeyEventHandler keyEventHandler = nullptr; ox::AnyPtr applicationData; diff --git a/src/olympic/turbine/src/glfw/turbine.cpp b/src/olympic/turbine/src/glfw/turbine.cpp index 4ad5d263..fb307e6d 100644 --- a/src/olympic/turbine/src/glfw/turbine.cpp +++ b/src/olympic/turbine/src/glfw/turbine.cpp @@ -68,24 +68,26 @@ static void tickFps(Context &ctx, uint64_t nowMs) noexcept { } ox::Error run(Context &ctx) noexcept { - int sleepTime = 0; + uint64_t sleepTime = 0; while (!glfwWindowShouldClose(ctx.window)) { ctx.refreshWithinMs = 10 * 1000; // refresh within 10 seconds glfwPollEvents(); auto const ticks = ticksMs(ctx); if (ctx.wakeupTime <= ticks) { - sleepTime = ctx.updateHandler(ctx); - if (sleepTime >= 0) { - ctx.wakeupTime = ticks + static_cast(sleepTime); + auto const st = ctx.updateHandler(ctx); + if (st >= 0) { + ctx.wakeupTime = ticks + static_cast(st); + sleepTime = static_cast(st); } else { ctx.wakeupTime = ~uint64_t(0); + sleepTime = ctx.wakeupTime - ticks; } } else { - sleepTime = static_cast(ctx.wakeupTime - ticks); + sleepTime = ctx.wakeupTime - ticks; } tickFps(ctx, ticks); draw(ctx); - auto const realSleepTime = ox::min(ctx.refreshWithinMs, sleepTime); + auto const realSleepTime = ox::min(static_cast(ctx.refreshWithinMs), sleepTime); if (realSleepTime) { if (ctx.uninterruptedRefreshes) { --ctx.uninterruptedRefreshes;