mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
4a6faf5505
commit
3cd9dfd800
2
doc.go
2
doc.go
@ -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
|
||||
|
@ -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)
|
||||
|
@ -37,7 +37,7 @@ var (
|
||||
)
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -250,7 +250,7 @@ func update(screen *ebiten.Image) error {
|
||||
thePlayer.Stabilize()
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ func update(screen *ebiten.Image) error {
|
||||
diff = float64(480-count) * 0.2
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ var (
|
||||
func update(screen *ebiten.Image) error {
|
||||
count++
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ func update(screen *ebiten.Image) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ func update(screen *ebiten.Image) error {
|
||||
player.Play()
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
|
||||
count++
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
w, h := gophersImage.Size()
|
||||
|
@ -283,7 +283,7 @@ func (g *Game) update(screen *ebiten.Image) error {
|
||||
}
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ var (
|
||||
)
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ func (g *Game) Update(screen *ebiten.Image) error {
|
||||
}
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ var (
|
||||
)
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
counter++
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ func update(screen *ebiten.Image) error {
|
||||
return regularTermination
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
prevPressedI = pressedI
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ var (
|
||||
func update(screen *ebiten.Image) error {
|
||||
count++
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ var (
|
||||
func update(screen *ebiten.Image) error {
|
||||
world.Update()
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ func init() {
|
||||
}
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ func update(screen *ebiten.Image) error {
|
||||
spotLightVY = -spotLightVY
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ func update(screen *ebiten.Image) error {
|
||||
ebiten.SetScreenScale(screenScale)
|
||||
ebiten.SetFullscreen(fullscreen)
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ func init() {
|
||||
}
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ func update(screen *ebiten.Image) error {
|
||||
noiseImage.Pix[4*i+3] = 0xff
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ func update(screen *ebiten.Image) error {
|
||||
count++
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
frames++
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ var (
|
||||
)
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ func update(screen *ebiten.Image) error {
|
||||
loadedSprite = idleSprite
|
||||
}
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ var (
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
count++
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
w, h := gophersImage.Size()
|
||||
|
@ -36,7 +36,7 @@ func update(screen *ebiten.Image) error {
|
||||
count++
|
||||
count %= 240
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
|
@ -153,7 +153,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
sprites.Update()
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
sprites.Update()
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ var (
|
||||
)
|
||||
|
||||
func update(screen *ebiten.Image) error {
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
counter++
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ func update(screen *ebiten.Image) error {
|
||||
checkBox.Update()
|
||||
textBoxLog.Update()
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -138,7 +138,7 @@ func update(screen *ebiten.Image) error {
|
||||
|
||||
count++
|
||||
|
||||
if ebiten.IsRunningSlowly() {
|
||||
if ebiten.IsDrawingSkipped() {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -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
30
run.go
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user