mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/ui: refactoring: reduce global-variable usages
This commit is contained in:
parent
fa108ca717
commit
3a0f28ce6b
@ -94,12 +94,12 @@ func newContext(game Game) *context {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *context) updateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error {
|
||||
func (c *context) updateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *userInterfaceImpl) error {
|
||||
// TODO: If updateCount is 0 and vsync is disabled, swapping buffers can be skipped.
|
||||
return c.updateFrameImpl(graphicsDriver, clock.UpdateFrame(), outsideWidth, outsideHeight, deviceScaleFactor)
|
||||
return c.updateFrameImpl(graphicsDriver, clock.UpdateFrame(), outsideWidth, outsideHeight, deviceScaleFactor, ui)
|
||||
}
|
||||
|
||||
func (c *context) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error {
|
||||
func (c *context) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *userInterfaceImpl) error {
|
||||
n := 1
|
||||
if graphicsDriver.IsDirectX() {
|
||||
// On DirectX, both framebuffers in the swap chain should be updated.
|
||||
@ -107,20 +107,20 @@ func (c *context) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsi
|
||||
n = 2
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
if err := c.updateFrameImpl(graphicsDriver, 1, outsideWidth, outsideHeight, deviceScaleFactor); err != nil {
|
||||
if err := c.updateFrameImpl(graphicsDriver, 1, outsideWidth, outsideHeight, deviceScaleFactor, ui); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, updateCount int, outsideWidth, outsideHeight float64, deviceScaleFactor float64) (err error) {
|
||||
func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, updateCount int, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *userInterfaceImpl) (err error) {
|
||||
if err := theGlobalState.error(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
theUI.beginFrame()
|
||||
defer theUI.endFrame()
|
||||
ui.beginFrame()
|
||||
defer ui.endFrame()
|
||||
|
||||
// The given outside size can be 0 e.g. just after restoring from the fullscreen mode on Windows (#1589)
|
||||
// Just ignore such cases. Otherwise, creating a zero-sized framebuffer causes a panic.
|
||||
@ -180,7 +180,7 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
|
||||
if err := theGlobalState.error(); err != nil {
|
||||
return err
|
||||
}
|
||||
theUI.resetForTick()
|
||||
ui.resetForTick()
|
||||
}
|
||||
|
||||
// Draw the game.
|
||||
|
@ -766,7 +766,7 @@ func (u *userInterfaceImpl) registerWindowSetSizeCallback() {
|
||||
// In order to call it safely, use runOnAnotherThreadFromMainThread.
|
||||
var err error
|
||||
u.runOnAnotherThreadFromMainThread(func() {
|
||||
err = u.context.forceUpdateFrame(u.graphicsDriver, outsideWidth, outsideHeight, deviceScaleFactor)
|
||||
err = u.context.forceUpdateFrame(u.graphicsDriver, outsideWidth, outsideHeight, deviceScaleFactor, u)
|
||||
})
|
||||
if err != nil {
|
||||
u.err = err
|
||||
@ -1118,7 +1118,7 @@ func (u *userInterfaceImpl) loop() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := u.context.updateFrame(u.graphicsDriver, outsideWidth, outsideHeight, deviceScaleFactor); err != nil {
|
||||
if err := u.context.updateFrame(u.graphicsDriver, outsideWidth, outsideHeight, deviceScaleFactor, u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -299,11 +299,11 @@ func (u *userInterfaceImpl) updateImpl(force bool) error {
|
||||
|
||||
w, h := u.outsideSize()
|
||||
if force {
|
||||
if err := u.context.forceUpdateFrame(u.graphicsDriver, w, h, u.DeviceScaleFactor()); err != nil {
|
||||
if err := u.context.forceUpdateFrame(u.graphicsDriver, w, h, u.DeviceScaleFactor(), u); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := u.context.updateFrame(u.graphicsDriver, w, h, u.DeviceScaleFactor()); err != nil {
|
||||
if err := u.context.updateFrame(u.graphicsDriver, w, h, u.DeviceScaleFactor(), u); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ func (u *userInterfaceImpl) update() error {
|
||||
}()
|
||||
|
||||
w, h := u.outsideSize()
|
||||
if err := u.context.updateFrame(u.graphicsDriver, w, h, deviceScale()); err != nil {
|
||||
if err := u.context.updateFrame(u.graphicsDriver, w, h, deviceScale(), u); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -70,7 +70,7 @@ func (u *userInterfaceImpl) Run(game Game) error {
|
||||
u.input.update(u.context)
|
||||
|
||||
w, h := nintendosdk.ScreenSize()
|
||||
if err := u.context.updateFrame(u.graphicsDriver, float64(w), float64(h), deviceScaleFactor); err != nil {
|
||||
if err := u.context.updateFrame(u.graphicsDriver, float64(w), float64(h), deviceScaleFactor, u); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user