Skip to content

Commit

Permalink
internal/clock: Rename UncappedTPS -> SyncWithFPS
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Jul 22, 2021
1 parent da2db2f commit c28bcc2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
8 changes: 4 additions & 4 deletions examples/windowsize/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/clock/clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit c28bcc2

Please sign in to comment.