Vesper 0.5.1
Vesper is short form for the Latin word for "Bat", as Vesper is designed to be small, lightweight, and easily handle things like particles and flocking behaviors in accordance with the nature of bats. \n It is meant to be a particle simulation, VFX editor, and CAN be used secondarily as a small game engine.
GitHub | Vesper Updates | Creator
Loading...
Searching...
No Matches
Vesper::Application Class Reference

The core application class that manages the main loop, window, layers, and event handling. More...

#include <Application.h>

Inheritance diagram for Vesper::Application:
Vesper::VesperEditor Vesper::VesperEditor

Public Member Functions

 Application (const std::string &name="")
 Constructs the Application with the given name.
virtual ~Application ()
void Run ()
 Starts the main application loop.
void OnEvent (Event &e)
 Handles incoming events and dispatches them to the appropriate handlers.
void PushLayer (Layer *layer)
 Adds a layer to the application layer stack.
void PushOverlay (Layer *overlay)
 Adds an overlay layer to the application layer stack.
void Close ()
 Closes the application.
ImGuiLayerGetImGuiLayer ()
 Retrieves the ImGui layer.
WindowGetWindow ()
 Retrieves the application window.

Static Public Member Functions

static ApplicationGet ()
 Retrieves the singleton instance of the Application.

Private Member Functions

bool OnWindowClose (WindowCloseEvent &e)
 Event handler for window close events.
bool OnWindowResize (WindowResizeEvent &e)
 Event handler for window resize events.

Private Attributes

Scope< Windowm_Window
 Scoped pointer to the applications underlying window.
ImGuiLayerm_ImGuiLayer
 ImGui layer for rendering GUI elements.
bool m_Running = true
 Flag indicating whether the application is running.
bool m_Minimized = false
 Flag indicating whether the application is minimized.
LayerStack m_LayerStack
 Stack of layers managed by the application.
float m_LastFrameTime = 0.0f
 Time of the last frame, used for calculating timestep.

Static Private Attributes

static Applications_Instance = nullptr

Detailed Description

The core application class that manages the main loop, window, layers, and event handling.

Todo
Update class to accept ApplicationSettings in constructor and verify its utility/use

Constructor & Destructor Documentation

◆ Application()

Vesper::Application::Application ( const std::string & name = "")

Constructs the Application with the given name.

Parameters
nameThe name of the application. Defaults to an empty string.
18 {
20
21 VZ_CORE_ASSERT(!s_Instance, "Application already exists!");
22 s_Instance = this;
23
24 m_Window = Window::Create(WindowProps(name));
25 m_Window->SetEventCallback(BIND_EVENT_FN(OnEvent));
26 m_Window->SetVSync(false);
27
28
30
31
32 m_ImGuiLayer = new ImGuiLayer();
34
35 }
#define VZ_CORE_ASSERT(x,...)
Definition Asserts.h:20
#define BIND_EVENT_FN(x)
Binds the given member function of the Application class as an event handler.
Definition Defines_Macros.h:21
#define VZ_PROFILE_FUNCTION()
Definition Instrumentor.h:240
static Application * s_Instance
Definition Application.h:92
void OnEvent(Event &e)
Handles incoming events and dispatches them to the appropriate handlers.
Definition Application.cpp:60
ImGuiLayer * m_ImGuiLayer
ImGui layer for rendering GUI elements.
Definition Application.h:81
void PushOverlay(Layer *overlay)
Adds an overlay layer to the application layer stack.
Definition Application.cpp:48
Scope< Window > m_Window
Scoped pointer to the applications underlying window.
Definition Application.h:79
static void Init()
Initializes the renderer.
Definition Renderer.cpp:13
static Scope< Window > Create(const WindowProps &props=WindowProps())
Creates a window instance with the specified properties.
Definition WindowsWindow.cpp:20

References Vesper::ImGuiLayer::ImGuiLayer(), Vesper::Renderer::Init(), m_ImGuiLayer, PushOverlay(), and s_Instance.

◆ ~Application()

Vesper::Application::~Application ( )
virtual
38 {
39 }

Member Function Documentation

◆ Close()

void Vesper::Application::Close ( )

Closes the application.

56 {
57 m_Running = false;
58 }
bool m_Running
Flag indicating whether the application is running.
Definition Application.h:83

References m_Running.

Referenced by Vesper::EditorLayer::OnImGuiRender().

◆ Get()

◆ GetImGuiLayer()

ImGuiLayer * Vesper::Application::GetImGuiLayer ( )
inline

Retrieves the ImGui layer.

64{ return m_ImGuiLayer; }

References m_ImGuiLayer.

Referenced by Vesper::EditorLayer::OnImGuiRender().

◆ GetWindow()

Window & Vesper::Application::GetWindow ( )
inline

◆ OnEvent()

void Vesper::Application::OnEvent ( Event & e)

Handles incoming events and dispatches them to the appropriate handlers.

61 {
63 EventDispatcher dispatcher(e);
64 dispatcher.Dispatch<WindowCloseEvent>(BIND_EVENT_FN(OnWindowClose));
65 dispatcher.Dispatch<WindowResizeEvent>(BIND_EVENT_FN(OnWindowResize));
66
67 for (auto it = m_LayerStack.rbegin(); it != m_LayerStack.rend(); ++it)
68 {
69 if (e.Handled)
70 break;
71 (*it)->OnEvent(e);
72 }
73
74 }
bool OnWindowResize(WindowResizeEvent &e)
Event handler for window resize events.
Definition Application.cpp:118
bool OnWindowClose(WindowCloseEvent &e)
Event handler for window close events.
Definition Application.cpp:111
LayerStack m_LayerStack
Stack of layers managed by the application.
Definition Application.h:87

References Vesper::EventDispatcher::EventDispatcher(), OnWindowClose(), and OnWindowResize().

◆ OnWindowClose()

bool Vesper::Application::OnWindowClose ( WindowCloseEvent & e)
private

Event handler for window close events.

112 {
114 m_Running = false;
115 return true;
116 }

References m_Running.

Referenced by OnEvent().

◆ OnWindowResize()

bool Vesper::Application::OnWindowResize ( WindowResizeEvent & e)
private

Event handler for window resize events.

119 {
121 if (e.GetWidth() == 0 || e.GetHeight() == 0)
122 {
123 m_Minimized = true;
124 return false;
125 }
126
127 m_Minimized = false;
128 Renderer::OnWindowResize(e.GetWidth(), e.GetHeight());
129 return false;
130 }
bool m_Minimized
Flag indicating whether the application is minimized.
Definition Application.h:85
static void OnWindowResize(uint32_t width, uint32_t height)
Handles window resize events by resizing the viewport.
Definition Renderer.cpp:21

References Vesper::WindowResizeEvent::GetHeight(), Vesper::WindowResizeEvent::GetWidth(), m_Minimized, and Vesper::Renderer::OnWindowResize().

Referenced by OnEvent().

◆ PushLayer()

void Vesper::Application::PushLayer ( Layer * layer)

Adds a layer to the application layer stack.

42 {
44 m_LayerStack.PushLayer(layer);
45 layer->OnAttach();
46 }

References Vesper::Layer::OnAttach().

Referenced by Vesper::VesperEditor::VesperEditor().

◆ PushOverlay()

void Vesper::Application::PushOverlay ( Layer * overlay)

Adds an overlay layer to the application layer stack.

49 {
51 m_LayerStack.PushOverlay(overlay);
52 overlay->OnAttach();
53 }

References Vesper::Layer::OnAttach().

Referenced by Application().

◆ Run()

void Vesper::Application::Run ( )

Starts the main application loop.

Todo

Add Layer rendering into the main loop

Add separate threads for rendering and updating

78 {
80 while (m_Running)
81 {
82 VZ_PROFILE_SCOPE("RunLoop");
83 float time = (float)glfwGetTime(); // TODO: Platform::GetTime()
84 Timestep timestep = time - m_LastFrameTime;
85 m_LastFrameTime = time;
86
87 if (!m_Minimized)
88 {
89 VZ_PROFILE_SCOPE("LayerStack OnUpdate");
90 // Update layers
91 for (auto layer : m_LayerStack)
92 layer->OnUpdate(timestep);
93 }
94
95 {
96 VZ_PROFILE_SCOPE("ImGuiLayer OnImGuiRender");
97 m_ImGuiLayer->Begin();
98 for (auto layer : m_LayerStack)
99 layer->OnImGuiRender();
100 m_ImGuiLayer->End();
101 }
102
103 {
104 VZ_PROFILE_SCOPE("Window OnUpdate");
105 // Update window second
106 m_Window->OnUpdate();
107 }
108 };
109 }
#define VZ_PROFILE_SCOPE(name)
Definition Instrumentor.h:239
float m_LastFrameTime
Time of the last frame, used for calculating timestep.
Definition Application.h:89

References Vesper::ImGuiLayer::Begin(), Vesper::ImGuiLayer::End(), m_ImGuiLayer, m_LastFrameTime, m_Minimized, and m_Running.

Member Data Documentation

◆ m_ImGuiLayer

ImGuiLayer* Vesper::Application::m_ImGuiLayer
private

ImGui layer for rendering GUI elements.

Referenced by Application(), GetImGuiLayer(), and Run().

◆ m_LastFrameTime

float Vesper::Application::m_LastFrameTime = 0.0f
private

Time of the last frame, used for calculating timestep.

Referenced by Run().

◆ m_LayerStack

LayerStack Vesper::Application::m_LayerStack
private

Stack of layers managed by the application.

◆ m_Minimized

bool Vesper::Application::m_Minimized = false
private

Flag indicating whether the application is minimized.

Referenced by OnWindowResize(), and Run().

◆ m_Running

bool Vesper::Application::m_Running = true
private

Flag indicating whether the application is running.

Referenced by Close(), OnWindowClose(), and Run().

◆ m_Window

Scope<Window> Vesper::Application::m_Window
private

Scoped pointer to the applications underlying window.

◆ s_Instance

Application * Vesper::Application::s_Instance = nullptr
staticprivate

Referenced by Application(), and Get().


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