[99d44b2] | 1 | #include "vulkan-game.hpp"
|
---|
[850e84c] | 2 |
|
---|
[0df3c9a] | 3 | #include <iostream>
|
---|
| 4 |
|
---|
[5edbd58] | 5 | #include "consts.hpp"
|
---|
| 6 |
|
---|
[0df3c9a] | 7 | using namespace std;
|
---|
| 8 |
|
---|
[99d44b2] | 9 | VulkanGame::VulkanGame() {
|
---|
[0df3c9a] | 10 | gui = nullptr;
|
---|
| 11 | window = nullptr;
|
---|
| 12 | }
|
---|
| 13 |
|
---|
[99d44b2] | 14 | VulkanGame::~VulkanGame() {
|
---|
[0df3c9a] | 15 | }
|
---|
| 16 |
|
---|
[b6e60b4] | 17 | void VulkanGame::run(int width, int height, unsigned char guiFlags) {
|
---|
[2e77b3f] | 18 | cout << "DEBUGGING IS " << (ENABLE_VALIDATION_LAYERS ? "ON" : "OFF") << endl;
|
---|
| 19 |
|
---|
| 20 | cout << "Vulkan Game" << endl;
|
---|
| 21 |
|
---|
[5edbd58] | 22 | if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
|
---|
[0df3c9a] | 23 | return;
|
---|
| 24 | }
|
---|
[b6e60b4] | 25 |
|
---|
[27c40ce] | 26 | SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
|
---|
| 27 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
---|
| 28 |
|
---|
| 29 | SDL_RenderClear(renderer);
|
---|
| 30 |
|
---|
| 31 | SDL_RenderPresent(renderer);
|
---|
| 32 |
|
---|
[0df3c9a] | 33 | initVulkan();
|
---|
| 34 | mainLoop();
|
---|
| 35 | cleanup();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[b6e60b4] | 38 | bool VulkanGame::initWindow(int width, int height, unsigned char guiFlags) {
|
---|
[0df3c9a] | 39 | gui = new GameGui_SDL();
|
---|
| 40 |
|
---|
[b6e60b4] | 41 | if (gui->init() == RTWO_ERROR) {
|
---|
[0df3c9a] | 42 | cout << "UI library could not be initialized!" << endl;
|
---|
[b6e60b4] | 43 | cout << gui->getError() << endl;
|
---|
[0df3c9a] | 44 | return RTWO_ERROR;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[b6e60b4] | 47 | window = (SDL_Window*) gui->createWindow("Vulkan Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
|
---|
[0df3c9a] | 48 | if (window == nullptr) {
|
---|
| 49 | cout << "Window could not be created!" << endl;
|
---|
[ed7c953] | 50 | cout << gui->getError() << endl;
|
---|
[0df3c9a] | 51 | return RTWO_ERROR;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[b6e60b4] | 54 | int actualWidth, actualHeight;
|
---|
| 55 | gui->getWindowSize(&actualWidth, &actualHeight);
|
---|
| 56 |
|
---|
| 57 | cout << "Target window size: (" << width << ", " << height << ")" << endl;
|
---|
| 58 | cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
|
---|
| 59 |
|
---|
[0df3c9a] | 60 | return RTWO_SUCCESS;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[99d44b2] | 63 | void VulkanGame::initVulkan() {
|
---|
[0df3c9a] | 64 | }
|
---|
| 65 |
|
---|
[99d44b2] | 66 | void VulkanGame::mainLoop() {
|
---|
[f6521fb] | 67 | UIEvent e;
|
---|
[0df3c9a] | 68 | bool quit = false;
|
---|
| 69 |
|
---|
| 70 | while (!quit) {
|
---|
[27c40ce] | 71 | gui->processEvents();
|
---|
| 72 |
|
---|
[f6521fb] | 73 | while (gui->pollEvent(&e)) {
|
---|
| 74 | switch(e.type) {
|
---|
| 75 | case UI_EVENT_QUIT:
|
---|
| 76 | cout << "Quit event detected" << endl;
|
---|
| 77 | quit = true;
|
---|
| 78 | break;
|
---|
| 79 | case UI_EVENT_WINDOW:
|
---|
| 80 | cout << "Window event detected" << endl;
|
---|
| 81 | // Currently unused
|
---|
| 82 | break;
|
---|
| 83 | case UI_EVENT_KEY:
|
---|
| 84 | if (e.key.keycode == SDL_SCANCODE_ESCAPE) {
|
---|
| 85 | quit = true;
|
---|
| 86 | } else {
|
---|
| 87 | cout << "Key event detected" << endl;
|
---|
| 88 | }
|
---|
| 89 | break;
|
---|
| 90 | case UI_EVENT_MOUSEBUTTONDOWN:
|
---|
| 91 | cout << "Mouse button down event detected" << endl;
|
---|
| 92 | break;
|
---|
| 93 | case UI_EVENT_MOUSEBUTTONUP:
|
---|
| 94 | cout << "Mouse button up event detected" << endl;
|
---|
| 95 | break;
|
---|
| 96 | case UI_EVENT_MOUSEMOTION:
|
---|
| 97 | break;
|
---|
[c61323a] | 98 | default:
|
---|
| 99 | cout << "Unhandled UI event: " << e.type << endl;
|
---|
[0df3c9a] | 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[99d44b2] | 105 | void VulkanGame::cleanup() {
|
---|
[b6e60b4] | 106 | gui->destroyWindow();
|
---|
| 107 | gui->shutdown();
|
---|
[0df3c9a] | 108 | delete gui;
|
---|
[850e84c] | 109 | } |
---|