From 93c27830060788dea1c364465d29e44d05a3064e Mon Sep 17 00:00:00 2001 From: iamcheeseman <[hidden email]> Date: Sat, 14 Feb 2026 18:02:47 -0500 Subject: Only process keys that are bound to an action --- src/fw/fw.odin | 3 ++- src/fw/input.odin | 50 +++++++++++++++++++------------------------------- src/fw/renderer.odin | 8 +++++++- 3 files changed, 28 insertions(+), 33 deletions(-) (limited to 'src/fw') diff --git a/src/fw/fw.odin b/src/fw/fw.odin index 556817b..9ab1918 100644 --- a/src/fw/fw.odin +++ b/src/fw/fw.odin @@ -28,6 +28,7 @@ Config :: struct { @(private) last_frame: f64 @(private) dt: f64 +@(require_results) rgba8 :: proc(r: u8, g: u8, b: u8, a: u8 = 255) -> Color { return Color{ f32(r) / 255, @@ -71,6 +72,7 @@ deinit :: proc() { glfw.Terminate() } +@(require_results) next_frame :: proc() -> bool { // End the previous frame if can_flush() { @@ -90,7 +92,6 @@ next_frame :: proc() -> bool { glfw.SwapBuffers(window) glfw.PollEvents() - _update_input() // log.debugf("Draw calls: %v", renderer.draw_calls_count) 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) diff --git a/src/fw/renderer.odin b/src/fw/renderer.odin index 7653938..75d2c38 100644 --- a/src/fw/renderer.odin +++ b/src/fw/renderer.odin @@ -13,6 +13,8 @@ RED :: Color{1, 0, 0, 1} GREEN :: Color{0, 1, 0, 1} BLUE :: Color{0, 0, 1, 1} +Image :: image.Image + Index :: u16 Renderer_Backend :: enum { @@ -130,6 +132,7 @@ set_camera_pos :: proc(pos: Vec2) { renderer.view = linalg.matrix4_translate(-Vec3{pos.x, pos.y, 0}) } +@(require_results) get_camera_pos :: #force_inline proc() -> Vec2 { return renderer.camera_pos } @@ -164,6 +167,7 @@ _add_index :: #force_inline proc(i: u16, start: Index) { append(&renderer.draw_call.indices, start + i) } +@(require_results) can_flush :: proc() -> bool { return renderer.draw_call.vertex_mode != .None && len(renderer.draw_call.vertices) != 0 && @@ -190,7 +194,8 @@ try_batch_calls :: proc( } } -create_texture_from_image :: #force_inline proc(img: ^image.Image) -> Texture { +@(require_results) +create_texture_from_image :: #force_inline proc(img: ^Image) -> Texture { return create_texture( img.pixels.buf[:], {i32(img.width), i32(img.height)}, @@ -198,6 +203,7 @@ create_texture_from_image :: #force_inline proc(img: ^image.Image) -> Texture { ) } +@(require_results) create_texture :: proc(data: []u8, size: Vec2i, channels: i32) -> Texture { texture := Texture{ size = size, -- cgit v1.3-2-g0d8e