-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
56 lines (48 loc) · 1.26 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
#include "Game.h"
#include <utils/init.h>
#include <utils/log.h>
//#include "windows.h"
#include <iostream>
#include <stdlib.h>
const int FPS = 60;
const int DELAY_TIME = 1000.0f / FPS;
int main(int argc, char const **argv)
{
dani::init::init(argc, argv);
if (argc > 1 && strcmp(argv[1], "--randomize") == 0)
{
time_t t = time(NULL);
//useful in case we want to repeat a given board
LOG_ERROR("Randomizing with value " << t);
srandom(t);
}
// AllocConsole();
//freopen("CON", "w", stdout);
Uint32 frameStart, frameTime;
std::cout << "game init attempt...\n";
if(TheGame::Instance()->init("SDL_test", 100, 100, 755, 600, false, FPS))
{
std::cout << "game init success!\n";
while(TheGame::Instance()->running())
{
frameStart = SDL_GetTicks();
LOG_DEBUG("---------------");
TheGame::Instance()->handleEvents();
TheGame::Instance()->update();
TheGame::Instance()->render();
frameTime = SDL_GetTicks() - frameStart;
if(frameTime < DELAY_TIME)
{
SDL_Delay((int)(DELAY_TIME - frameTime));
}
}
}
else
{
std::cout << "game init failure - " << SDL_GetError() << "\n";
return -1;
}
std::cout << "game closing...\n";
TheGame::Instance()->clean();
return 0;
}