mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 17:32:02 +01:00
ebiten: Implement SetClearingScreenSkipped/IsClearingScreenSkipped (#1302)
Fixes #1132
This commit is contained in:
parent
a1c7c18788
commit
e96a1fb1c7
24
run.go
24
run.go
@ -89,8 +89,9 @@ func CurrentFPS() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
isDrawingSkipped = int32(0)
|
isDrawingSkipped = int32(0)
|
||||||
currentMaxTPS = int32(DefaultTPS)
|
isClearingScreenSkipped = int32(0)
|
||||||
|
currentMaxTPS = int32(DefaultTPS)
|
||||||
)
|
)
|
||||||
|
|
||||||
func setDrawingSkipped(skipped bool) {
|
func setDrawingSkipped(skipped bool) {
|
||||||
@ -101,6 +102,25 @@ 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.
|
||||||
|
// The default value is false and the screen is cleared each frame by default.
|
||||||
|
//
|
||||||
|
// SetClearingScreenSkipped is concurrent-safe.
|
||||||
|
func SetClearingScreenSkipped(skipped bool) {
|
||||||
|
v := int32(0)
|
||||||
|
if skipped {
|
||||||
|
v = 1
|
||||||
|
}
|
||||||
|
atomic.StoreInt32(&isClearingScreenSkipped, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsClearingScreenSkipped returns true if the frame isn't cleared at the beginning.
|
||||||
|
//
|
||||||
|
// IsClearingScreenSkipped is concurrent-safe.
|
||||||
|
func IsClearingScreenSkipped() bool {
|
||||||
|
return atomic.LoadInt32(&isClearingScreenSkipped) != 0
|
||||||
|
}
|
||||||
|
|
||||||
// IsDrawingSkipped returns true if rendering result is not adopted.
|
// IsDrawingSkipped returns true if rendering result is not adopted.
|
||||||
// It is recommended to skip drawing images or screen
|
// It is recommended to skip drawing images or screen
|
||||||
// when IsDrawingSkipped is true.
|
// when IsDrawingSkipped is true.
|
||||||
|
@ -290,7 +290,9 @@ 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.
|
||||||
c.offscreen.Clear()
|
if !IsClearingScreenSkipped() {
|
||||||
|
c.offscreen.Clear()
|
||||||
|
}
|
||||||
if err := c.game.Update(c.offscreen); err != nil {
|
if err := c.game.Update(c.offscreen); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -306,7 +308,9 @@ func (c *uiContext) draw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if game, ok := c.game.(interface{ Draw(*Image) }); ok {
|
if game, ok := c.game.(interface{ Draw(*Image) }); ok {
|
||||||
c.offscreen.Clear()
|
if !IsClearingScreenSkipped() {
|
||||||
|
c.offscreen.Clear()
|
||||||
|
}
|
||||||
game.Draw(c.offscreen)
|
game.Draw(c.offscreen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user