diff --git a/examples/contextlost/main.go b/examples/contextlost/main.go index e8d3fbb2b..7c637035d 100644 --- a/examples/contextlost/main.go +++ b/examples/contextlost/main.go @@ -94,7 +94,7 @@ func (g *Game) Update(screen *ebiten.Image) error { } if inpututil.IsKeyJustPressed(ebiten.KeyS) { - ebiten.SetClearingScreenSkipped(!ebiten.IsClearingScreenSkipped()) + ebiten.SetScreenClearedEveryFrame(!ebiten.IsScreenClearedEveryFrame()) } g.count++ diff --git a/examples/windowsize/main.go b/examples/windowsize/main.go index 712f84a7a..7daef3469 100644 --- a/examples/windowsize/main.go +++ b/examples/windowsize/main.go @@ -143,7 +143,7 @@ func (g *game) Update(screen *ebiten.Image) error { g.transparent = ebiten.IsScreenTransparent() floating := ebiten.IsWindowFloating() resizable := ebiten.IsWindowResizable() - clearingScreenSkipped := ebiten.IsClearingScreenSkipped() + screenCleared := ebiten.IsScreenClearedEveryFrame() const d = 16 toUpdateWindowSize := false @@ -231,7 +231,7 @@ func (g *game) Update(screen *ebiten.Image) error { resizable = !resizable } if inpututil.IsKeyJustPressed(ebiten.KeyW) { - clearingScreenSkipped = !clearingScreenSkipped + screenCleared = !screenCleared } maximize := inpututil.IsKeyJustPressed(ebiten.KeyM) minimize := inpututil.IsKeyJustPressed(ebiten.KeyN) @@ -258,7 +258,7 @@ func (g *game) Update(screen *ebiten.Image) error { ebiten.SetWindowDecorated(decorated) ebiten.SetWindowPosition(positionX, positionY) ebiten.SetWindowFloating(floating) - ebiten.SetClearingScreenSkipped(clearingScreenSkipped) + ebiten.SetScreenClearedEveryFrame(screenCleared) if maximize && ebiten.IsWindowResizable() { ebiten.MaximizeWindow() } diff --git a/run.go b/run.go index f64eb5751..508329b5d 100644 --- a/run.go +++ b/run.go @@ -89,9 +89,9 @@ func CurrentFPS() float64 { } var ( - isDrawingSkipped = int32(0) - isClearingScreenSkipped = int32(0) - currentMaxTPS = int32(DefaultTPS) + isDrawingSkipped = int32(0) + isScreenClearedEveryFrame = int32(1) + currentMaxTPS = int32(DefaultTPS) ) func setDrawingSkipped(skipped bool) { @@ -102,24 +102,24 @@ func setDrawingSkipped(skipped bool) { atomic.StoreInt32(&isDrawingSkipped, v) } -// SetClearingScreenSkipped enables or disables the clearing of the screen at the beginning of each frame. +// SetScreenClearedEveryFrame enables or disables the clearing of the screen at the beginning of each frame. // The default value is false and the screen is cleared each frame by default. // -// SetClearingScreenSkipped is concurrent-safe. -func SetClearingScreenSkipped(skipped bool) { +// SetScreenClearedEveryFrame is concurrent-safe. +func SetScreenClearedEveryFrame(cleared bool) { v := int32(0) - if skipped { + if cleared { v = 1 } - atomic.StoreInt32(&isClearingScreenSkipped, v) - theUIContext.setClearingScreenSkipped(skipped) + atomic.StoreInt32(&isScreenClearedEveryFrame, v) + theUIContext.setScreenClearedEveryFrame(cleared) } -// IsClearingScreenSkipped returns true if the frame isn't cleared at the beginning. +// IsScreenClearedEveryFrame returns true if the frame isn't cleared at the beginning. // -// IsClearingScreenSkipped is concurrent-safe. -func IsClearingScreenSkipped() bool { - return atomic.LoadInt32(&isClearingScreenSkipped) != 0 +// IsScreenClearedEveryFrame is concurrent-safe. +func IsScreenClearedEveryFrame() bool { + return atomic.LoadInt32(&isScreenClearedEveryFrame) != 0 } // IsDrawingSkipped returns true if rendering result is not adopted. diff --git a/uicontext.go b/uicontext.go index ede097e8c..41aa0734d 100644 --- a/uicontext.go +++ b/uicontext.go @@ -176,7 +176,7 @@ func (c *uiContext) updateOffscreen() { } if c.offscreen == nil { c.offscreen = newImage(sw, sh, FilterDefault) - c.offscreen.mipmap.SetVolatile(!IsClearingScreenSkipped()) + c.offscreen.mipmap.SetVolatile(IsScreenClearedEveryFrame()) } // The window size is automatically adjusted when Run is used. @@ -193,12 +193,12 @@ func (c *uiContext) updateOffscreen() { // scale. This is fine since ebiten.ScreenScale will be deprecated. } -func (c *uiContext) setClearingScreenSkipped(skipped bool) { +func (c *uiContext) setScreenClearedEveryFrame(cleared bool) { c.m.Lock() defer c.m.Unlock() if c.offscreen != nil { - c.offscreen.mipmap.SetVolatile(!skipped) + c.offscreen.mipmap.SetVolatile(cleared) } } @@ -300,7 +300,7 @@ func (c *uiContext) update() error { // Multiple successive Clear call should be integrated into one graphics command, then // calling Clear on every Update should not affect the performance. - if !IsClearingScreenSkipped() { + if IsScreenClearedEveryFrame() { c.offscreen.Clear() } if err := c.game.Update(c.offscreen); err != nil { @@ -318,7 +318,7 @@ func (c *uiContext) draw() { } if game, ok := c.game.(interface{ Draw(*Image) }); ok { - if !IsClearingScreenSkipped() { + if IsScreenClearedEveryFrame() { c.offscreen.Clear() } game.Draw(c.offscreen)