delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/27/17:59:15

From: Jose Manuel Lopez-Cepero <sigma AT ctv DOT es>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Actual timing on different computers.
Date: Sun, 27 Apr 1997 20:24:38 +0200
Organization: Unisource Espana NEWS SERVER
Lines: 65
Message-ID: <336399E6.6922@ctv.es>
References: <335DF9AF DOT 1A59 AT geocities DOT com>
Reply-To: sigma AT ctv DOT es
NNTP-Posting-Host: macarena.ctv.es
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi Henri!

Henri Ossi wrote:
 
> How can I check the machines speed with Allegro?
> If I make the game with my P133 and someone plays it
> with a 486 DX2, it runs in different speed.

> It would be great to have a variable like this:
 
> if(one_second_elapsed == TRUE){

You can do that very easily with Allegro´s timer function. Just do
something like:

int one_second_elapsed;

void inthandle() { one_second_elapsed++; }
END_OF_FUNCTION(inthandle);

int main() {
...
LOCK_VARIABLE(one_second_elapsed);
LOCK_FUNCTION(inthandle);

allegro_init();
install_timer();
install_int(inthandle,1000); // 1000 ms = 1s

// From now on one_second_elapsed gets incremented every second
...

}

To time a second from an exact point:

one_second_elapsed=0;
while (!one_second_elapsed); // Hang out, because the above line won't
                             // (99% sure) be executed on an exact
                             // second, I mean, think about what goes
                             // on if you set it to 0 when an interrupt
                             // has happened .3 sec ago... this line 
                             // will hang .7 sec to keep sychronization.

// Now an 1 sec interrupt has just happened

one_second_elapsed=0;
while (!one_second_elapsed){
 // Whatever
}

If you desperately need to time a second without using the above time
lag you should think about setting a timer int every, say, 10 ms and
check when it gets to 100 after zeroing it... you would then have an .01
sec accuracy.

> I just cant use the timing functions properly, silly me.

:-)

Hope it does help
-- 
 _*                        
\ |/_|\/||\                                 sigma AT ctv DOT es      
_\|\/|  ||_\  (formerly Sigmatech)      Jerez / Cadiz / Spain

- Raw text -


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