11 void game_loop(
const float aMaxFramesPerSecond,
12 std::function<
bool (
const double ,
const double )> aLoopBehavior) {
13 bool shouldClose(
false);
16 double frameTime(1.0 / aMaxFramesPerSecond);
18 while (!shouldClose) {
19 using namespace std::chrono;
21 steady_clock::time_point currentFrameStartTimePoint(steady_clock::now());
23 shouldClose = aLoopBehavior(time, deltaTime);
28 steady_clock::time_point currentTimePoint(steady_clock::now());
30 duration<double> timeSpentOnCurrentFrame = duration_cast<duration<double>>(currentTimePoint - currentFrameStartTimePoint);
32 if (deltaTime = timeSpentOnCurrentFrame.count(); deltaTime >= frameTime)
break;
34 std::this_thread::sleep_for(1s * (frameTime - deltaTime) / 10.0);