how to compute fps?
Ok. Here is a short guide:
1) Store the current time as LastTime.
2) Count each frame you render as Count.
3) If Count reaches some predefined number NumFrames update the FPS:
(a) Set ElapsedTime is current time minus LastTime
(b) FPS is now NumFrames / ElapsedTime.
(c) Set LastTime to current time.
The number NumFrames determines your resolution -- the more frames the better the accuracy but the less up-to-date on average.
Greetz,
Illco
1) Store the current time as LastTime.
2) Count each frame you render as Count.
3) If Count reaches some predefined number NumFrames update the FPS:
(a) Set ElapsedTime is current time minus LastTime
(b) FPS is now NumFrames / ElapsedTime.
(c) Set LastTime to current time.
The number NumFrames determines your resolution -- the more frames the better the accuracy but the less up-to-date on average.
Greetz,
Illco
// C++DWORD EndTime = GetTickCount() + 1000;int frames = 0;// Game Loopwhile(true){ if(GetTickCount() > EndTime) { // Display your FPS, perhaps in the title bar of your application? // That seems to be easiest. EndTime = GetTickCount() + 1000; frames = 0; } YourNormalGameLoop(); frames++;}
// C#int lastSecond = DateTime.Now.Second;int frames = 0;// Game Loopwhile(app.Created){ if(DateTime.Now.Second != lastSecond) { app.Text = String.Format("{0} fps", frames); lastSecond = DateTime.Now.Second; frames = 0; } YourNormalGameLoop(); fames++;}
Neither solution is overly accurate but it'll ballpark it.
Yet another one! I think timeGetTime() requires winmm.lib to be linked, unless you're linking it already.
Call it once per loop, and use the value it returns to display the frame count.
DWORD FPS(){ static DWORD fpstimer=0; static uint fps=0; static uint frames=0; frames++; if(timeGetTime()-fpstimer>1000) { fpstimer=timeGetTime(); fps=frames; frames=0; } return fps;}
Call it once per loop, and use the value it returns to display the frame count.
Hi there Baf,
Thanks for that Grozzler, fantastic reply :)
Here is my 2 cents :)
[Calculating the FPS using C#]
I hope this helps a bit.
Keep cool.
Once again, Thank you Grozzler for the reply.
[Edited by - Armadon on August 11, 2005 12:16:33 PM]
Thanks for that Grozzler, fantastic reply :)
Here is my 2 cents :)
[Calculating the FPS using C#]
[source lang = c#]public void CalcFPS(){ frameCount++; if(Environment.TickCount - counter >= 1000) { fps = frameCount; counter = Environment.TickCount; frameCount = 0; }}private static float counter = 0;private static float frameCount = 0;private static float fps = 0;
I hope this helps a bit.
Keep cool.
Once again, Thank you Grozzler for the reply.
[Edited by - Armadon on August 11, 2005 12:16:33 PM]
Hey, that code looks awfully familiar. Can't place where you must've gotten it, though. Though I'm not sure it'll compile. Don't know what C# would think of a "private public" function.
thank you all
my fps is about 40 is it too slow? game is not finished. if i bypass gameloop i have 8000!!!
my fps is about 40 is it too slow? game is not finished. if i bypass gameloop i have 8000!!!
Quote:Original post by Baf
thank you all
my fps is about 40 is it too slow? game is not finished. if i bypass gameloop i have 8000!!!
Well, it depends. What kind of system is it? What kind of application? If you think it's too slow, take a preliminary look at it right now, to check for any major design flaws. However, save the optimizations for the end.
NOooooooo biggest problem!!!
i only added the code for fps view and computing but
if i move my created window i get a sistem crash
this is the code
DWORD EndTime = GetTickCount() + 1000;
int frames = 0;
char s[50];
RECT *rectTxt=new RECT();
rectTxt->......
//********************************
while (....) //MAIN MESSAGE LOOP
{
if(GetTickCount() > EndTime)
{
sprintf( s, " FPS= %d\n", frames );
EndTime = GetTickCount() + 1000;
frames = 0;
}
frames++;
DrawText ( GetDC(wndHandle), s, -1, rectTxt, DT_NOCLIP);
GameLoop();
}
whaz heppened? my mind is crashing
i only added the code for fps view and computing but
if i move my created window i get a sistem crash
this is the code
DWORD EndTime = GetTickCount() + 1000;
int frames = 0;
char s[50];
RECT *rectTxt=new RECT();
rectTxt->......
//********************************
while (....) //MAIN MESSAGE LOOP
{
if(GetTickCount() > EndTime)
{
sprintf( s, " FPS= %d\n", frames );
EndTime = GetTickCount() + 1000;
frames = 0;
}
frames++;
DrawText ( GetDC(wndHandle), s, -1, rectTxt, DT_NOCLIP);
GameLoop();
}
whaz heppened? my mind is crashing
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement