ui: Refactoring: Don't re-get ui.Now() to calculate FPS

This commit is contained in:
Hajime Hoshi 2016-04-09 02:33:00 +09:00
parent 9dfbb4161e
commit 5fa81ebe78

9
run.go
View File

@ -179,9 +179,9 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
} }
frames := 0 frames := 0
now := ui.Now() n := ui.Now()
beforeForUpdate := now beforeForUpdate := n
beforeForFPS := now beforeForFPS := n
for { for {
// TODO: setSize should be called after swapping buffers? // TODO: setSize should be called after swapping buffers?
if err := currentRunContext.updateScreenSize(graphicsContext); err != nil { 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 return err
} }
} }
beforeForUpdate += int64(t) * int64(time.Second/FPS)
ui.CurrentUI().SwapBuffers() ui.CurrentUI().SwapBuffers()
beforeForUpdate += int64(t) * int64(time.Second/FPS)
} }
// Calc the current FPS. // Calc the current FPS.
now = ui.Now()
frames++ frames++
if time.Second <= time.Duration(now-beforeForFPS) { if time.Second <= time.Duration(now-beforeForFPS) {
currentRunContext.updateFPS(float64(frames) * float64(time.Second) / float64(now-beforeForFPS)) currentRunContext.updateFPS(float64(frames) * float64(time.Second) / float64(now-beforeForFPS))