ui: Remove CurrentUI()

This commit is contained in:
Hajime Hoshi 2016-05-18 10:51:11 +09:00
parent 4d04413bf9
commit 7f19d4a1ac
3 changed files with 14 additions and 14 deletions

View File

@ -42,6 +42,10 @@ func SetScreenScale(scale int) error {
return currentRunContext.setScreenScale(scale) return currentRunContext.setScreenScale(scale)
} }
func ScreenScale() int {
return currentUI.ScreenScale()
}
type runContext struct { type runContext struct {
running bool running bool
fps float64 fps float64
@ -112,16 +116,16 @@ func (c *runContext) updateScreenSize(g GraphicsContext) error {
} }
changed := false changed := false
if 0 < c.newScreenWidth || 0 < c.newScreenHeight { if 0 < c.newScreenWidth || 0 < c.newScreenHeight {
c := CurrentUI().SetScreenSize(c.newScreenWidth, c.newScreenHeight) c := currentUI.SetScreenSize(c.newScreenWidth, c.newScreenHeight)
changed = changed || c changed = changed || c
} }
if 0 < c.newScreenScale { if 0 < c.newScreenScale {
c := CurrentUI().SetScreenScale(c.newScreenScale) c := currentUI.SetScreenScale(c.newScreenScale)
changed = changed || c changed = changed || c
} }
if changed { if changed {
w, h := c.newScreenWidth, c.newScreenHeight 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 return err
} }
} }
@ -167,12 +171,12 @@ func Run(g GraphicsContext, width, height, scale int, title string) error {
currentRunContext.startRunning() currentRunContext.startRunning()
defer currentRunContext.endRunning() 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 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 return err
} }
@ -184,7 +188,7 @@ func Run(g GraphicsContext, width, height, scale int, title string) error {
if err := currentRunContext.updateScreenSize(g); err != nil { if err := currentRunContext.updateScreenSize(g); err != nil {
return err return err
} }
e, err := CurrentUI().Update() e, err := currentUI.Update()
if err != nil { if err != nil {
return err return err
} }
@ -212,7 +216,7 @@ func Run(g GraphicsContext, width, height, scale int, title string) error {
return err return err
} }
} }
CurrentUI().SwapBuffers() currentUI.SwapBuffers()
beforeForUpdate += int64(tt) * int64(time.Second) / FPS beforeForUpdate += int64(tt) * int64(time.Second) / FPS
frames++ frames++
} }

View File

@ -43,10 +43,6 @@ type UserInterface struct {
var currentUI *UserInterface var currentUI *UserInterface
func CurrentUI() *UserInterface {
return currentUI
}
func Init() (*opengl.Context, error) { func Init() (*opengl.Context, error) {
runtime.LockOSThread() runtime.LockOSThread()
@ -96,7 +92,7 @@ func Init() (*opengl.Context, error) {
} }
func Main() error { func Main() error {
return CurrentUI().main() return currentUI.main()
} }
func (u *UserInterface) main() error { func (u *UserInterface) main() error {

2
run.go
View File

@ -85,5 +85,5 @@ func SetScreenScale(scale int) {
// //
// This function is concurrent-safe. // This function is concurrent-safe.
func ScreenScale() int { func ScreenScale() int {
return ui.CurrentUI().ScreenScale() return ui.ScreenScale()
} }