ui: Rename TPS -> MaxTPS

This commit is contained in:
Hajime Hoshi 2018-07-17 22:41:27 +09:00
parent eadbabffd9
commit e99f2f9f69
11 changed files with 19 additions and 19 deletions

View File

@ -51,7 +51,7 @@ func init() {
} }
func (r *recorder) delay() int { func (r *recorder) delay() int {
delay := 100 * r.skips / ebiten.TPS() delay := 100 * r.skips / ebiten.MaxTPS()
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.TPS() * 10 count %= ebiten.MaxTPS() * 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.TPS() s.countAfterSetting = ebiten.MaxTPS()
} }
} }
return nil return nil

View File

@ -242,7 +242,7 @@ func (s *GameScene) Update(state *GameState) error {
return nil return nil
} }
maxLandingCount := ebiten.TPS() maxLandingCount := ebiten.MaxTPS()
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 / float64(ebiten.TPS())) space.Step(1.0 / float64(ebiten.MaxTPS()))
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.TPS() == 0 { if counter%ebiten.MaxTPS() == 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,7 @@ 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)
tps := ebiten.TPS() tps := ebiten.MaxTPS()
theta := 2.0 * math.Pi * float64(count%tps) / float64(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

@ -119,7 +119,7 @@ func playNote(scoreIndex int) rune {
} }
const vol = 1.0 / 16.0 const vol = 1.0 / 16.0
size := 30 * sampleRate / ebiten.TPS() size := 30 * sampleRate / ebiten.MaxTPS()
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)

View File

@ -87,7 +87,7 @@ func update(screen *ebiten.Image) error {
runnableInBackground := ebiten.IsRunnableInBackground() runnableInBackground := ebiten.IsRunnableInBackground()
cursorVisible := ebiten.IsCursorVisible() cursorVisible := ebiten.IsCursorVisible()
vsyncEnabled := ebiten.IsVsyncEnabled() vsyncEnabled := ebiten.IsVsyncEnabled()
tps := ebiten.TPS() tps := ebiten.MaxTPS()
if inpututil.IsKeyJustPressed(ebiten.KeyUp) { if inpututil.IsKeyJustPressed(ebiten.KeyUp) {
screenHeight += d screenHeight += d
@ -176,8 +176,8 @@ func update(screen *ebiten.Image) error {
x, y := ebiten.CursorPosition() x, y := ebiten.CursorPosition()
tpsStr := "Uncapped" tpsStr := "Uncapped"
if tps := ebiten.TPS(); tps != ebiten.UncappedTPS { if maxTPS := ebiten.MaxTPS(); maxTPS != ebiten.UncappedTPS {
tpsStr = fmt.Sprintf("%d", tps) tpsStr = fmt.Sprintf("%d", maxTPS)
} }
msg := fmt.Sprintf(`Press arrow keys to change the window size msg := fmt.Sprintf(`Press arrow keys to change the window size
Press S key to change the window scale Press S key to change the window scale

View File

@ -82,7 +82,7 @@ func (c *graphicsContext) initializeIfNeeded() error {
} }
func (c *graphicsContext) Update(afterFrameUpdate func()) error { func (c *graphicsContext) Update(afterFrameUpdate func()) error {
tps := int(TPS()) tps := int(MaxTPS())
updateCount := clock.Update(tps) updateCount := clock.Update(tps)
if tps == UncappedTPS { if tps == UncappedTPS {
updateCount = 1 updateCount = 1

14
run.go
View File

@ -48,11 +48,11 @@ func CurrentFPS() float64 {
var ( var (
isDrawingSkipped = int32(0) isDrawingSkipped = int32(0)
currentTPS = int32(0) currentMaxTPS = int32(0)
) )
func init() { func init() {
atomic.StoreInt32(&currentTPS, DefaultTPS) atomic.StoreInt32(&currentMaxTPS, DefaultTPS)
} }
func setDrawingSkipped(skipped bool) { func setDrawingSkipped(skipped bool) {
@ -557,11 +557,11 @@ func SetVsyncEnabled(enabled bool) {
ui.SetVsyncEnabled(enabled) ui.SetVsyncEnabled(enabled)
} }
// TPS returns the current TPS. // MaxTPS returns the current maximum TPS.
// //
// TPS is concurrent-safe. // MaxTPS is concurrent-safe.
func TPS() int { func MaxTPS() int {
return int(atomic.LoadInt32(&currentTPS)) return int(atomic.LoadInt32(&currentMaxTPS))
} }
// UncappedTPS is a special TPS value that means the game doesn't have limitation on TPS. // UncappedTPS is a special TPS value that means the game doesn't have limitation on TPS.
@ -579,5 +579,5 @@ func SetMaxTPS(tps int) {
if tps < 0 && tps != UncappedTPS { if tps < 0 && tps != UncappedTPS {
panic("ebiten: tps must be >= 0 or UncappedTPS") panic("ebiten: tps must be >= 0 or UncappedTPS")
} }
atomic.StoreInt32(&currentTPS, int32(tps)) atomic.StoreInt32(&currentMaxTPS, int32(tps))
} }