summaryrefslogtreecommitdiff
path: root/src/systems/input.c
diff options
context:
space:
mode:
authoromnisci3nce <17525998+omnisci3nce@users.noreply.github.com>2024-04-04 20:25:40 +1100
committeromnisci3nce <17525998+omnisci3nce@users.noreply.github.com>2024-04-04 20:25:40 +1100
commitbb889d2edc1cc72b939edf47a2e03b7569c1a722 (patch)
tree59b7744d44bda7768ba908224a18d6a5046b186f /src/systems/input.c
parent1047d08258f6c56f5fa8067cc65694b1b5798602 (diff)
parent6a95b047998c0e0dcfdf60d17cf2cd0bd0bfee12 (diff)
Merge branch 'cel-60-scaffold-vulkan' into cel-67-load-animation-data-from-gltf
Diffstat (limited to 'src/systems/input.c')
-rw-r--r--src/systems/input.c19
1 files changed, 19 insertions, 0 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