www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/02/10:20:32

From: "Christopher Nelson" <paradox AT gye DOT satnet DOT net>
To: <djgpp AT delorie DOT com>
Subject: Re: Simple timer question...
Date: Sun, 2 May 1999 07:45:15 -0600
Message-ID: <01be94a2$026d8fa0$LocalHost@thendren>
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.71.1712.3
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Reply-To: djgpp AT delorie DOT com


>I'm about to start writing a game with DJGPP and Allegro. However, I
>don't have much experience with either, so I was wondering how to get a
>timer in milliseconds, so that each game loop would take 100
>milliseconds -- NOT doing stuff and *then* waiting 100 milliseconds.
>In QBasic (which I normally use), I'd do something like:
>
>  time! = TIMER
>  [do stuff here]
>  WHILE time! + .1 > TIMER: WEND


there is a simple and less simple answer.  the simple answer is to use the
delay() function in Allegro.  it will eat processor cycles for the specified
amount of time.  the other, more efficient way, is to setup a timer callback
with install_int().  then you can be processing stuff while waiting for the
timer.  e.g.

volatile int time_to_draw=0;

void my_handler( ... )
{
    time_to_draw=1;
}

then while you are waiting for time_to_draw to become 1, you can be doing
other stuff ... calculating AI movements, stage loading stuff, all sorts of
other interesting stuff. this way you're not wasting so many precious
cycles.

    -={C}=-

- Raw text -


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