rename next_tick -> tick

This commit is contained in:
jacob 2024-08-12 16:20:36 -05:00
parent b629f53f16
commit c0517a7df6

View File

@ -23,7 +23,7 @@ GLOBAL struct {
struct sys_mutex prev_tick_mutex; struct sys_mutex prev_tick_mutex;
struct atomic_u64 prev_tick_id; struct atomic_u64 prev_tick_id;
struct world prev_tick; struct world prev_tick;
struct world next_tick; struct world tick;
} G = { 0 }, DEBUG_ALIAS(G, G_game); } G = { 0 }, DEBUG_ALIAS(G, G_game);
/* ========================== * /* ========================== *
@ -46,12 +46,12 @@ struct game_startup_receipt game_startup(struct mixer_startup_receipt *mixer_sr,
G.game_cmds_arena = arena_alloc(GIGABYTE(64)); G.game_cmds_arena = arena_alloc(GIGABYTE(64));
/* Initialize ticks */ /* Initialize ticks */
world_alloc(&G.next_tick); world_alloc(&G.tick);
world_alloc(&G.prev_tick); world_alloc(&G.prev_tick);
G.prev_tick_mutex = sys_mutex_alloc(); G.prev_tick_mutex = sys_mutex_alloc();
arena_set_readonly(&G.prev_tick.entity_store->arena); arena_set_readonly(&G.prev_tick.entity_store->arena);
G.next_tick.timescale = GAME_TIMESCALE; G.tick.timescale = GAME_TIMESCALE;
G.game_thread = sys_thread_alloc(&game_thread_entry_point, NULL, STR("[P2] Game thread")); G.game_thread = sys_thread_alloc(&game_thread_entry_point, NULL, STR("[P2] Game thread"));
app_register_exit_callback(&game_shutdown); app_register_exit_callback(&game_shutdown);
@ -108,7 +108,7 @@ INTERNAL void spawn_test_entities(void)
struct v2 size = V2(1, 1); struct v2 size = V2(1, 1);
f32 r = 0; f32 r = 0;
struct entity *e = entity_alloc_top(G.next_tick.entity_store); struct entity *e = entity_alloc_top(G.tick.entity_store);
entity_set_xform(e, XFORM_TRS(.t = pos, .r = r, .s = size)); entity_set_xform(e, XFORM_TRS(.t = pos, .r = r, .s = size));
e->sprite = sprite_tag_from_path(STR("res/graphics/tim.ase")); e->sprite = sprite_tag_from_path(STR("res/graphics/tim.ase"));
@ -136,7 +136,7 @@ INTERNAL void spawn_test_entities(void)
struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size); struct xform xf = XFORM_TRS(.t = pos, .r = r, .s = size);
struct entity *e = entity_alloc_top(G.next_tick.entity_store); struct entity *e = entity_alloc_top(G.tick.entity_store);
entity_set_local_xform(e, xf); entity_set_local_xform(e, xf);
e->sprite = sprite_tag_from_path(STR("res/graphics/gun.ase")); e->sprite = sprite_tag_from_path(STR("res/graphics/gun.ase"));
@ -149,7 +149,7 @@ INTERNAL void spawn_test_entities(void)
/* Camera ent */ /* Camera ent */
{ {
struct entity *e = entity_alloc_top(G.next_tick.entity_store); struct entity *e = entity_alloc_top(G.tick.entity_store);
entity_set_xform(e, XFORM_IDENT); entity_set_xform(e, XFORM_IDENT);
entity_enable_prop(e, ENTITY_PROP_CAMERA); entity_enable_prop(e, ENTITY_PROP_CAMERA);
@ -172,7 +172,7 @@ INTERNAL void publish_game_tick(void)
struct sys_lock lock = sys_mutex_lock_e(&G.prev_tick_mutex); struct sys_lock lock = sys_mutex_lock_e(&G.prev_tick_mutex);
arena_set_readwrite(&G.prev_tick.entity_store->arena); arena_set_readwrite(&G.prev_tick.entity_store->arena);
{ {
world_copy_replace(&G.prev_tick, &G.next_tick); world_copy_replace(&G.prev_tick, &G.tick);
} }
arena_set_readonly(&G.prev_tick.entity_store->arena); arena_set_readonly(&G.prev_tick.entity_store->arena);
atomic_u64_eval_exchange(&G.prev_tick_id, G.prev_tick.tick_id); atomic_u64_eval_exchange(&G.prev_tick_id, G.prev_tick.tick_id);
@ -189,13 +189,13 @@ INTERNAL void game_update(void)
* Begin frame * Begin frame
* ========================== */ * ========================== */
++G.next_tick.tick_id; ++G.tick.tick_id;
G.next_tick.tick_ts = sys_timestamp(); G.tick.tick_ts = sys_timestamp();
G.next_tick.dt = max_f64(0.0, (1.0 / GAME_FPS) * G.next_tick.timescale); G.tick.dt = max_f64(0.0, (1.0 / GAME_FPS) * G.tick.timescale);
G.next_tick.time += G.next_tick.dt; G.tick.time += G.tick.dt;
struct game_cmd_array game_cmds = pop_cmds(scratch.arena); struct game_cmd_array game_cmds = pop_cmds(scratch.arena);
struct entity_store *store = G.next_tick.entity_store; struct entity_store *store = G.tick.entity_store;
struct entity *root = entity_from_handle(store, store->root); struct entity *root = entity_from_handle(store, store->root);
struct sprite_scope *sprite_frame_scope = sprite_scope_begin(); struct sprite_scope *sprite_frame_scope = sprite_scope_begin();
@ -257,7 +257,7 @@ INTERNAL void game_update(void)
struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite); struct sprite_sheet *sheet = sprite_sheet_from_tag_await(sprite_frame_scope, ent->sprite);
struct sprite_sheet_span span = sprite_sheet_get_span(sheet, ent->sprite_span_name); struct sprite_sheet_span span = sprite_sheet_get_span(sheet, ent->sprite_span_name);
f64 time_in_frame = ent->animation_time_in_frame + G.next_tick.dt; f64 time_in_frame = ent->animation_time_in_frame + G.tick.dt;
u64 frame_index = ent->animation_frame; u64 frame_index = ent->animation_frame;
if (frame_index < span.start || frame_index > span.end) { if (frame_index < span.start || frame_index > span.end) {
frame_index = span.start; frame_index = span.start;
@ -375,7 +375,7 @@ INTERNAL void game_update(void)
/* ENTITY_PROP_TEST */ /* ENTITY_PROP_TEST */
if (entity_has_prop(ent, ENTITY_PROP_TEST)) { if (entity_has_prop(ent, ENTITY_PROP_TEST)) {
f32 t = ((f32)G.next_tick.time); f32 t = ((f32)G.tick.time);
struct v2 og = v2_mul(V2(math_cos(t), math_sin(t)), 3); struct v2 og = v2_mul(V2(math_cos(t), math_sin(t)), 3);
f32 r = t * 3; f32 r = t * 3;
struct v2 s = V2(1 + (math_fabs(math_sin(t * 5)) * 3), 1); struct v2 s = V2(1 + (math_fabs(math_sin(t * 5)) * 3), 1);
@ -508,7 +508,7 @@ INTERNAL void game_update(void)
* ========================== */ * ========================== */
{ {
f32 dt = (f32)G.next_tick.dt; f32 dt = (f32)G.tick.dt;
/* Apply acceleration to velocity */ /* Apply acceleration to velocity */
struct v2 a = v2_mul(ent->acceleration, dt); struct v2 a = v2_mul(ent->acceleration, dt);
@ -558,7 +558,7 @@ INTERNAL void game_update(void)
/* Lerp camera */ /* Lerp camera */
if (ent->camera_applied_lerp_continuity_gen_plus_one == ent->camera_lerp_continuity_gen + 1) { if (ent->camera_applied_lerp_continuity_gen_plus_one == ent->camera_lerp_continuity_gen + 1) {
f32 t = 1 - math_pow(2.f, -20.f * (f32)G.next_tick.dt); f32 t = 1 - math_pow(2.f, -20.f * (f32)G.tick.dt);
xf = xform_lerp(xf, ent->camera_xform_target, t); xf = xform_lerp(xf, ent->camera_xform_target, t);
} else { } else {
/* Skip lerp */ /* Skip lerp */
@ -574,7 +574,7 @@ INTERNAL void game_update(void)
if (entity_has_prop(ent, ENTITY_PROP_TEST_SOUND_EMITTER)) { if (entity_has_prop(ent, ENTITY_PROP_TEST_SOUND_EMITTER)) {
struct mixer_desc desc = ent->sound_desc; struct mixer_desc desc = ent->sound_desc;
desc.speed = G.next_tick.timescale; desc.speed = G.tick.timescale;
desc.pos = entity_get_xform(ent).og; desc.pos = entity_get_xform(ent).og;
struct sound *sound = sound_load_async(ent->sound_name, 0); struct sound *sound = sound_load_async(ent->sound_name, 0);