track key repeats in user binds

This commit is contained in:
jacob 2024-08-15 16:18:02 -05:00
parent bd4e560f67
commit 0e658749b1
2 changed files with 12 additions and 8 deletions

View File

@ -530,7 +530,7 @@ INTERNAL void game_update(struct game_cmd_array game_cmds)
bullet->bullet_src = ent->handle; bullet->bullet_src = ent->handle;
bullet->bullet_src_pos = rel_pos; bullet->bullet_src_pos = rel_pos;
bullet->bullet_src_dir = rel_dir; bullet->bullet_src_dir = rel_dir;
bullet->bullet_impulse = 5; bullet->bullet_impulse = 100;
entity_enable_prop(bullet, ENTITY_PROP_BULLET); entity_enable_prop(bullet, ENTITY_PROP_BULLET);
} }

View File

@ -18,9 +18,10 @@
#include "app.h" #include "app.h"
struct bind_state { struct bind_state {
b32 is_held; /* Is this bind held down this 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; /* How many times was this bind pressed since last frame */
u32 num_releases; /* How many times was this bind released 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 { struct blend_tick {
@ -506,7 +507,7 @@ INTERNAL void user_update(void)
struct sys_event_array events = pop_sys_events(scratch.arena); 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) { for (u32 i = 0; i < ARRAY_COUNT(G.bind_states); ++i) {
G.bind_states[i] = (struct bind_state) { G.bind_states[i] = (struct bind_state) {
.is_held = G.bind_states[i].is_held .is_held = G.bind_states[i].is_held
@ -535,7 +536,7 @@ INTERNAL void user_update(void)
} }
/* Update bind states */ /* 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; enum sys_btn button = event->button;
button = button >= SYS_BTN_COUNT ? SYS_BTN_NONE : button; button = button >= SYS_BTN_COUNT ? SYS_BTN_NONE : button;
enum user_bind_kind bind = g_binds[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; G.bind_states[bind].is_held = pressed && !out_of_bounds;
if (pressed) { if (pressed) {
if (!out_of_bounds) { 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 { } else {
++G.bind_states[bind].num_releases; ++G.bind_states[bind].num_releases;
@ -595,7 +599,7 @@ INTERNAL void user_update(void)
/* Test step */ /* Test step */
{ {
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_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) { queue_game_cmd(&cmd_list, (struct game_cmd) {
.kind = GAME_CMD_KIND_STEP .kind = GAME_CMD_KIND_STEP
}); });