clock: Bug fix: The timer should continue even when the clock is adjusted

If the clock is reversed:
* lastSystemTime should be reset with the current time
* FPS/TPS calculation state should be reset
This commit is contained in:
Hajime Hoshi 2019-05-24 02:24:18 +09:00
parent 0eb5ef0141
commit 9c1b760016

View File

@ -63,6 +63,7 @@ func calcCountFromTPS(tps int64, now int64) int {
diff := now - lastSystemTime diff := now - lastSystemTime
if diff < 0 { if diff < 0 {
// It is theoretically possible to change the OS clock, so now can be older than lastSystemTime. // It is theoretically possible to change the OS clock, so now can be older than lastSystemTime.
lastSystemTime = now
return 0 return 0
} }
@ -101,6 +102,13 @@ func updateFPSAndTPS(now int64, count int) {
} }
fpsCount++ fpsCount++
tpsCount += count tpsCount += count
if now < lastUpdated {
// It is theoretically possible to change the OS clock, so now can be older than lastSystemTime.
lastUpdated = now
fpsCount = 0
tpsCount = 0
return
}
if time.Second > time.Duration(now-lastUpdated) { if time.Second > time.Duration(now-lastUpdated) {
return return
} }