clock: Move now() from loop to clock

This commit is contained in:
Hajime Hoshi 2017-08-06 02:12:23 +09:00
parent f0f115b612
commit d1cbfdeec7
4 changed files with 10 additions and 10 deletions

View File

@ -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
}

View File

@ -14,7 +14,7 @@
// +build js
package loop
package clock
import (
"time"

View File

@ -14,7 +14,7 @@
// +build !js
package loop
package clock
import (
"time"

View File

@ -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
}