<SOLVED>Allegro lags horribly....

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
mv2112
Chaos Rift Junior
Chaos Rift Junior
Posts: 240
Joined: Sat Feb 20, 2010 4:15 am
Current Project: Java Tower Defence Game
Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
Programming Language of Choice: C/++, Java
Location: /usr/home/mv2112
Contact:

<SOLVED>Allegro lags horribly....

Post by mv2112 »

I have absolutely no idea why it lags. Im trying to make a map editor and the tiles im using are 16 bit bitmaps, the problem is that its hard to lay them when it takes 2 seconds for the tile to catch up with my mouse lol. I cant set the color depth to 8 because the tile's colors become distorted, it needs to be 16. Is there anyway to fix this lag?
Last edited by mv2112 on Sun Mar 14, 2010 8:37 pm, edited 1 time in total.
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: Allegro lags horribly when the color depth is higher than 8

Post by short »

yeah... but you need to post more details... maybe some code.. something more then what you did
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
mv2112
Chaos Rift Junior
Chaos Rift Junior
Posts: 240
Joined: Sat Feb 20, 2010 4:15 am
Current Project: Java Tower Defence Game
Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
Programming Language of Choice: C/++, Java
Location: /usr/home/mv2112
Contact:

Re: Allegro lags horribly when the color depth is higher than 8

Post by mv2112 »

short wrote:yeah... but you need to post more details... maybe some code.. something more then what you did
It happens EVERY time set_color_depth is set to 16. Here is some code that lags:

Code: Select all


#include "dude.h"

int main()
{
	allegro_init();
	install_keyboard();
	set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
	set_color_depth(16); //LAGGGGGGGGGGGGG
	BITMAP* sprite;
	sprite=load_bitmap("sprite.bmp",NULL);
	BITMAP* buffer=create_bitmap(SCREEN_W,SCREEN_H);
	enemy test;
	test.setup(sprite,SCREEN_W/2,SCREEN_H/2,200,200);
	int x=100;
	int y=100;
	int w=0;
	int h=0;
	int xtl=0;
	int ytl=0;
	int xlr=0;
	int ylr=0;
	int v=5;
	blit(sprite,buffer,0,0,x,y,SCREEN_W,SCREEN_H);
	blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
		while(!key[KEY_ESC])
	{
		get_clip_rect(sprite,&xtl,&ytl,&xlr,&ylr);
		w=xlr;
		h=ylr;
		clear(buffer);
		if(key[KEY_UP])
		{
			outcheck(&x,&y,w,h,v);
			y-=v;
		}
		if(key[KEY_DOWN])
		{
			outcheck(&x,&y,w,h,v);
			y+=v;
		}
		if(key[KEY_RIGHT])
		{
			outcheck(&x,&y,w,h,v);
			x+=v;
		}
		if(key[KEY_LEFT])
		{
			outcheck(&x,&y,w,h,v);
			x-=v;
		}
		vsync();
		acquire_screen();
		test.move(buffer);
		blit(sprite,buffer,0,0,x,y,SCREEN_W,SCREEN_H);
		blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
		release_screen();
	}
	destroy_bitmap(sprite);
	destroy_bitmap(buffer);
	return 0;

}
END_OF_MAIN();

here is the dude.h file:

Code: Select all


#define USE_CONSOLE
#include "allegro.h"
#include <iostream>

void outcheck(int* x, int* y,int w,int h,int v)
{
	if(*x+1>=SCREEN_W-w)
	{
		*x-=v;
	}
	if(*x-1<=0)
	{
		*x+=v;
	}
	if(*y+1>=SCREEN_H-h)
	{
		*y-=v;
	}
	if(*y-1<=0)
	{
		*y+=v;
	}
}

class enemy
{
public:
	enemy();
	void setup(BITMAP* sprite,int x,int y,int u,int d);
	void move(BITMAP* buffer);
	void reset();
private:
	int x;
	int y;
	BITMAP* image;
	int up;
	int down;
	int u;
	int d;
};

enemy::enemy()
{
	u=0;
	d=0;
}

void enemy::setup(BITMAP *sprite, int xx, int yy, int u, int d)
{
	image=sprite;
	x=xx;
	y=yy;
	up=u;
	down=d;
}

void enemy::reset()
{
	u=0;
	d=0;
}

void enemy::move(BITMAP* buffer)
{
	if(u<=up)
	{
		y-=1;
		u+=1;
	}
	else if(d<=down)
	{
		y+=1;
		d+=1;
	}
	else
	{
		reset();
	}
	blit(image,buffer,0,0,x,y,SCREEN_W,SCREEN_H);
}

I think it has something to do with blitting images to the screen because i can print shapes on the screen SUPER fast in 16 and even 32 bit modes.
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: Allegro lags horribly when the color depth is higher than 8

Post by short »

Ok first of all I have never used allegro, I learned with SDL. That said, it seems like your performing the setf_gfx_mode and set_color_mode in reverse.

A quick google search revealed this to me:
http://www.allegro.cc/manual/api/graphi ... olor_depth

Code: Select all

 
set_color_depth(32);
      if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
	 abort_on_error("Couldn't set a 32 bit color resolution");
      }
Outside of that, you need to check the return value of set_gfx_mode which may reveal some insight.

Try setting up your code like the example I just posted. Set the color depth to 16, THEN call set_gfx_mode and check the return value. I learned this one the hard way (not checking function return values). Verify that set_gfx_mode isn't returning an error state. Hope this helps :)

like this:

Code: Select all

set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
   set_color_depth(16); //LAGGGGGGGGGGGGG
change to:

Code: Select all

set_color_depth(16); 
set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
edit: http://www.allegro.cc/manual/api/graphi ... t_gfx_mode
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
mv2112
Chaos Rift Junior
Chaos Rift Junior
Posts: 240
Joined: Sat Feb 20, 2010 4:15 am
Current Project: Java Tower Defence Game
Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
Programming Language of Choice: C/++, Java
Location: /usr/home/mv2112
Contact:

Re: Allegro lags horribly when the color depth is higher than 8

Post by mv2112 »

short wrote:Ok first of all I have never used allegro, I learned with SDL. That said, it seems like your performing the setf_gfx_mode and set_color_mode in reverse.

A quick google search revealed this to me:
http://www.allegro.cc/manual/api/graphi ... olor_depth

Code: Select all

 
set_color_depth(32);
      if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0) != 0) {
	 abort_on_error("Couldn't set a 32 bit color resolution");
      }
Outside of that, you need to check the return value of set_gfx_mode which may reveal some insight.

Try setting up your code like the example I just posted. Set the color depth to 16, THEN call set_gfx_mode and check the return value. I learned this one the hard way (not checking function return values). Verify that set_gfx_mode isn't returning an error state. Hope this helps :)

like this:

Code: Select all

set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
   set_color_depth(16); //LAGGGGGGGGGGGGG
change to:

Code: Select all

set_color_depth(16); 
set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
edit: http://www.allegro.cc/manual/api/graphi ... t_gfx_mode
Works Perfectly Now! :worship:
Post Reply