FPS

Started by
11 comments, last by The C modest god 18 years, 1 month ago
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.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
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.
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.
Hello?
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;
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.
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?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
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...
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 :)

It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
The drivers can always override it, just as you know.
Therefore if it doesn't work then your drivers' probably doing just that.
Killers don't end up in jailThey end up on a high-score!
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.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.

This topic is closed to new replies.

Advertisement