Reputation: 39
Hello i am programming a 2D game and i have found several ways how to calculate Frames per second but i didnot really get the architecture rules yet , one of them is :
//at the start of main function
Uint32 startclock = 0;
Uint32 deltaclock = 0;
Uint32 currentFPS = 0;
// at beginning of while(!end_of_game)
startclock = SDL_GetTicks();
//fps calculation inside loop
deltaclock = SDL_GetTicks() - startclock;
startclock = SDL_GetTicks();
//evaluate the formula inside loop
if ( deltaclock != 0 )
currentFPS = 1000 / deltaclock;
//now i can output the current fps
what i cant figure out is that , rendering a screen takes some time so should i put this part at the absolute end of the loop (after rendering getting input etc (absolute end) :
if ( deltaclock != 0 )
currentFPS = 1000 / deltaclock;
so basicaly at the start of the game loop i get start clock then i run every single function like movement collision rendering etc and then i evaluate delta clock and based on that i count fps ? there are tons of fps calculation "formulas" but i need a real program architecture i mean:
//main game loop
//get elapsed time
//game logic
//delta time a.k.a how much time it took to go through the game logic part
//output the fps
thanks
Upvotes: 1
Views: 1459
Reputation: 4265
If you start the clock once before entering your while-loop and then use the two lines calculating deltaclock and resetting startclock inside your loop, it doesn't matter at what point of the loop you do it. It will always calculate the delta in respect to your last loop.
If you place it at the beginning or at the end of your loop will then only affect your first/last iteration, which should not matter in a FPS-counter.
Upvotes: 4