use full rtt instead of half rtt for determining simulation tick count

This commit is contained in:
jacob 2025-02-26 07:58:05 -06:00
parent 6442998795
commit 89a4b3b22f
2 changed files with 11 additions and 5 deletions

View File

@ -85,6 +85,8 @@ struct host_channel {
u64 their_acked_seq;
u64 our_acked_seq;
u64 last_sent_seq;
i64 last_packet_received_ns;
};
struct host_channel_node {
@ -685,8 +687,11 @@ void host_update(struct host *host)
u8 packet_flags = br_read_ubits(&br, 8);
u64 their_acked_seq = br_read_uv(&br);
if (their_acked_seq > channel->their_acked_seq) {
channel->their_acked_seq = their_acked_seq;
if (channel->valid) {
channel->last_packet_received_ns = now_ns;
if (their_acked_seq > channel->their_acked_seq) {
channel->their_acked_seq = their_acked_seq;
}
}
b32 skip_packet = false;

View File

@ -2115,9 +2115,10 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_local_sim_thread_entry_point, arg)
if (is_master) {
desired_step_tick = local_client->last_tick + 1;
} else {
i64 half_rtt_ns = master_client->rtt_ns / 2;
i64 num_predict_ticks = (half_rtt_ns + (step_dt_ns - 1)) / step_dt_ns; /* Half rtt in ticks */
num_predict_ticks += 2; /* Jitter buffer */
i64 rtt_ns = master_client->rtt_ns;
f64 rtt_tick_ratio = (f64)(rtt_ns + (step_dt_ns - 1)) / (f64)step_dt_ns;
i64 num_predict_ticks = math_round_to_int64(rtt_tick_ratio);
num_predict_ticks += 2; /* Jitter buffer */
desired_step_tick = master_client->last_tick + num_predict_ticks;
}