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
|
// Update updates the inner clock state and returns an integer value
|
||||||
// indicating how many logical frames the game should update.
|
// indicating how many logical frames the game should update.
|
||||||
func Update(now int64) int {
|
func Update() int {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
|
n := now()
|
||||||
|
|
||||||
if ping != nil {
|
if ping != nil {
|
||||||
ping()
|
ping()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize logicalTime if needed.
|
// Initialize logicalTime if needed.
|
||||||
if logicalTime == 0 {
|
if logicalTime == 0 {
|
||||||
logicalTime = now
|
logicalTime = n
|
||||||
}
|
}
|
||||||
|
|
||||||
t := now - logicalTime
|
t := n - logicalTime
|
||||||
if t < 0 {
|
if t < 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -134,12 +136,12 @@ func Update(now int64) int {
|
|||||||
|
|
||||||
frames += int64(count)
|
frames += int64(count)
|
||||||
if sync {
|
if sync {
|
||||||
logicalTime = now
|
logicalTime = n
|
||||||
} else {
|
} else {
|
||||||
logicalTime += int64(count) * int64(time.Second) / FPS
|
logicalTime += int64(count) * int64(time.Second) / FPS
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFPS(now)
|
updateFPS(n)
|
||||||
|
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
// +build js
|
// +build js
|
||||||
|
|
||||||
package loop
|
package clock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
// +build !js
|
// +build !js
|
||||||
|
|
||||||
package loop
|
package clock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
@ -57,9 +57,7 @@ func Update(u Updater) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *runContext) update(u Updater) error {
|
func (c *runContext) update(u Updater) error {
|
||||||
n := now()
|
count := clock.Update()
|
||||||
|
|
||||||
count := clock.Update(n)
|
|
||||||
if err := u.Update(count); err != nil {
|
if err := u.Update(count); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user