ui: Use integers as much as possible

This commit is contained in:
Hajime Hoshi 2016-04-09 16:57:04 +09:00
parent 328900ec80
commit 884719264e

9
run.go
View File

@ -199,9 +199,10 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
currentRunContext.setRunningSlowly(false) currentRunContext.setRunningSlowly(false)
beforeForUpdate = now beforeForUpdate = now
} else { } else {
t := float64(now-beforeForUpdate) * FPS / float64(time.Second) t := now - beforeForUpdate
currentRunContext.setRunningSlowly(t >= 2.5) currentRunContext.setRunningSlowly(t*FPS >= int64(time.Second*5/2))
for i := 0; i < int(t); i++ { tt := int(t * FPS / int64(time.Second))
for i := 0; i < tt; i++ {
if err := ui.CurrentUI().DoEvents(); err != nil { if err := ui.CurrentUI().DoEvents(); err != nil {
return err return err
} }
@ -213,7 +214,7 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
} }
} }
ui.CurrentUI().SwapBuffers() ui.CurrentUI().SwapBuffers()
beforeForUpdate += int64(t) * int64(time.Second/FPS) beforeForUpdate += int64(tt) * int64(time.Second) / FPS
frames++ frames++
} }