Jump to content
  • Advertisement

Archived

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

Gilzu

handling FPS

This topic is 6196 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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!