From d38deeef3af2316a666f8fc0173940bd769b748e Mon Sep 17 00:00:00 2001 From: onelin Date: Sat, 1 Nov 2025 00:55:42 +0100 Subject: Flatten project structure This will make it easier to break up the code into smaller chunks again later. One would think doing this seems fun to me at this point. --- src/ctrl/include/engine/ctrl/input.h | 108 ------------------------------- src/ctrl/include/engine/ctrl/keycodes.h | 93 -------------------------- src/ctrl/include/engine/ctrl/scancodes.h | 89 ------------------------- 3 files changed, 290 deletions(-) delete mode 100644 src/ctrl/include/engine/ctrl/input.h delete mode 100644 src/ctrl/include/engine/ctrl/keycodes.h delete mode 100644 src/ctrl/include/engine/ctrl/scancodes.h (limited to 'src/ctrl/include') diff --git a/src/ctrl/include/engine/ctrl/input.h b/src/ctrl/include/engine/ctrl/input.h deleted file mode 100644 index 18a6797..0000000 --- a/src/ctrl/include/engine/ctrl/input.h +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef ENGINE_CTRL_INPUT_H -#define ENGINE_CTRL_INPUT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -typedef void input_callback_t(void*); -typedef i32 scancode_t; -typedef i32 keycode_t; - -typedef enum InputType { - InputType_error = 0, - InputType_action, - InputType_state, - InputType_range, /* TBD */ -} InputType; - -typedef union action_t { - InputType type; - - struct { - InputType type; - input_callback_t* callback; - char* callback_str; - } action; - - struct { - InputType type; - input_callback_t* activate; - input_callback_t* deactivate; - char* activate_str; - char* deactivate_str; - } state; -} action_t; - -typedef struct binding_t { - action_t action; - - // Change type depending on input handling back-end. like u16 for GLFW_KEY - keycode_t keycode; - keycode_t keycode_alt; - - u64 since_last_activation; -} binding_t; - -typedef struct i_ctx { - - // Current mouse position - ivec2 mouse_pos; - - usize len; - binding_t* bindings; -} i_ctx; - -void i_ctx_t_free(i_ctx* c); -/* Executes all callbacks that has been pushed onto the callstack and resets the - * callstack */ -void i_flush_bindings(u64 dt, usize numcalls, input_callback_t* c[], void* state_mem); -action_t i_get_action(const i_ctx* restrict ctx, u64 time, keycode_t keycode); - -void key_callback(void* window, int key, int scancode, int action, int mods); - -void i_ctx_push(i_ctx* ctx); -void i_ctx_pop(void); -void i_ctx_reset(void); - -/* Finds and updates the keycode of a binding with the given action in ctx */ -void i_bind_ctx(i_ctx* c, keycode_t s, action_t* a); -void i_bind_ctx_alt(i_ctx* c, keycode_t s, action_t* a); - -/* Update the keycode of a binding */ -void i_bind(binding_t* b, keycode_t s); -void i_bind_alt(binding_t* b, keycode_t s); - -#define BindAction(key, altkey, f_action) \ - (binding_t) { \ - .action = (action_t){.action = \ - { \ - .type = InputType_action, \ - .callback = (input_callback_t*)&f_action, \ - .callback_str = strdup(#f_action), \ - }}, \ - .keycode = key, .keycode_alt = altkey, .since_last_activation = 0 \ - } - -#define BindState(key, altkey, f_activate, f_deactivate) \ - (binding_t) { \ - .action = \ - (action_t){.state = \ - { \ - .type = InputType_state, \ - .activate = (input_callback_t*)&f_activate, \ - .deactivate = (input_callback_t*)&f_deactivate, \ - .activate_str = strdup(#f_activate), \ - .deactivate_str = strdup(#f_deactivate), \ - }}, \ - .keycode = key, .keycode_alt = altkey, .since_last_activation = 0 \ - } - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/ctrl/include/engine/ctrl/keycodes.h b/src/ctrl/include/engine/ctrl/keycodes.h deleted file mode 100644 index 4fff38e..0000000 --- a/src/ctrl/include/engine/ctrl/keycodes.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef ENGINE_CTRL_SCANCODES_H - -#ifdef __cplusplus -extern "C" { -#endif - -// We want to reserve the following bytes marked with X for MODS, -// one bit per MODIFIER (shift, control, alt, super): -// XXXX 0000 0000 0000 0000 0000 0000 0000 -// -// We want to reserve the following bytes marked with X for ACTIONS -// enumerate by action type, pressed, released, repeat -// 0000 0000 XXXX 0000 0000 0000 0000 0000 -// -// We want to reserve the following bytes marked with X for the KEYCODE -// 0000 0000 0000 0000 XXXX XXXX XXXX XXXX -#define KEY_MOD(x) 1 << (32-4 + x) -#define ACTION(x) (1 << (32-8)) + x - -typedef enum { - KEY_SPACE = ' ', - KEY_APOSTROPHE = '\'', - KEY_COMMA = ',', - KEY_MINUS = '-', - KEY_PERIOD = '.', - KEY_SLASH = '/', - - KEY_0 = '0', - KEY_1 = '1', - KEY_2 = '2', - KEY_3 = '3', - KEY_4 = '4', - KEY_5 = '5', - KEY_6 = '6', - KEY_7 = '7', - KEY_8 = '8', - KEY_9 = '9', - - KEY_SEMICOLON = ';', - KEY_EQUAL = '=', - - KEY_A = 'A', - KEY_B = 'B', - KEY_C = 'C', - KEY_D = 'D', - KEY_E = 'E', - KEY_F = 'F', - KEY_G = 'G', - KEY_H = 'H', - KEY_I = 'I', - KEY_J = 'J', - KEY_K = 'K', - KEY_L = 'L', - KEY_M = 'M', - KEY_N = 'N', - KEY_O = 'O', - KEY_P = 'P', - KEY_Q = 'Q', - KEY_R = 'R', - KEY_S = 'S', - KEY_T = 'T', - KEY_U = 'U', - KEY_V = 'V', - KEY_W = 'W', - KEY_X = 'X', - KEY_Y = 'Y', - KEY_Z = 'Z', - - KEY_LEFT_BRACKET = '[', - KEY_BACKSLASH = '\\', - KEY_RIGHT_BRACKET = ']', - KEY_GRAVE_ACCENT = '`', - - ACTION_PRESS = ACTION(0), - ACTION_RELEASE = ACTION(1), - ACTION_REPEAT = ACTION(2), - - MOD_SHIFT = KEY_MOD(0), - MOD_CONTROL = KEY_MOD(1), - MOD_ALT = KEY_MOD(2), - MOD_SUPER = KEY_MOD(3), -} KeyCode; -#define MOD_SHFT MOD_SHIFT -#define MOD_CTRL MOD_CONTROL -#define MOD_SUPR MOD_SUPER - -#undef ACTION -#undef KEY_MOD - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/ctrl/include/engine/ctrl/scancodes.h b/src/ctrl/include/engine/ctrl/scancodes.h deleted file mode 100644 index 5b18833..0000000 --- a/src/ctrl/include/engine/ctrl/scancodes.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef ENGINE_CTRL_SCANCODES_H - -#ifdef __cplusplus -extern "C" { -#endif - -// We want to reserve the following bytes marked with X for MODS, -// one bit per MODIFIER (shift, control, alt, super): -// XXXX 0000 0000 0000 0000 0000 0000 0000 -// -// We want to reserve the following bytes marked with X for ACTIONS -// enumerate by action type, pressed, released, repeat -// 0000 0000 XXXX 0000 0000 0000 0000 0000 -// -// We want to reserve the following bytes marked with X for the SCANCODE -// 0000 0000 0000 0000 XXXX XXXX XXXX XXXX -#define MOD(x) 1 << (32-4 + x) -#define ACTION(x) (1 << (32-8)) + x - -typedef enum { - SCAN_KEY_SPACE = ' ', - SCAN_KEY_APOSTROPHE = '\'', - SCAN_KEY_COMMA = ',', - SCAN_KEY_MINUS = '-', - SCAN_KEY_PERIOD = '.', - SCAN_KEY_SLASH = '/', - - SCAN_KEY_0 = '0', - SCAN_KEY_1 = '1', - SCAN_KEY_2 = '2', - SCAN_KEY_3 = '3', - SCAN_KEY_4 = '4', - SCAN_KEY_5 = '5', - SCAN_KEY_6 = '6', - SCAN_KEY_7 = '7', - SCAN_KEY_8 = '8', - SCAN_KEY_9 = '9', - - SCAN_KEY_SEMICOLON = ';', - SCAN_KEY_EQUAL = '=', - - SCAN_KEY_A = 'A', - SCAN_KEY_B = 'B', - SCAN_KEY_C = 'C', - SCAN_KEY_D = 'D', - SCAN_KEY_E = 'E', - SCAN_KEY_F = 'F', - SCAN_KEY_G = 'G', - SCAN_KEY_H = 'H', - SCAN_KEY_I = 'I', - SCAN_KEY_J = 'J', - SCAN_KEY_K = 'K', - SCAN_KEY_L = 'L', - SCAN_KEY_M = 'M', - SCAN_KEY_N = 'N', - SCAN_KEY_O = 'O', - SCAN_KEY_P = 'P', - SCAN_KEY_Q = 'Q', - SCAN_KEY_R = 'R', - SCAN_KEY_S = 'S', - SCAN_KEY_T = 'T', - SCAN_KEY_U = 'U', - SCAN_KEY_V = 'V', - SCAN_KEY_W = 'W', - SCAN_KEY_X = 'X', - SCAN_KEY_Y = 'Y', - SCAN_KEY_Z = 'Z', - - SCAN_KEY_LEFT_BRACKET = '[', - SCAN_KEY_BACKSLASH = '\\', - SCAN_KEY_RIGHT_BRACKET = ']', - SCAN_KEY_GRAVE_ACCENT = '`', - - SCAN_ACTION_PRESS = ACTION(0), - SCAN_ACTION_RELEASE = ACTION(1), - SCAN_ACTION_REPEAT = ACTION(2), - - SCAN_MOD_SHIFT = MOD(0), - SCAN_MOD_CONTROL = MOD(1), - SCAN_MOD_ALT = MOD(2), - SCAN_MOD_SUPER = MOD(3), -} ScanCode; -#undef ACTION -#undef MOD - -#ifdef __cplusplus -} -#endif -#endif -- cgit v1.3