From 5fa81ebe782295f5935b75a2dd1421340e4eb949 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 9 Apr 2016 02:33:00 +0900 Subject: [PATCH] ui: Refactoring: Don't re-get ui.Now() to calculate FPS --- run.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/run.go b/run.go index 09f89ce9e..0744ce721 100644 --- a/run.go +++ b/run.go @@ -179,9 +179,9 @@ func Run(f func(*Image) error, width, height, scale int, title string) error { } frames := 0 - now := ui.Now() - beforeForUpdate := now - beforeForFPS := now + n := ui.Now() + beforeForUpdate := n + beforeForFPS := n for { // TODO: setSize should be called after swapping buffers? if err := currentRunContext.updateScreenSize(graphicsContext); err != nil { @@ -212,12 +212,11 @@ func Run(f func(*Image) error, width, height, scale int, title string) error { return err } } - beforeForUpdate += int64(t) * int64(time.Second/FPS) ui.CurrentUI().SwapBuffers() + beforeForUpdate += int64(t) * int64(time.Second/FPS) } // Calc the current FPS. - now = ui.Now() frames++ if time.Second <= time.Duration(now-beforeForFPS) { currentRunContext.updateFPS(float64(frames) * float64(time.Second) / float64(now-beforeForFPS))