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
before I forget, I already tried this :
int GetFramerate()
{
frameratecounter++ ;
if (Framerate.getMsEllapsed()>=1000)
{
Framerate.reset() ;
frameratecounter=0 ;
return frameratecounter ;
} // end of if Framerate.getMsEllapsed()
} // end of getframerate()
only return the counter when & second has passed
but this doesn''t work also :/
int GetFramerate()
{
frameratecounter++ ;
if (Framerate.getMsEllapsed()>=1000)
{
Framerate.reset() ;
frameratecounter=0 ;
return frameratecounter ;
} // end of if Framerate.getMsEllapsed()
} // end of getframerate()
only return the counter when & second has passed
but this doesn''t work also :/
This is the system that I use:
Just remember to call UpdateFrameRate every frame. Hope this helps
---------------
I finally got it all together...
...and then forgot where I put it.
DWORD startFrame = 0;DWORD numFrames = 0;int curFrameRate = 0;void UpdateFrameRate(){ numFrames++; if (timeGetTime()-startFrame >= 1000) { curFrameRate = numFrames; numFrames = 0; startFrame = timeGetTime(); }}int GetFrameRate(){ return curFrameRate;}
Just remember to call UpdateFrameRate every frame. Hope this helps
---------------
I finally got it all together...
...and then forgot where I put it.
how about this :
you''ll get a false framerate when you call this function for the first time though.
float GetFrameRate(){ static DWORD lastFrameTick = timeGetTime(); DWORD currFrameTick; float delta; currFrameTick = timeGetTime(); delta = (float) (currFrameTick - lastFrameTick); lastFrameTick = currFrameTick; return (1000.0f/delta);}
you''ll get a false framerate when you call this function for the first time though.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement