Skip to content

Instantly share code, notes, and snippets.

@mortennobel
Created October 26, 2017 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortennobel/9931de796161cf2da56e167ad1ad22da to your computer and use it in GitHub Desktop.
Save mortennobel/9931de796161cf2da56e167ad1ad22da to your computer and use it in GitHub Desktop.
while (running){
frame(deltaTime);
auto tick = Clock::now();
deltaTime = std::chrono::duration_cast<FpSeconds>(tick - lastTick).count();
// todo fix busy wait
// https://forum.lazarus.freepascal.org/index.php?topic=35689.0
while (deltaTime < timePerFrame){
SDL_Delay((Uint32) ((timePerFrame - deltaTime) / 1000));
tick = Clock::now();
deltaTime = std::chrono::duration_cast<FpSeconds>(tick - lastTick).count();
}
lastTick = tick;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment