Run starts the update loop. It calls the user-provided update function every frame.
(update func(rend *renderer.Renderer, deltaTime time.Duration))
| 62 | // Run starts the update loop. |
| 63 | // It calls the user-provided update function every frame. |
| 64 | func (a *Application) Run(update func(rend *renderer.Renderer, deltaTime time.Duration)) { |
| 65 | |
| 66 | // Initialize start and frame time |
| 67 | a.startTime = time.Now() |
| 68 | a.frameStart = time.Now() |
| 69 | |
| 70 | // Set up recurring calls to user's update function |
| 71 | for { |
| 72 | // If Exit() was called or there was an attempt to close the window dispatch OnExit event for subscribers. |
| 73 | // If no subscriber cancelled the event, terminate the application. |
| 74 | if a.IWindow.(*window.GlfwWindow).ShouldClose() { |
| 75 | a.Dispatch(OnExit, nil) |
| 76 | // TODO allow for cancelling exit e.g. showing dialog asking the user if he/she wants to save changes |
| 77 | // if exit was cancelled { |
| 78 | // a.IWindow.(*window.GlfwWindow).SetShouldClose(false) |
| 79 | // } else { |
| 80 | break |
| 81 | // } |
| 82 | } |
| 83 | // Update frame start and frame delta |
| 84 | now := time.Now() |
| 85 | a.frameDelta = now.Sub(a.frameStart) |
| 86 | a.frameStart = now |
| 87 | // Call user's update function |
| 88 | update(a.renderer, a.frameDelta) |
| 89 | // Swap buffers and poll events |
| 90 | a.IWindow.(*window.GlfwWindow).SwapBuffers() |
| 91 | a.IWindow.(*window.GlfwWindow).PollEvents() |
| 92 | } |
| 93 | |
| 94 | // Close default audio device |
| 95 | if a.audioDev != nil { |
| 96 | al.CloseDevice(a.audioDev) |
| 97 | } |
| 98 | // Destroy window |
| 99 | a.Destroy() |
| 100 | } |
| 101 | |
| 102 | // Exit requests to terminate the application |
| 103 | // Application will dispatch OnQuit events to registered subscribers which |
nothing calls this directly
no test coverage detected