From 003f97201ffe7af3a301f994cc3227c5e9aacfd8 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 10 Dec 2024 23:29:50 -0600 Subject: [PATCH] [turbine/glfw] Move MandatoryRefreshPeriod to config.hpp --- src/olympic/turbine/src/glfw/config.hpp | 5 ++++- src/olympic/turbine/src/glfw/gfx.cpp | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/olympic/turbine/src/glfw/config.hpp b/src/olympic/turbine/src/glfw/config.hpp index 550e5b5a..7f84f851 100644 --- a/src/olympic/turbine/src/glfw/config.hpp +++ b/src/olympic/turbine/src/glfw/config.hpp @@ -4,8 +4,11 @@ #pragma once +#include + namespace turbine::config { -constexpr bool GlFpsPrint = TURBINE_GL_FPS_PRINT; +inline constexpr bool GlFpsPrint = TURBINE_GL_FPS_PRINT; +inline constexpr TimeMs MandatoryRefreshPeriod = 168; } diff --git a/src/olympic/turbine/src/glfw/gfx.cpp b/src/olympic/turbine/src/glfw/gfx.cpp index 89b937c0..231c3ed4 100644 --- a/src/olympic/turbine/src/glfw/gfx.cpp +++ b/src/olympic/turbine/src/glfw/gfx.cpp @@ -9,6 +9,8 @@ #include #endif +#include "config.hpp" + #include #include "context.hpp" @@ -62,26 +64,27 @@ static void handleKeyPress(Context &ctx, int key, bool down) noexcept { return map; }(); auto const eventHandler = keyEventHandler(ctx); - auto const k = keyMap[static_cast(key)]; - setKeyDownStatus(ctx, k, down); - if (eventHandler) { - eventHandler(ctx, k, down); + auto const keyIdx = static_cast(key); + if (keyIdx < keyMap.size()) { + auto const k = keyMap[keyIdx]; + setKeyDownStatus(ctx, k, down); + if (eventHandler) { + eventHandler(ctx, k, down); + } } } static void handleGlfwCursorPosEvent(GLFWwindow*, double, double) noexcept { } -static constexpr TimeMs MandatoryRefreshPeriod = 168; - static void handleGlfwMouseButtonEvent(GLFWwindow *window, int, int, int) noexcept { auto const ctx = static_cast(glfwGetWindowUserPointer(window)); - ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod; + ctx->mandatoryRefreshPeriodEnd = config::MandatoryRefreshPeriod; } static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int) noexcept { auto const ctx = static_cast(glfwGetWindowUserPointer(window)); - ctx->mandatoryRefreshPeriodEnd = MandatoryRefreshPeriod; + ctx->mandatoryRefreshPeriodEnd = config::MandatoryRefreshPeriod; if (action == GLFW_PRESS) { handleKeyPress(*ctx, key, true); } else if (action == GLFW_RELEASE) {