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,32 +126,28 @@ 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
}
switch e := e.(type) {
case ui.NopEvent:
case ui.ScreenSizeEvent:
if err := g.SetSize(e.Width, e.Height, e.ActualScale); err != nil {
return err return err
} }
switch e := e.(type) { e.Done <- struct{}{}
case ui.NopEvent: case ui.CloseEvent:
return nil return regularTermination{}
case ui.ScreenSizeEvent: case ui.RenderEvent:
if err := g.SetSize(e.Width, e.Height, e.ActualScale); err != nil { if err := currentRunContext.render(g); err != nil {
return err return err
}
e.Done <- struct{}{}
continue
case ui.CloseEvent:
return regularTermination{}
case ui.RenderEvent:
if err := currentRunContext.render(g); err != nil {
return err
}
e.Done <- struct{}{}
return nil
default:
panic("not reach")
} }
e.Done <- struct{}{}
default:
panic("not reach")
} }
return nil
} }
func (c *runContext) render(g GraphicsContext) error { func (c *runContext) render(g GraphicsContext) error {