Timing problems

Started by
1 comment, last by julienX 21 years, 1 month ago
Ok I can write simple Win32 games with directdraw (pong,breakout etc) but I didn''t use timing methods. All I did was use Sleep() to slow down the game. How would I go about setting a frame rate for my games? And how would I check the actual frame rate? Are their any specific functions and/or methods that YOU use for your games? Oh and I''ve looked around for some tutorials on this matter, but failed in finding anything relavant. Thanks for your time
chacha
Advertisement
there''s functions within C++ to allow for getting the current system time (stfw). If you get that each frame, then it''s obvious to get the current fps, and as far as capping the frame rate: simply put it into a while loop until enough time has passed (i.e. enough to keep the framerate acceptable), then process the rest of your frame.
GSACP: GameDev Society Against Crap PostingTo join: Put these lines in your signature and don't post crap!
Another good attempt would be to split your main loop up into two parts:
* logical part (do all the calculation / movement etc.)
* graphical part (draw results to the screen)

With this you''re able to manage two different situations:
1.) framerate is too high: the game''s to fast to follow
2.) framerate is too low: nothing''s going on

You can achieve this by defining a logical "multiplier" that counts how many steps in the logical loop to perform before doing all the drawing stuff. This multiplier set into relation with execution speed / current frames per second is the key to machine-independent code that seems to run equally fast on different systems. Get the main idea? Hope i could help you a little bit out ...

Indeterminatus

--si tacuisses, philosophus mansisses--
Indeterminatus--si tacuisses, philosophus mansisses--

This topic is closed to new replies.

Advertisement