vulkan-project/main.cpp
2022-10-14 20:58:20 +02:00

83 lines
3.4 KiB
C++

#include "main.hpp"
#include "shape.hpp"
#include "vulkan_instance.hpp"
#include "renderer2D.hpp"
#include <chrono>
#include <ratio>
#include <thread>
namespace gz::vk {
int mainLoop() {
Log log("", true, false, "Main", Color::BG_RED);
gz::SettingsManagerCreateInfo<SettingsTypes> smCI{};
smCI.filepath = gz::vk::CONFIG_FILE;
smCI.readFileOnCreation = true;
smCI.writeFileOnExit = true;
smCI.initialValues = gz::vk::INITIAL_SETTINGS;
smCI.throwExceptionWhenNewValueNotAllowed = true;
VulkanInstance vulkanInstance(smCI);
vulkanInstance.init();
TextureManager textureManager(vulkanInstance);
Renderer2D r2D(vulkanInstance, textureManager);
log("Startup complete. Drawing shapes");
Rectangle rect1( 90, 91, 92, 93, { 1.0f, 0.9f, 0.8f}, "blocks/leaves.png");
Rectangle rect2( 190, 191, 192, 193, { 0.7f, 0.6f, 0.5f}, "blocks/crate.png");
Rectangle rect3( 32, 120, 400, 400, { 0.0f, 0.0f, 1.0f}, "blocks/dirt.png");
Rectangle rect4(-600, -600, 800, 400, { 1.0f, 0.0f, 0.0f}, "blocks/ice.png");
Rectangle rect5( 90, 91, 92, 93, { 1.0f, 0.9f, 0.8f}, "items/sword.png");
Rectangle rect6( 190, 191, 192, 193, { 0.7f, 0.6f, 0.5f}, "items/crossbow.png");
Rectangle rect7( 32, 120, 400, 400, { 0.0f, 0.0f, 1.0f}, "special/hotbar.png");
Rectangle rect8(-600, -600, 800, 400, { 1.0f, 0.0f, 0.0f}, "special/func_nocol.png");
Rectangle rect9(-200, -400, 200, 200, { 0.0f, 1.0f, 0.0f}, "entities/sheep.png");
Rectangle rect10(-400, -400, 800, 800, { 0.0f, 1.0f, 0.0f}, "atlas");
r2D.drawShape(&rect1);
r2D.drawShape(&rect2);
r2D.drawShape(&rect3);
r2D.drawShape(&rect4);
r2D.drawShape(&rect5);
r2D.drawShape(&rect6);
r2D.drawShape(&rect7);
r2D.drawShape(&rect8);
r2D.drawShape(&rect9);
r2D.drawShape(&rect10);
log("Drawing complete. Filling r2D with shapes.");
r2D.fillVertexBufferWithShapes();
r2D.fillIndexBufferWithShapes();
/* gz::FontManager fm("fonts"); */
/* fm.loadFont("menu.ttf"); */
/* /1* fm.getFaces().at("menu.ttf"). *1/ */
try {
uint32_t imageIndex;
/* std::chrono::time_point now = std::chrono::system_clock::now(); */
while (! glfwWindowShouldClose(vulkanInstance.window)) {
glfwPollEvents();
imageIndex = vulkanInstance.beginFrameDraw();
r2D.drawFrame(imageIndex);
vulkanInstance.endFrameDraw(imageIndex);
auto SLEEP_TIME = std::chrono::milliseconds(1000 / vulkanInstance.settings.get<uint32_t>("framerate"));
std::this_thread::sleep_for(SLEEP_TIME);
/* std::chrono::time_point now2 = std::chrono::system_clock::now(); */
/* std::chrono::nanoseconds dur = std::chrono::duration_cast<std::chrono::nanoseconds>(now2 - now); */
/* std::cout << "Frametime: (ns)" << dur.count() << " in fps: " << 1e9 / (dur.count()) << "\n"; */
/* now = now2; */
}
vulkanInstance.cleanup();
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}
}
int main() {
return gz::vk::mainLoop();
}