mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
ui: Refactoring: Don't re-get ui.Now() to calculate FPS
This commit is contained in:
parent
9dfbb4161e
commit
5fa81ebe78
9
run.go
9
run.go
@ -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))
|
||||||
|
Loading…
Reference in New Issue
Block a user