Getting FPS in .net? |
Krisc | Hey I am currently writing my game in .net...although I am using C# I do know VB...anyways, I was wondering how to get the current FPS...? (I have forgotten the algorithm...)
Thanks!
[|)]
p.s. this is like my 20th time trying to finish this game and i finally drew out everything on a big poster-board and set a schedule with weekly checkpoints (roughly) that i have to make. it is keeping me interested so far and i haven't gotten confused. i'm ahead of schedule a little bit but whatever... [|)] |
Eric Coleman | Calculating the frames per second shouldn't be that difficult to figure out.
How do you think it should be calculated? |
Brykovian | I had an physics prof back in my college days that liked to go on a soap-boxy rant every once in a while -- usually intending it as entertainment for his students. One time he went off on a student who was having problems figuring out how to work out the calculation for something. He went off on this long series of things like "I wonder how you figure out meters-per-second ... hmmm ... let's see, I know how many miles the thing went ... and I know how long it took to get there ... but I just can't seem to put it all together."
Sorry ... but Krisc's question gave me the old flash-back ...
So, we have FPS, which stands for frames-per-second ... if only I knew how many frames I was able to generate, over a known amount of time ... hmmmm ... [;)][:D]
Or, in language-neutral terms ...
1> Count frames (FrameCount) for a specified period of time (T)
2> Do the math: FrameCount / T
3> Don't forget to reset your FrameCount to 0 for the next counting cycle
-Bryk |
Eric Coleman | I had a college professor that taught us how to do what he called "Fermi" problems, named after Enrico Fermi. I remember on one test he gave us the population of the state and asked how many dentists there are in the state. It pretty much amounts to dimensional analysis, which is the point of the problems. |
sdw | Even though Eric wants you to figure it out on your own and Bryk told you how to do it in language neautral terms, I'm going to tell you in Esdeedoublian which is my own language:
Three static or global variables:
- FPS 'Holds the number of frames counted since the last second
- LastTime 'Holds the time when we last started the count
- Count 'Holds the number of frames we've gone through since the last second
Next is the function we call each frame
[code]
Sub CountFPS()
If CurrentTime() - LastTime >= 1000 Then 'Has it been 1 second since we last counted?
FPS = Count 'Store the number of frames counted in the last second
Count = 1 'Reset the count. This can be 0 or 1, depending one where in your game loop it's called.
LastTime = CurrentTime() 'Use this to determine when 1000 ms (1 second) has passed (like above)
Else 'It hasn't been 1 second yet, continue counting
Count = Count + 1 'Since this function is called each frame, this is increased by 1 each frame
End If
End Sub
[/code]
Looking back now that actually looks like VB, not Esdeedoublian :\ |
Lachlan87 | You cheater! I wanted to learn some Esdeedoublian! |