mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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.SetRunnableInBackground(runnableInBackground)
|
||||||
ebiten.SetCursorVisible(cursorVisible)
|
ebiten.SetCursorVisible(cursorVisible)
|
||||||
ebiten.SetVsyncEnabled(vsyncEnabled)
|
ebiten.SetVsyncEnabled(vsyncEnabled)
|
||||||
ebiten.SetTPS(tps)
|
ebiten.SetMaxTPS(tps)
|
||||||
|
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeyI) {
|
if inpututil.IsKeyJustPressed(ebiten.KeyI) {
|
||||||
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})
|
ebiten.SetWindowIcon([]image.Image{createRandomIconImage()})
|
||||||
@ -175,6 +175,10 @@ func update(screen *ebiten.Image) error {
|
|||||||
screen.DrawImage(gophersImage, op)
|
screen.DrawImage(gophersImage, op)
|
||||||
|
|
||||||
x, y := ebiten.CursorPosition()
|
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
|
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
|
||||||
Press F key to switch the fullscreen state
|
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
|
Press Q key to quit
|
||||||
Cursor: (%d, %d)
|
Cursor: (%d, %d)
|
||||||
FPS: %0.2f
|
FPS: %0.2f
|
||||||
TPS: %d`, x, y, ebiten.CurrentFPS(), ebiten.TPS())
|
TPS: %s`, x, y, ebiten.CurrentFPS(), tpsStr)
|
||||||
ebitenutil.DebugPrint(screen, msg)
|
ebitenutil.DebugPrint(screen, msg)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -83,11 +83,9 @@ func (c *graphicsContext) initializeIfNeeded() error {
|
|||||||
|
|
||||||
func (c *graphicsContext) Update(afterFrameUpdate func()) error {
|
func (c *graphicsContext) Update(afterFrameUpdate func()) error {
|
||||||
tps := int(TPS())
|
tps := int(TPS())
|
||||||
count := clock.Update(tps)
|
updateCount := clock.Update(tps)
|
||||||
|
if tps == UncappedTPS {
|
||||||
updateCount := 1
|
updateCount = 1
|
||||||
if tps >= 0 {
|
|
||||||
updateCount = count
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.initializeIfNeeded(); err != nil {
|
if err := c.initializeIfNeeded(); err != nil {
|
||||||
|
17
run.go
17
run.go
@ -564,13 +564,20 @@ func TPS() int {
|
|||||||
return int(atomic.LoadInt32(¤tTPS))
|
return int(atomic.LoadInt32(¤tTPS))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTPS sets the TPS (ticks per second), that represents how many updating function is called
|
// UncappedTPS is a special TPS value that means the game doesn't have limitation on TPS.
|
||||||
// per second.
|
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.
|
// 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.
|
// SetMaxTPS is concurrent-safe.
|
||||||
func SetTPS(tps int) {
|
func SetMaxTPS(tps int) {
|
||||||
|
if tps < 0 && tps != UncappedTPS {
|
||||||
|
panic("ebiten: tps must be >= 0 or UncappedTPS")
|
||||||
|
}
|
||||||
atomic.StoreInt32(¤tTPS, int32(tps))
|
atomic.StoreInt32(¤tTPS, int32(tps))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user