From 0e658749b175be0ece877722af752da6eb30fa60 Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 15 Aug 2024 16:18:02 -0500 Subject: [PATCH] track key repeats in user binds --- src/game.c | 2 +- src/user.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/game.c b/src/game.c index 3b3ea045..5deb701e 100644 --- a/src/game.c +++ b/src/game.c @@ -530,7 +530,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds) bullet->bullet_src = ent->handle; bullet->bullet_src_pos = rel_pos; bullet->bullet_src_dir = rel_dir; - bullet->bullet_impulse = 5; + bullet->bullet_impulse = 100; entity_enable_prop(bullet, ENTITY_PROP_BULLET); } diff --git a/src/user.c b/src/user.c index aac118cb..b8fa1c4a 100644 --- a/src/user.c +++ b/src/user.c @@ -18,9 +18,10 @@ #include "app.h" struct bind_state { - b32 is_held; /* Is this bind held down this frame */ - u32 num_presses; /* How many times was this bind pressed since last frame */ - u32 num_releases; /* How many times was this bind released since last frame */ + b32 is_held; /* Is this bind held down this frame */ + u32 num_presses; /* How many times was this bind pressed since last frame */ + u32 num_presses_and_repeats; /* Same as `num_presses` but includes key repeats as well */ + u32 num_releases; /* How many times was this bind released since last frame */ }; struct blend_tick { @@ -506,7 +507,7 @@ INTERNAL void user_update(void) struct sys_event_array events = pop_sys_events(scratch.arena); - /* Reset bind states "was_pressed" */ + /* Reset bind pressed / released states */ for (u32 i = 0; i < ARRAY_COUNT(G.bind_states); ++i) { G.bind_states[i] = (struct bind_state) { .is_held = G.bind_states[i].is_held @@ -535,7 +536,7 @@ INTERNAL void user_update(void) } /* Update bind states */ - if ((event->kind == SYS_EVENT_KIND_BUTTON_DOWN || event->kind == SYS_EVENT_KIND_BUTTON_UP) && !event->is_repeat) { + if ((event->kind == SYS_EVENT_KIND_BUTTON_DOWN || event->kind == SYS_EVENT_KIND_BUTTON_UP)) { enum sys_btn button = event->button; button = button >= SYS_BTN_COUNT ? SYS_BTN_NONE : button; enum user_bind_kind bind = g_binds[button]; @@ -549,7 +550,10 @@ INTERNAL void user_update(void) G.bind_states[bind].is_held = pressed && !out_of_bounds; if (pressed) { if (!out_of_bounds) { - ++G.bind_states[bind].num_presses; + ++G.bind_states[bind].num_presses_and_repeats; + if (!event->is_repeat) { + ++G.bind_states[bind].num_presses; + } } } else { ++G.bind_states[bind].num_releases; @@ -595,7 +599,7 @@ INTERNAL void user_update(void) /* Test step */ { struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_STEP]; - if (state.num_presses) { + for (u32 i = 0; i < state.num_presses_and_repeats; ++i) { queue_game_cmd(&cmd_list, (struct game_cmd) { .kind = GAME_CMD_KIND_STEP });