Frames Per Second (FPS)

Started by
13 comments, last by Gf11speed 23 years ago
Magmai: We use code similar to the following to calculate FPS. I added your filtered framerate calculation alongside it and get a 5 fps difference. That is, your function returns 25 whereas this function returns 30. The game loop is locked into a fixed time step of 30 fps. This code seems to be returning the correct value (I believe), whereas yours is 5 fps lower. Any ideas as to why the difference?

  static int oldtime, count, time;  count++;  if (count >= 10)  {    time = GetTickCount;    FPS = 10000.0f / max(time - oldtime, 1);    oldtime = time;    count = 0;  } 


Steve ''Sly'' Williams  Code Monkey  Krome Studios
Steve 'Sly' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers
Advertisement
I thinks it's due to the low accuracy of GetTickCount (+/- 10ms, QueryP... is good to +/-5us)... just a guess.

try this:
      	static float FPS;	static int oldtime, count, time;	static LARGE_INTEGER liTime, liOldTime;	count++;	if (count >= 10)		{		QueryPerformanceCounter(&liTime);		FPS = 10000000.0f / max((liTime.QuadPart - liOldTime.QuadPart), 1);		liOldTime.QuadPart = liTime.QuadPart;		count = 0;		}      


the numbers match then - I get a 5fps difference using tickcount as well.

Magmai Kai Holmlor
- The disgruntled & disillusioned

Call CalcFrameRate every frame; you can display the results every frame as well.

Edited by - Magmai Kai Holmlor on March 19, 2001 1:18:38 AM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I tried your code and it was giving the same results (unfiltered) as your filtered routine does. So I guess the accuracy of the timers come into play here. On Win95 and possibly 98, GetTickCount is only accurate to 55ms as stated in MSDN.

Steve ''Sly'' Williams  Code Monkey  Krome Studios
Steve 'Sly' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers
Use timeGetTime() instead, it may not be as accurate as QueryPerformanceCounter(), but msdn states that the resolution in W9x is 1ms, in NT or W2k it''s >= 5ms by default, but can be changed by timeBeginPeriod()/timeEndPeriod(). It is also available on all systems.
I use almost the exact same code as you Sly (except for GetTickCount()) and it works pretty ok.
Are there any systems out there these days that do not support QueryPerformanceCounter? I have also been told of a few systems that return an incorrect value for QueryPerformanceFrequency. Can anyone confirm this? I found the following KB article about it, and it seems to be fairly rare. There is also this KB article about possible leaps forward in responses from QueryPerformanceCounter due to a design defect in certain chipsets.

Steve ''Sly'' Williams  Code Monkey  Krome Studios
Steve 'Sly' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers

This topic is closed to new replies.

Advertisement