www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/03/12:28:26

From: Sean Proctor <sproctor AT ccs DOT neu DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Using timers to speed up a program
Message-ID: <1tdvlsor6lf5pts9ft4l0ca37kvrjrq704@4ax.com>
References: <395e61e0_2 AT spamkiller DOT newsfeeds DOT com>
X-Newsreader: Forte Agent 1.7/32.534
MIME-Version: 1.0
Lines: 128
Date: Sun, 02 Jul 2000 21:57:23 GMT
NNTP-Posting-Host: 207.16.154.218
X-Complaints-To: Abuse Role <abuse AT enter DOT net>, We Care <abuse AT newsread DOT com>
X-Trace: newshog.newsread.com 962575043 207.16.154.218 (Sun, 02 Jul 2000 17:57:23 EDT)
NNTP-Posting-Date: Sun, 02 Jul 2000 17:57:23 EDT
Organization: ENTER.net (enter.net)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Sat, 1 Jul 2000 16:24:07 -0500, "23yrold3yrold" <cbarry AT pangea DOT ca>
wrote:

<snip>

okay, I see a few problems here... first you're redrawing the entire
screen everytime (stated before I know)... that's a little sluggish...
second... you're setting your flags after you redraw... so if I
understand how this works right, you won't be getting input during
that time.
next... the input seems rather inefficient to me... this makes my
above point rather pointless... but I don't think someone's going to
be hitting more than one key in the interval of updating the screen...
at least they shouldn't be able to... so it might be better to use
allegro's other method of testing input get_key or whatever it is.
(been a while since I used allegro, I don't remember the name).

and irrelevently... 
>  if(key_left ==1)
>    {dir = 4; if(sx > 0)   {sx = sx - 5;} else {sx = 0;};};

is clearer as
	if(key_left) {
		dir = 4;
		if(sx > 0)
			sx -= 5;
		else
			sx = 0;
	}

or if you want it to be in that more compact form...
	if(key_left) {dir = 4; sx > 0 ? sx -= 5 : sx = 0;}

hope that's of some help.

Sean

oh, btw.  you're going to want to make the that sx > 5 instead of sx >
0 in the line I changed... and likewise for the others... or else
you're going to have it going off the screen for one iterating
anyway...
>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 <stdlib.h>
>#include <stdio.h>
>#include <allegro.h>
>
>
>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;
>}
>
>

- Raw text -


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