Archived

This topic is now archived and is closed to further replies.

Estauns

Calculating FPS

Recommended Posts

I''ve got a Timer class, and it updates each frame. I can also add StartFrame and EndFrame times if neccessary. Whats my calculation to see how many frames per second I''m getting? Also, how do I move my game objects? Is it: Object.x = 4.0f * (EndFrameTime - StartFrameTime); Like, I want the character to move 4 pixels a second. Is that it or am I way off? Thanks =)

Share this post


Link to post
Share on other sites
Depending on what units your timer times in (e.g. milliseconds or seconds) things can vary slightly, but basically here''s an outline.

To see how many fps you are getting:

1 / seconds_taken_to_do_a_frame

e.g. if it takes 0.1 second to do a frame this would be:

1 / 0.1

Which is 10, so 10fps.

That calculation to perform character movement looks about right (I usually store a variable called ''deltatime'' to avoid calculating time differences repeatedly).

-Mezz

Share this post


Link to post
Share on other sites
Hrm..

I didn''t think of this before, but, do you calculate movement based on the speed of the previous frame?

ie
Loop:
StartTime
UpdateObjects
RenderScene
EndTime

Would you store the EndTime - StartTime from the previous frame, to do the Update objects? Or do you put the Update OBjects _AFTER_ EndTime and use that value?

Share this post


Link to post
Share on other sites
The way I calculate FPS is simple:

Dim FPS_Val as Long
Dim FPS_Count as Long
Dim Last_Second as Long

Do

Render ''All the rendering stuff

FPS_Count = FPS_Count + 1

If GetTickCount >= Last_Second + 1000 Then
FPS_Val = FPS_Count
FPS_Count = 0
Last_Second = GetTickCount
End If

Loop

FPS_Val contains the FPS value, updated once per second.

Share this post


Link to post
Share on other sites