aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/input.hpp
diff options
context:
space:
mode:
authorVaino Kauppila <vaino@vke.fi>2026-07-02 22:58:25 +0300
committerVaino Kauppila <vaino@vke.fi>2026-07-02 23:47:07 +0300
commitcd0c08dc7ce754473178ad3f32f7740a1dddc1eb (patch)
tree589c676b41d6f3d322ea5ce339ddb0811f29ec31 /src/engine/input.hpp
downloadforts_clone-cd0c08dc7ce754473178ad3f32f7740a1dddc1eb.tar.gz
forts_clone-cd0c08dc7ce754473178ad3f32f7740a1dddc1eb.zip
Initial import: LibreForts (M0-M5 in progress)
Open-source Forts clone: custom C++20 engine + data-driven (Lua) 2D physics artillery RTS. - Building: node/strut graph on a stiff mass-spring solver (canon Forts model), triangulation rigidity, axial + 30-degree angle-stress breaking, cascading collapse, fire (DoT + spread), ground destroys debris. - Weapons (M4): cannon (ballistic) + laser (beam/ignite) with select-and-aim-in- arc UX; splash / beam damage; bg-brace passthrough. - Devices + economy (M5): reactors + win/loss + restart, mines/turbines/battery, metal deposits, storage caps, per-shot energy cost. - Data-driven via Lua/sol2 with a layered mod loader; enemy-fort scenario mod. - Renderer: SDL3 + textures + ImGui dev UI. stb_image + ImGui vendored. - Assets: CC0 placeholders only; real game art loaded at runtime from the user's own install via forts: paths (bring-your-own; nothing copyrighted committed). See README.md / CLAUDE.md and research/ + requirements/ for detail.
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;
+};