problem using my FPS function
I have the following function
/////////////////////////////////////////
// function that returns the framerate //
/////////////////////////////////////////
int GetFramerate()
{
frameratecounter++ ;
if (Framerate.getMsEllapsed()>=1000)
{
Framerate.reset() ;
frameratecounter=0 ;
} // end of if Framerate.getMsEllapsed()
return frameratecounter ;
} // end of getframerate()
and in my gameloop I have
Framerate=GetFramerate() ;
and
a function that shows Framerate
but when I run my game i see a counter that counts to +/- 70 and then restarts
so I guess my framerate is +/- 70
but what am I doing wrong
how do I get a steady number
(I already looked in the forum, but because I want to use my own function I want to solve this problem)
thanx in advance
Well that''s exactly what you have programmed
Let''s look at the code : each time the function is called, it increments the counter by one, and returns the value, unless 1 second has elapsed, in which case it just resets the counter...
You need to decompose the problem as follow :
- increment a private counter every frame
- every second, copy the private counter into a public counter and reset the private counter.
- calls to your FPS function returns the value of the public counter.
Let''s look at the code : each time the function is called, it increments the counter by one, and returns the value, unless 1 second has elapsed, in which case it just resets the counter...
You need to decompose the problem as follow :
- increment a private counter every frame
- every second, copy the private counter into a public counter and reset the private counter.
- calls to your FPS function returns the value of the public counter.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement