[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;
|
ox::AnyPtr applicationData;
|
||||||
|
|
||||||
// GLFW impl data ////////////////////////////////////////////////////////
|
// GLFW impl data ////////////////////////////////////////////////////////
|
||||||
int uninterruptedRefreshes = 3;
|
TimeMs mandatoryRefreshPeriodEnd{};
|
||||||
ox::UPtr<BaseClipboardObject> clipboard;
|
ox::UPtr<BaseClipboardObject> clipboard;
|
||||||
struct GLFWwindow *window = nullptr;
|
struct GLFWwindow *window = nullptr;
|
||||||
int refreshWithinMs = 0;
|
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 void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr TimeMs MandatoryRefreshPeriod = 168;
|
||||||
|
|
||||||
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 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 {
|
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
|
||||||
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
|
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
|
||||||
ctx->uninterruptedRefreshes = 25;
|
ctx->mandatoryRefreshPeriodEnd = 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) {
|
||||||
|
@ -88,12 +88,8 @@ 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) {
|
if (realSleepTime && ctx.mandatoryRefreshPeriodEnd >= ticks) {
|
||||||
if (ctx.uninterruptedRefreshes) {
|
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
|
||||||
--ctx.uninterruptedRefreshes;
|
|
||||||
} else {
|
|
||||||
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shutdown(ctx);
|
shutdown(ctx);
|
||||||
|
Loading…
Reference in New Issue
Block a user