[turbine/glfw] Replace uninterruptedRefreshes with mandatoryRefreshPeriodEnd
Some checks failed
Build / build (push) Has been cancelled

This commit is contained in:
Gary Talent 2024-12-10 01:49:20 -06:00
parent 7679403742
commit ff05d860c4
3 changed files with 7 additions and 9 deletions

View File

@ -20,7 +20,7 @@ class Context {
ox::AnyPtr applicationData;
// GLFW impl data ////////////////////////////////////////////////////////
int uninterruptedRefreshes = 3;
TimeMs mandatoryRefreshPeriodEnd{};
ox::UPtr<BaseClipboardObject> clipboard;
struct GLFWwindow *window = nullptr;
int refreshWithinMs = 0;

View File

@ -72,14 +72,16 @@ static void handleKeyPress(Context &ctx, int key, bool down) noexcept {
static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept {
}
static constexpr TimeMs MandatoryRefreshPeriod = 168;
static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->uninterruptedRefreshes = 25;
ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod;
}
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->uninterruptedRefreshes = 25;
ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod;
if (action == GLFW_PRESS) {
handleKeyPress(*ctx, key, true);
} else if (action == GLFW_RELEASE) {

View File

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