internal/ui: rename contextImpl -> context

This commit is contained in:
Hajime Hoshi 2022-04-01 17:59:44 +09:00
parent 09a548e055
commit ea1c18d124
9 changed files with 20 additions and 20 deletions

View File

@ -35,7 +35,7 @@ type Game interface {
Draw(screenScale float64, offsetX, offsetY float64, needsClearingScreen bool, framebufferYDirection graphicsdriver.YDirection, screenClearedEveryFrame, filterEnabled bool) error Draw(screenScale float64, offsetX, offsetY float64, needsClearingScreen bool, framebufferYDirection graphicsdriver.YDirection, screenClearedEveryFrame, filterEnabled bool) error
} }
type contextImpl struct { type context struct {
game Game game Game
updateCalled bool updateCalled bool
@ -49,18 +49,18 @@ type contextImpl struct {
m sync.Mutex m sync.Mutex
} }
func newContextImpl(game Game) *contextImpl { func newContext(game Game) *context {
return &contextImpl{ return &context{
game: game, game: game,
} }
} }
func (c *contextImpl) updateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error { func (c *context) updateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error {
// TODO: If updateCount is 0 and vsync is disabled, swapping buffers can be skipped. // TODO: If updateCount is 0 and vsync is disabled, swapping buffers can be skipped.
return c.updateFrameImpl(graphicsDriver, clock.Update(theGlobalState.maxTPS()), outsideWidth, outsideHeight, deviceScaleFactor) return c.updateFrameImpl(graphicsDriver, clock.Update(theGlobalState.maxTPS()), outsideWidth, outsideHeight, deviceScaleFactor)
} }
func (c *contextImpl) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error { func (c *context) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error {
n := 1 n := 1
if graphicsDriver.IsDirectX() { if graphicsDriver.IsDirectX() {
// On DirectX, both framebuffers in the swap chain should be updated. // On DirectX, both framebuffers in the swap chain should be updated.
@ -75,7 +75,7 @@ func (c *contextImpl) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, o
return nil return nil
} }
func (c *contextImpl) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, updateCount int, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error { func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, updateCount int, outsideWidth, outsideHeight float64, deviceScaleFactor float64) error {
if err := theGlobalState.error(); err != nil { if err := theGlobalState.error(); err != nil {
return err return err
} }
@ -135,7 +135,7 @@ func (c *contextImpl) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, up
}) })
} }
func (c *contextImpl) layoutGame(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) { func (c *context) layoutGame(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int) {
c.m.Lock() c.m.Lock()
defer c.m.Unlock() defer c.m.Unlock()
@ -147,7 +147,7 @@ func (c *contextImpl) layoutGame(outsideWidth, outsideHeight float64, deviceScal
return w, h return w, h
} }
func (c *contextImpl) adjustPosition(x, y float64, deviceScaleFactor float64) (float64, float64) { func (c *context) adjustPosition(x, y float64, deviceScaleFactor float64) (float64, float64) {
s, ox, oy := c.screenScaleAndOffsets(deviceScaleFactor) s, ox, oy := c.screenScaleAndOffsets(deviceScaleFactor)
// The scale 0 indicates that the screen is not initialized yet. // The scale 0 indicates that the screen is not initialized yet.
// As any cursor values don't make sense, just return NaN. // As any cursor values don't make sense, just return NaN.
@ -157,7 +157,7 @@ func (c *contextImpl) adjustPosition(x, y float64, deviceScaleFactor float64) (f
return (x*deviceScaleFactor - ox) / s, (y*deviceScaleFactor - oy) / s return (x*deviceScaleFactor - ox) / s, (y*deviceScaleFactor - oy) / s
} }
func (c *contextImpl) screenScaleAndOffsets(deviceScaleFactor float64) (float64, float64, float64) { func (c *context) screenScaleAndOffsets(deviceScaleFactor float64) (float64, float64, float64) {
c.m.Lock() c.m.Lock()
defer c.m.Unlock() defer c.m.Unlock()

View File

@ -31,7 +31,7 @@ type Input struct {
m sync.Mutex m sync.Mutex
} }
func (i *Input) update(context *contextImpl) { func (i *Input) update(context *context) {
i.m.Lock() i.m.Lock()
defer i.m.Unlock() defer i.m.Unlock()

View File

@ -155,7 +155,7 @@ var glfwMouseButtonToMouseButton = map[glfw.MouseButton]MouseButton{
} }
// update must be called from the main thread. // update must be called from the main thread.
func (i *Input) update(window *glfw.Window, context *contextImpl) error { func (i *Input) update(window *glfw.Window, context *context) error {
i.ui.m.Lock() i.ui.m.Lock()
defer i.ui.m.Unlock() defer i.ui.m.Unlock()

View File

@ -23,7 +23,7 @@ import (
) )
func (u *userInterfaceImpl) Run(game Game) error { func (u *userInterfaceImpl) Run(game Game) error {
u.context = newContextImpl(game) u.context = newContext(game)
// Initialize the main thread first so the thread is available at u.run (#809). // Initialize the main thread first so the thread is available at u.run (#809).
u.t = thread.NewOSThread() u.t = thread.NewOSThread()

View File

@ -23,7 +23,7 @@ import (
) )
func (u *userInterfaceImpl) Run(game Game) error { func (u *userInterfaceImpl) Run(game Game) error {
u.context = newContextImpl(game) u.context = newContext(game)
// Initialize the main thread first so the thread is available at u.run (#809). // Initialize the main thread first so the thread is available at u.run (#809).
u.t = thread.NewNoopThread() u.t = thread.NewNoopThread()

View File

@ -55,12 +55,12 @@ func init() {
type userInterfaceImpl struct { type userInterfaceImpl struct {
graphicsDriver graphicsdriver.Graphics graphicsDriver graphicsdriver.Graphics
context *contextImpl context *context
input Input input Input
} }
func (u *userInterfaceImpl) Run(game Game) error { func (u *userInterfaceImpl) Run(game Game) error {
u.context = newContextImpl(game) u.context = newContext(game)
g, err := chooseGraphicsDriver(&graphicsDriverGetterImpl{}) g, err := chooseGraphicsDriver(&graphicsDriverGetterImpl{})
if err != nil { if err != nil {
return err return err

View File

@ -50,7 +50,7 @@ func driverCursorModeToGLFWCursorMode(mode CursorMode) int {
type userInterfaceImpl struct { type userInterfaceImpl struct {
graphicsDriver graphicsdriver.Graphics graphicsDriver graphicsdriver.Graphics
context *contextImpl context *context
title string title string
window *glfw.Window window *glfw.Window

View File

@ -84,7 +84,7 @@ type userInterfaceImpl struct {
lastDeviceScaleFactor float64 lastDeviceScaleFactor float64
context *contextImpl context *context
input Input input Input
} }
@ -330,7 +330,7 @@ func (u *userInterfaceImpl) needsUpdate() bool {
} }
func (u *userInterfaceImpl) loop(game Game) <-chan error { func (u *userInterfaceImpl) loop(game Game) <-chan error {
u.context = newContextImpl(game) u.context = newContext(game)
errCh := make(chan error, 1) errCh := make(chan error, 1)
reqStopAudioCh := make(chan struct{}) reqStopAudioCh := make(chan struct{})

View File

@ -105,7 +105,7 @@ type userInterfaceImpl struct {
setGBuildSizeCh chan struct{} setGBuildSizeCh chan struct{}
once sync.Once once sync.Once
context *contextImpl context *context
input Input input Input
@ -269,7 +269,7 @@ func (u *userInterfaceImpl) run(game Game, mainloop bool) (err error) {
} }
}() }()
u.context = newContextImpl(game) u.context = newContext(game)
g, err := chooseGraphicsDriver(&graphicsDriverGetterImpl{ g, err := chooseGraphicsDriver(&graphicsDriverGetterImpl{
gomobileBuild: mainloop, gomobileBuild: mainloop,
}) })