loop: Simplify update

This commit is contained in:
Hajime Hoshi 2016-09-01 22:21:58 +09:00
parent 068bc55ded
commit b95d714eed

View File

@ -126,20 +126,17 @@ func Run(g GraphicsContext, width, height int, scale float64, title string, fps
} }
func (c *runContext) update(g GraphicsContext) error { func (c *runContext) update(g GraphicsContext) error {
for {
e, err := ui.CurrentUI().Update() e, err := ui.CurrentUI().Update()
if err != nil { if err != nil {
return err return err
} }
switch e := e.(type) { switch e := e.(type) {
case ui.NopEvent: case ui.NopEvent:
return nil
case ui.ScreenSizeEvent: case ui.ScreenSizeEvent:
if err := g.SetSize(e.Width, e.Height, e.ActualScale); err != nil { if err := g.SetSize(e.Width, e.Height, e.ActualScale); err != nil {
return err return err
} }
e.Done <- struct{}{} e.Done <- struct{}{}
continue
case ui.CloseEvent: case ui.CloseEvent:
return regularTermination{} return regularTermination{}
case ui.RenderEvent: case ui.RenderEvent:
@ -147,11 +144,10 @@ func (c *runContext) update(g GraphicsContext) error {
return err return err
} }
e.Done <- struct{}{} e.Done <- struct{}{}
return nil
default: default:
panic("not reach") panic("not reach")
} }
} return nil
} }
func (c *runContext) render(g GraphicsContext) error { func (c *runContext) render(g GraphicsContext) error {