QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
Application.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <quasar/core/Base.h>
10#include <quasar/core/Layer.h>
12#include <quasar/core/Timer.h>
13#include <quasar/core/Window.h>
14#include <quasar/events/Event.h>
15
16#include <cstdint>
17#include <filesystem>
18#include <string>
19#include <vector>
20
21namespace Quasar
22{
25 {
26 std::string Name = "QuasarEngine";
27
30 std::filesystem::path WorkingDirectory{};
31
32 std::vector<std::string> Arguments{};
34 };
35
40 class Application
41 {
42 public:
43 ~Application();
44
45 Application(const Application&) = delete;
46 Application& operator=(const Application&) = delete;
47 Application(Application&&) = delete;
48 Application& operator=(Application&&) = delete;
49
54 [[nodiscard]] static Scope<Application> Create(const ApplicationSpecification& specification);
55
57 static Application& Get();
58
73 void Run();
74
76 void Close();
77
85
93
99 void PopLayer(Layer& layer);
100
106 void PopOverlay(Layer& overlay);
107
109 Window& GetWindow() { return *m_Window; }
110
112 ImGuiLayer* GetImGuiLayer() { return m_ImGuiLayer.get(); }
113
117 const LayerStack& GetLayerStack() const { return m_LayerStack; }
118
120 const ApplicationSpecification& GetSpecification() const { return m_Specification; }
121
122 private:
124
125 struct LayerChange
126 {
127 enum class Type : std::uint8_t
128 {
129 PushLayer,
131 PopLayer,
133 };
134
135 Type Kind{};
136 Scope<Layer> Added{};
137 Layer* Removed = nullptr;
138 };
139
140 void OnEvent(Event& event);
141 void ApplyLayerChanges();
142
143 ApplicationSpecification m_Specification;
144
145 Scope<Window> m_Window;
146 LayerStack m_LayerStack;
147 Scope<ImGuiLayer> m_ImGuiLayer;
148 std::vector<LayerChange> m_LayerChanges;
149 Timer m_FrameTimer;
150 double m_LastFrameTime = 0.0;
151 bool m_Running = false;
152 bool m_Minimized = false;
153 bool m_DeferLayerChanges = false;
154 };
155}
Contains the base definitions and utilities for the Quasar engine.
Base class of all events, with their types and categories.
The layer that runs Dear ImGui, so that every layer can draw ImGui windows.
Ordered list of the layers of an application, with overlays always above regular layers.
Base class for every part of an application that is updated, rendered and receives events.
A high-resolution (steady) timer for measuring elapsed time.
Application window, created with GLFW.
The application: it creates the window, owns the layers and runs the main loop.
Definition Application.h:41
void PopLayer(Layer &layer)
Detaches, removes and destroys a regular layer.
Layer & PushOverlay(Scope< Layer > overlay)
Adds an overlay above every layer.
void PopOverlay(Layer &overlay)
Detaches, removes and destroys an overlay.
Layer & PushLayer(Scope< Layer > layer)
Adds a regular layer above the other regular layers.
Window & GetWindow()
Returns the main window.
Definition Application.h:109
ImGuiLayer * GetImGuiLayer()
Returns the layer that runs ImGui, or nullptr when the window has no OpenGL context.
Definition Application.h:112
static Scope< Application > Create(const ApplicationSpecification &specification)
Creates the application and its window.
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.
const ApplicationSpecification & GetSpecification() const
Returns the settings the application was created with, including the command-line arguments.
Definition Application.h:120
static Application & Get()
Returns the application. An application must exist.
const LayerStack & GetLayerStack() const
Returns the layers and overlays of the application, from the bottom of the stack to the top.
Definition Application.h:117
Overlay that starts Dear ImGui with its GLFW and OpenGL backends, and wraps each frame.
Definition ImGuiLayer.h:31
Owns the layers of an application and keeps them in order, from the bottom to the top.
Definition LayerStack.h:27
Part of an application that is updated, rendered and receives events.
Definition Layer.h:23
Application window.
Definition Window.h:42
Contains all the engine code.
std::unique_ptr< T > Scope
Pointer with a single owner. Alias of std::unique_ptr.
Definition Base.h:23
Settings used to create the application.
Definition Application.h:25
std::filesystem::path WorkingDirectory
Directory used as the current directory, so that relative paths start from it.
Definition Application.h:30
std::string Name
Name of the application, used in the logs.
Definition Application.h:26
WindowSpecification Window
Settings of the main window, created with the application.
Definition Application.h:33
std::vector< std::string > Arguments
Command-line arguments, without the name of the program.
Definition Application.h:32
Settings used to create a window.
Definition Window.h:26