mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
ui: Refactoring
This commit is contained in:
parent
a718ddbf7e
commit
4976460af3
48
uicontext.go
48
uicontext.go
@ -260,45 +260,27 @@ func (c *uiContext) Draw() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *uiContext) update(afterFrameUpdate func()) error {
|
func (c *uiContext) update(afterFrameUpdate func()) error {
|
||||||
|
_, hasDraw := c.game.(interface{ Draw(*Image) })
|
||||||
|
|
||||||
updateCount := clock.Update(MaxTPS())
|
updateCount := clock.Update(MaxTPS())
|
||||||
|
for i := 0; i < updateCount; i++ {
|
||||||
|
c.updateOffscreen()
|
||||||
|
|
||||||
if _, ok := c.game.(interface{ Draw(*Image) }); ok {
|
// When Draw exists, rendering should be always skipped.
|
||||||
for i := 0; i < updateCount; i++ {
|
setDrawingSkipped(hasDraw || i < updateCount-1)
|
||||||
c.updateOffscreen()
|
|
||||||
|
|
||||||
// Rendering should be always skipped.
|
if err := hooks.RunBeforeUpdateHooks(); err != nil {
|
||||||
setDrawingSkipped(true)
|
return err
|
||||||
|
|
||||||
if err := hooks.RunBeforeUpdateHooks(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Multiple successive Clear call should be integrated into one graphics command, then
|
|
||||||
// calling Clear on every Update should not affect the performance.
|
|
||||||
c.offscreen.Clear()
|
|
||||||
if err := c.game.Update(c.offscreen); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
uiDriver().Input().ResetForFrame()
|
|
||||||
afterFrameUpdate()
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
for i := 0; i < updateCount; i++ {
|
|
||||||
c.updateOffscreen()
|
|
||||||
|
|
||||||
c.offscreen.Clear()
|
// Multiple successive Clear call should be integrated into one graphics command, then
|
||||||
|
// calling Clear on every Update should not affect the performance.
|
||||||
setDrawingSkipped(i < updateCount-1)
|
c.offscreen.Clear()
|
||||||
|
if err := c.game.Update(c.offscreen); err != nil {
|
||||||
if err := hooks.RunBeforeUpdateHooks(); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := c.game.Update(c.offscreen); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
uiDriver().Input().ResetForFrame()
|
|
||||||
afterFrameUpdate()
|
|
||||||
}
|
}
|
||||||
|
uiDriver().Input().ResetForFrame()
|
||||||
|
afterFrameUpdate()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user