www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/31/02:05:25

Sender: nate AT cartsys DOT com
Message-ID: <36B4001D.97592345@cartsys.com>
Date: Sat, 30 Jan 1999 23:02:53 -0800
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.0.36 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Timing
References: <36b31e2e DOT 0 AT nemo DOT idirect DOT com>
Reply-To: djgpp AT delorie DOT com

Dylan Trotter wrote:
> 
> I have been programming for a while, and have a good grip on how to program
> the system timer using an interrupt service routine to create a useful
> timing system, but I fail to grasp how to time things so that they are the
> same speed on all machines, so that the frames per second differ depending
> on the speed of the machine. Please note that I am referring to game
> programming.

Actually, you don't necessarily even need interrupts, just some sort of
fairly high-res timer.  I would make the main loop something like this:

- Read the timer and determine how much time has elapsed since the last
loop
- Update the state of the game (positions, etc) based on this elapse. 
So, if 0.02 seconds have elapsed, and you have an object moving 100
pixels/second, move it 2 pixels.
- Render the frame and draw it to the screen.
- Repeat, as fast as possible.

That way, you only get as many frames per second as you can, while the
game speed stays constant.
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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