[nostalgia/core] Make clicks trigger 10 refreshes

This commit is contained in:
Gary Talent 2022-03-05 11:39:46 -06:00
parent 4966aaffe4
commit 921cb97a14
3 changed files with 22 additions and 6 deletions

View File

@ -57,6 +57,7 @@ class Context {
const char *appName = "Nostalgia"; const char *appName = "Nostalgia";
#ifndef OX_BARE_METAL #ifndef OX_BARE_METAL
AssetManager assetManager; AssetManager assetManager;
int uninterruptedRefreshes = 0;
#endif #endif
protected: protected:
#ifndef OX_BARE_METAL #ifndef OX_BARE_METAL

View File

@ -47,13 +47,13 @@ ox::Error run(Context *ctx) noexcept {
draw(ctx); draw(ctx);
glfwSwapBuffers(id->window); glfwSwapBuffers(id->window);
if (!ctx->constantRefresh) { if (!ctx->constantRefresh) {
// redraw before sleeping to update things that may have changed due if (ctx->uninterruptedRefreshes) {
// to user input this round --ctx->uninterruptedRefreshes;
draw(ctx); } else {
glfwSwapBuffers(id->window);
glfwWaitEventsTimeout(sleepTime); glfwWaitEventsTimeout(sleepTime);
} }
} }
}
// destroy GLFW window // destroy GLFW window
renderer::shutdown(ctx, ctx->rendererData<void>()); renderer::shutdown(ctx, ctx->rendererData<void>());
glfwDestroyWindow(id->window); glfwDestroyWindow(id->window);

View File

@ -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<Context*>(glfwGetWindowUserPointer(window));
ctx->uninterruptedRefreshes = 10;
}
static void handleGlfwWindowResize(GLFWwindow*, int, int) noexcept {
}
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept { static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
const auto ctx = static_cast<Context*>(glfwGetWindowUserPointer(window)); const auto ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->uninterruptedRefreshes = 2;
if (action == GLFW_PRESS) { if (action == GLFW_PRESS) {
handleKeyPress(ctx, key); handleKeyPress(ctx, key);
} }
@ -48,7 +60,7 @@ ox::Error initGfx(Context *ctx) noexcept {
auto id = ctx->windowerData<GlfwImplData>(); auto id = ctx->windowerData<GlfwImplData>();
glfwSetErrorCallback(handleGlfwError); glfwSetErrorCallback(handleGlfwError);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 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); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
if constexpr(ox::defines::OS == ox::OS::Darwin) { if constexpr(ox::defines::OS == ox::OS::Darwin) {
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
@ -58,6 +70,9 @@ ox::Error initGfx(Context *ctx) noexcept {
if (id->window == nullptr) { if (id->window == nullptr) {
return OxError(1, "Could not open GLFW window"); return OxError(1, "Could not open GLFW window");
} }
glfwSetCursorPosCallback(id->window, handleGlfwCursorPosEvent);
glfwSetMouseButtonCallback(id->window, handleGlfwMouseButtonEvent);
glfwSetWindowSizeCallback(id->window, handleGlfwWindowResize);
glfwSetKeyCallback(id->window, handleGlfwKeyEvent); glfwSetKeyCallback(id->window, handleGlfwKeyEvent);
glfwSetWindowUserPointer(id->window, ctx); glfwSetWindowUserPointer(id->window, ctx);
glfwMakeContextCurrent(id->window); glfwMakeContextCurrent(id->window);