From f25dda1318c88809f1ddaca37a42b3d825c0baf0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 14 Apr 2022 00:56:37 +0900 Subject: [PATCH] internal/clock: force to sync the timer when TPS is updated --- internal/clock/clock.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/clock/clock.go b/internal/clock/clock.go index 480dc6e38..eb983b472 100644 --- a/internal/clock/clock.go +++ b/internal/clock/clock.go @@ -29,6 +29,7 @@ var ( currentFPS float64 currentTPS float64 + prevTPS int64 lastUpdated int64 fpsCount = 0 tpsCount = 0 @@ -82,13 +83,14 @@ func calcCountFromTPS(tps int64, now int64) int { // Detect whether the previous time is too old. // Use either 5 ticks or 5/60 sec in the case when TPS is too big like 300 (#1444). - if diff > max(int64(time.Second)*5/tps, int64(time.Second)*5/60) { + if diff > max(int64(time.Second)*5/tps, int64(time.Second)*5/60) || prevTPS != tps { // The previous time is too old. // Let's force to sync the game time with the system clock. syncWithSystemClock = true } else { count = int(diff * tps / int64(time.Second)) } + prevTPS = tps // Stabilize the count. // Without this adjustment, count can be unstable like 0, 2, 0, 2, ...