[turbine] Fix refresh logic to handle default refresh within value
All checks were successful
Build / build (push) Successful in 2m36s

This commit is contained in:
Gary Talent 2024-06-17 22:37:36 -05:00
parent 6cf7bf9628
commit 3b874c6e6a
2 changed files with 9 additions and 7 deletions

View File

@ -14,7 +14,7 @@ namespace turbine {
class Context { class Context {
public: public:
UpdateHandler updateHandler = [](Context&) -> int {return 0;}; UpdateHandler updateHandler = [](Context&) -> int {return -1;};
keel::Context keelCtx; keel::Context keelCtx;
KeyEventHandler keyEventHandler = nullptr; KeyEventHandler keyEventHandler = nullptr;
ox::AnyPtr applicationData; ox::AnyPtr applicationData;

View File

@ -68,24 +68,26 @@ static void tickFps(Context &ctx, uint64_t nowMs) noexcept {
} }
ox::Error run(Context &ctx) noexcept { ox::Error run(Context &ctx) noexcept {
int sleepTime = 0; uint64_t sleepTime = 0;
while (!glfwWindowShouldClose(ctx.window)) { while (!glfwWindowShouldClose(ctx.window)) {
ctx.refreshWithinMs = 10 * 1000; // refresh within 10 seconds ctx.refreshWithinMs = 10 * 1000; // refresh within 10 seconds
glfwPollEvents(); glfwPollEvents();
auto const ticks = ticksMs(ctx); auto const ticks = ticksMs(ctx);
if (ctx.wakeupTime <= ticks) { if (ctx.wakeupTime <= ticks) {
sleepTime = ctx.updateHandler(ctx); auto const st = ctx.updateHandler(ctx);
if (sleepTime >= 0) { if (st >= 0) {
ctx.wakeupTime = ticks + static_cast<unsigned>(sleepTime); ctx.wakeupTime = ticks + static_cast<unsigned>(st);
sleepTime = static_cast<uint64_t>(st);
} else { } else {
ctx.wakeupTime = ~uint64_t(0); ctx.wakeupTime = ~uint64_t(0);
sleepTime = ctx.wakeupTime - ticks;
} }
} else { } else {
sleepTime = static_cast<int>(ctx.wakeupTime - ticks); sleepTime = ctx.wakeupTime - ticks;
} }
tickFps(ctx, ticks); tickFps(ctx, ticks);
draw(ctx); draw(ctx);
auto const realSleepTime = ox::min(ctx.refreshWithinMs, sleepTime); auto const realSleepTime = ox::min(static_cast<uint64_t>(ctx.refreshWithinMs), sleepTime);
if (realSleepTime) { if (realSleepTime) {
if (ctx.uninterruptedRefreshes) { if (ctx.uninterruptedRefreshes) {
--ctx.uninterruptedRefreshes; --ctx.uninterruptedRefreshes;