diff --git a/internal/loop/run.go b/internal/loop/run.go index cee358529..d5b471ddf 100644 --- a/internal/loop/run.go +++ b/internal/loop/run.go @@ -114,7 +114,7 @@ func Run(g GraphicsContext, width, height int, scale float64, title string, fps currentRunContext.lastFPSUpdated = n lg := &loopGraphicsContext{currentRunContext, g} - if err := ui.CurrentUI().Run(width, height, scale, title, lg); err != nil { + if err := ui.Run(width, height, scale, title, lg); err != nil { if _, ok := err.(*ui.RegularTermination); ok { return nil } diff --git a/internal/ui/ui.go b/internal/ui/ui.go index b788dd14d..7c7a570a5 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -19,10 +19,6 @@ type GraphicsContext interface { Update() error } -type UserInterface interface { - Run(width, height int, scale float64, title string, g GraphicsContext) error -} - type RegularTermination struct { } diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 6f36a3c56..d7dfd5ed7 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -39,10 +39,6 @@ type userInterface struct { var currentUI *userInterface -func CurrentUI() UserInterface { - return currentUI -} - func init() { if err := initialize(); err != nil { panic(err) @@ -146,7 +142,8 @@ func ScreenScale() float64 { return s } -func (u *userInterface) Run(width, height int, scale float64, title string, g GraphicsContext) error { +func Run(width, height int, scale float64, title string, g GraphicsContext) error { + u := currentUI // GLContext must be created before setting the screen size, which requires // swapping buffers. var err error diff --git a/internal/ui/ui_js.go b/internal/ui/ui_js.go index 7ce7429bf..69509ee47 100644 --- a/internal/ui/ui_js.go +++ b/internal/ui/ui_js.go @@ -39,10 +39,6 @@ var currentUI = &userInterface{ windowFocus: true, } -func CurrentUI() UserInterface { - return currentUI -} - // NOTE: This returns true even when the browser is not active. func shown() bool { return !js.Global.Get("document").Get("hidden").Bool() @@ -262,7 +258,8 @@ func RunMainThreadLoop(ch <-chan error) error { return <-ch } -func (u *userInterface) Run(width, height int, scale float64, title string, g GraphicsContext) error { +func Run(width, height int, scale float64, title string, g GraphicsContext) error { + u := currentUI doc := js.Global.Get("document") doc.Set("title", title) u.setScreenSize(width, height, scale) diff --git a/internal/ui/ui_mobile.go b/internal/ui/ui_mobile.go index ebbd44a22..7ad596c02 100644 --- a/internal/ui/ui_mobile.go +++ b/internal/ui/ui_mobile.go @@ -60,11 +60,8 @@ var ( } ) -func CurrentUI() UserInterface { - return currentUI -} - -func (u *userInterface) Run(width, height int, scale float64, title string, g GraphicsContext) error { +func Run(width, height int, scale float64, title string, g GraphicsContext) error { + u := currentUI u.width = width u.height = height u.scale = scale