Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Gf11speed

Frames Per Second (FPS)

This topic is 6475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Now that I think about it, I have no idea how to display FPS in my game. It seems simple, but I just can''t figure it out. How exactly could I calculate FPS? I''m pretty sure I know how to find the the ''frames'' part, but not sure how to find the ''per second'' part. Does anyone know how to do this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
what you do is this

var1 = GetTimeInMilliSeconds();


//code


var2 = GetTimeInMilliSeconds() - var1;

FPS = 1000 / var2

=)

to get the milliseconds you could use GetTickCount() but, thats not the best method...






Share this post


Link to post
Share on other sites
I use Borland C++ Builder 5, and this is how I''d do it. In the idle loop just have counter like:
framecount++;

Then put a timer onto the form that has an interval of 1000 milliseconds. In the OnTimer event output the framecount, then set it to zero.

Share this post


Link to post
Share on other sites
Where is the GetTimeInMilliSeconds() function located? What .h file should I include? I can''t find it. I used GetTickCount() but that can''t possibly be returning correct results. I not doing anything and its fluctuating between 50 and 100 FPS.

Share this post


Link to post
Share on other sites
Here''s my fps calculator:

thisTick = GetTickCount();
incTick = thisTick - lastTick;
lastTick = thisTick;
if(incTick <= 0)
incTick = 1; //don''t div by zero
fps = (fps + (1000 / incTick)) / 2;


It''s about the same as Sprochet''s though, and does fluctuate, but it averages the 2 most recent rame rates, so it should be a little more accurate.



-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)

Share this post


Link to post
Share on other sites
Ok I think I got it right. I''m getting anywhere from 50-80 FPS in the game. That seems very smooth, I wonder if its right?

Share this post


Link to post
Share on other sites
quote:
Original post by Gf11speed

Ok I think I got it right. I''m getting anywhere from 50-80 FPS in the game. That seems very smooth, I wonder if its right?


What you could do to find out if it''s right is increment some variable every frame and output it onto the screen. Then just use a watch to see if the FPS you were getting is close. Not perfect, but it may at least tell you if the code you''re using to approximate the FPS was close. If it is close it''s probably right.



Need help? Well, go FAQ yourself.
What a plight we who try to make a story-based game have...writers of conventional media have words, we have but binary numbers

Share this post


Link to post
Share on other sites
I think I'm gonna make a macro for this. Maybe I should do a sweet snippets for it...

Single Pole Digitally Filtered FrameRate.
No crappy twiddle, sub fps accuracy.
Downside is that is lags, but that's almost good in this instance.
Takes 17us to calculate on a K6-3 450MHz. (3D rendering times are around around 20,000us)
    
float CGameEngine::CalcFrameRate(LARGE_INTEGER liNow_us, float* pfElapsed_sec)
{
//Original framerate calculation had really crappy twiddle

//framerate = 1000.0f / (float)elapsed;


const float e = 2.718281828f;

//0.5Hz filter, time in ms, so /1000.0

static float filter = (float)pow(e, -2.0f * 0.5f / 1000.0f);

static LARGE_INTEGER liTimeSnap_us;

//guess at initial framerate, so it doesn't lag so bad on init

static float fFrameRate_fps = 33.3f;

float fElapsed_ms = (liNow_us.QuadPart - liTimeSnap_us.QuadPart) /1000.0f; //convert us to ms

liTimeSnap_us = liNow_us;

float factor = (float)pow(filter, fElapsed_ms);
float ifactor = 1.0f - factor;

if(fElapsed_ms<=0.0f)
//if the elasped time is 0, it took less than 5us to render the frame!

fFrameRate_fps = 200000.0f;
else
//filter, *1000.0f to convert ms to sec (again)

fFrameRate_fps = fFrameRate_fps * factor + ifactor * 1000.0f / fElapsed_ms;

if(pfElapsed_sec)
*pfElapsed_sec = fElapsed_ms / 1000.0f;

return(fFrameRate_fps);
}



Magmai Kai Holmlor
- The disgruntled & disillusioned

Fixed a bug


Edited by - Magmai Kai Holmlor on March 18, 2001 10:21:57 PM

Share this post


Link to post
Share on other sites
I simply do

FPS=0;
LastTimeCheck=0;
FrameCount=0;

main ()
{
do everything

TextOut(0,0,FPS);

if(GetTickCount()-LastTimeCheck>1000)
{
FPS=FrameCount;
LastTimeCheck=GetTickCount();
FrameCount=0;
}
else
FrameCount++;

}


Simple and it works.

Ben
http://therabbithole.redback.inficad.com

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!