-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (40 loc) · 870 Bytes
/
Copy pathmain.cpp
File metadata and controls
51 lines (40 loc) · 870 Bytes
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
#include "Engine/Includes/Game.h"
Game *game = nullptr;
int main(int argc, char *argv[])
{
u_int32_t frameStart;
int frameTime;
game = new Game();
game->init("GameWindow", 800, 640, false);
SDL_DisplayMode currentDisMode;
int FPS;
if(SDL_GetCurrentDisplayMode(0,¤tDisMode) != 0)
{
std::string error = "SDL error getting displaymode" + std::string(SDL_GetError());
SDL_Log(error.c_str());
FPS = 60;
}
else
{
FPS = currentDisMode.refresh_rate;
if(FPS == 0)
{
FPS = 60;
}
}
const int frameDelay = 1000/FPS;
while (game->running())
{
frameStart = SDL_GetTicks();
game->handleEvents();
game->update();
game->render();
frameTime = SDL_GetTicks() - frameStart;
if(frameDelay > frameTime)
{
SDL_Delay(frameDelay-frameTime);
}
}
game->clean();
return 0;
}