(defaultScene Scene, headless bool)
| 77 | func DestroyWindow() { /* nothing to do here? */ } |
| 78 | |
| 79 | func runLoop(defaultScene Scene, headless bool) { |
| 80 | c := make(chan os.Signal, 1) |
| 81 | signal.Notify(c, os.Interrupt) |
| 82 | signal.Notify(c, syscall.SIGTERM) |
| 83 | go func() { |
| 84 | <-c |
| 85 | closeEvent() |
| 86 | }() |
| 87 | |
| 88 | app.Main(func(a app.App) { |
| 89 | var ( |
| 90 | ticker *time.Ticker |
| 91 | ) |
| 92 | |
| 93 | for e := range a.Events() { |
| 94 | switch e := a.Filter(e).(type) { |
| 95 | case lifecycle.Event: |
| 96 | switch e.Crosses(lifecycle.StageVisible) { |
| 97 | case lifecycle.CrossOn: |
| 98 | Gl = gl.NewContext(e.DrawContext) |
| 99 | RunPreparation(defaultScene) |
| 100 | |
| 101 | ticker = time.NewTicker(time.Duration(int(time.Second) / opts.FPSLimit)) |
| 102 | // Start tick, minimize the delta |
| 103 | Time.Tick() |
| 104 | |
| 105 | // Let the device know we want to start painting :-) |
| 106 | a.Send(paint.Event{}) |
| 107 | case lifecycle.CrossOff: |
| 108 | closeEvent() |
| 109 | ticker.Stop() |
| 110 | Gl = nil |
| 111 | } |
| 112 | |
| 113 | case size.Event: |
| 114 | sz = e |
| 115 | windowWidth = float32(sz.WidthPx) |
| 116 | windowHeight = float32(sz.HeightPx) |
| 117 | canvasWidth = float32(sz.WidthPx) |
| 118 | canvasHeight = float32(sz.HeightPx) |
| 119 | Gl.Viewport(0, 0, sz.WidthPx, sz.HeightPx) |
| 120 | ResizeXOffset = (gameWidth - canvasWidth) |
| 121 | ResizeYOffset = (gameHeight - canvasHeight) |
| 122 | case paint.Event: |
| 123 | if e.External { |
| 124 | // As we are actively painting as fast as |
| 125 | // we can (usually 60 FPS), skip any paint |
| 126 | // events sent by the system. |
| 127 | continue |
| 128 | } |
| 129 | |
| 130 | select { |
| 131 | case <-ticker.C: |
| 132 | RunIteration() |
| 133 | case <-resetLoopTicker: |
| 134 | ticker.Stop() |
| 135 | ticker = time.NewTicker(time.Duration(int(time.Second) / opts.FPSLimit)) |
| 136 | } |
nothing calls this directly
no test coverage detected