loop: Much better slow-running detection (#223)

This commit is contained in:
Hajime Hoshi 2016-05-29 22:02:06 +09:00
parent deb2ab1cbf
commit 683c692a5b

View File

@ -139,7 +139,6 @@ func Run(g GraphicsContext, width, height, scale int, title string, fps int) err
} else {
// Note that generally t is a little different from 1/60[sec].
t := n2 - beforeForUpdate
currentRunContext.setRunningSlowly(t*int64(fps) >= int64(time.Second*5/2))
tt := int(t * int64(fps) / int64(time.Second))
// As t is not accurate 1/60[sec], errors are accumulated.
// To make the FPS stable, set tt 1 if t is a little less than 1/60[sec].
@ -147,6 +146,8 @@ func Run(g GraphicsContext, width, height, scale int, title string, fps int) err
tt = 1
}
for i := 0; i < tt; i++ {
slow := i < tt-1
currentRunContext.setRunningSlowly(slow)
if err := g.Update(); err != nil {
return err
}