Mail Archives: djgpp/1997/04/27/17:59:15
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 -