Mail Archives: djgpp/1998/06/23/18:02:20
On 23 Jun 1998 18:06:22 GMT, xsyphinex AT aol DOT com (XSyphineX) wrote:
>ok ok... Im new at this but how do I control the speed of my computer so that
>sprites dont go 2000 times per second? I have Allegro, I know thats a big help?
>Any suggestions on how they work?
The easiest way would probably be to use the timers in Allegro.
You can read more about timers in the Allegro.txt file or in the guide
called Allegro Vivace (http://www.canvaslink.com/gfoot/vivace/)
If you are in a hurry you can use this to limit the speed of a loop.
It's pretty crude but you can start with it.
#include <allegro.h>
//====================================
volatile unsigned long ticks;
const int delay = 10; //millisecs
void timer_ticker(...) {
ticks++;
}
END_OF_FUNCTION(timer_ticker);
void loop() {
LOCK_VARIABLE(ticks);
LOCK_FUNCTION(timer_ticker);
ticks = 0;
install_int(timer_ticker,delay);
do {
do {/* nothing */} while (ticks == 0);
ticks--;
// do your stuff here
} while (/*something*/);
remove_int(timer_ticker);
}
//====================================
You can try that out. Im too lazy to explain in detail :) I hope it
helps you.
Nicklas Lindgren <nil AT hem1 DOT passagen DOT se>
- Raw text -