Elevate Engine 1
Loading...
Searching...
No Matches
Elevate::Application Class Reference

#include <Application.h>

Public Member Functions

 Application ()
 
virtual ~Application ()=default
 
void Init ()
 
void EngineFrame ()
 
void Run ()
 
void Exit ()
 
void OnEvent (Event &e)
 
void PushLayer (Layer *layer)
 
void PushOverlay (Layer *overlay)
 
WindowGetWindow ()
 

Static Public Member Functions

static void Start (int argc, char **argv)
 
static ApplicationGet ()
 
static ApplicationArguments GetArguments ()
 
static const GameContextStateGetGameState ()
 
static void SetGameState (GameContextState newState)
 

Public Attributes

std::unique_ptr< FramebufferFrameBuffer
 

Protected Member Functions

void OnStateChange (GameContextState oldState, GameContextState newState)
 

Friends

class Elevate::Editor::EditorLayer
 

Detailed Description

Definition at line 40 of file Application.h.

Constructor & Destructor Documentation

◆ Application()

Elevate::Application::Application ( )

Definition at line 35 of file Application.cpp.

36 {
37 EE_CORE_ASSERT(!s_Instance, "Application already exists!");
38 s_Instance = this;
39
40 EE_CORE_TRACE("Current working directory : {}", std::filesystem::current_path().string().c_str());
41
42 m_Window = std::unique_ptr<Window>(Window::Create());
43 m_Window->SetEventCallback(BIND_EVENT_FN(OnEvent));
44
46
47 FrameBuffer.reset(Framebuffer::Create(m_Window->GetWidth(), m_Window->GetHeight()));
48 FrameBuffer->SetClearColor({ 0.8f, 0.4f, 0.7f, 1.0f }); // Pink / purple for debug purposes
49
50 #ifdef EE_EDITOR_BUILD
51 PushOverlay(new Elevate::Editor::EditorLayer());
53 #else
55 #endif
56
57 m_ImGuiLayer = new ImGuiLayer();
58 PushOverlay(m_ImGuiLayer);
59 }
#define BIND_EVENT_FN(x)
std::unique_ptr< Framebuffer > FrameBuffer
Definition Application.h:60
static void SetGameState(GameContextState newState)
void OnEvent(Event &e)
void PushOverlay(Layer *overlay)
static Framebuffer * Create(uint32_t width=1280, uint32_t height=720)
static Window * Create(const WindowProps &props=WindowProps("app.config"))
Definition Window.cpp:77
@ EditorMode
Definition GameContext.h:8

◆ ~Application()

virtual Elevate::Application::~Application ( )
virtualdefault

Member Function Documentation

◆ EngineFrame()

void Elevate::Application::EngineFrame ( )

Definition at line 124 of file Application.cpp.

125 {
126 static float lastTime = 0.0f;
127
128#if !EE_ASSERTS_ENABLED
129 try
130 {
131#endif // #if EE_ASSERTS_ENABLED
132 // TIME UPDATE //////////////////
133 Time::currentTime_ = (float) m_Window->GetTime();
134 Time::deltaTime_ = Time::currentTime_ - lastTime;
135 lastTime = Time::currentTime_;
137
140
141 FrameBuffer->Bind(); // Rendering the screen in a single texture
142 FrameBuffer->Clear();
143
144 for (Layer* layer : m_LayerStack)
145 layer->OnUpdate();
146
147 // Draw Layers and Scenes
148 for (Layer* layer : m_LayerStack)
149 layer->OnRender();
150
153
154 FrameBuffer->Unbind(); // Back to normal
155
156 #ifndef EE_EDITOR_BUILD
157 FrameBuffer->BlitFramebufferToScreen(m_Window->GetWidth(), m_Window->GetHeight());
158 #endif
159
160 //imgui
161 m_ImGuiLayer->PreRender();
162 m_ImGuiLayer->Begin();
163
164 for (Layer* layer : m_LayerStack)
165 layer->OnImGuiRender();
166
167 m_ImGuiLayer->Render(); // render imgui
168 m_ImGuiLayer->End(); // finish the imgui rendering
169
170 Renderer::InvalidateStateCache(); // Clear the renderer state after ImGui rendering
171 Input::ManageMidStates(); // Manage Key/Button up and down state
172
174 // Poll events and swap buffers
175 m_Window->OnUpdate();
176
177#ifdef EE_PLATFORM_WEB
178 if (!m_Running)
179 {
180 emscripten_cancel_main_loop();
181 Exit();
182 }
183#endif
184
185#if !EE_ASSERTS_ENABLED
186 }
187 catch (const std::exception& exc)
188 {
189 EE_CORE_ERROR("{}", exc.what());
190 }
191#endif // #if EE_ASSERTS_ENABLED
192 }
static void ManageMidStates()
Definition Input.h:52
static void FlushBuffers()
Definition Renderer.cpp:63
static void InvalidateStateCache()
Definition Renderer.cpp:174
static void DrawStack()
Definition Renderer.cpp:86
static void RenderAudio()
static void UpdateLoadingTextures()

◆ Exit()

void Elevate::Application::Exit ( )

Definition at line 207 of file Application.cpp.

208 {
209 m_ImGuiLayer->Cleanup();
211 }
static void Terminate()

◆ Get()

static Application & Elevate::Application::Get ( )
inlinestatic

Definition at line 62 of file Application.h.

62{ return *s_Instance; }

◆ GetArguments()

ApplicationArguments Elevate::Application::GetArguments ( )
static

Definition at line 233 of file Application.cpp.

234 {
235 return s_Instance->m_args;
236 }

◆ GetGameState()

const GameContextState & Elevate::Application::GetGameState ( )
static

Definition at line 213 of file Application.cpp.

214 {
215 return s_Instance->m_state;
216 }

◆ GetWindow()

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

Definition at line 63 of file Application.h.

63{ return *m_Window; }

◆ Init()

void Elevate::Application::Init ( )

Definition at line 119 of file Application.cpp.

120 {
122 }

◆ OnEvent()

void Elevate::Application::OnEvent ( Event e)

Definition at line 74 of file Application.cpp.

75 {
76 EventDispatcher dispatcher(e);
77 dispatcher.Dispatch<WindowCloseEvent>(BIND_EVENT_FN(OnWindowClose));
78 dispatcher.Dispatch<WindowResizeEvent>(BIND_EVENT_FN(OnWindowResize));
79 dispatcher.Dispatch<WindowFocusEvent>(BIND_EVENT_FN(OnWindowFocusEvent));
80
81 // Keyboard
82 dispatcher.Dispatch<KeyPressedEvent>(BIND_EVENT_FN(OnKeyPressedEvent));
83 dispatcher.Dispatch<KeyReleasedEvent>(BIND_EVENT_FN(OnKeyReleasedEvent));
84
85 // Mousse
86 dispatcher.Dispatch<MouseButtonPressedEvent>(BIND_EVENT_FN(OnMouseButtonPressedEvent));
87 dispatcher.Dispatch<MouseButtonReleasedEvent>(BIND_EVENT_FN(OnMouseButtonReleasedEvent));
88
89 for (auto it = m_LayerStack.end(); it != m_LayerStack.begin();)
90 {
91 (*--it)->OnEvent(e);
92 if (e.Handled)
93 break;
94 }
95 }
std::vector< Layer * >::iterator begin()
Definition LayerStack.h:19
std::vector< Layer * >::iterator end()
Definition LayerStack.h:20

◆ OnStateChange()

void Elevate::Application::OnStateChange ( GameContextState  oldState,
GameContextState  newState 
)
protected

Definition at line 239 of file Application.cpp.

240 {
241 GameContextEvent e(oldState, newState);
242 OnEvent(e);
243 }

◆ PushLayer()

void Elevate::Application::PushLayer ( Layer layer)

Definition at line 61 of file Application.cpp.

62 {
63 m_LayerStack.PushLayer(layer);
64 layer->OnAttach();
65 }
void PushLayer(Layer *layer)

◆ PushOverlay()

void Elevate::Application::PushOverlay ( Layer overlay)

Definition at line 67 of file Application.cpp.

68 {
69 m_LayerStack.PushOverlay(overlay);
70 overlay->OnAttach();
71 }
void PushOverlay(Layer *overlay)

◆ Run()

void Elevate::Application::Run ( )

Definition at line 194 of file Application.cpp.

195 {
196#ifdef EE_PLATFORM_WEB
197 emscripten_set_main_loop_arg(WebMainLoop, this, 0, true);
198#else
199 while (m_Running)
200 {
201 EngineFrame();
202 }
203 Exit();
204#endif
205 }

◆ SetGameState()

void Elevate::Application::SetGameState ( GameContextState  newState)
static

Definition at line 218 of file Application.cpp.

219 {
220 if (s_Instance->m_state != newState)
221 {
222 GameContextState oldState = s_Instance->m_state;
223 s_Instance->m_state = newState;
224
225 EE_CORE_INFO("GameContext state changed from {} to {}",
226 GetGameContextStateName(oldState),
227 GetGameContextStateName(newState));
228
229 s_Instance->OnStateChange(oldState, newState);
230 }
231 }
void OnStateChange(GameContextState oldState, GameContextState newState)
const char * GetGameContextStateName(GameContextState state)
GameContextState
Definition GameContext.h:6

◆ Start()

void Elevate::Application::Start ( int  argc,
char **  argv 
)
static

Definition at line 105 of file Application.cpp.

106 {
107 //Log::Init(); // todo remove or uncomment depending on if the workarround worked
108 EE_CORE_INFO("Initializing ElevateEngine...");
109 auto app = CreateApplication();
110 app->m_args = ApplicationArguments(argc, argv);
111 EE_CORE_TRACE("Application Initialized.");
112 app->Run();
113
114#ifndef EE_PLATFORM_WEB
115 delete app;
116#endif
117 }
Application * CreateApplication()

Friends And Related Symbol Documentation

◆ Elevate::Editor::EditorLayer

friend class Elevate::Editor::EditorLayer
friend

Definition at line 43 of file Application.h.

Member Data Documentation

◆ FrameBuffer

std::unique_ptr<Framebuffer> Elevate::Application::FrameBuffer

Definition at line 60 of file Application.h.


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