From 256fe766ccf0a0b2d43f205e37ee1c852bdc73b1 Mon Sep 17 00:00:00 2001 From: Renzo Crisostomo Date: Fri, 26 Jul 2019 21:03:25 +0200 Subject: [PATCH] Add framerate limiter to main loop --- src/main.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index eb10b2f..3d3c3c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include "Logger.hpp" #include #include +#include "Constants.h" using namespace std; @@ -24,6 +25,9 @@ int main(int argc, char* argv[]) { this_thread::sleep_for(chrono::milliseconds(10 * 1000)); } bool quit = false; + uint32_t initTicks = SDL_GetTicks(); + float interval = 1000; + interval /= FrameRateTarget; while (!quit) { SDL_Event event; while (SDL_PollEvent(&event)) { @@ -57,6 +61,10 @@ int main(int argc, char* argv[]) { quit = true; continue; } - emulator->emulateFrame(); + uint32_t currentTicks = SDL_GetTicks(); + if (initTicks + interval < currentTicks) { + emulator->emulateFrame(); + initTicks = SDL_GetTicks(); + } } }