• Advertisement
Sign in to follow this  

Allegro RAM maxxing...

This topic is 4458 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I put in my code like this (keep in mind that this isnt the final, just a test...)
#include <allegro.h>

void init();
void deinit();

int main() {
	init();

	BITMAP* spaceship;        spaceship = load_bitmap("Spaceship Stationary.bmp",NULL);
    if(!spaceship)
    {
                  allegro_message(allegro_error);
                  exit(-1);
    }
    
    
    BITMAP *source;            source = create_bitmap(200, 200);
    
    blit(spaceship, source, 0, 0, 0, 0, 50, 50);
    
    
    
    while (!key[KEY_ESC]) 
    {
		int    red;               red                 = 1;
        int    orange;            orange              = 1;
        int    yellow;            yellow              = 1;
        int    green;             green               = 1;
        int    blue;              blue                = 1;
        int    purple;            purple              = 1;
        
        int    shipspeedx;        shipspeedx          = 0;
        int    shipspeedy;        shipspeedy          = 0;
        int    shipbitmap;        shipbitmap          = 1;
        int    shipposx;          shipposx            = 200;
        int    shipposy;          shipposy            = 200;
        int    shiphp;            shiphp              = 5;
        
        int    starmove;          starmove            = 2;
        
        int    redammo;           redammo             = 20;
        int    yellowammo;        yellowammo          = 20;
        int    blueammo;          blueammo            = 20;
        int    ammocharge;        ammocharge          = 1;
        
        double score;             score               = 0;
        double time;              time                = 1;
        int    gameover;          gameover            = FALSE;
        
        typedef struct RGB
        {
        unsigned char r, g, b;
        } RGB;
        
        
        
        
        
        
        while(!key[KEY_ESC] && time > 0)
        {
                            
                            
                            //------------------------------------------------------------------------
                            //Slow the ship down
                            //------------------------------------------------------------------------
                            if(shipspeedx > 0)
                            {
                                          shipspeedx = shipspeedx - 1;
                            }
                            
                            if(shipspeedx < 0)
                            {
                                          shipspeedx = shipspeedx + 1;
                            }
                            
                            if(shipspeedy > 0)
                            {
                                          shipspeedy = shipspeedy - 1;
                            }
                            
                            if(shipspeedy < 0)
                            {
                                          shipspeedy = shipspeedy + 1;
                            }
                            //------------------------------------------------------------------------
                            //Move the ship according to the speed
                            //------------------------------------------------------------------------
                            
                            if(shipspeedx != 0)
                            {
                                          shipposx = shipposx + shipspeedx;
                            }
                            
                            if(shipspeedy != 0)
                            {
                                          shipposy = shipposy + shipspeedy;
                            }
                            //------------------------------------------------------------------------
                            //See if the ship is dead, if so, gameover
                            //------------------------------------------------------------------------
                            
                            if(shiphp <= 0)
                            {
                                          textout_centre_ex(screen, font, "GAME OVER!!!", 300, 300,
                                          makecol(255, 255, 255), -1);
                                          destroy_bitmap(spaceship);
                                          rest(10000);
                                          return 0;
                            }
                            
                            //------------------------------------------------------------------------
                            //Process user input
                            //------------------------------------------------------------------------
                            
                            if(key[KEY_RIGHT])
                            {
                                           shipspeedx = shipspeedx + 2;
                            }
                            
                            if(key[KEY_LEFT])
                            {
                                           shipspeedx = shipspeedx - 2;
                            }
                            
                            if(key[KEY_UP])
                            {
                                           shipspeedy = shipspeedy - 2;
                            }
                            
                            if(key[KEY_DOWN])
                            {
                                           shipspeedy = shipspeedy + 2;
                            }
                            //--------------------------------------------------
                            //Cheats (Muwah ha ha...)
                            //--------------------------------------------------
                            if(!key[KEY_ALT] && key[KEY_R] && key[KEY_E] && key[KEY_D])
                            {
                                          red = red + 1;
                                          rest(100);
                            }
                            
                            if(key[KEY_ALT] && key[KEY_R] && key[KEY_E] && key[KEY_D])
                            {
                                          redammo = redammo + 10;
                            }
                            //--------------------------------------------------
                            //Keep the ship moving at a reasonable speed
                            //--------------------------------------------------
                            
                            if(shipspeedx <= -10)
                            {
                                           shipspeedx = -10;
                            }  
                            
                            if(shipspeedy >= 10)
                            {
                                           shipspeedx = 10;
                            }  
                            
                            if(shipspeedy <= -10)
                            {
                                           shipspeedy = -10;
                            }  
                            
                            if(shipspeedy >= 10)
                            {
                                           shipspeedx = 10;
                            }  
                            
                            
                            
                            //------------------------------------------------------------------------
                            //Draw Everything
                            //------------------------------------------------------------------------
                            
                            BITMAP *buffer = create_bitmap(1024, 768);
                            
                            
                            clear_bitmap(buffer);
                            
                            
                            textprintf_ex(buffer, font, 100, 610, makecol(255, 0, 0),
                            -1, "Red Ammo Remaining: %d", redammo);
                            
                            textprintf_ex(buffer, font, 100, 635, makecol(255, 255, 0),
                            -1, "Yellow Ammo Remaining: %d", yellowammo);
                            
                            textprintf_ex(buffer, font, 100, 660, makecol(0, 0, 255),
                            -1, "Blue Ammo Remaining: %d", blueammo);
                            
                            textprintf_ex(buffer, font, 800, 610, makecol(255, 255, 255),
                            -1, "Life Remaining: %d", shiphp);
                            
                            textprintf_ex(buffer, font, 400, 610, makecol(255, 0, 0),
                            -1, "Red Level: %d", red);
                            
                            textprintf_ex(buffer, font, 400, 635, makecol(255, 255, 0),
                            -1, "Yellow Level: %d", yellow);
                            
                            textprintf_ex(buffer, font, 400, 660, makecol(0, 0, 255),
                            -1, "Blue Level: %d", blue);
                            
                            textprintf_ex(buffer, font, 600, 610, makecol(255, 192, 0),
                            -1, "Orange Level: %d", orange);
                            
                            textprintf_ex(buffer, font, 600, 635, makecol(0, 255, 0),
                            -1, "Green Level: %d", green);
                            
                            textprintf_ex(buffer, font, 600, 660, makecol(255, 0, 255),
                            -1, "Purple Level: %d", purple);
                            
                            masked_blit(source, buffer, 0, 0, shipposx, shipposy, 50, 50);
                            
                            blit(buffer, screen, 0, 0, 0, 0, 1024, 768);
                            
                            
                            
                            
                            
                            rest(10);
                            
                            
                            
                            
                            
                            time = time;
                            
        }
                            
                            
                  
        
        
        /* put your code here */
	}
	destroy_bitmap(source);
	destroy_bitmap(screen);
	destroy_bitmap(spaceship);

	deinit();
	return 0;
}
END_OF_MAIN();

void init() {
	int depth, res;
	allegro_init();
	depth = desktop_color_depth();
	if (depth == 0) depth = 32;
	set_color_depth(depth);
	res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0);
	if (res != 0) {
		allegro_message(allegro_error);
		exit(-1);
	}

	install_timer();
	install_keyboard();
	install_mouse();
	/* add other initializations here */
}

void deinit() {
	clear_keybuf();
	
	/* add other deinitializations here */
}

and when I run it, it starts out good, but after about a minute, my RAM is maxxed... I know that it's one of three problems. 1. I'm not clearing the screen. 2. I have hanging pointers. 3. Allegro sucks. I would clear the screen, but if I do, I destroy my double-buffer... I'm kind of a noob, so I dont know how to safely remove pointers without destroying the bitmap it points to... I probably missed something else, so any help is appreciated. (editted for source tags) [Edited by - 23yrold3yrold on November 10, 2005 11:32:42 AM]

Share this post


Link to post
Share on other sites
Advertisement
1. Whenever posting source on the GD forums, use the [source] and [/source] tags. Makes it much easier for the rest of us to understand.

2. Move the "BITMAP *buffer = create_bitmap(1024, 768);" line out of the main loop. Add a call to destroy it along with the rest of your bitmaps. As it is, you're creating a new buffer bitmap each time through the loop and never deleting it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement