diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index 39c36ac5..3ae10330 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -57,6 +57,7 @@ class Context { const char *appName = "Nostalgia"; #ifndef OX_BARE_METAL AssetManager assetManager; + int uninterruptedRefreshes = 0; #endif protected: #ifndef OX_BARE_METAL diff --git a/src/nostalgia/core/glfw/core.cpp b/src/nostalgia/core/glfw/core.cpp index 48a43db5..fbf4b275 100644 --- a/src/nostalgia/core/glfw/core.cpp +++ b/src/nostalgia/core/glfw/core.cpp @@ -47,11 +47,11 @@ ox::Error run(Context *ctx) noexcept { draw(ctx); glfwSwapBuffers(id->window); if (!ctx->constantRefresh) { - // redraw before sleeping to update things that may have changed due - // to user input this round - draw(ctx); - glfwSwapBuffers(id->window); - glfwWaitEventsTimeout(sleepTime); + if (ctx->uninterruptedRefreshes) { + --ctx->uninterruptedRefreshes; + } else { + glfwWaitEventsTimeout(sleepTime); + } } } // destroy GLFW window diff --git a/src/nostalgia/core/glfw/gfx.cpp b/src/nostalgia/core/glfw/gfx.cpp index e539d2fa..fd7a8eec 100644 --- a/src/nostalgia/core/glfw/gfx.cpp +++ b/src/nostalgia/core/glfw/gfx.cpp @@ -33,8 +33,20 @@ static void handleKeyPress(Context *ctx, int key) noexcept { } } +static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept { +} + +static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept { + const auto ctx = static_cast(glfwGetWindowUserPointer(window)); + ctx->uninterruptedRefreshes = 10; +} + +static void handleGlfwWindowResize(GLFWwindow*, int, int) noexcept { +} + static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept { const auto ctx = static_cast(glfwGetWindowUserPointer(window)); + ctx->uninterruptedRefreshes = 2; if (action == GLFW_PRESS) { handleKeyPress(ctx, key); } @@ -48,7 +60,7 @@ ox::Error initGfx(Context *ctx) noexcept { auto id = ctx->windowerData(); glfwSetErrorCallback(handleGlfwError); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); if constexpr(ox::defines::OS == ox::OS::Darwin) { glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); @@ -58,6 +70,9 @@ ox::Error initGfx(Context *ctx) noexcept { if (id->window == nullptr) { return OxError(1, "Could not open GLFW window"); } + glfwSetCursorPosCallback(id->window, handleGlfwCursorPosEvent); + glfwSetMouseButtonCallback(id->window, handleGlfwMouseButtonEvent); + glfwSetWindowSizeCallback(id->window, handleGlfwWindowResize); glfwSetKeyCallback(id->window, handleGlfwKeyEvent); glfwSetWindowUserPointer(id->window, ctx); glfwMakeContextCurrent(id->window);