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_pos = rel_pos;
bullet->bullet_src_dir = rel_dir;
bullet->bullet_impulse = 5;
bullet->bullet_impulse = 100;
entity_enable_prop(bullet, ENTITY_PROP_BULLET);
}

View File

@ -20,6 +20,7 @@
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_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 */
};
@ -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,8 +550,11 @@ 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_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
});