-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
89 lines (74 loc) · 2.55 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <vector>
#include <string>
#include <util/defer_action.h>
#include <util/macro_shared.h>
#include <windowing/window.h>
#include <game/game.h>
#include <game/game_stage.h>
int main(int argc, char** argv) {
if(argc > 1) {
for(int i = 1; i < argc; ++i) {
std::string param{argv[i]};
if(param.compare("windowed") == 0) {
Game::windowed() = true;
}
else if(param.compare("640") == 0) {
Game::window_width() = 640;
Game::window_height() = 480;
}
else if(param.compare("800") == 0) {
Game::window_width() = 800;
Game::window_height() = 600;
}
else if(param.compare("1280") == 0) {
Game::window_width() = 1280;
Game::window_height() = 768;
}
else if(param.compare("1366") == 0) {
Game::window_width() = 1366;
Game::window_height() = 768;
}
}
}
WindowCreationParams window_params {
"Open Rage Of Mages", // title
Game::window_width(), // width
Game::window_height(), // height
!Game::windowed(), // fullscreen
0x07, 0x02, 0x13 // clear color
};
Game::clear_r() = window_params.clear_color_r;
Game::clear_g() = window_params.clear_color_g;
Game::clear_b() = window_params.clear_color_b;
LifetimeProcHolder lifetime_procs {
Game::init_proc_ptr(),
Game::update_proc_ptr(),
Game::render_proc_ptr()
};
using callback_holder = std::variant<
KeyCallbackHolder,
CursorPosCallbackHolder,
MouseButtonCallbackHolder>;
std::vector<callback_holder> event_callbacks;
event_callbacks.emplace_back(KeyCallbackHolder{Game::key_callback_ptr()});
event_callbacks.emplace_back(CursorPosCallbackHolder{Game::mouse_callback_ptr()});
event_callbacks.emplace_back(MouseButtonCallbackHolder{Game::mouse_button_callback_ptr()});
if(!glfwInit()) {
return 1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
*Game::glfw_window() = INIT_WINDOW(window_params);
if(!*Game::glfw_window()) {
return 1;
}
DEFER([&](){ glfwDestroyWindow(*Game::glfw_window()); })
if(!start_main_loop(
*Game::glfw_window(),
window_params,
lifetime_procs,
event_callbacks
)) return 1;
return 0;
}