From 89a4b3b22f4b1fe08d5a4d007b1d7893f40ab254 Mon Sep 17 00:00:00 2001 From: jacob Date: Wed, 26 Feb 2025 07:58:05 -0600 Subject: [PATCH] use full rtt instead of half rtt for determining simulation tick count --- src/host.c | 9 +++++++-- src/user.c | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/host.c b/src/host.c index c3a48d0e..fdf60fde 100644 --- a/src/host.c +++ b/src/host.c @@ -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; diff --git a/src/user.c b/src/user.c index e3ca6520..5da9585a 100644 --- a/src/user.c +++ b/src/user.c @@ -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; }