internal/clock: Rename UncappedTPS -> SyncWithFPS

Closes #1726
This commit is contained in:
Hajime Hoshi 2021-07-22 22:44:58 +09:00
parent da2db2f54e
commit c28bcc26fc
3 changed files with 19 additions and 14 deletions

View File

@ -209,14 +209,14 @@ func (g *game) Update() error {
}
if inpututil.IsKeyJustPressed(ebiten.KeyT) {
switch tps {
case ebiten.UncappedTPS:
case ebiten.SyncWithFPS:
tps = 30
case 30:
tps = 60
case 60:
tps = 120
case 120:
tps = ebiten.UncappedTPS
tps = ebiten.SyncWithFPS
default:
panic("not reached")
}
@ -293,8 +293,8 @@ func (g *game) Draw(screen *ebiten.Image) {
wx, wy := ebiten.WindowPosition()
minw, minh, maxw, maxh := ebiten.WindowSizeLimits()
cx, cy := ebiten.CursorPosition()
tpsStr := "Uncapped"
if t := ebiten.MaxTPS(); t != ebiten.UncappedTPS {
tpsStr := "Sync with FPS"
if t := ebiten.MaxTPS(); t != ebiten.SyncWithFPS {
tpsStr = fmt.Sprintf("%d", t)
}

View File

@ -125,13 +125,13 @@ func updateFPSAndTPS(now int64, count int) {
tpsCount = 0
}
const UncappedTPS = -1
const SyncWithFPS = -1
// Update updates the inner clock state and returns an integer value
// indicating how many times the game should update based on given tps.
// tps represents TPS (ticks per second).
// If tps is UncappedTPS, Update always returns 1.
// If tps <= 0 and not UncappedTPS, Update always returns 0.
// If tps is SyncWithFPS, Update always returns 1.
// If tps <= 0 and not SyncWithFPS, Update always returns 0.
//
// Update is expected to be called per frame.
func Update(tps int) int {
@ -146,7 +146,7 @@ func Update(tps int) int {
lastNow = n
c := 0
if tps == UncappedTPS {
if tps == SyncWithFPS {
c = 1
} else if tps > 0 {
c = calcCountFromTPS(int64(tps), n)

17
run.go
View File

@ -364,20 +364,25 @@ func CurrentTPS() float64 {
return clock.CurrentTPS()
}
// UncappedTPS is a special TPS value that means the game doesn't have limitation on TPS.
const UncappedTPS = clock.UncappedTPS
// SyncWithFPS is a special TPS value that means TPS syncs with FPS.
const SyncWithFPS = clock.SyncWithFPS
// UncappedTPS is a special TPS value that means TPS syncs with FPS.
//
// Deprecated: as of v2.2. Use SyncWithFPS instead.
const UncappedTPS = SyncWithFPS
// SetMaxTPS sets the maximum TPS (ticks per second),
// that represents how many updating function is called per second.
// The initial value is 60.
//
// If tps is UncappedTPS, TPS is uncapped and the game is updated per frame.
// If tps is negative but not UncappedTPS, SetMaxTPS panics.
// If tps is SyncWithFPS, TPS is uncapped and the game is updated per frame.
// If tps is negative but not SyncWithFPS, SetMaxTPS panics.
//
// SetMaxTPS is concurrent-safe.
func SetMaxTPS(tps int) {
if tps < 0 && tps != UncappedTPS {
panic("ebiten: tps must be >= 0 or UncappedTPS")
if tps < 0 && tps != SyncWithFPS {
panic("ebiten: tps must be >= 0 or SyncWithFPS")
}
atomic.StoreInt32(&currentMaxTPS, int32(tps))
}