[turbine/glfw] Fix mandatoryRefreshPeriodEnd tracking
All checks were successful
Build / build (push) Successful in 2m54s

This commit is contained in:
Gary Talent 2024-12-11 22:13:28 -06:00
parent 003f97201f
commit c488c336de
2 changed files with 7 additions and 7 deletions

View File

@ -78,17 +78,17 @@ static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept {
} }
static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept { static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window)); auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->mandatoryRefreshPeriodEnd = config::MandatoryRefreshPeriod; ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
} }
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept { static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window)); auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->mandatoryRefreshPeriodEnd = config::MandatoryRefreshPeriod; ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
if (action == GLFW_PRESS) { if (action == GLFW_PRESS) {
handleKeyPress(*ctx, key, true); handleKeyPress(ctx, key, true);
} else if (action == GLFW_RELEASE) { } else if (action == GLFW_RELEASE) {
handleKeyPress(*ctx, key, false); handleKeyPress(ctx, key, false);
} }
} }

View File

@ -88,7 +88,7 @@ ox::Error run(Context &ctx) noexcept {
tickFps(ctx, ticks); tickFps(ctx, ticks);
draw(ctx); draw(ctx);
auto const realSleepTime = ox::min(static_cast<uint64_t>(ctx.refreshWithinMs), sleepTime); auto const realSleepTime = ox::min(static_cast<uint64_t>(ctx.refreshWithinMs), sleepTime);
if (realSleepTime && ctx.mandatoryRefreshPeriodEnd >= ticks) { if (realSleepTime && ctx.mandatoryRefreshPeriodEnd <= ticks) {
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000); glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
} }
} }