2022-09-13 18:25:18 +00:00
|
|
|
#include "engine.hpp"
|
|
|
|
|
2022-10-04 10:54:23 +00:00
|
|
|
#include "window.hpp"
|
|
|
|
#include "gfx_device.hpp"
|
2022-10-20 19:28:51 +00:00
|
|
|
#include "resource_manager.hpp"
|
2022-10-21 16:03:36 +00:00
|
|
|
#include "log.hpp"
|
2022-09-17 00:22:35 +00:00
|
|
|
|
2022-09-13 18:25:18 +00:00
|
|
|
namespace engine {
|
|
|
|
|
2022-10-04 10:54:23 +00:00
|
|
|
Application::Application(const char* appName, const char* appVersion)
|
|
|
|
{
|
2022-10-21 12:58:59 +00:00
|
|
|
m_win = std::make_unique<Window>(appName, true);
|
2022-10-05 16:01:40 +00:00
|
|
|
m_gfx = std::make_unique<GFXDevice>(appName, appVersion, m_win->getHandle());
|
2022-10-20 19:28:51 +00:00
|
|
|
|
|
|
|
engine::ResourceManager resMan{};
|
|
|
|
|
|
|
|
m_gfx->createPipeline(resMan.getFilePath("shader.vert.spv").string().c_str(), resMan.getFilePath("shader.frag.spv").string().c_str());
|
2022-10-21 16:03:36 +00:00
|
|
|
|
|
|
|
gfx::BufferDesc bufferDesc {
|
|
|
|
.size = 65536,
|
|
|
|
};
|
|
|
|
gfx::BufferHandle* buffer = m_gfx->createBuffer(bufferDesc, nullptr);
|
|
|
|
|
|
|
|
m_gfx->destroyBuffer(buffer);
|
2022-10-04 10:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::gameLoop()
|
|
|
|
{
|
|
|
|
uint64_t lastTick = m_win->getNanos();
|
2022-10-20 19:28:51 +00:00
|
|
|
constexpr int TICKFREQ = 1; // in hz
|
2022-10-04 10:54:23 +00:00
|
|
|
|
|
|
|
// single-threaded game loop
|
|
|
|
while (m_win->isRunning()) {
|
|
|
|
|
|
|
|
/* logic */
|
|
|
|
|
|
|
|
if (m_win->getLastFrameStamp() >= lastTick + (BILLION / TICKFREQ)) {
|
|
|
|
lastTick = m_win->getLastFrameStamp();
|
|
|
|
|
|
|
|
// do tick stuff here
|
2022-10-21 12:58:59 +00:00
|
|
|
m_win->setTitle("frame time: " + std::to_string(m_win->dt() * 1000.0f) + " ms, " + std::to_string(m_win->getFPS()) + " fps");
|
2022-10-04 10:54:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_win->getKeyPress(inputs::Key::F11)) {
|
2022-10-06 10:30:44 +00:00
|
|
|
m_win->toggleFullscreen();
|
2022-10-04 10:54:23 +00:00
|
|
|
}
|
|
|
|
if (m_win->getKeyPress(inputs::Key::ESCAPE)) {
|
|
|
|
m_win->setCloseFlag();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw */
|
|
|
|
m_gfx->draw();
|
|
|
|
|
|
|
|
/* poll events */
|
|
|
|
m_win->getInputAndEvents();
|
|
|
|
|
|
|
|
}
|
2022-10-20 19:28:51 +00:00
|
|
|
|
|
|
|
m_gfx->waitIdle();
|
2022-09-13 18:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|