-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (65 loc) · 1.79 KB
/
main.cpp
File metadata and controls
73 lines (65 loc) · 1.79 KB
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
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <chrono>
#include "Engine/Window.h"
#include "Globals.h"
#include "Minesweeper/GameSettings.h"
#include "Minesweeper/UI.h"
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_VIDEO);
#ifdef SHOW_DEBUG_HELPERS
Utils::CheckSDLError("SDL_Init");
#endif
IMG_Init(IMG_INIT_PNG);
#ifdef SHOW_DEBUG_HELPERS
Utils::CheckSDLError("IMG_Init");
#endif
TTF_Init();
#ifdef SHOW_DEBUG_HELPERS
Utils::CheckSDLError("TTF_Init");
#endif
GameSettings::SetNextMode(DifficultyMode::Hard);
GameSettings::UpdateSettings();
Engine::Window GameWindow;
MinesweeperUI UI;
SDL_Event Event;
bool shouldQuit{false};
#ifdef FRAME_PERF_DEBUG
double totalFrameTime{0};
int frames{0};
double averageFrameTime;
#endif
while (!shouldQuit)
{
#ifdef FRAME_PERF_DEBUG
const auto frameStart{std::chrono::steady_clock::now()};
#endif
while (SDL_PollEvent(&Event))
{
if (Event.type == SDL_QUIT)
{
shouldQuit = true;
}
else
{
GameWindow.HandelEvents(Event);
UI.HandleEvent(Event);
}
}
GameWindow.Render();
UI.Render(GameWindow.GetSurface());
GameWindow.Update();
#ifdef FRAME_PERF_DEBUG
const auto frameEnd{std::chrono::steady_clock::now()};
const std::chrono::duration<double> elapsed_seconds_frame{frameEnd - frameStart};
totalFrameTime += elapsed_seconds_frame.count();
averageFrameTime = totalFrameTime / ++frames;
std::cout << "AFT ms: " << averageFrameTime * 1000
<< "; Last frame time ms: " << elapsed_seconds_frame.count() * 1000
<< std::endl;
#endif
}
SDL_Quit();
return 0;
}