loop: Bug fix: the clock needs to be stopped when the window is unfocused

This commit is contained in:
Hajime Hoshi 2017-07-16 23:54:14 +09:00
parent f591ca3d2b
commit 717efd097d

View File

@ -142,9 +142,15 @@ func (c *runContext) updateCount(now int64) int {
count = int(f - c.frames) count = int(f - c.frames)
} }
c.lastClockFrame = f c.lastClockFrame = f
} else {
if t > 5*int64(time.Second)/int64(clock.FPS) {
// The previous time is too old. Let's assume that the window was unfocused.
count = 0
c.lastUpdated = now
} else { } else {
count = int(t * int64(clock.FPS) / int64(time.Second)) count = int(t * int64(clock.FPS) / int64(time.Second))
} }
}
// Stabilize FPS. // Stabilize FPS.
if count == 0 && (int64(time.Second)/int64(clock.FPS)/2) < t { if count == 0 && (int64(time.Second)/int64(clock.FPS)/2) < t {