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