mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
clock: Move now() from loop to clock
This commit is contained in:
parent
f0f115b612
commit
d1cbfdeec7
@ -72,20 +72,22 @@ func updateFPS(now int64) {
|
||||
|
||||
// Update updates the inner clock state and returns an integer value
|
||||
// indicating how many logical frames the game should update.
|
||||
func Update(now int64) int {
|
||||
func Update() int {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
n := now()
|
||||
|
||||
if ping != nil {
|
||||
ping()
|
||||
}
|
||||
|
||||
// Initialize logicalTime if needed.
|
||||
if logicalTime == 0 {
|
||||
logicalTime = now
|
||||
logicalTime = n
|
||||
}
|
||||
|
||||
t := now - logicalTime
|
||||
t := n - logicalTime
|
||||
if t < 0 {
|
||||
return 0
|
||||
}
|
||||
@ -134,12 +136,12 @@ func Update(now int64) int {
|
||||
|
||||
frames += int64(count)
|
||||
if sync {
|
||||
logicalTime = now
|
||||
logicalTime = n
|
||||
} else {
|
||||
logicalTime += int64(count) * int64(time.Second) / FPS
|
||||
}
|
||||
|
||||
updateFPS(now)
|
||||
updateFPS(n)
|
||||
|
||||
return count
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
// +build js
|
||||
|
||||
package loop
|
||||
package clock
|
||||
|
||||
import (
|
||||
"time"
|
@ -14,7 +14,7 @@
|
||||
|
||||
// +build !js
|
||||
|
||||
package loop
|
||||
package clock
|
||||
|
||||
import (
|
||||
"time"
|
@ -57,9 +57,7 @@ func Update(u Updater) error {
|
||||
}
|
||||
|
||||
func (c *runContext) update(u Updater) error {
|
||||
n := now()
|
||||
|
||||
count := clock.Update(n)
|
||||
count := clock.Update()
|
||||
if err := u.Update(count); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user