mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: refactoring: reduce call of ui.Get()
This commit is contained in:
parent
6a8e45e6c1
commit
31aa01131d
@ -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
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user