mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
internal/clock: force to sync the timer when TPS is updated
This commit is contained in:
parent
ad9abe19a6
commit
f25dda1318
@ -29,6 +29,7 @@ var (
|
|||||||
|
|
||||||
currentFPS float64
|
currentFPS float64
|
||||||
currentTPS float64
|
currentTPS float64
|
||||||
|
prevTPS int64
|
||||||
lastUpdated int64
|
lastUpdated int64
|
||||||
fpsCount = 0
|
fpsCount = 0
|
||||||
tpsCount = 0
|
tpsCount = 0
|
||||||
@ -82,13 +83,14 @@ func calcCountFromTPS(tps int64, now int64) int {
|
|||||||
|
|
||||||
// Detect whether the previous time is too old.
|
// 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).
|
// 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.
|
// The previous time is too old.
|
||||||
// Let's force to sync the game time with the system clock.
|
// Let's force to sync the game time with the system clock.
|
||||||
syncWithSystemClock = true
|
syncWithSystemClock = true
|
||||||
} else {
|
} else {
|
||||||
count = int(diff * tps / int64(time.Second))
|
count = int(diff * tps / int64(time.Second))
|
||||||
}
|
}
|
||||||
|
prevTPS = tps
|
||||||
|
|
||||||
// Stabilize the count.
|
// Stabilize the count.
|
||||||
// Without this adjustment, count can be unstable like 0, 2, 0, 2, ...
|
// Without this adjustment, count can be unstable like 0, 2, 0, 2, ...
|
||||||
|
Loading…
Reference in New Issue
Block a user