mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 19:58:54 +01:00
loop: Fix FPS calculation
This commit is contained in:
parent
c3202b8e58
commit
0de9828e20
@ -156,15 +156,16 @@ func (c *runContext) adjustedNowWithAudio() int64 {
|
|||||||
|
|
||||||
func (c *runContext) render(g GraphicsContext) error {
|
func (c *runContext) render(g GraphicsContext) error {
|
||||||
fps := c.fps
|
fps := c.fps
|
||||||
|
clockN := now()
|
||||||
n := c.adjustedNowWithAudio()
|
n := c.adjustedNowWithAudio()
|
||||||
defer func() {
|
defer func() {
|
||||||
// Calc the current FPS.
|
// Calc the current FPS.
|
||||||
if time.Second > time.Duration(n-c.lastFPSUpdated) {
|
if time.Second > time.Duration(clockN-c.lastFPSUpdated) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentFPS := float64(c.frames) * float64(time.Second) / float64(n-c.lastFPSUpdated)
|
currentFPS := float64(c.frames) * float64(time.Second) / float64(clockN-c.lastFPSUpdated)
|
||||||
c.updateFPS(currentFPS)
|
c.updateFPS(currentFPS)
|
||||||
c.lastFPSUpdated = n
|
c.lastFPSUpdated = clockN
|
||||||
c.frames = 0
|
c.frames = 0
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user