I'm really new to game development and I've already made a few programs using SDL2. Frame rate wasn't much of an issue since I never planned to release those programs and just used the SDL_RENDER_PRESENTVSYNC to cap the frame rate to 60 (the refresh rate of my monitor). Now I want to make an application I can send to friends and I wanted to know if my frame-rate implementation is any good.
unsigned int a = SDL_GetTicks();
unsigned int b = SDL_GetTicks();
double delta = 0;
while (running)
{
a = SDL_GetTicks();
delta += a - b;
if (delta > 1000/60.0)
{
std::cout << "fps: " << 1000 / delta << std::endl;
Update();
Render();
delta = 0;
}
b = SDL_GetTicks();
}
I have a good feeling that I've messed up my calculations horribly but many of the other implementations I have found online usually seem pretty long winded. If possible I would like to keep the frame cap implementation within the game loop and as simple as possible. Any help appreciated!