mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
ui: Rename SetTPS -> SetMaxTPS, Introduce UncappedTPS
This commit is contained in:
parent
328c5ff7e1
commit
a7a1f6b4c6
@ -152,7 +152,7 @@ func update(screen *ebiten.Image) error {
|
||||
ebiten.SetRunnableInBackground(runnableInBackground)
|
||||
ebiten.SetCursorVisible(cursorVisible)
|
||||
ebiten.SetVsyncEnabled(vsyncEnabled)
|
||||
ebiten.SetTPS(tps)
|
||||
ebiten.SetMaxTPS(tps)
|
||||
|
||||
if inpututil.IsKeyJustPressed(ebiten.KeyI) {
|
||||
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})
|
||||
@ -175,6 +175,10 @@ func update(screen *ebiten.Image) error {
|
||||
screen.DrawImage(gophersImage, op)
|
||||
|
||||
x, y := ebiten.CursorPosition()
|
||||
tpsStr := "Uncapped"
|
||||
if tps := ebiten.TPS(); tps != ebiten.UncappedTPS {
|
||||
tpsStr = fmt.Sprintf("%d", tps)
|
||||
}
|
||||
msg := fmt.Sprintf(`Press arrow keys to change the window size
|
||||
Press S key to change the window scale
|
||||
Press F key to switch the fullscreen state
|
||||
@ -186,7 +190,7 @@ Press T key to switch TPS (ticks per second)
|
||||
Press Q key to quit
|
||||
Cursor: (%d, %d)
|
||||
FPS: %0.2f
|
||||
TPS: %d`, x, y, ebiten.CurrentFPS(), ebiten.TPS())
|
||||
TPS: %s`, x, y, ebiten.CurrentFPS(), tpsStr)
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
return nil
|
||||
}
|
||||
|
@ -83,11 +83,9 @@ func (c *graphicsContext) initializeIfNeeded() error {
|
||||
|
||||
func (c *graphicsContext) Update(afterFrameUpdate func()) error {
|
||||
tps := int(TPS())
|
||||
count := clock.Update(tps)
|
||||
|
||||
updateCount := 1
|
||||
if tps >= 0 {
|
||||
updateCount = count
|
||||
updateCount := clock.Update(tps)
|
||||
if tps == UncappedTPS {
|
||||
updateCount = 1
|
||||
}
|
||||
|
||||
if err := c.initializeIfNeeded(); err != nil {
|
||||
|
17
run.go
17
run.go
@ -564,13 +564,20 @@ func TPS() int {
|
||||
return int(atomic.LoadInt32(¤tTPS))
|
||||
}
|
||||
|
||||
// SetTPS sets the TPS (ticks per second), that represents how many updating function is called
|
||||
// per second.
|
||||
// UncappedTPS is a special TPS value that means the game doesn't have limitation on TPS.
|
||||
const UncappedTPS = -1
|
||||
|
||||
// SetMaxTPS sets the maximum TPS (ticks per second),
|
||||
// that represents how many updating function is called per second.
|
||||
// The initial value is 60.
|
||||
//
|
||||
// If the given tps is negative, TPS is unfixed and the game is updated per frame.
|
||||
// If tps is UncappedTPS, TPS is uncapped and the game is updated per frame.
|
||||
// If tps is negative but not UncappedTPS, SetMaxTPS panics.
|
||||
//
|
||||
// SetTPS is concurrent-safe.
|
||||
func SetTPS(tps int) {
|
||||
// SetMaxTPS is concurrent-safe.
|
||||
func SetMaxTPS(tps int) {
|
||||
if tps < 0 && tps != UncappedTPS {
|
||||
panic("ebiten: tps must be >= 0 or UncappedTPS")
|
||||
}
|
||||
atomic.StoreInt32(¤tTPS, int32(tps))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user