From cad051437d82e68c0d542ebab0689ab42e09142e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 3 Mar 2017 11:15:07 +0900 Subject: [PATCH] ui: Refactoring --- internal/ui/input_glfw.go | 3 +-- internal/ui/ui_glfw.go | 18 ++++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/internal/ui/input_glfw.go b/internal/ui/input_glfw.go index c56b4eea5..a50fd613f 100644 --- a/internal/ui/input_glfw.go +++ b/internal/ui/input_glfw.go @@ -29,7 +29,7 @@ var glfwMouseButtonToMouseButton = map[glfw.MouseButton]MouseButton{ glfw.MouseButtonMiddle: MouseButtonMiddle, } -func (i *input) update(window *glfw.Window, scale float64) error { +func (i *input) update(window *glfw.Window, scale float64) { i.m.Lock() defer i.m.Unlock() @@ -65,5 +65,4 @@ func (i *input) update(window *glfw.Window, scale float64) error { i.gamepads[id].buttonPressed[b] = glfw.Action(buttons[b]) == glfw.Press } } - return nil } diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index a75188df1..9e5b5ec74 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -210,9 +210,9 @@ func (u *userInterface) actualScreenScale() float64 { return u.scale * deviceScale() } -func (u *userInterface) pollEvents() error { +func (u *userInterface) pollEvents() { glfw.PollEvents() - return currentInput.update(u.window, u.scale*glfwScale()) + currentInput.update(u.window, u.scale*glfwScale()) } func (u *userInterface) update(g GraphicsContext) error { @@ -240,24 +240,18 @@ func (u *userInterface) update(g GraphicsContext) error { } } - if err := u.runOnMainThread(func() error { - if err := u.pollEvents(); err != nil { - return err - } + _ = u.runOnMainThread(func() error { + u.pollEvents() for u.window.GetAttrib(glfw.Focused) == 0 { // Wait for an arbitrary period to avoid busy loop. time.Sleep(time.Second / 60) - if err := u.pollEvents(); err != nil { - return err - } + u.pollEvents() if u.window.ShouldClose() { return nil } } return nil - }); err != nil { - return err - } + }) if err := g.Update(); err != nil { return err }