|
QuasarEngine
Cross-platform 3D engine and editor
|
The application: it creates the window, owns the layers and runs the main loop. More...
#include <quasar/core/Application.h>
Public Member Functions | |
| Application (const Application &)=delete | |
| Application & | operator= (const Application &)=delete |
| Application (Application &&)=delete | |
| Application & | operator= (Application &&)=delete |
| void | Run () |
| Runs the main loop until the window is closed or Close() is called. | |
| void | Close () |
| Asks the main loop to stop at the end of the current frame. | |
| Layer & | PushLayer (Scope< Layer > layer) |
| Adds a regular layer above the other regular layers. | |
| Layer & | PushOverlay (Scope< Layer > overlay) |
| Adds an overlay above every layer. | |
| void | PopLayer (Layer &layer) |
| Detaches, removes and destroys a regular layer. | |
| void | PopOverlay (Layer &overlay) |
| Detaches, removes and destroys an overlay. | |
| Window & | GetWindow () |
| Returns the main window. | |
| Gamepads & | GetGamepads () |
| Returns the gamepads, read once per frame by the main loop. | |
| const Gamepads & | GetGamepads () const |
| Returns the gamepads, read once per frame by the main loop. | |
| ImGuiLayer * | GetImGuiLayer () |
| Returns the layer that runs ImGui, or nullptr when the window has no OpenGL context. | |
| const LayerStack & | GetLayerStack () const |
| Returns the layers and overlays of the application, from the bottom of the stack to the top. | |
| const ApplicationSpecification & | GetSpecification () const |
| Returns the settings the application was created with, including the command-line arguments. | |
| std::optional< std::filesystem::path > | GetUserDataDirectory () const |
| Returns the folder where the application stores the files of the current user, such as its settings or its saved games. | |
Static Public Member Functions | |
| static Scope< Application > | Create (const ApplicationSpecification &specification) |
| Creates the application and its window. | |
| static Application & | Get () |
| Returns the application. An application must exist. | |
The application: it creates the window, owns the layers and runs the main loop.
An application is built by adding layers to it, then calling Run(). Only one application can exist at a time, and it can be reached from anywhere with Get().
|
staticnodiscard |
Creates the application and its window.
| specification | Settings of the application and of its window. |
| void Quasar::Application::Run | ( | ) |
Runs the main loop until the window is closed or Close() is called.
Each frame, the loop computes the time elapsed since the previous frame, updates every layer, renders every layer, lets every layer draw its ImGui windows with Layer::OnImGuiRender(), then shows the image and processes the messages of the operating system and reads the gamepads. Layers are updated and rendered from the bottom of the stack to the top. While the window is minimized, or while its drawing area is empty, the layers are still updated but not rendered.
The events of the window and of the gamepads go to the application first, then to the ImGui layer, then to the layers from the top of the stack to the bottom, until one of them handles them. Closing the window stops the loop.
Layers added or removed during a frame, by a layer or by an event, are added or removed at the end of the frame, in the order they were asked for. The layers being updated, rendered or receiving an event never change while they are being gone through.
Adds a regular layer above the other regular layers.
During the main loop, the layer is added and attached at the end of the current frame. Otherwise it is added right away.
| layer | The layer to add. It must not be empty. |
Adds an overlay above every layer.
See LayerStack::PushOverlay().
During the main loop, the overlay is added and attached at the end of the current frame. Otherwise it is added right away.
| overlay | The overlay to add. It must not be empty. |
| void Quasar::Application::PopLayer | ( | Layer & | layer | ) |
Detaches, removes and destroys a regular layer.
During the main loop, this happens at the end of the current frame, so a layer can remove itself. Otherwise it happens right away.
| layer | A regular layer of this application. |
| void Quasar::Application::PopOverlay | ( | Layer & | overlay | ) |
Detaches, removes and destroys an overlay.
During the main loop, this happens at the end of the current frame, so an overlay can remove itself. Otherwise it happens right away.
| overlay | An overlay of this application. |
|
inline |
Returns the layers and overlays of the application, from the bottom of the stack to the top.
Layers added or removed during a frame only appear in it, or leave it, at the end of the frame.
| std::optional< std::filesystem::path > Quasar::Application::GetUserDataDirectory | ( | ) | const |
Returns the folder where the application stores the files of the current user, such as its settings or its saved games.
The folder is created if it does not exist yet.
The folder is named after the organization and the name of the application. See Quasar::GetUserDataDirectory() for where it is placed.