summaryrefslogtreecommitdiff
path: root/src/ctrl/include/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/ctrl/include/engine')
-rw-r--r--src/ctrl/include/engine/ctrl/input.h11
-rw-r--r--src/ctrl/include/engine/ctrl/scancodes.h82
2 files changed, 89 insertions, 4 deletions
diff --git a/src/ctrl/include/engine/ctrl/input.h b/src/ctrl/include/engine/ctrl/input.h
index 26a5f5b..d06dcfe 100644
--- a/src/ctrl/include/engine/ctrl/input.h
+++ b/src/ctrl/include/engine/ctrl/input.h
@@ -1,9 +1,10 @@
-#ifndef INPUT_H
-#define INPUT_H
+#ifndef ENGINE_CTRL_INPUT_H
+#define ENGINE_CTRL_INPUT_H
#include <engine/core/types.h>
+#include <engine/ctrl/scancodes.h>
-typedef void input_callback_t(void*);
+typedef void input_callback_t(f64, void*);
typedef i32 scancode_t;
typedef enum InputType {
@@ -49,9 +50,11 @@ typedef struct 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(usize numcalls, void* state_mem, input_callback_t* c[]);
+void i_flush_bindings(f64 dt, usize numcalls, input_callback_t* c[], void* state_mem);
action_t i_get_action(const i_ctx* restrict ctx, u32 time, scancode_t scancode);
+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);
diff --git a/src/ctrl/include/engine/ctrl/scancodes.h b/src/ctrl/include/engine/ctrl/scancodes.h
new file mode 100644
index 0000000..90bd749
--- /dev/null
+++ b/src/ctrl/include/engine/ctrl/scancodes.h
@@ -0,0 +1,82 @@
+#ifndef ENGINE_CTRL_SCANCODES_H
+
+// 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 {
+ 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 = MOD(0),
+ MOD_CONTROL = MOD(1),
+ MOD_ALT = MOD(2),
+ MOD_SUPER = MOD(3),
+} ScanCode;
+#undef ACTION
+#undef MOD
+
+#endif