Mail Archives: djgpp/1996/09/15/10:02:39
Mark Fleig (markfleig AT worldnet DOT att DOT net) wrote:
: Just getting started with DJGPP/Allegro/etcblahblah. So I know how to
: create timers, and I know how to use them safely... I just don't know what
: to use them for.
: Could someone give me an overview of the best use for timers in a standard
: game program. I imagine it's used to do all of the hard work and draw the
: buffers, but only blit when the timer hits a particular tick. Am I close.
: thanks,
: -fleig
Well, they work particularly well for making your game speed
machine-independant. They aren't really used for the drawing (although
they could be) so much as they are for everything that goes on while you
aren't drawing. For example, suppose you wanted your game to run a 35
tics per second, regardless of machine. Now, also suppose that your game
is pretty expensive rendering-wise. You can make sure that the game runs
at the correct speed by makeing a variable called e.g. NumUpdates that is
set to a timer that tics 35 times per second. This timer function would
basically say NumUpdates++. Then, in your game loop, after your
rendering, you check the value of NumUpdates. You then update the world
that many times and reset NumUpdates.
Of course, there any many other uses of timers, but this is by far the
most important one. If you want to see an actual example of this, the
demo game that comes with allegro has a good example of how this is done.
Hope this helps.
--
-- Rubicant --
- Raw text -