ui: Refactoring: rename variables

This commit is contained in:
Hajime Hoshi 2016-02-28 02:16:57 +09:00
parent fc200ec6f2
commit 8132264a88

32
run.go
View File

@ -60,8 +60,9 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
} }
frames := 0 frames := 0
gameTime := ui.Now() now := ui.Now()
before := ui.Now() beforeForUpdate := now
beforeForFPS := now
for { for {
// TODO: setSize should be called after swapping buffers? // TODO: setSize should be called after swapping buffers?
if 0 < runContext.newScreenWidth || 0 < runContext.newScreenHeight || 0 < runContext.newScreenScale { if 0 < runContext.newScreenWidth || 0 < runContext.newScreenHeight || 0 < runContext.newScreenScale {
@ -92,25 +93,26 @@ func Run(f func(*Image) error, width, height, scale int, title string) error {
return nil return nil
} }
now := ui.Now() now := ui.Now()
// If gameTime is too old, we assume that screen is not shown. // If beforeForUpdate is too old, we assume that screen is not shown.
if int64(5*time.Second/60) < now-gameTime { if int64(5*time.Second/60) < now-beforeForUpdate {
gameTime = now beforeForUpdate = now
} } else {
c := int((now - gameTime) * 60 / int64(time.Second)) c := int((now - beforeForUpdate) * 60 / int64(time.Second))
for i := 0; i < c; i++ { for i := 0; i < c; i++ {
if err := graphicsContext.update(f); err != nil { if err := graphicsContext.update(f); err != nil {
return err return err
}
} }
beforeForUpdate += int64(c) * int64(time.Second/60)
ui.SwapBuffers()
} }
gameTime += int64(c) * int64(time.Second/60)
ui.SwapBuffers()
// Calc the current FPS. // Calc the current FPS.
now = ui.Now() now = ui.Now()
frames++ frames++
if time.Second <= time.Duration(now-before) { if time.Second <= time.Duration(now-beforeForFPS) {
runContext.fps = float64(frames) * float64(time.Second) / float64(now-before) runContext.fps = float64(frames) * float64(time.Second) / float64(now-beforeForFPS)
before = now beforeForFPS = now
frames = 0 frames = 0
} }
} }