🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

problem using my FPS function

Started by
3 comments, last by da_cobra 22 years, 6 months ago
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
Advertisement
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 :/
This is the system that I use:

  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.
that helped alot thanx!!!
how about this :

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