70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
//
|
|
// Created by sebastian on 23.12.25.
|
|
//
|
|
|
|
#include "Application.h"
|
|
|
|
#include "EngineTime.h"
|
|
#include "../../game/scenes/main/events/QuitEvent.h"
|
|
#include "../platform/glfw/InputManager.h"
|
|
#include "inputsOutputs/stateControl/StateRegistry.h"
|
|
#include "../core/scenes/SceneManager.h"
|
|
#include "../core/scenes/Scene.h"
|
|
Application* Application::instance = nullptr;
|
|
|
|
void Application::updateTime() {
|
|
const auto now = static_cast<float>(glfwGetTime());
|
|
EngineTime::deltaTime = now - lastFrame;
|
|
EngineTime::totalTime += EngineTime::deltaTime;
|
|
lastFrame = now;
|
|
|
|
// printf("Frametime: %f\n", EngineTime::deltaTime);
|
|
}
|
|
|
|
Application::Application()
|
|
{
|
|
instance = this;
|
|
context = std::make_unique<EngineContext>();
|
|
sceneManager = std::make_unique<SceneManager>(*context.get());
|
|
|
|
WindowProps window_props = WindowProps();
|
|
window_props.Width = 1280;
|
|
window_props.Height = 720;
|
|
window_props.Title = "DiceSettlers v0.0.1";
|
|
window_props.VSync = true;
|
|
|
|
window.reset(Window::Create(window_props));
|
|
keyboard = std::make_unique<Keyboard>(*window);
|
|
mouse = std::make_unique<Mouse>(*window);
|
|
stateManager = std::make_unique<StateManager>(StateRegistry::get().empty, StateRegistry::get().game);
|
|
|
|
EventBus::getInstance().subscribe<QuitEvent>([this](const QuitEvent& e) {
|
|
window->close();
|
|
});
|
|
}
|
|
|
|
Application::~Application()
|
|
{
|
|
}
|
|
|
|
void Application::run() {
|
|
while (!window->shouldClose())
|
|
{
|
|
window->OnUpdate();
|
|
updateTime();
|
|
|
|
sceneManager->update();
|
|
sceneManager->render();
|
|
|
|
InputManager::update();
|
|
|
|
mouse->update();
|
|
keyboard->update();
|
|
stateManager->updateState();
|
|
}
|
|
}
|
|
|
|
Application& Application::getInstance()
|
|
{
|
|
return *instance;
|
|
} |