[nostalgia/core/glfw] Cleanup up main loop is running check to use GLFW

This commit is contained in:
Gary Talent 2021-07-17 01:37:45 -05:00
parent 43c67eacaa
commit 2be31cca5c
2 changed files with 2 additions and 9 deletions

View File

@ -23,7 +23,7 @@ static void handleKeyPress(Context *ctx, int key) {
switch (key) { switch (key) {
case GLFW_KEY_ESCAPE: case GLFW_KEY_ESCAPE:
case GLFW_KEY_Q: case GLFW_KEY_Q:
id->running = false; glfwSetWindowShouldClose(id->window, true);
break; break;
default: default:
break; break;
@ -50,13 +50,7 @@ ox::Error init(Context *ctx) noexcept {
ox::Error run(Context *ctx) noexcept { ox::Error run(Context *ctx) noexcept {
const auto id = ctx->windowerData<GlfwImplData>(); const auto id = ctx->windowerData<GlfwImplData>();
id->running = true; while (!glfwWindowShouldClose(id->window)) {
// try adaptive vsync
//if (SDL_GL_SetSwapInterval(config::SdlVsyncOption) < 0) {
// oxTrace("nostalgia::core::sdl", "Could not enable adaptive vsync, falling back on vsync");
// SDL_GL_SetSwapInterval(1); // fallback on normal vsync
//}
while (id->running && !glfwWindowShouldClose(id->window)) {
glfwPollEvents(); glfwPollEvents();
const auto ticks = ticksMs(ctx); const auto ticks = ticksMs(ctx);
if (id->wakeupTime <= ticks && id->eventHandler) { if (id->wakeupTime <= ticks && id->eventHandler) {

View File

@ -15,7 +15,6 @@ namespace nostalgia::core {
struct GlfwImplData { struct GlfwImplData {
struct GLFWwindow *window = nullptr; struct GLFWwindow *window = nullptr;
int64_t startTime = 0; int64_t startTime = 0;
bool running = false;
event_handler eventHandler = nullptr; event_handler eventHandler = nullptr;
uint64_t wakeupTime = 0; uint64_t wakeupTime = 0;
}; };