aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/input.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/input.hpp')
-rw-r--r--src/engine/input.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/engine/input.hpp b/src/engine/input.hpp
new file mode 100644
index 0000000..764ca96
--- /dev/null
+++ b/src/engine/input.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include <SDL3/SDL.h>
+#include <glm/glm.hpp>
+
+// Simple polling-based input state. Call begin_frame() once per frame,
+// then query state during update.
+
+class Input {
+public:
+ // Call once per frame BEFORE reading any input state.
+ // Processes the SDL event queue and updates internal state.
+ void begin_frame();
+
+ // Keyboard
+
+ bool key_down(SDL_Keycode key) const;
+ bool key_pressed(SDL_Keycode key) const; // true only on the frame it went down
+ bool key_released(SDL_Keycode key) const; // true only on the frame it went up
+
+ // Mouse
+
+ glm::vec2 mouse_pos() const; // in window coordinates
+ glm::vec2 mouse_delta() const; // movement since last frame
+ float scroll_delta() const; // vertical scroll (positive = scroll up)
+
+ bool mouse_down(int button) const; // SDL_BUTTON_LEFT, MIDDLE, RIGHT
+ bool mouse_pressed(int button) const;
+ bool mouse_released(int button) const;
+
+ // Window
+
+ bool quit_requested() const { return quit_; }
+
+private:
+ // Keyboard
+ bool key_state_[SDL_SCANCODE_COUNT] = {};
+ bool key_prev_[SDL_SCANCODE_COUNT] = {};
+ bool key_just_pressed_[SDL_SCANCODE_COUNT] = {};
+ bool key_just_released_[SDL_SCANCODE_COUNT] = {};
+
+ // Mouse
+ glm::vec2 mouse_pos_ = {0.0f, 0.0f};
+ glm::vec2 mouse_prev_ = {0.0f, 0.0f};
+ glm::vec2 mouse_delta_ = {0.0f, 0.0f};
+ float scroll_ = 0.0f;
+ bool mouse_state_[8] = {};
+ bool mouse_prev_state_[8] = {};
+ bool mouse_pressed_[8] = {};
+ bool mouse_released_[8] = {};
+
+ bool quit_ = false;
+};