Mail Archives: djgpp/1997/08/09/20:21:16
I know an interesting way to implement a framerate monitor
(interesting mainly because it never occurred to me, although it's a
really neat way to do it) I discovered in the source code of the
Allegro demo program. Shawn uses a timer interrupt to increment a
variable every twentieth of a second or something (this should be the
number of times the gameworld is re-evaluated). In the main code
loop, the variable is used to determine whether the world needs to be
updated.
Pseudo-code follows:
GameCounter is the variable the interrupt increments
while not done
{
while (GameCounter)
{
Update Game World
GameCounter - -
}
Draw the Frame
}
In this manner, if the timer hasn't updated the GameCounter
since the last frame, the program merely draws the frame again. If
more than one interrupt has occured since the last update, the Game
World is updated that many times and a frame is "dropped." You can
keep track of dropped frames to tell you how to optimize the code or
whether you need a faster computer. You may also wonder why I draw
the frame every loop. Not only to compensate for lost frames, but you
can also add code in here that updates certain aspects of the world
faster than the regular update occurs. For instance, in a game I'm
working on, the game world is checked about every 50000 clock cycles,
and when objects are falling, they are advanced and drawn at every
possible frame, so that the illusion of motion is much more
convincing.
Hope that this helps.
--
Aragorn AT Harborcom DOT net
Targoth Dragon -=UDIC=-
Ginsberg's Restatement of the Three Laws of Thermodynamics:
You can't win.
You can't break even.
You can't quit.
Check my homepage out, http://harborcom.net/~aragorn
--
- Raw text -