From fa6df3152ce32dab219977c8409c92f012fc2a4a Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 14 Mar 2024 14:00:25 -0500 Subject: [PATCH] add interp enable def in config --- src/config.h | 4 +++- src/game.c | 9 ++++++++- src/user.c | 7 +++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/config.h b/src/config.h index 5b2ea5ee..2c3576dc 100644 --- a/src/config.h +++ b/src/config.h @@ -8,6 +8,7 @@ #define PIXELS_PER_UNIT 256 #define GAME_FPS 30 +#define GAME_TIMESCALE 1 #define USER_FRAME_LIMIT 300 @@ -15,7 +16,8 @@ * Delay ms = USER_INTERP_OFFSET_TICK_RATIO * Game tick rate * E.g: At 1.5, the user thread will render 49.5ms back in time (if game thread runs at 30FPS) */ -#define USER_INTERP_OFFSET_TICK_RATIO 1.2 +#define USER_INTERP_OFFSET_TICK_RATIO 1.1 +#define USER_INTERP_ENABLED 1 /* ========================== * diff --git a/src/game.c b/src/game.c index 8ed8bda4..ab8f732d 100644 --- a/src/game.c +++ b/src/game.c @@ -457,6 +457,13 @@ INTERNAL void game_update(void) ent->world_xform = follow->world_xform; ent->world_xform = xform_with_rotation(ent->world_xform, 0); ent->world_xform = xform_with_scale(ent->world_xform, V2(1, 1)); + + if (entity_has_prop(follow, ENTITY_PROP_PLAYER_CONTROLLED)) { + struct v2 focus_dir = follow->player_focus_dir; + struct v2 focus_half_dir = v2_mul(focus_dir, 0.5f); + struct v2 focus_half_pos = v2_add(follow->world_xform.og, focus_half_dir); + ent->world_xform.og = focus_half_pos; + } } /* ========================== * @@ -521,7 +528,7 @@ void game_startup(void) L.published_tick_mutex = sys_mutex_alloc(); - L.world.timescale = 1.0; + L.world.timescale = GAME_TIMESCALE; L.game_thread = sys_thread_init(&game_thread_entry_point, NULL, STR("[P2] Game thread")); } diff --git a/src/user.c b/src/user.c index b6bd89b0..ee44362d 100644 --- a/src/user.c +++ b/src/user.c @@ -363,6 +363,7 @@ INTERNAL void user_update(void) { __profscope(produce_interpolated_tick); +#if USER_INTERP_ENABLED f64 blend_time_offset = (1.0 / GAME_FPS) * USER_INTERP_OFFSET_TICK_RATIO; f64 blend_time = L.time > blend_time_offset ? L.time - blend_time_offset : 0; @@ -384,7 +385,7 @@ INTERNAL void user_update(void) } world_copy_replace(&L.world, t1); -#if 1 + /* Blend time */ L.world.time = math_lerp_f64(t0->time, t1->time, (f64)tick_blend); @@ -414,7 +415,9 @@ INTERNAL void user_update(void) } } #else - (UNUSED)tick_blend; + struct interp_ticks interp_ticks = pull_ticks(L.time); + world_copy_replace(&L.world, interp_ticks.to_tick); + tick_is_first_frame = L.world.tick_id == 0; #endif }