-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
96 lines (77 loc) · 2.25 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
90
91
92
93
94
95
96
#define SDL_MAIN_HANDLED
#include "window.hpp"
#include "state.hpp"
#include "menus/main_menu.hpp"
// State manager
StateManager stateManager;
// State manager's window
Window* window;
int main(int argc, char* argv[])
{
// Initialise everything
stateManager.init();
// Get window handler for easier usage
window = stateManager.getWindow();
// Create menu state
State* menuState = new MenuState();
// Push the menu state
stateManager.pushState(menuState);
// Event and main loop
SDL_Event event;
while(stateManager.isRunning())
{
// Update delta time
window -> updateDelta();
// Reset the inputs
window -> updateInput();
// Poll the events and handle them
while(SDL_PollEvent(&event))
{
// Event types
switch(event.type)
{
// Window events
case SDL_WINDOWEVENT:
switch(event.window.event)
{
// Resize
case SDL_WINDOWEVENT_RESIZED:
window -> resize(event.window.data1, event.window.data2);
break;
}
break;
// Keyboard events
case SDL_KEYDOWN:
case SDL_KEYUP:
window -> updateInput(event);
break;
// Gamepad events
case SDL_JOYAXISMOTION:
case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
case SDL_JOYHATMOTION:
case SDL_JOYDEVICEADDED:
case SDL_JOYDEVICEREMOVED:
window -> getGamepadManager() -> updateInput(event);
break;
// Quit events
case SDL_QUIT:
stateManager.quit();
break;
}
}
// Update
stateManager.update();
// Clear the window
window -> clear();
// Draw
stateManager.draw();
// Update the screen
window -> update();
// Small delay
SDL_Delay(8);
}
SDL_Quit();
TTF_Quit();
return EXIT_SUCCESS;
}