ui: Refactoring

This commit is contained in:
Hajime Hoshi 2017-03-03 11:15:07 +09:00
parent e11bc62059
commit cad051437d
2 changed files with 7 additions and 14 deletions

View File

@ -29,7 +29,7 @@ var glfwMouseButtonToMouseButton = map[glfw.MouseButton]MouseButton{
glfw.MouseButtonMiddle: MouseButtonMiddle, 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() i.m.Lock()
defer i.m.Unlock() 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 i.gamepads[id].buttonPressed[b] = glfw.Action(buttons[b]) == glfw.Press
} }
} }
return nil
} }

View File

@ -210,9 +210,9 @@ func (u *userInterface) actualScreenScale() float64 {
return u.scale * deviceScale() return u.scale * deviceScale()
} }
func (u *userInterface) pollEvents() error { func (u *userInterface) pollEvents() {
glfw.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 { func (u *userInterface) update(g GraphicsContext) error {
@ -240,24 +240,18 @@ func (u *userInterface) update(g GraphicsContext) error {
} }
} }
if err := u.runOnMainThread(func() error { _ = u.runOnMainThread(func() error {
if err := u.pollEvents(); err != nil { u.pollEvents()
return err
}
for u.window.GetAttrib(glfw.Focused) == 0 { for u.window.GetAttrib(glfw.Focused) == 0 {
// Wait for an arbitrary period to avoid busy loop. // Wait for an arbitrary period to avoid busy loop.
time.Sleep(time.Second / 60) time.Sleep(time.Second / 60)
if err := u.pollEvents(); err != nil { u.pollEvents()
return err
}
if u.window.ShouldClose() { if u.window.ShouldClose() {
return nil return nil
} }
} }
return nil return nil
}); err != nil { })
return err
}
if err := g.Update(); err != nil { if err := g.Update(); err != nil {
return err return err
} }