From: "23yrold3yrold" Newsgroups: comp.os.msdos.djgpp Subject: Using timers to speed up a program Date: Sat, 1 Jul 2000 16:24:07 -0500 Lines: 99 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 NNTP-Posting-Host: 64.4.88.132 Message-ID: <395e61e0_2@spamkiller.newsfeeds.com> X-Trace: 1 Jul 2000 16:25:52 -0500, 64.4.88.132 X-Comments: This message was posted through Newsfeeds.com X-Comments2: IMPORTANT: Newsfeeds.com does not condone, nor support, spam or any illegal or copyrighted postings. X-Comments3: IMPORTANT: Under NO circumstances will postings containing illegal or copyrighted material through this service be tolerated!! X-Report: Please report illegal or inappropriate use to You may also use our online abuse reporting from: http://www.newsfeeds.com/abuseform.htm X-Abuse-Info: Please be sure to forward a copy of ALL headers, INCLUDING the body (DO NOT SEND ATTACHMENTS) Organization: Newsfeeds.com http://www.newsfeeds.com 73,000+ UNCENSORED Newsgroups. To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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. #include #include #include volatile int game_time; void t_handler(void){ game_time++; }END_OF_FUNCTION(t_handler); short int sx = 0, sy = 0, // for ship's co-ordinates key_left = 0, // * key_right = 0, // * These are for handling key_up = 0, // * ship's controls key_down = 0; // * PALETTE pal; BITMAP *dbl_buffer; RLE_SPRITE *ship; int main() { allegro_init(); install_keyboard(); install_timer(); set_color_depth(16); set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); LOCK_VARIABLE(game_time); LOCK_FUNCTION(t_handler); install_int_ex(t_handler, MSEC_TO_TIMER(5)); ship = get_rle_sprite(load_bmp("Ship.bmp", pal)); dbl_buffer = create_bitmap(640,480); do { game_time = 0; clear(dbl_buffer); draw_rle_sprite(dbl_buffer, ship, sx, sy); blit(dbl_buffer, screen, 0, 0, 0, 0, 640, 480); key_left = 0; key_right = 0; key_up = 0; key_down = 0; do if(key[KEY_LEFT]) {key_left = 1;}; if(key[KEY_RIGHT]){key_right = 1;}; if(key[KEY_UP]) {key_up = 1;}; if(key[KEY_DOWN]) {key_down = 1;}; } while(game_time<10); if(key_left ==1) {dir = 4; if(sx > 0) {sx = sx - 5;} else {sx = 0;};}; if(key_right==1) {dir = 6; if(sx < 550) {sx = sx + 5;} else {sx = 550;};}; if(key_up ==1) {dir = 8; if(sy > 0) {sy = sy - 5;} else {sy = 0;};}; if(key_down ==1) {dir = 2; if(sy < 365) {sy = sy + 5;} else {sy = 365;};}; } while(!key[KEY_ESC]); set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); destroy_rle_sprite(ship); destroy_bitmap(dbl_buffer); return 0; }