From: Lukas Krickl Date: Thu, 26 Feb 2026 06:41:09 +0000 (+0100) Subject: input: Added basic struct for input handling X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=3fea103d12a03da2958d8fddef4398db4ea610e8;p=lrts%2F.git input: Added basic struct for input handling --- diff --git a/STYLE.md b/STYLE.md index 7f1a27a..98926a3 100644 --- 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 index 0000000..24d0ecd --- /dev/null +++ b/src/i_input.c @@ -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 index 0000000..c2a53be --- /dev/null +++ b/src/i_input.h @@ -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 diff --git a/src/lrts.c b/src/lrts.c index ded1e9f..f43239f 100644 --- a/src/lrts.c +++ b/src/lrts.c @@ -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) { diff --git a/src/lrts_impl.h b/src/lrts_impl.h index a74fbf4..0e7f219 100644 --- a/src/lrts_impl.h +++ b/src/lrts_impl.h @@ -48,6 +48,7 @@ #include "r_render.c" #include "r_color.c" #include "r_assets.c" +#include "i_input.c" #endif