mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
clock: Rename function names; loop: Rename variables
This commit is contained in:
parent
94843fbe73
commit
a92f77c207
@ -262,7 +262,7 @@ func (c *Context) loop() {
|
||||
c.pingCount--
|
||||
c.m.Unlock()
|
||||
c.frames++
|
||||
clock.Inc()
|
||||
clock.Tick()
|
||||
bytesPerFrame := c.sampleRate * bytesPerSample * channelNum / loop.FPS
|
||||
l := (c.frames * int64(bytesPerFrame)) - c.writtenBytes
|
||||
l &= mask
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
var (
|
||||
m sync.Mutex
|
||||
valid bool
|
||||
frame int64
|
||||
now int64
|
||||
)
|
||||
|
||||
func IsValid() bool {
|
||||
@ -31,16 +31,16 @@ func IsValid() bool {
|
||||
return v
|
||||
}
|
||||
|
||||
func Inc() {
|
||||
func Tick() {
|
||||
m.Lock()
|
||||
valid = true
|
||||
frame++
|
||||
now++
|
||||
m.Unlock()
|
||||
}
|
||||
|
||||
func Frame() int64 {
|
||||
func Now() int64 {
|
||||
m.Lock()
|
||||
n := frame
|
||||
n := now
|
||||
m.Unlock()
|
||||
return n
|
||||
}
|
||||
|
@ -25,10 +25,10 @@ import (
|
||||
const FPS = 60
|
||||
|
||||
func CurrentFPS() float64 {
|
||||
if currentRunContext == nil {
|
||||
if theRunContext == nil {
|
||||
return 0
|
||||
}
|
||||
return currentRunContext.getCurrentFPS()
|
||||
return theRunContext.getCurrentFPS()
|
||||
}
|
||||
|
||||
type runContext struct {
|
||||
@ -44,7 +44,7 @@ type runContext struct {
|
||||
}
|
||||
|
||||
var (
|
||||
currentRunContext *runContext
|
||||
theRunContext *runContext
|
||||
contextInitCh = make(chan struct{})
|
||||
)
|
||||
|
||||
@ -63,21 +63,21 @@ func (c *runContext) updateFPS(fps float64) {
|
||||
|
||||
func Start() error {
|
||||
// TODO: Need lock here?
|
||||
if currentRunContext != nil {
|
||||
if theRunContext != nil {
|
||||
return errors.New("loop: The game is already running")
|
||||
}
|
||||
currentRunContext = &runContext{}
|
||||
theRunContext = &runContext{}
|
||||
|
||||
n := now()
|
||||
currentRunContext.lastUpdated = n
|
||||
currentRunContext.lastFPSUpdated = n
|
||||
theRunContext.lastUpdated = n
|
||||
theRunContext.lastFPSUpdated = n
|
||||
|
||||
close(contextInitCh)
|
||||
return nil
|
||||
}
|
||||
|
||||
func End() {
|
||||
currentRunContext = nil
|
||||
theRunContext = nil
|
||||
}
|
||||
|
||||
func (c *runContext) updateCount(now int64) int {
|
||||
@ -89,9 +89,9 @@ func (c *runContext) updateCount(now int64) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
if clock.IsValid() && c.lastClockFrame != clock.Frame() {
|
||||
if clock.IsValid() && c.lastClockFrame != clock.Now() {
|
||||
sync = true
|
||||
f := clock.Frame()
|
||||
f := clock.Now()
|
||||
if c.frames < f {
|
||||
count = int(f - c.frames)
|
||||
}
|
||||
@ -130,7 +130,7 @@ func (c *runContext) updateCount(now int64) int {
|
||||
|
||||
func RegisterPing(ping func()) {
|
||||
<-contextInitCh
|
||||
currentRunContext.registerPing(ping)
|
||||
theRunContext.registerPing(ping)
|
||||
}
|
||||
|
||||
func (c *runContext) registerPing(ping func()) {
|
||||
@ -145,7 +145,7 @@ type Updater interface {
|
||||
|
||||
func Update(u Updater) error {
|
||||
<-contextInitCh
|
||||
return currentRunContext.update(u)
|
||||
return theRunContext.update(u)
|
||||
}
|
||||
|
||||
func (c *runContext) update(u Updater) error {
|
||||
|
Loading…
Reference in New Issue
Block a user