diff options
| -rw-r--r-- | src/Input.cpp | 20 | ||||
| -rw-r--r-- | src/Input.hpp | 6 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/Input.cpp b/src/Input.cpp index 2362794..b0b58bc 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -189,7 +189,7 @@ Key Input::from_glfw_key(I32 const key) { case GLFW_KEY_F10: return Key::F10; case GLFW_KEY_F11: return Key::F11; case GLFW_KEY_F12: return Key::F12; - default: UNREACHABLE("Unknown key."); return TO(Key, 0); + default: return Key::Unknown; } } @@ -198,13 +198,16 @@ Mouse Input::from_glfw_mouse(I32 const button) { case GLFW_MOUSE_BUTTON_LEFT: return Mouse::Left; case GLFW_MOUSE_BUTTON_RIGHT: return Mouse::Right; case GLFW_MOUSE_BUTTON_MIDDLE: return Mouse::Middle; - default: UNREACHABLE("Unknown mouse button."); return TO(Mouse, 0); + default: return Mouse::Unknown; } } -void Input::key_callback(GLFWwindow* _window, I32 const key, I32 _scancode, I32 const action, I32 _mods) { - if (action == GLFW_PRESS) s_key_buffer[key_value(from_glfw_key(key))] = true; - else if (action == GLFW_RELEASE) s_key_buffer[key_value(from_glfw_key(key))] = false; +void Input::key_callback(GLFWwindow* _window, I32 const key, I32 const scancode, I32 const action, I32 _mods) { + auto mapped = from_glfw_key(key); + if (mapped == Key::Unknown) return; + + if (action == GLFW_PRESS) s_key_buffer[key_value(mapped)] = true; + else if (action == GLFW_RELEASE) s_key_buffer[key_value(mapped)] = false; } void Input::cursor_position_callback(GLFWwindow* _window, F64 x, F64 y) { @@ -214,8 +217,11 @@ void Input::cursor_position_callback(GLFWwindow* _window, F64 x, F64 y) { } void Input::mouse_button_callback(GLFWwindow* _window, I32 const button, I32 const action, I32 _mods) { - if (action == GLFW_PRESS) s_mouse_buffer[mouse_button_value(from_glfw_mouse(button))] = true; - else if (action == GLFW_RELEASE) s_mouse_buffer[mouse_button_value(from_glfw_mouse(button))] = false; + auto mapped = from_glfw_mouse(button); + if (mapped == Mouse::Unknown) return; + + if (action == GLFW_PRESS) s_mouse_buffer[mouse_button_value(mapped)] = true; + else if (action == GLFW_RELEASE) s_mouse_buffer[mouse_button_value(mapped)] = false; } } diff --git a/src/Input.hpp b/src/Input.hpp index b6f24b6..98d8691 100644 --- a/src/Input.hpp +++ b/src/Input.hpp @@ -13,6 +13,7 @@ namespace MC { // TODO: Add some more keys. // TODO: I think some of these keys are "modifiers" under GLFW, and should be handled differently. enum class Key { + Unknown, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine, @@ -21,14 +22,15 @@ enum class Key { Space, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, }; -constexpr USize KeyCount = 65; +constexpr USize KeyCount = 66; static_assert(KeyCount == TO(USize, Key::F12) + 1, "Key count mismatch."); enum class Mouse { + Unknown, Left, Right, Middle, }; -constexpr USize MouseCount = 3; +constexpr USize MouseCount = 4; static_assert(MouseCount == TO(USize, Mouse::Middle) + 1, "Mouse count mismatch."); // The simple input system. |
