#include "application.h" #include namespace Donut { Application* Application::s_instance = nullptr; Application::Application(const std::string& name, int width, int height) : m_running(true), m_minimized(false) { s_instance = this; m_window = std::make_unique(name, width, height); m_window->set_event_callback([this](Event& event) { on_event(event); }); on_init(); } Application::~Application() { on_shutdown(); s_instance = nullptr; } void Application::run() { while (m_running) { if (!m_minimized) { on_update(); on_render(); } m_window->on_update(); } } void Application::close() { m_running = false; } void Application::on_event(Event& event) { EventDispatcher dispatcher(event); dispatcher.dispatch([this, &event](WindowCloseEvent& e) { m_running = false; event.handled = true; return true; }); dispatcher.dispatch([this, &event](WindowResizeEvent& e) { if (e.get_width() == 0 || e.get_height() == 0) m_minimized = true; else m_minimized = false; event.handled = true; return true; }); dispatcher.dispatch([this, &event](KeyPressedEvent& e) { if (e.get_key_code() == 256) close(); return true; }); } void Application::on_init() { } void Application::on_shutdown() { } void Application::on_update() { } void Application::on_render() { } }