[turbine/glfw] Replace uninterruptedRefreshes with mandatoryRefreshPeriodEnd
Some checks failed
Build / build (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
This commit is contained in:
parent
7679403742
commit
ff05d860c4
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -88,12 +88,8 @@ 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 {
|
||||
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
|
||||
}
|
||||
if (realSleepTime && ctx.mandatoryRefreshPeriodEnd >= ticks) {
|
||||
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
|
||||
}
|
||||
}
|
||||
shutdown(ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user