[99d44b2] | 1 | #include "vulkan-game.hpp"
|
---|
[850e84c] | 2 |
|
---|
[0df3c9a] | 3 | #include <iostream>
|
---|
| 4 |
|
---|
[5edbd58] | 5 | #include "consts.hpp"
|
---|
| 6 |
|
---|
[99d44b2] | 7 | #define GAMEGUI_INCLUDE_VULKAN
|
---|
[0df3c9a] | 8 | #include "game-gui-sdl.hpp"
|
---|
| 9 |
|
---|
| 10 | using namespace std;
|
---|
| 11 |
|
---|
[99d44b2] | 12 | VulkanGame::VulkanGame() {
|
---|
[0df3c9a] | 13 | gui = nullptr;
|
---|
| 14 | window = nullptr;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
[99d44b2] | 17 | VulkanGame::~VulkanGame() {
|
---|
[0df3c9a] | 18 | }
|
---|
| 19 |
|
---|
[b6e60b4] | 20 | void VulkanGame::run(int width, int height, unsigned char guiFlags) {
|
---|
[5edbd58] | 21 | if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
|
---|
[0df3c9a] | 22 | return;
|
---|
| 23 | }
|
---|
[b6e60b4] | 24 |
|
---|
[0df3c9a] | 25 | initVulkan();
|
---|
| 26 | mainLoop();
|
---|
| 27 | cleanup();
|
---|
| 28 | }
|
---|
| 29 |
|
---|
[b6e60b4] | 30 | bool VulkanGame::initWindow(int width, int height, unsigned char guiFlags) {
|
---|
[0df3c9a] | 31 | gui = new GameGui_SDL();
|
---|
| 32 |
|
---|
[b6e60b4] | 33 | if (gui->init() == RTWO_ERROR) {
|
---|
[0df3c9a] | 34 | cout << "UI library could not be initialized!" << endl;
|
---|
[b6e60b4] | 35 | cout << gui->getError() << endl;
|
---|
[0df3c9a] | 36 | return RTWO_ERROR;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
[b6e60b4] | 39 | window = (SDL_Window*) gui->createWindow("Vulkan Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
|
---|
[0df3c9a] | 40 | if (window == nullptr) {
|
---|
| 41 | cout << "Window could not be created!" << endl;
|
---|
| 42 | return RTWO_ERROR;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[b6e60b4] | 45 | int actualWidth, actualHeight;
|
---|
| 46 | gui->getWindowSize(&actualWidth, &actualHeight);
|
---|
| 47 |
|
---|
| 48 | cout << "Target window size: (" << width << ", " << height << ")" << endl;
|
---|
| 49 | cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
|
---|
| 50 |
|
---|
[0df3c9a] | 51 | return RTWO_SUCCESS;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[99d44b2] | 54 | void VulkanGame::initVulkan() {
|
---|
[0df3c9a] | 55 | }
|
---|
| 56 |
|
---|
[99d44b2] | 57 | void VulkanGame::mainLoop() {
|
---|
[0df3c9a] | 58 | SDL_Event e;
|
---|
| 59 | bool quit = false;
|
---|
| 60 |
|
---|
| 61 | while (!quit) {
|
---|
| 62 | while (SDL_PollEvent(&e)) {
|
---|
| 63 | if (e.type == SDL_QUIT) {
|
---|
| 64 | quit = true;
|
---|
| 65 | }
|
---|
| 66 | if (e.type == SDL_KEYDOWN) {
|
---|
| 67 | quit = true;
|
---|
| 68 | }
|
---|
| 69 | if (e.type == SDL_MOUSEBUTTONDOWN) {
|
---|
| 70 | quit = true;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[99d44b2] | 76 | void VulkanGame::cleanup() {
|
---|
[b6e60b4] | 77 | gui->destroyWindow();
|
---|
| 78 | gui->shutdown();
|
---|
[0df3c9a] | 79 | delete gui;
|
---|
[850e84c] | 80 | }
|
---|