[turbine/glfw] Move MandatoryRefreshPeriod to config.hpp
All checks were successful
Build / build (push) Successful in 2m45s

This commit is contained in:
Gary Talent 2024-12-10 23:29:50 -06:00
parent d85a10af84
commit 003f97201f
2 changed files with 15 additions and 9 deletions

View File

@ -4,8 +4,11 @@
#pragma once #pragma once
#include <turbine/turbine.hpp>
namespace turbine::config { namespace turbine::config {
constexpr bool GlFpsPrint = TURBINE_GL_FPS_PRINT; inline constexpr bool GlFpsPrint = TURBINE_GL_FPS_PRINT;
inline constexpr TimeMs MandatoryRefreshPeriod = 168;
} }

View File

@ -9,6 +9,8 @@
#include <imgui_impl_opengl3.h> #include <imgui_impl_opengl3.h>
#endif #endif
#include "config.hpp"
#include <ox/std/span.hpp> #include <ox/std/span.hpp>
#include "context.hpp" #include "context.hpp"
@ -62,26 +64,27 @@ static void handleKeyPress(Context &ctx, int key, bool down) noexcept {
return map; return map;
}(); }();
auto const eventHandler = keyEventHandler(ctx); auto const eventHandler = keyEventHandler(ctx);
auto const k = keyMap[static_cast<std::size_t>(key)]; auto const keyIdx = static_cast<std::size_t>(key);
setKeyDownStatus(ctx, k, down); if (keyIdx < keyMap.size()) {
if (eventHandler) { auto const k = keyMap[keyIdx];
eventHandler(ctx, k, down); setKeyDownStatus(ctx, k, down);
if (eventHandler) {
eventHandler(ctx, k, down);
}
} }
} }
static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept { static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept {
} }
static constexpr TimeMs MandatoryRefreshPeriod = 168;
static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept { static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window)); auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod; ctx->mandatoryRefreshPeriodEnd = config::MandatoryRefreshPeriod;
} }
static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept { static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept {
auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window)); auto const ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod; ctx->mandatoryRefreshPeriodEnd = config::MandatoryRefreshPeriod;
if (action == GLFW_PRESS) { if (action == GLFW_PRESS) {
handleKeyPress(*ctx, key, true); handleKeyPress(*ctx, key, true);
} else if (action == GLFW_RELEASE) { } else if (action == GLFW_RELEASE) {