mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
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:
parent
0eb5ef0141
commit
9c1b760016
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user