ebiten: refactoring: reduce call of ui.Get()

This commit is contained in:
Hajime Hoshi 2022-02-13 19:40:03 +09:00
parent 6a8e45e6c1
commit 31aa01131d
2 changed files with 5 additions and 7 deletions

View File

@ -27,7 +27,7 @@ import (
const DefaultTPS = 60
type Context interface {
UpdateOffscreen(outsideWidth, outsideHeight float64) (int, int)
UpdateOffscreen(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int)
UpdateFrame(updateCount int, screenScale float64, offsetX, offsetY float64) error
}
@ -56,7 +56,7 @@ func (c *contextImpl) forceUpdateFrame(deviceScaleFactor float64) error {
}
func (c *contextImpl) updateFrameImpl(updateCount int, deviceScaleFactor float64) error {
ow, oh := c.context.UpdateOffscreen(c.outsideWidth, c.outsideHeight)
ow, oh := c.context.UpdateOffscreen(c.outsideWidth, c.outsideHeight, deviceScaleFactor)
c.offscreenWidth = ow
c.offscreenHeight = oh

View File

@ -42,15 +42,13 @@ func (c *uiContext) set(game Game) {
c.game = game
}
func (c *uiContext) UpdateOffscreen(outsideWidth, outsideHeight float64) (int, int) {
d := ui.Get().DeviceScaleFactor()
sw, sh := int(outsideWidth*d), int(outsideHeight*d)
func (c *uiContext) UpdateOffscreen(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) {
ow, oh := c.game.Layout(int(outsideWidth), int(outsideHeight))
if ow <= 0 || oh <= 0 {
panic("ebiten: Layout must return positive numbers")
}
sw, sh := int(outsideWidth*deviceScaleFactor), int(outsideHeight*deviceScaleFactor)
if c.screen != nil {
if w, h := c.screen.Size(); w != sw || h != sh {
c.screen.Dispose()
@ -58,7 +56,7 @@ func (c *uiContext) UpdateOffscreen(outsideWidth, outsideHeight float64) (int, i
}
}
if c.screen == nil {
c.screen = newScreenFramebufferImage(int(outsideWidth*d), int(outsideHeight*d))
c.screen = newScreenFramebufferImage(sw, sh)
}
if c.offscreen != nil {