Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 FPS Counter
 New Topic  Reply to Topic
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 3

Lachlan87
Moderator

USA
160 Posts

Posted - Jun 10 2004 :  4:12:29 PM  Show Profile  Reply with Quote
Yes, a very simple concept, but I've seen so many different ways of doing it, I want to double check and make sure the way I am doing it is acceptable. If I run this code everytime I draw everthing to the screen, I should get accurate FPS, right?
  
        numFrames += 1  
        If timeGetTime - FirstTime >= 1000 Then
            FPS = numFrames  
            FirstTime = timeGetTime  
            numFrames = 0  
        End If
  


Really, I feel silly asking this question since I understand the concept just fine. But after I tried implementing someone elses version of a FPS counter, and it didn't work, I'm not sure I trust myself to have got it right this time around.

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 10 2004 :  4:14:25 PM  Show Profile  Reply with Quote
That is one way of doing it (and how I do it). You could use QueryPerformanceCounter for more accuracy, but it really isn't needed. That should work fine.

Go to Top of Page

EACam
Warrior

154 Posts

Posted - Jun 10 2004 :  4:17:55 PM  Show Profile  Reply with Quote
Just to be picky...i like to place the FirstTime = timeGetTime statement LAST because it would supposedly be more accurate that way...but then again, the 2 lines before it would barely take a phemtosecond, so it's no big deal...or even a little deal.
Go to Top of Page

Lachlan87
Moderator

USA
160 Posts

Posted - Jun 10 2004 :  4:26:21 PM  Show Profile  Reply with Quote
Ok, thanks. I have one more question though. Why does useing GetTickCount make my FPS so much lower than using TimeGetTime? TimeGetTime will put me at about 85 FPS, whereas GetTickCount will put me at about 20 FPS.
Go to Top of Page

EACam
Warrior

154 Posts

Posted - Jun 10 2004 :  6:23:37 PM  Show Profile  Reply with Quote
Um...what IS TimeGetTime? I've never heard of it.
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 10 2004 :  6:29:07 PM  Show Profile  Reply with Quote
I've seen it, but I always though it was the same as GetTickCount... Guess not...
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 10 2004 :  6:49:10 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
That's odd, there shouldn't be that much of a difference between the two functions.

Go to Top of Page

masterbooda
Swordmaster

277 Posts

Posted - Jun 10 2004 :  7:06:42 PM  Show Profile  Visit masterbooda's Homepage  Reply with Quote
Just to add my 2cents to this post, Query Perfomance is a lot better to use when you are wanting to manage a frame rate, for example I used the above method and my program starts at 400, but I want it to run to 60fps... It took a long time to go down to 60fps(because the program has to find the best delay)... but with query I can put a delay into the loop that will only allow it to draw 60fps... Of course this is just my opinion... for even better accuracy use timed movement, and then you don't have to worry about fps at all...

DaBooda out...

P.S. If all you are doing is reading the FPS the above method works fine...

DaBooda Team is back: http://dabooda.789mb.com/
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 10 2004 :  7:18:48 PM  Show Profile  Reply with Quote
Yes, QPC (for short) is much better for setting a framerate and doing things like time based modelling, but for only calculating the FPS, getTickCount/timeGetTime should be more than enough...
Go to Top of Page

Sr. Guapo
Swordmaster

USA
272 Posts

Posted - Jun 10 2004 :  9:57:56 PM  Show Profile  Reply with Quote
Also, have you checked your various processes and CPU usage with Task Manager? It is possible that GetTickCount is using a different (and more congested) thread than timeGetTime... If you are still having problems with either of those, just switch to QPC. It is very easy to do, and it never has any problems that I've heard of...
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 11 2004 :  09:25:03 AM  Show Profile  Visit game_maker's Homepage  Reply with Quote
will if you agree that there is no game should run with speed of < 5

then put a condition if fps < 5 then fps = 60 (to manage the first second)

another thing the comparing (>=) may do some further calculation than >

so I always like to use x > (y-1) insteed of x >= y ,,,ie > 999 for integers
Go to Top of Page

EACam
Warrior

154 Posts

Posted - Jun 11 2004 :  10:00:05 AM  Show Profile  Reply with Quote
Really? Does that speed it up? I've never heard of it, but doing > (y - 1) seems that it COULD be faster, i wouldn't know.
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jun 11 2004 :  10:11:56 AM  Show Profile  Reply with Quote
To me it seems slower, because first it needs to do the calculation (y - 1) and then compare the values.

(oh and just for you all to know, I just made my first subscription to pscode , if you want to take a look at it, see here.

Whatever. Who knows...
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 11 2004 :  10:56:15 AM  Show Profile  Visit game_maker's Homepage  Reply with Quote
VBBR : (y - 1) is pre-calculation. I.e. you don't put 1000-1, you just put 999

Still not that sure

There is 2 way to solve (>=)

It may be separate (meaning first compare > then compare = )

I.e. x >= y change to (x > y or x = y)

For this, clearly x > (y-1) faster, where (y-1) is pre-calculated

Or combining method (test >= together): witch I don't know

I don't know what vb is using but doing x > (y-1) seems to got more logic percentage
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Jun 11 2004 :  12:03:59 PM  Show Profile  Reply with Quote
But it will be slower if (y - 1) can't be pre-calculated i.e. a varible-sized array loop.

Whatever. Who knows...
Go to Top of Page

game_maker
Knave

Saudi Arabia
83 Posts

Posted - Jun 11 2004 :  12:42:34 PM  Show Profile  Visit game_maker's Homepage  Reply with Quote
unquestionably
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.16 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.