Skip to content

Commit

Permalink
Add framerate limiter to main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
UnsafePointer committed Jul 26, 2019
1 parent 311ad8e commit 256fe76
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Logger.hpp"
#include <chrono>
#include <thread>
#include "Constants.h"

using namespace std;

Expand All @@ -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)) {
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit 256fe76

Please sign in to comment.