add interp enable def in config

This commit is contained in:
jacob 2024-03-14 14:00:25 -05:00
parent 1d2e7c0b9f
commit fa6df3152c
3 changed files with 16 additions and 4 deletions

View File

@ -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
/* ========================== *

View File

@ -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"));
}

View File

@ -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
}