specify arena when queueing game cmds from user thread
This commit is contained in:
parent
83b0b3f255
commit
4b10be1b17
27
src/user.c
27
src/user.c
@ -309,14 +309,13 @@ struct game_cmd_node {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct game_cmd_list {
|
struct game_cmd_list {
|
||||||
struct arena *arena;
|
|
||||||
struct game_cmd_node *first;
|
struct game_cmd_node *first;
|
||||||
struct game_cmd_node *last;
|
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;
|
node->cmd = cmd;
|
||||||
if (list->first) {
|
if (list->first) {
|
||||||
list->last->next = node;
|
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)
|
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 */
|
/* Construct array */
|
||||||
struct game_cmd_array array = { .cmds = arena_dry_push(scratch.arena, struct game_cmd) };
|
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 entity_store *store = G.world.entity_store;
|
||||||
struct sprite_scope *sprite_frame_scope = sprite_scope_begin();
|
struct sprite_scope *sprite_frame_scope = sprite_scope_begin();
|
||||||
struct game_cmd_list cmd_list = {
|
struct game_cmd_list cmd_list = { 0 };
|
||||||
.arena = scratch.arena
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Produce interpolated tick
|
* Produce interpolated tick
|
||||||
@ -455,7 +452,7 @@ INTERNAL void user_update(void)
|
|||||||
struct entity *e = &store->entities[i];
|
struct entity *e = &store->entities[i];
|
||||||
struct entity *e0 = &t0->entity_store->entities[i];
|
struct entity *e0 = &t0->entity_store->entities[i];
|
||||||
struct entity *e1 = &t1->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)) {
|
if (entity_has_prop(e, ENTITY_PROP_TEST)) {
|
||||||
DEBUGBREAKABLE;
|
DEBUGBREAKABLE;
|
||||||
@ -582,7 +579,7 @@ INTERNAL void user_update(void)
|
|||||||
{
|
{
|
||||||
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_CLEAR];
|
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_CLEAR];
|
||||||
if (state.num_presses) {
|
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
|
.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];
|
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_PAUSE];
|
||||||
if (state.num_presses) {
|
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
|
.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];
|
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_STEP];
|
||||||
for (u32 i = 0; i < state.num_presses_and_repeats; ++i) {
|
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
|
.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];
|
struct bind_state state = G.bind_states[USER_BIND_KIND_DEBUG_SPAWN];
|
||||||
if (state.num_presses) {
|
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
|
.kind = GAME_CMD_KIND_SPAWN_TEST
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -796,6 +793,7 @@ INTERNAL void user_update(void)
|
|||||||
__profscope(user_entity_iter);
|
__profscope(user_entity_iter);
|
||||||
struct entity *ent = &store->entities[entity_index];
|
struct entity *ent = &store->entities[entity_index];
|
||||||
if (!(ent->valid && entity_has_prop(ent, ENTITY_PROP_ACTIVE))) continue;
|
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;
|
struct sprite_tag sprite = ent->sprite;
|
||||||
|
|
||||||
@ -843,7 +841,6 @@ INTERNAL void user_update(void)
|
|||||||
/* Calculate sprite xform */
|
/* Calculate sprite xform */
|
||||||
sprite_xform = xform_mul(xf, ent->sprite_local_xform);
|
sprite_xform = xform_mul(xf, ent->sprite_local_xform);
|
||||||
|
|
||||||
|
|
||||||
/* Async load */
|
/* Async load */
|
||||||
struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite);
|
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);
|
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;
|
struct v2 input_aim_pos = G.world_cursor;
|
||||||
if (!G.debug_camera) {
|
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,
|
.kind = GAME_CMD_KIND_PLAYER_MOVE,
|
||||||
.move_dir = input_move_dir,
|
.move_dir = input_move_dir,
|
||||||
.aim_pos = input_aim_pos
|
.aim_pos = input_aim_pos
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Queue player fire cmd */
|
/* 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,
|
.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
|
.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
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user