Mail Archives: djgpp/1997/08/09/20:21:16

From: aragorn AT harborcom DOT net (Aragorn)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Making a virtual framerate system with Allegro
Date: Sat, 09 Aug 1997 21:57:02 GMT
Organization: Harbor Communications
Lines: 47
Message-ID: <>
References: <5s5mpk$53l$1 AT cub DOT flex DOT net>
NNTP-Posting-Host: 7601 AT 206 DOT 158 DOT 4 DOT 5
Mime-Version: 1.0
Cache-Post-Path:!unknown AT pve-pm3-4-220 DOT harborcom DOT net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

	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
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

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,

- Raw text -

  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019