-
Notifications
You must be signed in to change notification settings - Fork 0
/
planck.cpp
79 lines (67 loc) · 1.5 KB
/
planck.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
#include "constants.h"
#include "frame.h"
#include "planck.h"
#include "ui/event.h"
#include "SDL_ttf.h"
#include <cstdlib>
#include <random>
int Planck::run() {
SDL_Event event;
// init
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
throw SDL_GetError();
}
SDL_Window *win = SDL_CreateWindow(
"Planck",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
SCREEN_WIDTH,
SCREEN_HEIGHT,
SDL_WINDOW_SHOWN
);
if (win == nullptr) {
SDL_Quit();
throw SDL_GetError();
}
SDL_Renderer *renderer = SDL_CreateRenderer(win, -1,
SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTVSYNC |
SDL_RENDERER_TARGETTEXTURE
);
if (renderer == nullptr) {
SDL_DestroyWindow(win);
SDL_Quit();
throw SDL_GetError();
}
if (TTF_Init() != 0) {
SDL_Quit();
throw "TTF_Init";
}
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<double> real;
while (m_running) {
while (SDL_PollEvent(&event)) {
// process events
if (event.type == SDL_QUIT) {
m_running = false;
}
Event::send(event);
}
// process loop logic
TimeDomainFrame frame = m_inputManager->sample();
// render
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
m_ui.render(renderer);
if (frame.left.render(renderer, 255, 150, 150) != 0) { return 6; }
SDL_RenderPresent(renderer);
}
TTF_Quit();
SDL_Quit();
return 0;
}
int main(int argc, char* argv[]) {
Planck p;
return p.run();
}