[turbine/glfw] Treat close window event like other events with regard to a mandatory refresh period
Some checks are pending
Build / build (push) Waiting to run
Some checks are pending
Build / build (push) Waiting to run
This commit is contained in:
parent
cd43fb7f38
commit
88a6cd59f3
@ -93,6 +93,14 @@ static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handleGlfwWindowCloseEvent(GLFWwindow *window) noexcept {
|
||||||
|
auto &ctx = *static_cast<Context*>(glfwGetWindowUserPointer(window));
|
||||||
|
ctx.mandatoryRefreshPeriodEnd = ticksMs(ctx) + config::MandatoryRefreshPeriod;
|
||||||
|
ctx.running = !ctx.shutdownHandler(ctx);
|
||||||
|
glfwSetWindowShouldClose(window, !ctx.running);
|
||||||
|
glfwPostEmptyEvent();
|
||||||
|
}
|
||||||
|
|
||||||
#if TURBINE_USE_IMGUI
|
#if TURBINE_USE_IMGUI
|
||||||
static void themeImgui() noexcept {
|
static void themeImgui() noexcept {
|
||||||
// Dark Ruda style by Raikiri from ImThemes
|
// Dark Ruda style by Raikiri from ImThemes
|
||||||
@ -210,6 +218,7 @@ ox::Error initGfx(Context &ctx) noexcept {
|
|||||||
glfwSetCursorPosCallback(ctx.window, handleGlfwCursorPosEvent);
|
glfwSetCursorPosCallback(ctx.window, handleGlfwCursorPosEvent);
|
||||||
glfwSetMouseButtonCallback(ctx.window, handleGlfwMouseButtonEvent);
|
glfwSetMouseButtonCallback(ctx.window, handleGlfwMouseButtonEvent);
|
||||||
glfwSetKeyCallback(ctx.window, handleGlfwKeyEvent);
|
glfwSetKeyCallback(ctx.window, handleGlfwKeyEvent);
|
||||||
|
glfwSetWindowCloseCallback(ctx.window, handleGlfwWindowCloseEvent);
|
||||||
glfwSetWindowUserPointer(ctx.window, &ctx);
|
glfwSetWindowUserPointer(ctx.window, &ctx);
|
||||||
glfwMakeContextCurrent(ctx.window);
|
glfwMakeContextCurrent(ctx.window);
|
||||||
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress))) {
|
if (!gladLoadGLES2Loader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress))) {
|
||||||
|
@ -92,7 +92,7 @@ ox::Error run(Context &ctx) noexcept {
|
|||||||
ctx.wakeupTime = ticks + static_cast<unsigned>(st);
|
ctx.wakeupTime = ticks + static_cast<unsigned>(st);
|
||||||
sleepTime = static_cast<uint64_t>(st);
|
sleepTime = static_cast<uint64_t>(st);
|
||||||
} else {
|
} else {
|
||||||
ctx.wakeupTime = ~uint64_t(0);
|
ctx.wakeupTime = ~uint64_t{0};
|
||||||
sleepTime = ctx.wakeupTime - ticks;
|
sleepTime = ctx.wakeupTime - ticks;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -104,12 +104,6 @@ ox::Error run(Context &ctx) noexcept {
|
|||||||
if (realSleepTime && ctx.mandatoryRefreshPeriodEnd <= ticks) {
|
if (realSleepTime && ctx.mandatoryRefreshPeriodEnd <= ticks) {
|
||||||
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
|
glfwWaitEventsTimeout(static_cast<double>(realSleepTime) / 1000);
|
||||||
}
|
}
|
||||||
if (glfwWindowShouldClose(ctx.window)) {
|
|
||||||
if (ctx.shutdownHandler(ctx)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
glfwSetWindowShouldClose(ctx.window, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
shutdown(ctx);
|
shutdown(ctx);
|
||||||
return {};
|
return {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user