Skip to main content
GameDev.net gamedev.net
🔒 Locked

Time and Frame control

Started by nullmind Jan 3, 2004 at 1:54 PM 1 replies 400+ views
Original Post
nullmind
nullmind
Hi, Controlling the amount of frames updated per second is very important in my games. I have had a system that works like this: The framecount is stored in an integer, and increased every frame. I calculate how many frames *should* be done, so the amount of frames to update is TotalFrames - FrameCount. Problem is this always is 1 or more. So if a user is running 80hz and my FPS is locked at 60, it looks ugly! I want to put a floating based system in, or something similar. But I have fears I won''t be able to re-create some of my math related code. Things like this: speed = speed * .96; any thoughts or theory would be awesome, thanks in advance ya''ll!
Dreamforger
Dreamforger
I''m not entirely sure if I understood your problem but I''ll give it a shot:

Your entire game(math) relies on updates being of a fixed length. A fixed integration stepsize. Nothing wrong with the idea, especially since it results in simple and fast math.

My problem is that I don''t get your problem (seems it''s not just my problem with your problem, or others would have answered to this problem already) - ''Nuff problems for now

You don''t draw each frame updated every time, do you? Sometimes there are more updates between frames, sometimes less. And this results in jumpy movement.

How about the following:
Don''t make the number of frame updates flexible. Find an Integer so the refreshrate of the monitor is the multiplication of your sustainable Framerate and that Integer. Your Framerate will probably not be as high as before but the animation will be more constant.

But then you do not have a constant integration stepsize, which seems to be the whole point
I may be getting older, but I refuse to grow up
nullmind
nullmind
I will most likely look very newb-ish after this post

Ok, basically I do something like this while coding it:

At the start, I create a variable that holds the starting time:
int StartTime = (tickcount);

Then each time I update, I do this:
int TimeDur = (tickcount) - StartTime;
int Frames = TimeDur / (1000.0 / maxfps);

StartTime = (tickcount)

I''ve took out the casting (so that variables round off correctly). Rendering is done every frame with vSyncing.

Cheers.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.