ui: Introduce DefaultTPS and deprecate FPS

This commit is contained in:
Hajime Hoshi 2018-07-17 02:07:03 +09:00
parent 3a8ca5ad73
commit 16c6ab4d07
9 changed files with 15 additions and 17 deletions

View File

@ -51,7 +51,7 @@ func init() {
}
func (r *recorder) delay() int {
delay := 100 * r.skips / ebiten.FPS
delay := 100 * r.skips / ebiten.TPS()
if delay < 2 {
return 2
}

View File

@ -39,7 +39,7 @@ var (
func update(screen *ebiten.Image) error {
count++
count %= ebiten.FPS * 10
count %= ebiten.TPS() * 10
diff := float64(count) * 0.2
switch {
case 480 < count:

View File

@ -66,7 +66,7 @@ func (s *GamepadScene) Update(state *GameState) error {
if state.Input.gamepadConfig.Scan(gamepadID, b) {
s.currentIndex++
if s.currentIndex == len(virtualGamepadButtons) {
s.countAfterSetting = ebiten.FPS
s.countAfterSetting = ebiten.TPS()
}
}
return nil

View File

@ -242,7 +242,7 @@ func (s *GameScene) Update(state *GameState) error {
return nil
}
const maxLandingCount = ebiten.FPS
maxLandingCount := ebiten.TPS()
if s.currentPiece == nil {
s.initCurrentPiece(s.choosePiece())
}

View File

@ -38,7 +38,7 @@ func init() {
}
func update(screen *ebiten.Image) error {
space.Step(1.0 / ebiten.FPS)
space.Step(1.0 / float64(ebiten.TPS()))
if ebiten.IsDrawingSkipped() {
return nil

View File

@ -117,7 +117,7 @@ func init() {
func update(screen *ebiten.Image) error {
// Change the text color for each second.
if counter%ebiten.FPS == 0 {
if counter%ebiten.TPS() == 0 {
kanjiText = []rune{}
for j := 0; j < 4; j++ {
for i := 0; i < 8; i++ {

View File

@ -66,7 +66,8 @@ func paint(canvas *ebiten.Image, x, y int) {
op.GeoM.Translate(float64(x), float64(y))
// Scale the color and rotate the hue so that colors vary on each frame.
op.ColorM.Scale(1.0, 0.50, 0.125, 1.0)
theta := 2.0 * math.Pi * float64(count%ebiten.FPS) / ebiten.FPS
tps := ebiten.TPS()
theta := 2.0 * math.Pi * float64(count%tps) / float64(tps)
op.ColorM.RotateHue(theta)
canvas.DrawImage(brushImage, op)
}

View File

@ -118,10 +118,8 @@ func playNote(scoreIndex int) rune {
panic("note out of range")
}
const (
vol = 1.0 / 16.0
size = 30 * sampleRate / ebiten.FPS
)
const vol = 1.0 / 16.0
size := 30 * sampleRate / ebiten.TPS()
l := make([]int16, size)
r := make([]int16, size)
square(l, vol, freq, 0.25)

11
run.go
View File

@ -29,12 +29,11 @@ import (
"github.com/hajimehoshi/ebiten/internal/ui"
)
const defaultTPS = 60
// TPS represents a default ticks per second, that represents how many times game updating happens in a second.
const DefaultTPS = 60
// FPS represents how many times game updating happens in a second (60).
//
// BUG: This actually represents TPS, not FPS.
const FPS = defaultTPS
// FPS is deprecated as of 1.8.0-alpha: Use DefaultTPS instead.
const FPS = DefaultTPS
// CurrentFPS returns the current number of frames per second of rendering.
//
@ -53,7 +52,7 @@ var (
)
func init() {
atomic.StoreInt32(&currentTPS, defaultTPS)
atomic.StoreInt32(&currentTPS, DefaultTPS)
}
func setDrawingSkipped(skipped bool) {