diff --git a/src/nostalgia/core/glfw/core.cpp b/src/nostalgia/core/glfw/core.cpp index 8d8f0044..e3d33f48 100644 --- a/src/nostalgia/core/glfw/core.cpp +++ b/src/nostalgia/core/glfw/core.cpp @@ -30,19 +30,25 @@ ox::Result> init(ox::UniquePtr fs, const ox::Error run(Context *ctx) noexcept { const auto id = ctx->windowerData(); + int sleepTime = 0; while (!glfwWindowShouldClose(id->window)) { glfwPollEvents(); const auto ticks = ticksMs(ctx); - if (id->wakeupTime <= ticks && id->eventHandler) { - auto sleepTime = id->eventHandler(ctx); - if (sleepTime >= 0) { - id->wakeupTime = ticks + static_cast(sleepTime); - } else { - id->wakeupTime = ~uint64_t(0); + if (id->eventHandler) { + if (id->wakeupTime <= ticks) { + sleepTime = id->eventHandler(ctx); + if (sleepTime >= 0) { + id->wakeupTime = ticks + static_cast(sleepTime); + } else { + id->wakeupTime = ~uint64_t(0); + } } + } else { + sleepTime = 2; } draw(ctx); glfwSwapBuffers(id->window); + glfwWaitEventsTimeout(sleepTime); } // destroy GLFW window renderer::shutdown(ctx, ctx->rendererData()); diff --git a/src/nostalgia/core/glfw/gfx.cpp b/src/nostalgia/core/glfw/gfx.cpp index ef6a1714..7ce5f2c0 100644 --- a/src/nostalgia/core/glfw/gfx.cpp +++ b/src/nostalgia/core/glfw/gfx.cpp @@ -31,7 +31,7 @@ static void handleKeyPress(Context *ctx, int key) noexcept { } static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept { - const auto ctx = static_cast(glfwGetWindowUserPointer(window)); + const auto ctx = static_cast(glfwGetWindowUserPointer(window)); if (action == GLFW_PRESS) { handleKeyPress(ctx, key); }