summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-30 21:39:31 +1100
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-30 21:39:31 +1100
commitf7b91c2eae24ecb7a20b638246fb849d6c63615a (patch)
tree4bdf8fd3425db9f0203f7cf1c58464f4be88e720 /src/systems
parent16237e6499f47d963df35c0f0c4649900ec98d84 (diff)
start adding mouse input processing
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/input.c19
-rw-r--r--src/systems/keys.h15
2 files changed, 33 insertions, 1 deletions
diff --git a/src/systems/input.c b/src/systems/input.c
index 292d438..fc62db8 100644
--- a/src/systems/input.c
+++ b/src/systems/input.c
@@ -1,11 +1,17 @@
#include "input.h"
+#include <assert.h>
#include <glfw3.h>
+#include <string.h>
#include "log.h"
+static input_state *g_input; // Use a global to simplify caller code
+
bool input_system_init(input_state *input, GLFWwindow *window) {
INFO("Input init");
+ memset(input, 0, sizeof(input_state));
+
input->window = window;
// Set everything to false. Could just set memory to zero but where's the fun in that
for (int i = 0; i < KEYCODE_MAX; i++) {
@@ -14,9 +20,16 @@ bool input_system_init(input_state *input, GLFWwindow *window) {
input->just_released_keys[i] = false;
}
+ g_input = input;
+
+ assert(input->mouse.x_delta == 0);
+ assert(input->mouse.y_delta == 0);
+
return true;
}
+void input_system_shutdown(input_state *input) {}
+
void input_update(input_state *input) {
// --- update keyboard input
@@ -75,3 +88,9 @@ void input_update(input_state *input) {
input->mouse = new_mouse_state;
}
+
+bool key_is_pressed(keycode key) { return g_input->depressed_keys[key]; }
+
+bool key_just_pressed(keycode key) { return g_input->just_pressed_keys[key]; }
+
+bool key_just_released(keycode key) { return g_input->just_released_keys[key]; } \ No newline at end of file
diff --git a/src/systems/keys.h b/src/systems/keys.h
index 090bb49..a76e101 100644
--- a/src/systems/keys.h
+++ b/src/systems/keys.h
@@ -2,5 +2,18 @@
typedef enum keycode {
// TODO: add all keycodes
- KEYCODE_MAX
+ KEYCODE_SPACE = 32,
+ KEYCODE_A = 65,
+ KEYCODE_D = 68,
+ KEYCODE_S = 83,
+ KEYCODE_W = 87,
+ KEYCODE_ESCAPE = 256,
+ KEYCODE_ENTER = 257,
+ KEYCODE_TAB = 258,
+ KEYCODE_BACKSPACE = 259,
+ KEYCODE_KEY_RIGHT = 262,
+ KEYCODE_KEY_LEFT = 263,
+ KEYCODE_KEY_DOWN = 264,
+ KEYCODE_KEY_UP = 265,
+ KEYCODE_MAX = 348
} keycode; \ No newline at end of file