[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) {
|
---|
[5edbd58] | 18 | if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
|
---|
[0df3c9a] | 19 | return;
|
---|
| 20 | }
|
---|
[b6e60b4] | 21 |
|
---|
[27c40ce] | 22 | SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
|
---|
| 23 | SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
---|
| 24 |
|
---|
| 25 | SDL_RenderClear(renderer);
|
---|
| 26 |
|
---|
| 27 | SDL_RenderPresent(renderer);
|
---|
| 28 |
|
---|
[0df3c9a] | 29 | initVulkan();
|
---|
| 30 | mainLoop();
|
---|
| 31 | cleanup();
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[b6e60b4] | 34 | bool VulkanGame::initWindow(int width, int height, unsigned char guiFlags) {
|
---|
[0df3c9a] | 35 | gui = new GameGui_SDL();
|
---|
| 36 |
|
---|
[b6e60b4] | 37 | if (gui->init() == RTWO_ERROR) {
|
---|
[0df3c9a] | 38 | cout << "UI library could not be initialized!" << endl;
|
---|
[b6e60b4] | 39 | cout << gui->getError() << endl;
|
---|
[0df3c9a] | 40 | return RTWO_ERROR;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[b6e60b4] | 43 | window = (SDL_Window*) gui->createWindow("Vulkan Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
|
---|
[0df3c9a] | 44 | if (window == nullptr) {
|
---|
| 45 | cout << "Window could not be created!" << endl;
|
---|
[ed7c953] | 46 | cout << gui->getError() << endl;
|
---|
[0df3c9a] | 47 | return RTWO_ERROR;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[b6e60b4] | 50 | int actualWidth, actualHeight;
|
---|
| 51 | gui->getWindowSize(&actualWidth, &actualHeight);
|
---|
| 52 |
|
---|
| 53 | cout << "Target window size: (" << width << ", " << height << ")" << endl;
|
---|
| 54 | cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
|
---|
| 55 |
|
---|
[0df3c9a] | 56 | return RTWO_SUCCESS;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[99d44b2] | 59 | void VulkanGame::initVulkan() {
|
---|
[0df3c9a] | 60 | }
|
---|
| 61 |
|
---|
[99d44b2] | 62 | void VulkanGame::mainLoop() {
|
---|
[0df3c9a] | 63 | SDL_Event e;
|
---|
[27c40ce] | 64 | //MouseEvent mouseEvent;
|
---|
[0df3c9a] | 65 | bool quit = false;
|
---|
| 66 |
|
---|
| 67 | while (!quit) {
|
---|
[27c40ce] | 68 | /*
|
---|
| 69 | gui->processEvents();
|
---|
| 70 |
|
---|
| 71 | if (gui->getKeyEvent(SDLK_ESCAPE) == RTWO_KEY_EVENT_PRESSED) {
|
---|
| 72 | quit = true;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | while (gui->pollMouseEvent(&mouseEvent)) {
|
---|
| 76 | cout << "Mouse click detected at (" << mouseEvent.x << ", " << mouseEvent.y << ")" << endl;
|
---|
| 77 | }
|
---|
| 78 | */
|
---|
| 79 |
|
---|
[0df3c9a] | 80 | while (SDL_PollEvent(&e)) {
|
---|
| 81 | if (e.type == SDL_QUIT) {
|
---|
| 82 | quit = true;
|
---|
| 83 | }
|
---|
| 84 | if (e.type == SDL_KEYDOWN) {
|
---|
| 85 | quit = true;
|
---|
| 86 | }
|
---|
| 87 | if (e.type == SDL_MOUSEBUTTONDOWN) {
|
---|
| 88 | quit = true;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[99d44b2] | 94 | void VulkanGame::cleanup() {
|
---|
[b6e60b4] | 95 | gui->destroyWindow();
|
---|
| 96 | gui->shutdown();
|
---|
[0df3c9a] | 97 | delete gui;
|
---|
[850e84c] | 98 | } |
---|