[turbine] Fix refresh logic to handle default refresh within value
All checks were successful
Build / build (push) Successful in 2m36s
All checks were successful
Build / build (push) Successful in 2m36s
This commit is contained in:
parent
6cf7bf9628
commit
3b874c6e6a
@ -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;
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user