[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";
#ifndef OX_BARE_METAL
AssetManager assetManager;
int uninterruptedRefreshes = 0;
#endif
protected:
#ifndef OX_BARE_METAL

View File

@ -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

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 {
const auto ctx = static_cast<Context*>(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<GlfwImplData>();
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);