loop: Fix FPS calculation

This commit is contained in:
Hajime Hoshi 2017-07-13 00:18:46 +09:00
parent c3202b8e58
commit 0de9828e20

View File

@ -156,15 +156,16 @@ func (c *runContext) adjustedNowWithAudio() int64 {
func (c *runContext) render(g GraphicsContext) error { func (c *runContext) render(g GraphicsContext) error {
fps := c.fps fps := c.fps
clockN := now()
n := c.adjustedNowWithAudio() n := c.adjustedNowWithAudio()
defer func() { defer func() {
// Calc the current FPS. // Calc the current FPS.
if time.Second > time.Duration(n-c.lastFPSUpdated) { if time.Second > time.Duration(clockN-c.lastFPSUpdated) {
return return
} }
currentFPS := float64(c.frames) * float64(time.Second) / float64(n-c.lastFPSUpdated) currentFPS := float64(c.frames) * float64(time.Second) / float64(clockN-c.lastFPSUpdated)
c.updateFPS(currentFPS) c.updateFPS(currentFPS)
c.lastFPSUpdated = n c.lastFPSUpdated = clockN
c.frames = 0 c.frames = 0
}() }()