light/Engine/src/Engine/Core/Application.cpp

70 lines
1.5 KiB
C++
Raw Normal View History

2021-05-26 16:28:37 +04:30
#include "ltpch.h"
2021-05-20 10:21:08 +04:30
#include "Application.h"
2021-05-21 10:55:39 +04:30
#include "Logger.h"
2021-05-21 20:33:37 +04:30
#include "Window.h"
2021-05-21 10:55:39 +04:30
2021-05-27 18:55:30 +04:30
#include "Events/Event.h"
2021-05-23 18:10:11 +04:30
2021-05-27 18:55:30 +04:30
#include "Graphics/GraphicsContext.h"
2021-05-30 16:45:54 +04:30
#include "Graphics/Renderer.h"
2021-05-27 18:55:30 +04:30
#include "Graphics/RenderCommand.h"
#include "UserInterface/UserInterface.h"
2021-05-23 18:10:11 +04:30
2021-05-20 10:21:08 +04:30
namespace Light {
Application::Application()
{
2021-05-21 10:55:39 +04:30
Logger::Initialize();
2021-05-23 18:10:11 +04:30
m_Window = std::unique_ptr<Window>(Window::Create({ "Title", 800u, 600u, false }, std::bind(&Application::OnEvent, this , std::placeholders::_1)));
2021-05-20 10:21:08 +04:30
}
Application::~Application()
{
2021-05-27 18:55:30 +04:30
LT_ENGINE_INFO("Application::~Application: Terminating Application");
2021-05-20 10:21:08 +04:30
}
void Application::GameLoop()
{
2021-05-27 19:54:05 +04:30
LT_ENGINE_ASSERT(!m_LayerStack.IsEmpty(), "Application::GameLoop: Layerstack is empty");
while (m_Window->IsOpen())
{
2021-05-27 18:55:30 +04:30
// Events
2021-05-26 18:39:40 +04:30
m_Window->PollEvents();
2021-05-27 18:55:30 +04:30
// Rendering
2021-05-30 16:45:54 +04:30
m_Window->GetGfxContext()->GetRenderer()->Draw();
// Buffer updates
2021-05-26 18:39:40 +04:30
m_Window->GetGfxContext()->GetRenderCommand()->SwapBuffers();
m_Window->GetGfxContext()->GetRenderCommand()->ClearBackBuffer();
2021-05-27 10:41:32 +04:30
2021-05-27 18:55:30 +04:30
// Update
// ...
2021-05-27 10:41:32 +04:30
2021-05-27 18:55:30 +04:30
// UserInterface
m_Window->GetGfxContext()->GetUserInterface()->Begin();
2021-05-27 10:41:32 +04:30
m_Window->GetGfxContext()->GetUserInterface()->End();
}
2021-05-20 10:21:08 +04:30
}
2021-05-25 18:35:52 +04:30
void Application::OnEvent(const Event& event)
2021-05-23 18:10:11 +04:30
{
2021-05-27 18:55:30 +04:30
// Window
2021-05-27 12:51:39 +04:30
if (event.HasCategory(WindowEventCategory))
m_Window->OnEvent(event);
2021-05-27 18:55:30 +04:30
// UserInterface
2021-05-27 12:51:39 +04:30
if (event.HasCategory(InputEventCategory))
m_Window->GetGfxContext()->GetUserInterface()->OnInput(event);
2021-05-27 18:55:30 +04:30
// Input
// ...
// Layers
m_LayerStack.OnEvent(event);
2021-05-23 18:10:11 +04:30
}
2021-05-20 10:21:08 +04:30
}