From 7f19d4a1ac97d708c9726914b5937eddd7369d43 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 18 May 2016 10:51:11 +0900 Subject: [PATCH] ui: Remove CurrentUI() --- internal/ui/run.go | 20 ++++++++++++-------- internal/ui/ui_glfw.go | 6 +----- run.go | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/ui/run.go b/internal/ui/run.go index 2b517b699..c51ec2731 100644 --- a/internal/ui/run.go +++ b/internal/ui/run.go @@ -42,6 +42,10 @@ func SetScreenScale(scale int) error { return currentRunContext.setScreenScale(scale) } +func ScreenScale() int { + return currentUI.ScreenScale() +} + type runContext struct { running bool fps float64 @@ -112,16 +116,16 @@ func (c *runContext) updateScreenSize(g GraphicsContext) error { } changed := false if 0 < c.newScreenWidth || 0 < c.newScreenHeight { - c := CurrentUI().SetScreenSize(c.newScreenWidth, c.newScreenHeight) + c := currentUI.SetScreenSize(c.newScreenWidth, c.newScreenHeight) changed = changed || c } if 0 < c.newScreenScale { - c := CurrentUI().SetScreenScale(c.newScreenScale) + c := currentUI.SetScreenScale(c.newScreenScale) changed = changed || c } if changed { w, h := c.newScreenWidth, c.newScreenHeight - if err := g.SetSize(w, h, CurrentUI().ActualScreenScale()); err != nil { + if err := g.SetSize(w, h, currentUI.ActualScreenScale()); err != nil { return err } } @@ -167,12 +171,12 @@ func Run(g GraphicsContext, width, height, scale int, title string) error { currentRunContext.startRunning() defer currentRunContext.endRunning() - if err := CurrentUI().Start(width, height, scale, title); err != nil { + if err := currentUI.Start(width, height, scale, title); err != nil { return err } - defer CurrentUI().Terminate() + defer currentUI.Terminate() - if err := g.SetSize(width, height, CurrentUI().ActualScreenScale()); err != nil { + if err := g.SetSize(width, height, currentUI.ActualScreenScale()); err != nil { return err } @@ -184,7 +188,7 @@ func Run(g GraphicsContext, width, height, scale int, title string) error { if err := currentRunContext.updateScreenSize(g); err != nil { return err } - e, err := CurrentUI().Update() + e, err := currentUI.Update() if err != nil { return err } @@ -212,7 +216,7 @@ func Run(g GraphicsContext, width, height, scale int, title string) error { return err } } - CurrentUI().SwapBuffers() + currentUI.SwapBuffers() beforeForUpdate += int64(tt) * int64(time.Second) / FPS frames++ } diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 630b050a9..577708863 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -43,10 +43,6 @@ type UserInterface struct { var currentUI *UserInterface -func CurrentUI() *UserInterface { - return currentUI -} - func Init() (*opengl.Context, error) { runtime.LockOSThread() @@ -96,7 +92,7 @@ func Init() (*opengl.Context, error) { } func Main() error { - return CurrentUI().main() + return currentUI.main() } func (u *UserInterface) main() error { diff --git a/run.go b/run.go index f74821a40..8b673791e 100644 --- a/run.go +++ b/run.go @@ -85,5 +85,5 @@ func SetScreenScale(scale int) { // // This function is concurrent-safe. func ScreenScale() int { - return ui.CurrentUI().ScreenScale() + return ui.ScreenScale() }