From fc8546e61da0bc3db8d74bf1816b4979028b9b59 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 10 Aug 2021 00:48:39 -0700 Subject: [PATCH] 1-frame smoothing of network area timer --- src/pc/network/network.c | 8 ++++++++ src/pc/utils/misc.c | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 0b926dae..9f21c9af 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -266,7 +266,15 @@ void network_update(void) { network_on_loaded_area(); } } + + // update network area timer + u32 desiredNAT = gNetworkAreaTimer + 1; gNetworkAreaTimer = (clock_elapsed_ticks() - gNetworkAreaTimerClock); + if (gNetworkAreaTimer < desiredNAT) { + gNetworkAreaTimer++; + } else if (gNetworkAreaTimer > desiredNAT) { + gNetworkAreaTimer--; + } // send out update packets if (gNetworkType != NT_NONE) { diff --git a/src/pc/utils/misc.c b/src/pc/utils/misc.c index 3b2a0db1..d89d0f1b 100644 --- a/src/pc/utils/misc.c +++ b/src/pc/utils/misc.c @@ -56,14 +56,14 @@ static u64 clock_elapsed_ns(void) { if (!sClockInitialized) { struct timespec clock_start; _clock_gettime(&clock_start); - clock_start_ns = ((u64)clock_start.tv_sec) * 1000000000 + clock_start.tv_nsec; + clock_start_ns = ((u64)clock_start.tv_sec) * 1000000000 + ((u64)clock_start.tv_nsec); sClockInitialized = true; } struct timespec clock_current; _clock_gettime(&clock_current); - u64 clock_current_ns = ((u64)clock_current.tv_sec) * 1000000000 + clock_current.tv_nsec; + u64 clock_current_ns = ((u64)clock_current.tv_sec) * 1000000000 + ((u64)clock_current.tv_nsec); return (clock_current_ns - clock_start_ns); }