Archived

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

handling FPS

This topic is 5974 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

see, i''m using a timer on my game to draw&flip. but as i see it, its not the optimal method (not that i know of others) due to the different speed of each computer (faster ones need small interval and slower ones needs faster) suggestions? Gil Micro$oft beta testing: "Does the splash screen works? SHIP IT!!!"

Share this post


Link to post
Share on other sites
don''t lock your frame rate. keep track of the starting frame''s time and the ending frame''s time. get the difference between the two and use that for your moving distance like this:
Delta=StartTime-EndTime

object.x=Delta*0.01f;
object.y=Delta*0.01f;

you can change the second parameter to anything you like. It will move the same speed on all machines. Check out my timer class on my page for more reference.



How many Microsoft employees does it take to screw in a light bulb?
None, they just declare drakness as a new standard.

Share this post


Link to post
Share on other sites
I still dont understand...
i know that the fps may vary from time to time
and to do what you proposed, i need to have linar
program, not event driven like windows''s....


gil

Share this post


Link to post
Share on other sites
yes, the distance the objects will move will remain constant. if the frame draws slower, (takes more time), then more will be taken off of that time when it''s multiplied by 0.01. when the frame rendering time is fast, less distance is taken off when multiplied by 0.01. example:
100 ms * 0.01=1 -difference=99
10 ms * 0.01=.1 -different=9.9



How many Microsoft employees does it take to screw in a light bulb?
None, they just declare drakness as a new standard.

Share this post


Link to post
Share on other sites
Or to put it more simply, scale object movements and rotations (including the camera, if we're talking 3d) by the current frame time. Windows applications are event driven but that doesn't mean you should write event driven DirectX programs.

You should be drawing a new frame whether an event has occured or not.

Edited by - simon_brown75 on August 3, 2001 7:26:35 PM

Share this post


Link to post
Share on other sites
let me see if i got you guys straight:

i need to draw by event?
i.e. mouse move

ok, with you so far, np.


BUT
i have this HeartBeat function,
which calculate the next screen
for all objects in tha game (2d btw)


what should call it?
a WM_TIMER command? i cant change its interval,
and if i got you correctly, i should send my
heart beat how much time has passed? (the interval)
but the time passed here is constant! and if i want
the fps to change, i need to change the interval....


gosh, i lost smting here.
someone, help?

Gil

Micro$oft beta testing:
"Does the splash screen works? SHIP IT!!!"

Share this post


Link to post
Share on other sites
i wouldnt of had that problem if i didnt use windows... (

again, how to do that in windows?

Gil

Micro$oft beta testing:
"Does the splash screen works? SHIP IT!!!"

Share this post


Link to post
Share on other sites
No...

You should always redraw you frame...

inorder that the movement is the same on fast and slower machines, use the code Julio mentioned above...

It''s framerate independent... you scale your movement down so that it fits the Framerate..

cya,
Phil


Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

Share this post


Link to post
Share on other sites
Just to make sure this is as clear as possible for you:

You can call your heartbeat function as often as you can (giving you the best frame-rate possible on that machine).

BUT, if you are calling this function as often as you can and you are updating positions of objects in your world in such a method as: ObjectX = ObjectX + SpeedX, then you will have a problem because people on faster machines will execute this function more times per second then people with slower machines, so that means objects in their game will be moving faster. To compenstate for this you must instead store the object''s speed as a velocity (distance/second). This way, in each call to your main game loop you find out how long it has been from the last call to the game loop, and move your sprites accordingly.

For instance, if for some horrible reason your game loop only executed twice per second on my 486, and your movement velocity is 10 pixels/second. your code would look like:

ObjextX = ObjectX + (timeElapsed * VelocityX);

Since timeElapsed is .5 seconds (2 times per second), and velocity is 10, the your loop will move your object 5 pixels. Which is correct. If someone elses computer did the function 10 times a second, then timeElapsed would be .1 second, and the result would be moving the object 1 pixel 10 times a second.

Is this clear?

So you don''t need to use windows timers, or any sort of message loop, just store your movement parameters as velocities, and keep track of time between each game loop call.


Hope this helps,
-Terrax

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
sometimes a fixed framerate is best, especially when you''re new. If you aren''t advanced enough to keep your rending and your gamestate in seperate threads that is the only way for certain types of games to work. In peer to peer games you must have a locked game update loop (though frame rates can be whatever), for multiple reasons the velocity trick just won''t work if you want to stay in synch. I''m new to this timing buisiness too so it would be nice if someone would answer assuming a fixed game update loop. I assumed that the timer was speed independant, so if you have a 30 ms timer it would call the function every 30 ms, not call it 30 ms after the function returned last. There isn''t really any documention on timers in my MSVC++, does anyone know exactly how they work?

Share this post


Link to post
Share on other sites
Thanks to Terrax i got the idea.
maybe because it''s 4:13 AM here and i only
had 2 hrs of sleep last night (day?)

anyway, fully understood.
thanks again

Gil



Micro$oft beta testing:
"Does the splash screen works? SHIP IT!!!"

Share this post


Link to post
Share on other sites
Anonymous Poster:

I think having a fixed time game loop can get a bit sticky. The main reason is lets say you want your loop to execute ever 30ms. You can get the time at the top of your game function, then retrieve the time at the bottom of your function and do the following:

timeElapsed = GetCurrentTime() - startFunctionTime;
if (timeElapsed < 30)
Sleep(30-timeElapsed);

With this method if your game loop gets over in 5 milliseconds, then it will sleep for 25, so your loop will execute ever 30 milliseconds no matter what.

The problem is, what if I''m over here with your program on my POS 386, and I can do the main game function in 40 milliseconds, what now?

Also, you get Joe Shmoe with his 1.5 gHz computer and he can only get 30 fps because your limiting his frame-rate.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
DarkTerrax: I said game loop, not frame rate. Of course when you are still kind of new you have to make them both the same. Or even if you aren''t new, I think Starcraft is fixed at 15 frames per second on normal speed (which no one plays at), and as you up the game speed the frame rate scales up too, to maybe 30 at fastest. So if it is good enough for the best strategy game it is good enough for me. Anyway though even though the framerate should be independant the game thing can''t be if things are to stay in synch in peer to peer games. That is simply a requirement and you will not find a single peer to peer game that uses the velocity method. Age of Empires, etc... all strategy games use peer to peer and so they all have fixed game loops.

Well anyway I''m not using the time elapsed sleep method, though maybe I will switch to it. Right now I am using a windows timer, I register my TimerProc with it and it gets called every so often. Does anyone have details on how it works?

Share this post


Link to post
Share on other sites
You have frames displayed per second and game loop executions per second.

Instead of using while or sleep or seperate threads, just use ifs. It takes two ifs to lock the displayed frames per second while allowing the game loop to be executed as fast the the processor will allow.

Tombstone displays at most 30fps (drops if necessary) but runs through the game loop 264,000 times per second.

Ben

Icarus Independent

Jump Down The Rabbithole

Share this post


Link to post
Share on other sites