mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
loop: Move clock.FPS to loop.FPS to reduce dependencies
This commit is contained in:
parent
19760be346
commit
94843fbe73
@ -263,7 +263,7 @@ func (c *Context) loop() {
|
||||
c.m.Unlock()
|
||||
c.frames++
|
||||
clock.Inc()
|
||||
bytesPerFrame := c.sampleRate * bytesPerSample * channelNum / clock.FPS
|
||||
bytesPerFrame := c.sampleRate * bytesPerSample * channelNum / loop.FPS
|
||||
l := (c.frames * int64(bytesPerFrame)) - c.writtenBytes
|
||||
l &= mask
|
||||
c.writtenBytes += l
|
||||
|
@ -18,8 +18,6 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/internal/sync"
|
||||
)
|
||||
|
||||
const FPS = 60
|
||||
|
||||
var (
|
||||
m sync.Mutex
|
||||
valid bool
|
||||
|
@ -22,6 +22,8 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/internal/sync"
|
||||
)
|
||||
|
||||
const FPS = 60
|
||||
|
||||
func CurrentFPS() float64 {
|
||||
if currentRunContext == nil {
|
||||
return 0
|
||||
@ -95,20 +97,20 @@ func (c *runContext) updateCount(now int64) int {
|
||||
}
|
||||
c.lastClockFrame = f
|
||||
} 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.
|
||||
count = 0
|
||||
c.lastUpdated = now
|
||||
} else {
|
||||
count = int(t * int64(clock.FPS) / int64(time.Second))
|
||||
count = int(t * int64(FPS) / int64(time.Second))
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@ -119,7 +121,7 @@ func (c *runContext) updateCount(now int64) int {
|
||||
if sync {
|
||||
c.lastUpdated = now
|
||||
} else {
|
||||
c.lastUpdated += int64(count) * int64(time.Second) / int64(clock.FPS)
|
||||
c.lastUpdated += int64(count) * int64(time.Second) / int64(FPS)
|
||||
}
|
||||
|
||||
c.frames += int64(count)
|
||||
|
3
run.go
3
run.go
@ -17,13 +17,12 @@ package ebiten
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
||||
"github.com/hajimehoshi/ebiten/internal/loop"
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
|
||||
// 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.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user