ebiten: Rename SetClearingScreenSkipped/IsClearingScreenSkipped functions (#1317)

Fixes #1315
This commit is contained in:
Tom Lister 2020-08-20 18:12:22 +10:00 committed by GitHub
parent 4f791a8e85
commit 65d5b64d29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 22 deletions

View File

@ -94,7 +94,7 @@ func (g *Game) Update(screen *ebiten.Image) error {
} }
if inpututil.IsKeyJustPressed(ebiten.KeyS) { if inpututil.IsKeyJustPressed(ebiten.KeyS) {
ebiten.SetClearingScreenSkipped(!ebiten.IsClearingScreenSkipped()) ebiten.SetScreenClearedEveryFrame(!ebiten.IsScreenClearedEveryFrame())
} }
g.count++ g.count++

View File

@ -143,7 +143,7 @@ func (g *game) Update(screen *ebiten.Image) error {
g.transparent = ebiten.IsScreenTransparent() g.transparent = ebiten.IsScreenTransparent()
floating := ebiten.IsWindowFloating() floating := ebiten.IsWindowFloating()
resizable := ebiten.IsWindowResizable() resizable := ebiten.IsWindowResizable()
clearingScreenSkipped := ebiten.IsClearingScreenSkipped() screenCleared := ebiten.IsScreenClearedEveryFrame()
const d = 16 const d = 16
toUpdateWindowSize := false toUpdateWindowSize := false
@ -231,7 +231,7 @@ func (g *game) Update(screen *ebiten.Image) error {
resizable = !resizable resizable = !resizable
} }
if inpututil.IsKeyJustPressed(ebiten.KeyW) { if inpututil.IsKeyJustPressed(ebiten.KeyW) {
clearingScreenSkipped = !clearingScreenSkipped screenCleared = !screenCleared
} }
maximize := inpututil.IsKeyJustPressed(ebiten.KeyM) maximize := inpututil.IsKeyJustPressed(ebiten.KeyM)
minimize := inpututil.IsKeyJustPressed(ebiten.KeyN) minimize := inpututil.IsKeyJustPressed(ebiten.KeyN)
@ -258,7 +258,7 @@ func (g *game) Update(screen *ebiten.Image) error {
ebiten.SetWindowDecorated(decorated) ebiten.SetWindowDecorated(decorated)
ebiten.SetWindowPosition(positionX, positionY) ebiten.SetWindowPosition(positionX, positionY)
ebiten.SetWindowFloating(floating) ebiten.SetWindowFloating(floating)
ebiten.SetClearingScreenSkipped(clearingScreenSkipped) ebiten.SetScreenClearedEveryFrame(screenCleared)
if maximize && ebiten.IsWindowResizable() { if maximize && ebiten.IsWindowResizable() {
ebiten.MaximizeWindow() ebiten.MaximizeWindow()
} }

26
run.go
View File

@ -89,9 +89,9 @@ func CurrentFPS() float64 {
} }
var ( var (
isDrawingSkipped = int32(0) isDrawingSkipped = int32(0)
isClearingScreenSkipped = int32(0) isScreenClearedEveryFrame = int32(1)
currentMaxTPS = int32(DefaultTPS) currentMaxTPS = int32(DefaultTPS)
) )
func setDrawingSkipped(skipped bool) { func setDrawingSkipped(skipped bool) {
@ -102,24 +102,24 @@ func setDrawingSkipped(skipped bool) {
atomic.StoreInt32(&isDrawingSkipped, v) 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. // The default value is false and the screen is cleared each frame by default.
// //
// SetClearingScreenSkipped is concurrent-safe. // SetScreenClearedEveryFrame is concurrent-safe.
func SetClearingScreenSkipped(skipped bool) { func SetScreenClearedEveryFrame(cleared bool) {
v := int32(0) v := int32(0)
if skipped { if cleared {
v = 1 v = 1
} }
atomic.StoreInt32(&isClearingScreenSkipped, v) atomic.StoreInt32(&isScreenClearedEveryFrame, v)
theUIContext.setClearingScreenSkipped(skipped) 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. // IsScreenClearedEveryFrame is concurrent-safe.
func IsClearingScreenSkipped() bool { func IsScreenClearedEveryFrame() bool {
return atomic.LoadInt32(&isClearingScreenSkipped) != 0 return atomic.LoadInt32(&isScreenClearedEveryFrame) != 0
} }
// IsDrawingSkipped returns true if rendering result is not adopted. // IsDrawingSkipped returns true if rendering result is not adopted.

View File

@ -176,7 +176,7 @@ func (c *uiContext) updateOffscreen() {
} }
if c.offscreen == nil { if c.offscreen == nil {
c.offscreen = newImage(sw, sh, FilterDefault) 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. // 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. // 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() c.m.Lock()
defer c.m.Unlock() defer c.m.Unlock()
if c.offscreen != nil { 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 // Multiple successive Clear call should be integrated into one graphics command, then
// calling Clear on every Update should not affect the performance. // calling Clear on every Update should not affect the performance.
if !IsClearingScreenSkipped() { if IsScreenClearedEveryFrame() {
c.offscreen.Clear() c.offscreen.Clear()
} }
if err := c.game.Update(c.offscreen); err != nil { 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 game, ok := c.game.(interface{ Draw(*Image) }); ok {
if !IsClearingScreenSkipped() { if IsScreenClearedEveryFrame() {
c.offscreen.Clear() c.offscreen.Clear()
} }
game.Draw(c.offscreen) game.Draw(c.offscreen)