# Is my frame rate being calculated correctly?

I'm having a long headache (which may not be that complicated) with this frame rate thing. I already tested several frame rate algorithms, lastly I tested this here and they all gave something strange at some point, like choppy movements, skipping and other bizarre things.

Now I've used this "Variable Step" from the answer of this link and everything is running fine, but with all the stress past because of this I would like to know if the frame rate is actually right now:

(Just mentioning that this frame rate algorithm is from the user "Stephane Hockenhull" that is on the last link.)

Uint32 iMinimum_Fps_Delta_Time = (1000/50); // minimum 50 fps, if the computer is slower than this: slow down.
Uint32 iLast_Game_Step = SDL_GetTicks(); // initial value

while(bRunning) {
Uint32 iNow = SDL_GetTicks();

// Check so we don't render for no reason, avoid having a 0 delta time
if(iLast_Game_Step < iNow) {

Uint32 iDelta = iNow - iLast_Game_Step;

if(iDelta > iMinimum_Fps_Delta_Time) iDelta = iMinimum_Fps_Delta_Time; // slow down if the computer is too slow

//////////////////////////////////////////////////////////////////////////////////////////////////////////
pState_Manager->handle_events(iDelta);
pState_Manager->update(iDelta);

iLast_Game_Step = iNow;

SDL_SetRenderDrawColor(cEngine::oWindow.get_renderer(), 0, 0xAC, 0xE6, 0xFF);
SDL_RenderClear(cEngine::oWindow.get_renderer());
pState_Manager->draw();
SDL_RenderPresent(cEngine::oWindow.get_renderer());

cKey_Handler::clear_keys();
cJoystick_Handler::check_joystick_connection();

while(SDL_PollEvent(&oEvent)) {
if(oEvent.type == SDL_QUIT) {
bRunning = false;
break;
}
else if(oEvent.key.keysym.scancode == SDL_SCANCODE_RETURN){
bRunning = false;
break;
}

if(oEvent.type == SDL_KEYDOWN) {
if(oEvent.key.repeat == 0) cKey_Handler::set_pressed_keys(oEvent);
}
else if(oEvent.type == SDL_KEYUP) cKey_Handler::set_released_keys(oEvent);

if(oEvent.type == SDL_JOYHATMOTION) cJoystick_Handler::set_hat(oEvent);
else if(oEvent.type == SDL_JOYAXISMOTION) cJoystick_Handler::set_axis(oEvent);
}
}

pState_Manager->handle_inputs();
//////////////////////////////////////////////////////////////////////////////////////////////////////////
}
else SDL_Delay(1);
}


Some useful (maybe) information:

Renderer is set to:

SDL_CreateRenderer(this->aWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);


Window's size is 960x720 and renderer logical size is:

SDL_RenderSetLogicalSize(this->aRenderer, 960, 720);

• It's not clear what you're asking. Are you trying to construct a loop for rendering? Or are you trying to measure the actual frame rate? – Jay Jan 22 '18 at 3:17
• @Jay I just want to know if there's something wrong with this frame rate calculation, if it has a weak point somewhere and what precautions should I have using it – Dormin Jan 22 '18 at 15:42

iLast_Game_Step = iNow;