Rename IsRunningSlowly to IsDrawingSkipped

Fixes #643
This commit is contained in:
Hajime Hoshi 2018-07-10 00:36:43 +09:00
parent 4a6faf5505
commit 3cd9dfd800
46 changed files with 63 additions and 57 deletions

2
doc.go
View File

@ -21,7 +21,7 @@
//
// // Write your game's logical update.
//
// if IsRunningSlowly() {
// if IsDrawingSkipped() {
// // When the game is running slowly, the rendering result
// // will not be adopted.
// return nil

View File

@ -31,7 +31,7 @@ func update(screen *ebiten.Image) error {
if err := game.Update(); err != nil {
return err
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}
game.Draw(screen)

View File

@ -37,7 +37,7 @@ var (
)
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -250,7 +250,7 @@ func update(screen *ebiten.Image) error {
thePlayer.Stabilize()
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -48,7 +48,7 @@ func update(screen *ebiten.Image) error {
diff = float64(480-count) * 0.2
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -45,7 +45,7 @@ var (
func update(screen *ebiten.Image) error {
count++
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -227,7 +227,7 @@ func update(screen *ebiten.Image) error {
return err
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -67,7 +67,7 @@ func update(screen *ebiten.Image) error {
player.Play()
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -38,7 +38,7 @@ func (g *Game) Update(r *ebiten.Image) error {
if err := g.sceneManager.Update(&g.input); err != nil {
return err
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -40,7 +40,7 @@ func init() {
func update(screen *ebiten.Image) error {
space.Step(1.0 / ebiten.FPS)
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -63,7 +63,7 @@ func update(screen *ebiten.Image) error {
}
count++
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}
w, h := gophersImage.Size()

View File

@ -283,7 +283,7 @@ func (g *Game) update(screen *ebiten.Image) error {
}
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -37,7 +37,7 @@ var (
)
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -232,7 +232,7 @@ func (g *Game) Update(screen *ebiten.Image) error {
}
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -47,7 +47,7 @@ var (
)
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -133,7 +133,7 @@ func update(screen *ebiten.Image) error {
}
counter++
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -80,7 +80,7 @@ func update(screen *ebiten.Image) error {
return regularTermination
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -75,7 +75,7 @@ func update(screen *ebiten.Image) error {
}
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -57,7 +57,7 @@ func update(screen *ebiten.Image) error {
}
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -90,7 +90,7 @@ func update(screen *ebiten.Image) error {
}
prevPressedI = pressedI
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -40,7 +40,7 @@ var (
func update(screen *ebiten.Image) error {
count++
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -81,7 +81,7 @@ func (p *viewport) Position() (int, int) {
func update(screen *ebiten.Image) error {
theViewport.Move()
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -53,7 +53,7 @@ func update(screen *ebiten.Image) error {
}
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -163,7 +163,7 @@ var (
func update(screen *ebiten.Image) error {
world.Update()
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -82,7 +82,7 @@ func init() {
}
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -106,7 +106,7 @@ func update(screen *ebiten.Image) error {
spotLightVY = -spotLightVY
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -80,7 +80,7 @@ func update(screen *ebiten.Image) error {
ebiten.SetScreenScale(screenScale)
ebiten.SetFullscreen(fullscreen)
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -56,7 +56,7 @@ func init() {
}
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -60,7 +60,7 @@ func update(screen *ebiten.Image) error {
noiseImage.Pix[4*i+3] = 0xff
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -91,7 +91,7 @@ func update(screen *ebiten.Image) error {
count++
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -148,7 +148,7 @@ func update(screen *ebiten.Image) error {
}
frames++
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -36,7 +36,7 @@ var (
)
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -221,7 +221,7 @@ func update(screen *ebiten.Image) error {
}
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -89,7 +89,7 @@ func update(screen *ebiten.Image) error {
loadedSprite = idleSprite
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -39,7 +39,7 @@ var (
func update(screen *ebiten.Image) error {
count++
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}
w, h := gophersImage.Size()

View File

@ -36,7 +36,7 @@ func update(screen *ebiten.Image) error {
count++
count %= 240
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -90,7 +90,7 @@ func update(screen *ebiten.Image) error {
}
player.Play()
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}
msg := fmt.Sprintf("FPS: %0.2f\nThis is an example using infinite audio stream.", ebiten.CurrentFPS())

View File

@ -153,7 +153,7 @@ func update(screen *ebiten.Image) error {
sprites.Update()
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -159,7 +159,7 @@ func update(screen *ebiten.Image) error {
sprites.Update()
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -103,7 +103,7 @@ var (
)
func update(screen *ebiten.Image) error {
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -72,7 +72,7 @@ func update(screen *ebiten.Image) error {
counter++
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -488,7 +488,7 @@ func update(screen *ebiten.Image) error {
checkBox.Update()
textBoxLog.Update()
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -79,7 +79,7 @@ func update(screen *ebiten.Image) error {
audioPlayer.Rewind()
audioPlayer.Play()
}
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}
if audioPlayer.IsPlaying() {

View File

@ -138,7 +138,7 @@ func update(screen *ebiten.Image) error {
count++
if ebiten.IsRunningSlowly() {
if ebiten.IsDrawingSkipped() {
return nil
}

View File

@ -90,7 +90,7 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error {
for i := 0; i < updateCount; i++ {
c.offscreen.fill(0, 0, 0, 0)
setRunningSlowly(i < updateCount-1)
setDrawingSkipped(i < updateCount-1)
if err := hooks.RunBeforeUpdateHooks(); err != nil {
return err
}

30
run.go
View File

@ -44,31 +44,31 @@ func CurrentFPS() float64 {
}
var (
isRunningSlowly = int32(0)
isDrawingSkipped = int32(0)
)
func setRunningSlowly(slow bool) {
func setDrawingSkipped(skipped bool) {
v := int32(0)
if slow {
if skipped {
v = 1
}
atomic.StoreInt32(&isRunningSlowly, v)
atomic.StoreInt32(&isDrawingSkipped, v)
}
// IsRunningSlowly returns true if the game is running too slowly to keep 60 FPS of rendering.
// The game screen is not updated when IsRunningSlowly is true.
// IsDrawingSkipped returns true if the game is running too slowly to keep 60 FPS of rendering.
// The game screen is not updated when IsDrawingSkipped is true.
// It is recommended to skip heavy processing, especially drawing screen,
// when IsRunningSlowly is true.
// when IsDrawingSkipped is true.
//
// The typical code with IsRunningSlowly is this:
// The typical code with IsDrawingSkipped is this:
//
// func update(screen *ebiten.Image) error {
//
// // Update the state.
//
// // When IsRunningSlowly is true, the rendered result is not adopted.
// // When IsDrawingSkipped is true, the rendered result is not adopted.
// // Skip rendering then.
// if ebiten.IsRunningSlowly() {
// if ebiten.IsDrawingSkipped() {
// return nil
// }
//
@ -78,8 +78,14 @@ func setRunningSlowly(slow bool) {
// }
//
// This function is concurrent-safe.
func IsDrawingSkipped() bool {
return atomic.LoadInt32(&isDrawingSkipped) != 0
}
// IsRunningSlowly is deprecated as of 1.8.0-alpha.
// Use IsDrawingSkipped instead.
func IsRunningSlowly() bool {
return atomic.LoadInt32(&isRunningSlowly) != 0
return IsDrawingSkipped()
}
var theGraphicsContext atomic.Value
@ -165,7 +171,7 @@ func (i *imageDumper) update(screen *Image) error {
}
}
if IsRunningSlowly() {
if IsDrawingSkipped() {
return nil
}