input: Added basic struct for input handling
authorLukas Krickl <lukas@krickl.dev>
Thu, 26 Feb 2026 06:41:09 +0000 (07:41 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 26 Feb 2026 06:41:09 +0000 (07:41 +0100)
STYLE.md
src/i_input.c [new file with mode: 0644]
src/i_input.h [new file with mode: 0644]
src/lrts.c
src/lrts_impl.h

index 7f1a27a670293ae31ada2d3932eac1e4a422c096..98926a30beaaf534246342593429a8c39c91a740 100644 (file)
--- a/STYLE.md
+++ b/STYLE.md
@@ -14,9 +14,15 @@ Files and all functions therein are prefixed with one of the following:
 - `s_`: server side code
 - `u_`: system utility code
 - `p_`: platform module directory
+- `i_`: input handling
 - `t_`: test case
 
 
+## Goto
+
+Goto is allowed for error handling or breaking out of nested loops. 
+e.g. `goto error` or `goto loop_done`.
+
 ## Library functions
 
 Third party functions (even the C stdlib) should be wrapped at all times.
diff --git a/src/i_input.c b/src/i_input.c
new file mode 100644 (file)
index 0000000..24d0ecd
--- /dev/null
@@ -0,0 +1,7 @@
+#include "i_input.h"
+
+struct i_cursor i_cursor;
+struct i_keyboard i_keyboard;
+
+void i_input_init(void) {
+}
diff --git a/src/i_input.h b/src/i_input.h
new file mode 100644 (file)
index 0000000..c2a53be
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef I_INPUT_H__
+#define I_INPUT_H__
+
+/**
+ * This module is used for user input
+ * state management.
+ * The structs in this module should not be used
+ * directly to interact with gemplay. They should instead
+ * be translated to action commands. 
+ */
+
+#define I_CURSOR_BUTTONS 3
+#define I_KEYBOARD_KEYS 128
+
+enum i_button_state {
+       I_BUTTON_RELEASE = 0,
+       I_BUTTON_JUST_PRESSED = 1,
+       I_BUTTON_HELD = 2
+};
+
+
+/* describes the current cursor state */
+struct i_cursor {
+       struct u_vec2 pos;
+
+       enum i_button_state buttons[I_CURSOR_BUTTONS];
+};
+
+struct i_keyboard {
+       enum i_button_state shift;
+       enum i_button_state ctrl;
+       enum i_button_state alt;
+       enum i_button_state super;
+       enum i_button_state enter;
+       enum i_button_state space;
+       enum i_button_state backspace;
+
+       /* ascii table for all other keys */
+       enum i_button_state keys[I_KEYBOARD_KEYS];
+};
+
+/* primary IO devices */
+extern struct i_cursor i_cursor;
+extern struct i_keyboard i_keyboard;
+
+void i_input_init(void);
+
+#endif
index ded1e9f8da2288b948e5f4240ea99e95ff96ca94..f43239f30c58a87bb745d7750987ebe4c81c8b96 100644 (file)
@@ -3,6 +3,7 @@
 #include "p_platform.h"
 #include "r_render.h"
 #include "r_assets.h"
+#include "i_input.h"
 
 struct lrts_config lrts_global_cfg;
 
@@ -64,6 +65,7 @@ struct u_vec2 lrts_get_screen_res(void) {
 void lrts_init(void) {
        /* init the fallback tile mask */
        r_asset_init_fallback_tile();
+       i_input_init();
 }
 
 int lrts_main(int argc, char **argv) {
index a74fbf4dfa4edd037ca94b6f4a3da06d27281b25..0e7f21981ae9a2fea4b53efb74c520469d3365ee 100644 (file)
@@ -48,6 +48,7 @@
 #include "r_render.c"
 #include "r_color.c"
 #include "r_assets.c"
+#include "i_input.c"
 
 #endif