aboutsummaryrefslogtreecommitdiff
path: root/src/fw/input.odin
diff options
context:
space:
mode:
Diffstat (limited to 'src/fw/input.odin')
-rw-r--r--src/fw/input.odin50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/fw/input.odin b/src/fw/input.odin
index 2c15017..3c1236f 100644
--- a/src/fw/input.odin
+++ b/src/fw/input.odin
@@ -1,6 +1,8 @@
package fw
import "core:c"
+import "core:log"
+
import "vendor:glfw"
Keyboard_Input :: union {
@@ -13,57 +15,43 @@ Controller_Input :: union {
Keybind :: struct {
input: Keyboard_Input,
- pressed: bool,
+ was_pressed: bool,
just_pressed: bool,
}
-key_down_last_frame: #sparse [Key]bool
-key_just_down: #sparse [Key]bool
-
-mouse_down_last_frame: #sparse [Mouse_Button]bool
-mouse_just_down: #sparse [Mouse_Button]bool
-
-@(private)
-_update_input :: proc() {
- for key in Key {
- status := glfw.GetKey(window, c.int(key))
- key_pressed := status == glfw.PRESS
- key_just_down[key] = key_pressed && !key_down_last_frame[key]
+update_keybind :: proc(keybind: ^Keybind) {
+ pressed: bool
- key_down_last_frame[key] = key_pressed
+ switch val in keybind.input {
+ case Key:
+ pressed = glfw.GetKey(window, c.int(val)) == glfw.PRESS
+ case Mouse_Button:
+ pressed = glfw.GetMouseButton(window, c.int(val)) == glfw.PRESS
}
- for mb in Mouse_Button {
- status := glfw.GetMouseButton(window, c.int(mb))
- mouse_pressed := status == glfw.PRESS
- mouse_just_down[mb] = mouse_pressed && !mouse_down_last_frame[mb]
-
- mouse_down_last_frame[mb] = mouse_pressed
- }
+ keybind.just_pressed = !keybind.was_pressed && pressed
+ keybind.was_pressed = pressed
}
+@(require_results)
is_keybind_down :: proc(keybind: Keybind) -> bool {
switch val in keybind.input {
case Key:
return glfw.GetKey(window, c.int(val)) == glfw.PRESS
case Mouse_Button:
return glfw.GetMouseButton(window, c.int(val)) == glfw.PRESS
+ case:
+ log.warn("Keybind input is invalid")
+ return false
}
-
- assert(false)
- return false
}
+@(require_results)
is_keybind_just_down :: proc(keybind: Keybind) -> bool {
- switch val in keybind.input {
- case Key: return key_just_down[val]
- case Mouse_Button: return mouse_just_down[val]
- }
-
- assert(false)
- return false
+ return keybind.just_pressed
}
+@(require_results)
get_mouse_pos :: proc() -> (mouse_pos: Vec2) {
w_width, w_height := glfw.GetWindowSize(window)
mx, my := glfw.GetCursorPos(window)