From 0de9828e202e3225a3877e0e3c72a4b3ee04be6c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 13 Jul 2017 00:18:46 +0900 Subject: [PATCH] loop: Fix FPS calculation --- internal/loop/run.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/loop/run.go b/internal/loop/run.go index e02d144d8..1e23e60e5 100644 --- a/internal/loop/run.go +++ b/internal/loop/run.go @@ -156,15 +156,16 @@ func (c *runContext) adjustedNowWithAudio() int64 { func (c *runContext) render(g GraphicsContext) error { fps := c.fps + clockN := now() n := c.adjustedNowWithAudio() defer func() { // Calc the current FPS. - if time.Second > time.Duration(n-c.lastFPSUpdated) { + if time.Second > time.Duration(clockN-c.lastFPSUpdated) { 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.lastFPSUpdated = n + c.lastFPSUpdated = clockN c.frames = 0 }()