delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/02/15:58:43

From: eglebbk AT phys DOT uva DOT nl (Evert Glebbeek)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Using timers to speed up a program
Date: Sun, 02 Jul 2000 18:35:30 GMT
Organization: Physics student, University of Amsterdam
Lines: 69
Distribution: world
Message-ID: <395f84cd.4168309@news.wins.uva.nl>
References: <395e61e0_2 AT spamkiller DOT newsfeeds DOT com>
NNTP-Posting-Host: stol-117-251.uva.studentennet.nl
X-Trace: info.wins.uva.nl 962562870 26572 145.98.117.251 (2 Jul 2000 18:34:30 GMT)
X-Complaints-To: usenet AT science DOT uva DOT nl
NNTP-Posting-Date: Sun, 2 Jul 2000 18:34:30 +0000 (UTC)
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


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