From aa8dd7a4fa437d0e971e471f09ee104ef646f6c1 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 13 Mar 2024 15:10:16 -0500 Subject: [PATCH] minor tweaks --- src/game.c | 8 ++------ src/user.c | 27 +++++++++++++-------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/game.c b/src/game.c index 761f2321..183c422c 100644 --- a/src/game.c +++ b/src/game.c @@ -32,10 +32,8 @@ INTERNAL void push_cmds(struct game_cmd_array cmd_array) { sys_mutex_lock(&L.game_cmds_mutex); { - for (u64 i = 0; i < cmd_array.count; ++i) { - struct game_cmd *write_cmd = arena_push(&L.game_cmds_arena, struct game_cmd); - *write_cmd = cmd_array.cmds[i]; - } + struct game_cmd *cmds = arena_push_array(&L.game_cmds_arena, struct game_cmd, cmd_array.count); + MEMCPY(cmds, cmd_array.cmds, cmd_array.count * sizeof(*cmds)); } sys_mutex_unlock(&L.game_cmds_mutex); } @@ -81,7 +79,6 @@ INTERNAL void game_update(void) static b32 run = 0; if (!run) { run = 1; - (UNUSED)entity_link; /* Player ent */ struct entity *player_ent; @@ -227,7 +224,6 @@ INTERNAL void game_update(void) /* Movement */ case GAME_CMD_KIND_PLAYER_MOVE: { struct v2 dir = cmd.dir; - L.world.player_move_dir = v2_add(L.world.player_move_dir, dir); } break; diff --git a/src/user.c b/src/user.c index 14aed7dd..187e1bd0 100644 --- a/src/user.c +++ b/src/user.c @@ -98,17 +98,7 @@ GLOBAL READONLY enum user_bind_kind g_binds[SYS_BTN_COUNT] = { * Window -> user communication * ========================== */ -INTERNAL void window_event_callback(struct sys_event event) -{ - sys_mutex_lock(&L.sys_events_mutex); - { - struct sys_event *write_event = arena_push(&L.sys_events_arena, struct sys_event); - *write_event = event; - } - sys_mutex_unlock(&L.sys_events_mutex); -} - -INTERNAL struct sys_event_array pull_sys_events(struct arena *arena) +INTERNAL struct sys_event_array pop_sys_events(struct arena *arena) { struct sys_event_array array = { 0 }; if (L.sys_events_arena.pos > 0) { @@ -126,6 +116,15 @@ INTERNAL struct sys_event_array pull_sys_events(struct arena *arena) return array; } +INTERNAL void window_event_callback(struct sys_event event) +{ + sys_mutex_lock(&L.sys_events_mutex); + { + *arena_push(&L.sys_events_arena, struct sys_event) = event; + } + sys_mutex_unlock(&L.sys_events_mutex); +} + /* ========================== * * Game -> user communication * ========================== */ @@ -274,7 +273,7 @@ INTERNAL void queue_game_cmd(struct game_cmd_list *list, struct game_cmd cmd) list->last = node; } -INTERNAL void push_game_cmds(struct game_cmd_list *list) +INTERNAL void pubilsh_game_cmds(struct game_cmd_list *list) { struct temp_arena scratch = scratch_begin(list->arena); @@ -397,7 +396,7 @@ INTERNAL void user_update(void) /* Read input */ L.screen_mouse = sys_window_get_mouse_pos(L.window); - struct sys_event_array events = pull_sys_events(scratch.arena); + struct sys_event_array events = pop_sys_events(scratch.arena); /* ========================== * * Read sys events @@ -891,7 +890,7 @@ INTERNAL void user_update(void) } /* Push game cmds */ - push_game_cmds(&cmd_list); + pubilsh_game_cmds(&cmd_list); /* ========================== * * Present