1 | #include "vulkan-game.hpp"
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | #include "consts.hpp"
|
---|
6 |
|
---|
7 | using namespace std;
|
---|
8 |
|
---|
9 | VulkanGame::VulkanGame() {
|
---|
10 | gui = nullptr;
|
---|
11 | window = nullptr;
|
---|
12 | }
|
---|
13 |
|
---|
14 | VulkanGame::~VulkanGame() {
|
---|
15 | }
|
---|
16 |
|
---|
17 | void VulkanGame::run(int width, int height, unsigned char guiFlags) {
|
---|
18 | if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
|
---|
19 | return;
|
---|
20 | }
|
---|
21 |
|
---|
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 |
|
---|
29 | initVulkan();
|
---|
30 | mainLoop();
|
---|
31 | cleanup();
|
---|
32 | }
|
---|
33 |
|
---|
34 | bool VulkanGame::initWindow(int width, int height, unsigned char guiFlags) {
|
---|
35 | gui = new GameGui_SDL();
|
---|
36 |
|
---|
37 | if (gui->init() == RTWO_ERROR) {
|
---|
38 | cout << "UI library could not be initialized!" << endl;
|
---|
39 | cout << gui->getError() << endl;
|
---|
40 | return RTWO_ERROR;
|
---|
41 | }
|
---|
42 |
|
---|
43 | window = (SDL_Window*) gui->createWindow("Vulkan Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
|
---|
44 | if (window == nullptr) {
|
---|
45 | cout << "Window could not be created!" << endl;
|
---|
46 | cout << gui->getError() << endl;
|
---|
47 | return RTWO_ERROR;
|
---|
48 | }
|
---|
49 |
|
---|
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 |
|
---|
56 | return RTWO_SUCCESS;
|
---|
57 | }
|
---|
58 |
|
---|
59 | void VulkanGame::initVulkan() {
|
---|
60 | }
|
---|
61 |
|
---|
62 | void VulkanGame::mainLoop() {
|
---|
63 | UIEvent e;
|
---|
64 | bool quit = false;
|
---|
65 |
|
---|
66 | while (!quit) {
|
---|
67 | gui->processEvents();
|
---|
68 |
|
---|
69 | while (gui->pollEvent(&e)) {
|
---|
70 | switch(e.type) {
|
---|
71 | case UI_EVENT_QUIT:
|
---|
72 | cout << "Quit event detected" << endl;
|
---|
73 | quit = true;
|
---|
74 | break;
|
---|
75 | case UI_EVENT_WINDOW:
|
---|
76 | cout << "Window event detected" << endl;
|
---|
77 | // Currently unused
|
---|
78 | break;
|
---|
79 | case UI_EVENT_KEY:
|
---|
80 | if (e.key.keycode == SDL_SCANCODE_ESCAPE) {
|
---|
81 | quit = true;
|
---|
82 | } else {
|
---|
83 | cout << "Key event detected" << endl;
|
---|
84 | }
|
---|
85 | break;
|
---|
86 | case UI_EVENT_MOUSEBUTTONDOWN:
|
---|
87 | cout << "Mouse button down event detected" << endl;
|
---|
88 | break;
|
---|
89 | case UI_EVENT_MOUSEBUTTONUP:
|
---|
90 | cout << "Mouse button up event detected" << endl;
|
---|
91 | break;
|
---|
92 | case UI_EVENT_MOUSEMOTION:
|
---|
93 | break;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | void VulkanGame::cleanup() {
|
---|
100 | gui->destroyWindow();
|
---|
101 | gui->shutdown();
|
---|
102 | delete gui;
|
---|
103 | }
|
---|