refactor main loop
This commit is contained in:
parent
6410b5ee6f
commit
9d16b2970c
30
cmd/root.go
30
cmd/root.go
|
@ -87,6 +87,23 @@ func handleEvent(event sdl.Event, m *milkDropWindow) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
/*
|
||||
* update handles events and renders new frames of the visualization. It
|
||||
* returns a bool indicating whether the program should keep running and an
|
||||
* error, if any.
|
||||
*/
|
||||
func update(m *milkDropWindow) (bool, error) {
|
||||
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
||||
keepRunning := handleEvent(event, m)
|
||||
if !keepRunning {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
keepRunning, err := m.render()
|
||||
return keepRunning, err
|
||||
}
|
||||
|
||||
/*
|
||||
* milkbucket sets up the program and starts a rendering loop.
|
||||
*/
|
||||
|
@ -119,18 +136,7 @@ func milkbucket(cmd *cobra.Command, args []string) {
|
|||
|
||||
running := true
|
||||
for running {
|
||||
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
||||
running = handleEvent(event, m)
|
||||
if !running {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !running {
|
||||
break
|
||||
}
|
||||
|
||||
running, err = m.render()
|
||||
running, err = update(m)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue