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
|
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.
|
* milkbucket sets up the program and starts a rendering loop.
|
||||||
*/
|
*/
|
||||||
|
@ -119,18 +136,7 @@ func milkbucket(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
running := true
|
running := true
|
||||||
for running {
|
for running {
|
||||||
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
running, err = update(m)
|
||||||
running = handleEvent(event, m)
|
|
||||||
if !running {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !running {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
running, err = m.render()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue