mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
da2db2f54e
commit
c28bcc26fc
@ -209,14 +209,14 @@ func (g *game) Update() error {
|
|||||||
}
|
}
|
||||||
if inpututil.IsKeyJustPressed(ebiten.KeyT) {
|
if inpututil.IsKeyJustPressed(ebiten.KeyT) {
|
||||||
switch tps {
|
switch tps {
|
||||||
case ebiten.UncappedTPS:
|
case ebiten.SyncWithFPS:
|
||||||
tps = 30
|
tps = 30
|
||||||
case 30:
|
case 30:
|
||||||
tps = 60
|
tps = 60
|
||||||
case 60:
|
case 60:
|
||||||
tps = 120
|
tps = 120
|
||||||
case 120:
|
case 120:
|
||||||
tps = ebiten.UncappedTPS
|
tps = ebiten.SyncWithFPS
|
||||||
default:
|
default:
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
@ -293,8 +293,8 @@ func (g *game) Draw(screen *ebiten.Image) {
|
|||||||
wx, wy := ebiten.WindowPosition()
|
wx, wy := ebiten.WindowPosition()
|
||||||
minw, minh, maxw, maxh := ebiten.WindowSizeLimits()
|
minw, minh, maxw, maxh := ebiten.WindowSizeLimits()
|
||||||
cx, cy := ebiten.CursorPosition()
|
cx, cy := ebiten.CursorPosition()
|
||||||
tpsStr := "Uncapped"
|
tpsStr := "Sync with FPS"
|
||||||
if t := ebiten.MaxTPS(); t != ebiten.UncappedTPS {
|
if t := ebiten.MaxTPS(); t != ebiten.SyncWithFPS {
|
||||||
tpsStr = fmt.Sprintf("%d", t)
|
tpsStr = fmt.Sprintf("%d", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,13 +125,13 @@ func updateFPSAndTPS(now int64, count int) {
|
|||||||
tpsCount = 0
|
tpsCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const UncappedTPS = -1
|
const SyncWithFPS = -1
|
||||||
|
|
||||||
// Update updates the inner clock state and returns an integer value
|
// Update updates the inner clock state and returns an integer value
|
||||||
// indicating how many times the game should update based on given tps.
|
// indicating how many times the game should update based on given tps.
|
||||||
// tps represents TPS (ticks per second).
|
// tps represents TPS (ticks per second).
|
||||||
// If tps is UncappedTPS, Update always returns 1.
|
// If tps is SyncWithFPS, Update always returns 1.
|
||||||
// If tps <= 0 and not UncappedTPS, Update always returns 0.
|
// If tps <= 0 and not SyncWithFPS, Update always returns 0.
|
||||||
//
|
//
|
||||||
// Update is expected to be called per frame.
|
// Update is expected to be called per frame.
|
||||||
func Update(tps int) int {
|
func Update(tps int) int {
|
||||||
@ -146,7 +146,7 @@ func Update(tps int) int {
|
|||||||
lastNow = n
|
lastNow = n
|
||||||
|
|
||||||
c := 0
|
c := 0
|
||||||
if tps == UncappedTPS {
|
if tps == SyncWithFPS {
|
||||||
c = 1
|
c = 1
|
||||||
} else if tps > 0 {
|
} else if tps > 0 {
|
||||||
c = calcCountFromTPS(int64(tps), n)
|
c = calcCountFromTPS(int64(tps), n)
|
||||||
|
17
run.go
17
run.go
@ -364,20 +364,25 @@ func CurrentTPS() float64 {
|
|||||||
return clock.CurrentTPS()
|
return clock.CurrentTPS()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UncappedTPS is a special TPS value that means the game doesn't have limitation on TPS.
|
// SyncWithFPS is a special TPS value that means TPS syncs with FPS.
|
||||||
const UncappedTPS = clock.UncappedTPS
|
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),
|
// SetMaxTPS sets the maximum TPS (ticks per second),
|
||||||
// that represents how many updating function is called per second.
|
// that represents how many updating function is called per second.
|
||||||
// The initial value is 60.
|
// The initial value is 60.
|
||||||
//
|
//
|
||||||
// If tps is UncappedTPS, TPS is uncapped and the game is updated per frame.
|
// If tps is SyncWithFPS, TPS is uncapped and the game is updated per frame.
|
||||||
// If tps is negative but not UncappedTPS, SetMaxTPS panics.
|
// If tps is negative but not SyncWithFPS, SetMaxTPS panics.
|
||||||
//
|
//
|
||||||
// SetMaxTPS is concurrent-safe.
|
// SetMaxTPS is concurrent-safe.
|
||||||
func SetMaxTPS(tps int) {
|
func SetMaxTPS(tps int) {
|
||||||
if tps < 0 && tps != UncappedTPS {
|
if tps < 0 && tps != SyncWithFPS {
|
||||||
panic("ebiten: tps must be >= 0 or UncappedTPS")
|
panic("ebiten: tps must be >= 0 or SyncWithFPS")
|
||||||
}
|
}
|
||||||
atomic.StoreInt32(¤tMaxTPS, int32(tps))
|
atomic.StoreInt32(¤tMaxTPS, int32(tps))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user