Jump to content
  • Advertisement

This topic is 4492 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

How do you measure Frames Per Second. Up till now I have just stamped the time after present and by the time between each present I measured the FPS. Of course this will give me an FPS no better then the screen's refresh rate (the render is set to ONE, so the present is not faster then one refresh of the screen). However, this does not tell me how fast are all the calculation without the present "lag". So how do you measure the FPS in your game? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Hello. I use this class:

#ifndef FRAMERATE_H
#define FRAMERATE_H

#include "globals.h"

class cFramerate
{
public:
cFramerate();
~cFramerate();

void process();
float dtime() { return m_deltatime; }
float fps() { return m_fps; }
private:
float m_deltatime;
float m_start;
float m_end;

float m_fps;
float m_fpscounter;
float m_last;
float m_current;
};

#endif



#include "globals.h"

cFramerate::cFramerate()
{
m_start==0;
m_end=SDL_GetTicks();
m_deltatime=0;
m_fps=0;
m_fpscounter=0;
}

cFramerate::~cFramerate()
{

}

void cFramerate::process()
{
m_end=SDL_GetTicks();
m_deltatime=m_end-m_start;
m_deltatime=m_deltatime/1000;
m_start=m_end;

m_current=SDL_GetTicks() * 0.001f;
++m_fpscounter;
if(m_current-m_last > 1.0f)
{
m_last=m_current;
m_fps=m_fpscounter;
m_fpscounter=0;
}
}



Then I use cFramerate::process() in my main game loop.
Then I get the fps using cFramerate::fps().

Hope it helps.

Share this post


Link to post
Share on other sites
void FPS()					// This function calculates FPS
{
static float fps = 0.0f;
static float previousTime = 0.0f;
static char strFPS[20] = {0};

float currentTime = (GetTickCount() * 0.001f);

++fps; // Increment the FPS counter

if( currentTime - previousTime > 1.0f )
{
previousTime = currentTime;
sprintf(strFPS, "FPS: %d", int(fps));
SetWindowText(hWnd, strFPS);
fps = 0.0f;
}
}


Then just call the function wherever you want and there you have it.

Share this post


Link to post
Share on other sites
this code will give you precise framerate and animation movement thats machine independent even at very high frame rates...I am told the QueryPerformance functions dont return a value on older machines, but in that case you replace them with timeGetTime or GetTickCount and then lock the frame rate to 60, or enable vsync. I use this because I want to enable the game to run 500+ FPS and still have perfect movement speeds even at 30 FPS.



LARGE_INTEGER timer_freq;
LARGE_INTEGER timer_start;
LARGE_INTEGER timer_end;

QueryPerformanceFrequency( &timer_freq);

game_loop
{
QueryPerformanceCounter( &timer_start);

// game code

QueryPerformanceCounter( &timer_end);
float delta = (float)timer_start.QuadPart - timer_end.QuadPart;
float fps = (float)-timer_freq.QuadPart / delta;
frame_time = (float) -delta / timer_freq.QuadPart;
}




fps is the current frames per second and frame_time is the modifer you want to use for game movment....

I use the frame_time variable to vary my game character's speeds...something like this

character_velx = MAX_SPEED * frame_time;

Share this post


Link to post
Share on other sites

class FPS: Renderable{
int Frames=0;
timer LocalTimer=new timer(1s);
public event Change(int newFPS);
public override void Render(){
Frames++;
if( LocalTimer.Triggered ){
LocalTimer.Reset();
Change(Frames);
Frames=0;
}
}
}



In Psuedocode; Good enough for my use.

Share this post


Link to post
Share on other sites
Ok I want to reopen this subject.
First I know how to do an FPS timer.
What I did until now is stamp the time once in the game loop like you showed.
However, this ment that the time is confined to the monitor's refresh rate.
I want to do an fps measurement like it is done in the direct3D samples.
There you can see FPS of 1500 for instance.
I looked into one of the samples code, but didnt find where they calculate and draw the fps timer.
So basically, I want the fps of the graphic card HAL rendering time, is that possible?

Share this post


Link to post
Share on other sites
Its limited to your monitor because you have vsync on, its a simple matter of switching it off. It'll be somewhere in your display settings/graphics card settings.

I'm assuming your using OpenGL on a Nvidia graphics card...

Share this post


Link to post
Share on other sites
Quote:
Original post by Bounds
Its limited to your monitor because you have vsync on, its a simple matter of switching it off. It'll be somewhere in your display settings/graphics card settings.

I'm assuming your using OpenGL on a Nvidia graphics card...

I think I can set VSYNC with directX, I will try that.
Actually I am using Direct3D on an ATI card :)

Share this post


Link to post
Share on other sites
The drivers can always override it, just as you know.
Therefore if it doesn't work then your drivers' probably doing just that.

Share this post


Link to post
Share on other sites
I got about 200 fps on my game without vsync.
Its a 2D game, thats not really fast isnt it?
Also I checked the fps while taking the time without the present, so it was also the cpu calculations FPS and it was 200 FPS as well.
Is that not really fast? but I don't do any big calculations.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!