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 { func (r *recorder) delay() int {
delay := 100 * r.skips / ebiten.FPS delay := 100 * r.skips / ebiten.TPS()
if delay < 2 { if delay < 2 {
return 2 return 2
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -117,7 +117,7 @@ func init() {
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
// Change the text color for each second. // Change the text color for each second.
if counter%ebiten.FPS == 0 { if counter%ebiten.TPS() == 0 {
kanjiText = []rune{} kanjiText = []rune{}
for j := 0; j < 4; j++ { for j := 0; j < 4; j++ {
for i := 0; i < 8; i++ { 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)) op.GeoM.Translate(float64(x), float64(y))
// Scale the color and rotate the hue so that colors vary on each frame. // 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) 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) op.ColorM.RotateHue(theta)
canvas.DrawImage(brushImage, op) canvas.DrawImage(brushImage, op)
} }

View File

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

11
run.go
View File

@ -29,12 +29,11 @@ import (
"github.com/hajimehoshi/ebiten/internal/ui" "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). // FPS is deprecated as of 1.8.0-alpha: Use DefaultTPS instead.
// const FPS = DefaultTPS
// BUG: This actually represents TPS, not FPS.
const FPS = defaultTPS
// CurrentFPS returns the current number of frames per second of rendering. // CurrentFPS returns the current number of frames per second of rendering.
// //
@ -53,7 +52,7 @@ var (
) )
func init() { func init() {
atomic.StoreInt32(&currentTPS, defaultTPS) atomic.StoreInt32(&currentTPS, DefaultTPS)
} }
func setDrawingSkipped(skipped bool) { func setDrawingSkipped(skipped bool) {