loop: Move clock.FPS to loop.FPS to reduce dependencies

This commit is contained in:
Hajime Hoshi 2017-08-05 22:08:58 +09:00
parent 19760be346
commit 94843fbe73
4 changed files with 9 additions and 10 deletions

View File

@ -263,7 +263,7 @@ func (c *Context) loop() {
c.m.Unlock() c.m.Unlock()
c.frames++ c.frames++
clock.Inc() clock.Inc()
bytesPerFrame := c.sampleRate * bytesPerSample * channelNum / clock.FPS bytesPerFrame := c.sampleRate * bytesPerSample * channelNum / loop.FPS
l := (c.frames * int64(bytesPerFrame)) - c.writtenBytes l := (c.frames * int64(bytesPerFrame)) - c.writtenBytes
l &= mask l &= mask
c.writtenBytes += l c.writtenBytes += l

View File

@ -18,8 +18,6 @@ import (
"github.com/hajimehoshi/ebiten/internal/sync" "github.com/hajimehoshi/ebiten/internal/sync"
) )
const FPS = 60
var ( var (
m sync.Mutex m sync.Mutex
valid bool valid bool

View File

@ -22,6 +22,8 @@ import (
"github.com/hajimehoshi/ebiten/internal/sync" "github.com/hajimehoshi/ebiten/internal/sync"
) )
const FPS = 60
func CurrentFPS() float64 { func CurrentFPS() float64 {
if currentRunContext == nil { if currentRunContext == nil {
return 0 return 0
@ -95,20 +97,20 @@ func (c *runContext) updateCount(now int64) int {
} }
c.lastClockFrame = f c.lastClockFrame = f
} else { } else {
if t > 5*int64(time.Second)/int64(clock.FPS) { if t > 5*int64(time.Second)/int64(FPS) {
// The previous time is too old. Let's assume that the window was unfocused. // The previous time is too old. Let's assume that the window was unfocused.
count = 0 count = 0
c.lastUpdated = now c.lastUpdated = now
} else { } else {
count = int(t * int64(clock.FPS) / int64(time.Second)) count = int(t * int64(FPS) / int64(time.Second))
} }
} }
// Stabilize FPS. // Stabilize FPS.
if count == 0 && (int64(time.Second)/int64(clock.FPS)/2) < t { if count == 0 && (int64(time.Second)/int64(FPS)/2) < t {
count = 1 count = 1
} }
if count == 2 && (int64(time.Second)/int64(clock.FPS)*3/2) > t { if count == 2 && (int64(time.Second)/int64(FPS)*3/2) > t {
count = 1 count = 1
} }
@ -119,7 +121,7 @@ func (c *runContext) updateCount(now int64) int {
if sync { if sync {
c.lastUpdated = now c.lastUpdated = now
} else { } else {
c.lastUpdated += int64(count) * int64(time.Second) / int64(clock.FPS) c.lastUpdated += int64(count) * int64(time.Second) / int64(FPS)
} }
c.frames += int64(count) c.frames += int64(count)

3
run.go
View File

@ -17,13 +17,12 @@ package ebiten
import ( import (
"sync/atomic" "sync/atomic"
"github.com/hajimehoshi/ebiten/internal/clock"
"github.com/hajimehoshi/ebiten/internal/loop" "github.com/hajimehoshi/ebiten/internal/loop"
"github.com/hajimehoshi/ebiten/internal/ui" "github.com/hajimehoshi/ebiten/internal/ui"
) )
// FPS represents how many times game updating happens in a second (60). // FPS represents how many times game updating happens in a second (60).
const FPS = clock.FPS const FPS = loop.FPS
// CurrentFPS returns the current number of frames per second of rendering. // CurrentFPS returns the current number of frames per second of rendering.
// //