Mail Archives: djgpp/2000/07/02/15:58:43
Newsgroup: comp.os.msdos.djgpp
From: "23yrold3yrold" <cbarry AT pangea DOT ca>
On Sat, 1 Jul 2000 16:24:07 -0500
>Hello. I've been working on a simple vertical scroller engine with DJGPP and
>Allegro and had a query. One of the main things tutorials have been
>mentioning about creating games is the inclusion of a timer so they will run
>the same speed on any computer. Easy enough to slow down a game to run
>consistently, but I have a question about speeding them up. A quote from
>Allegro's docs:
>
>The standard PC clock only ticks 18.2 times a second, which is not much good
>for fast action games. Allegro can replace the system timer routine with a
>custom one, which reprograms the clock for higher tick rates while still
>calling the BIOS handler at the old speed.
>
>My problem is that when I try to slow the game down, no prob, but it won't
>go faster past a certian point. I know graphics ain't quick, but at the
>speed this little program runs, it will crawl if I try making something even
>half as intense as the first level of any commercial shooter. If anyone can
>find a way of increasing the tick rates of the following program, I would
>greatly appreciate it. Thank you.
If by `increasing tick rates' you mean speeding up the system clock,
you can't do it. I noticed in your code that the timer interval time
is 5ms and that you wait until it has counted 10 ticks. You should
call your timer routine as little as possible, because interrupt
handling is slow and high frequencies will gobble up a lot of time
(even if your routine contains only the single int++ statement).
Anyway, it seems to me that your code doesn't do what is suggested by
the Allegro documentation. You want to do something like
volatile int global_game_ticks; // update this in a timer handler
int local_game_ticks;
local_game_ticks = global_game_ticks = 0;
do {
update_gfx();
do {
update_game_state();
local_game_ticks ++;
} while (global_game_ticks>local_game_ticks);
local_game_ticks = global_game_ticks;
handle_user_input();
} while (!done)
>ship = get_rle_sprite(load_bmp("Ship.bmp", pal));
You have a memory leak here: load_bmp (BTW, IMO it is better to use
load_bitmap) creates a BITMAP that isn't destroyed (but you loose the
pointer).
> clear(dbl_buffer);
> draw_rle_sprite(dbl_buffer, ship, sx, sy);
> blit(dbl_buffer, screen, 0, 0, 0, 0, 640, 480);
and this is the real botleneck. Like Christian Werle already pointed
out, you may want to use Dirty Rectangles instead of doublebuffering.
Pageflipping could also be an alternative. If at all possible, I would
recommend supporting several screen update methods in your program so
you can easily experiment with them later on. Examining the Allegro
demo should give you a clue how to set these things up.
Apart from these things, there are several other tweaks that might
help. Depending on your hardware, it may be faster to store some of
your bitmaps as video bitmaps or system bitmaps instead of memory
bitmaps. See the Allegro docs on bitmaps.
hope that helps,
Evert Glebbeek
- Raw text -