-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameMain.cpp
More file actions
29 lines (25 loc) · 747 Bytes
/
GameMain.cpp
File metadata and controls
29 lines (25 loc) · 747 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
#include <iostream>
#include <chrono>
#include <thread>
#include "Game.hpp"
int main(int argc, char* argv[])
{
Game game;
// TODO: Investigate frame rate discrepancy (nvidia showing 58 fps - should be exactly 60)
const double FPS = 60.0;
double frameDelay = 1000.0 / FPS;
Uint64 lastFrameTime = 0;
while (game.isRunning()) {
Uint64 startTime = SDL_GetTicks64();
game.handleEvents();
game.update();
game.render();
Uint64 currTime = SDL_GetTicks64();
if (currTime < startTime + frameDelay)
{
//std::cout << "Sleeping for " << (int)(startTime + frameDelay - currTime) << " milliseconds" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds((int)(startTime + frameDelay - currTime)));
}
}
return 0;
}