specify arena when queueing game cmds from user thread

This commit is contained in:
jacob 2024-08-19 13:32:30 -05:00
parent 83b0b3f255
commit 4b10be1b17

View File

@ -309,14 +309,13 @@ struct game_cmd_node {
};
struct game_cmd_list {
struct arena *arena;
struct game_cmd_node *first;
struct game_cmd_node *last;
};
INTERNAL void queue_game_cmd(struct game_cmd_list *list, struct game_cmd cmd)
INTERNAL void queue_game_cmd(struct arena *arena, struct game_cmd_list *list, struct game_cmd cmd)
{
struct game_cmd_node *node = arena_push_zero(list->arena, struct game_cmd_node);
struct game_cmd_node *node = arena_push_zero(arena, struct game_cmd_node);
node->cmd = cmd;
if (list->first) {
list->last->next = node;
@ -328,7 +327,7 @@ INTERNAL void queue_game_cmd(struct game_cmd_list *list, struct game_cmd cmd)
INTERNAL void pubilsh_game_cmds(struct game_cmd_list *list)
{
struct temp_arena scratch = scratch_begin(list->arena);
struct temp_arena scratch = scratch_begin_no_conflict();
/* Construct array */
struct game_cmd_array array = { .cmds = arena_dry_push(scratch.arena, struct game_cmd) };
@ -409,9 +408,7 @@ INTERNAL void user_update(void)
struct entity_store *store = G.world.entity_store;
struct sprite_scope *sprite_frame_scope = sprite_scope_begin();
struct game_cmd_list cmd_list = {
.arena = scratch.arena
};
struct game_cmd_list cmd_list = { 0 };
/* ========================== *
* Produce interpolated tick
@ -455,7 +452,7 @@ INTERNAL void user_update(void)
struct entity *e = &store->entities[i];
struct entity *e0 = &t0->entity_store->entities[i];
struct entity *e1 = &t1->entity_store->entities[i];
ASSERT(e->cached_global_xform_dirty == false); /* Game thread should have cached all global xforms before publishing */
ASSERT(!e->valid || e->cached_global_xform_dirty == false); /* Game thread should have cached all global xforms before publishing */
if (entity_has_prop(e, ENTITY_PROP_TEST)) {
DEBUGBREAKABLE;
@ -582,7 +579,7 @@ INTERNAL void user_update(void)
{
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_CLEAR];
if (state.num_presses) {
queue_game_cmd(&cmd_list, (struct game_cmd) {
queue_game_cmd(scratch.arena, &cmd_list, (struct game_cmd) {
.kind = GAME_CMD_KIND_CLEAR_ALL
});
}
@ -592,7 +589,7 @@ INTERNAL void user_update(void)
{
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_PAUSE];
if (state.num_presses) {
queue_game_cmd(&cmd_list, (struct game_cmd) {
queue_game_cmd(scratch.arena, &cmd_list, (struct game_cmd) {
.kind = GAME_CMD_KIND_PAUSE
});
}
@ -602,7 +599,7 @@ INTERNAL void user_update(void)
{
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_STEP];
for (u32 i = 0; i < state.num_presses_and_repeats; ++i) {
queue_game_cmd(&cmd_list, (struct game_cmd) {
queue_game_cmd(scratch.arena, &cmd_list, (struct game_cmd) {
.kind = GAME_CMD_KIND_STEP
});
}
@ -612,7 +609,7 @@ INTERNAL void user_update(void)
{
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_SPAWN];
if (state.num_presses) {
queue_game_cmd(&cmd_list, (struct game_cmd) {
queue_game_cmd(scratch.arena, &cmd_list, (struct game_cmd) {
.kind = GAME_CMD_KIND_SPAWN_TEST
});
}
@ -796,6 +793,7 @@ INTERNAL void user_update(void)
__profscope(user_entity_iter);
struct entity *ent = &store->entities[entity_index];
if (!(ent->valid && entity_has_prop(ent, ENTITY_PROP_ACTIVE))) continue;
if (sprite_tag_is_nil(ent->sprite)) continue;
struct sprite_tag sprite = ent->sprite;
@ -843,7 +841,6 @@ INTERNAL void user_update(void)
/* Calculate sprite xform */
sprite_xform = xform_mul(xf, ent->sprite_local_xform);
/* Async load */
struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite);
struct sprite_texture *texture = sprite_texture_from_tag_async(sprite_frame_scope, sprite);
@ -1043,14 +1040,14 @@ INTERNAL void user_update(void)
}
struct v2 input_aim_pos = G.world_cursor;
if (!G.debug_camera) {
queue_game_cmd(&cmd_list, (struct game_cmd) {
queue_game_cmd(scratch.arena, &cmd_list, (struct game_cmd) {
.kind = GAME_CMD_KIND_PLAYER_MOVE,
.move_dir = input_move_dir,
.aim_pos = input_aim_pos
});
/* Queue player fire cmd */
queue_game_cmd(&cmd_list, (struct game_cmd) {
queue_game_cmd(scratch.arena, &cmd_list, (struct game_cmd) {
.kind = GAME_CMD_KIND_PLAYER_FIRE,
.state = (G.bind_states[USER_BIND_KIND_FIRE].num_presses > 0 || G.bind_states[USER_BIND_KIND_FIRE].is_held) ? GAME_CMD_STATE_START : GAME_CMD_STATE_STOP
});