func newRenderingLoop(sdlrenderer *clingon.SDLRenderer) { go func() { var y int16 breakLoop := make(chan byte) var animationValueCh <-chan float64 = nil var animationDirection int loop: for { select { case <-terminateRendering: go func() { done := make(chan bool) sdlrenderer.EventCh() <- clingon.Cmd_Terminate{done} <-done breakLoop <- 0 }() case <-breakLoop: renderingLoopTerminated <- 0 break loop case animationSpec := <-animationCh: animationValueCh = animationSpec.animation.ValueCh() animationDirection = animationSpec.direction case value := <-animationValueCh: if animationDirection == clingon.SCROLL_DOWN { y = 40 + int16(value) } else { y = appSurfaceH - int16(value) } render(sdlrenderer, nil, y) case rects := <-sdlrenderer.UpdatedRectsCh(): render(sdlrenderer, rects, y) } } }() }