26 #include <emscripten.h>
31#define BIND_EVENT_FN(x) std::bind(&Application::x, this, std::placeholders::_1)
33 Application* Application::s_Instance =
nullptr;
37 EE_CORE_ASSERT(!s_Instance,
"Application already exists!");
40 EE_CORE_TRACE(
"Current working directory : {}", std::filesystem::current_path().
string().c_str());
48 FrameBuffer->SetClearColor({ 0.8f, 0.4f, 0.7f, 1.0f });
50 #ifdef EE_EDITOR_BUILD
89 for (
auto it = m_LayerStack.
end(); it != m_LayerStack.
begin();)
99 void WebMainLoop(
void* arg)
108 EE_CORE_INFO(
"Initializing ElevateEngine...");
111 EE_CORE_TRACE(
"Application Initialized.");
114#ifndef EE_PLATFORM_WEB
126 static float lastTime = 0.0f;
128#if !EE_ASSERTS_ENABLED
133 Time::currentTime_ = (float) m_Window->GetTime();
134 Time::deltaTime_ = Time::currentTime_ - lastTime;
135 lastTime = Time::currentTime_;
144 for (
Layer* layer : m_LayerStack)
148 for (
Layer* layer : m_LayerStack)
156 #ifndef EE_EDITOR_BUILD
157 FrameBuffer->BlitFramebufferToScreen(m_Window->GetWidth(), m_Window->GetHeight());
162 m_ImGuiLayer->
Begin();
164 for (
Layer* layer : m_LayerStack)
165 layer->OnImGuiRender();
175 m_Window->OnUpdate();
177#ifdef EE_PLATFORM_WEB
180 emscripten_cancel_main_loop();
185#if !EE_ASSERTS_ENABLED
187 catch (
const std::exception& exc)
189 EE_CORE_ERROR(
"{}", exc.what());
196#ifdef EE_PLATFORM_WEB
197 emscripten_set_main_loop_arg(WebMainLoop,
this, 0,
true);
215 return s_Instance->m_state;
220 if (s_Instance->m_state != newState)
223 s_Instance->m_state = newState;
225 EE_CORE_INFO(
"GameContext state changed from {} to {}",
235 return s_Instance->m_args;
251 bool Application::OnKeyReleasedEvent(KeyReleasedEvent& e)
257 bool Application::OnMouseButtonPressedEvent(MouseButtonPressedEvent& e)
263 bool Application::OnMouseButtonReleasedEvent(MouseButtonReleasedEvent& e)
269 bool Application::OnWindowClose(WindowCloseEvent& e)
275 bool Application::OnWindowResize(WindowResizeEvent& e)
281 bool Application::OnWindowFocusEvent(WindowFocusEvent& e)
285 if (e.GetFocusState())
std::unique_ptr< Framebuffer > FrameBuffer
void PushLayer(Layer *layer)
static void SetGameState(GameContextState newState)
static const GameContextState & GetGameState()
void PushOverlay(Layer *overlay)
void OnStateChange(GameContextState oldState, GameContextState newState)
static void Start(int argc, char **argv)
static ApplicationArguments GetArguments()
friend class Elevate::Editor::EditorLayer
bool Dispatch(EventFn< T > func)
static Framebuffer * Create(uint32_t width=1280, uint32_t height=720)
std::vector< Layer * >::iterator begin()
std::vector< Layer * >::iterator end()
void PushOverlay(Layer *overlay)
void PushLayer(Layer *layer)
static void FlushBuffers()
static void SetViewport(int x, int y, int width, int height)
static void InvalidateStateCache()
static void Suspend(bool renderAnyway=false, bool fadeOut=true)
static void RenderAudio()
static void UpdateLoadingTextures()
static Window * Create(const WindowProps &props=WindowProps("app.config"))
const char * GetGameContextStateName(GameContextState state)
Application * CreateApplication()