<SOLVED>Allegro lags horribly....
Moderator: Coders of Rage
- mv2112
- 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....
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.
- short
- 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
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
link: https://github.com/bjadamson
- mv2112
- 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
It happens EVERY time set_color_depth is set to 16. Here is some code that lags:short wrote:yeah... but you need to post more details... maybe some code.. something more then what you did
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();
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);
}
- short
- 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
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
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:
change to:
edit: http://www.allegro.cc/manual/api/graphi ... t_gfx_mode
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");
}
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
Code: Select all
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
- mv2112
- 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
Works Perfectly Now!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_depthOutside of that, you need to check the return value of set_gfx_mode which may reveal some insight.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"); }
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:change to:Code: Select all
set_gfx_mode(GFX_AUTODETECT,640,480,0,0); set_color_depth(16); //LAGGGGGGGGGGGGG
edit: http://www.allegro.cc/manual/api/graphi ... t_gfx_modeCode: Select all
set_color_depth(16); set_gfx_mode(GFX_AUTODETECT,640,480,0,0);