QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
Quasar::Application Class Reference

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.

Detailed Description

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().

Member Function Documentation

◆ Create()

Scope< Application > Quasar::Application::Create ( const ApplicationSpecification & specification)
staticnodiscard

Creates the application and its window.

Parameters
specificationSettings of the application and of its window.
Returns
The new application, or nullptr if an application already exists, if the working directory cannot be used or if the window cannot be created. The reason is logged as an engine error.

◆ Run()

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.

◆ PushLayer()

Layer & Quasar::Application::PushLayer ( Scope< Layer > layer)

Adds a regular layer above the other regular layers.

See LayerStack::PushLayer().

During the main loop, the layer is added and attached at the end of the current frame. Otherwise it is added right away.

Parameters
layerThe layer to add. It must not be empty.
Returns
The layer, which stays at the same address until it is removed.

◆ PushOverlay()

Layer & Quasar::Application::PushOverlay ( Scope< Layer > overlay)

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.

Parameters
overlayThe overlay to add. It must not be empty.
Returns
The overlay, which stays at the same address until it is removed.

◆ PopLayer()

void Quasar::Application::PopLayer ( Layer & layer)

Detaches, removes and destroys a regular layer.

See LayerStack::PopLayer().

During the main loop, this happens at the end of the current frame, so a layer can remove itself. Otherwise it happens right away.

Parameters
layerA regular layer of this application.

◆ PopOverlay()

void Quasar::Application::PopOverlay ( Layer & overlay)

Detaches, removes and destroys an overlay.

See LayerStack::PopOverlay().

During the main loop, this happens at the end of the current frame, so an overlay can remove itself. Otherwise it happens right away.

Parameters
overlayAn overlay of this application.

◆ GetLayerStack()

const LayerStack & Quasar::Application::GetLayerStack ( ) const
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.

◆ GetUserDataDirectory()

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.

Returns
The absolute path of the folder, or no value if a name is not valid or if the folder cannot be found or created. The reason is logged as an engine error.

The documentation for this class was generated from the following file: