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) {
ebiten.SetClearingScreenSkipped(!ebiten.IsClearingScreenSkipped())
ebiten.SetScreenClearedEveryFrame(!ebiten.IsScreenClearedEveryFrame())
}
g.count++

View File

@ -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()
}

22
run.go
View File

@ -90,7 +90,7 @@ func CurrentFPS() float64 {
var (
isDrawingSkipped = int32(0)
isClearingScreenSkipped = int32(0)
isScreenClearedEveryFrame = int32(1)
currentMaxTPS = int32(DefaultTPS)
)
@ -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.

View File

@ -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)