Ok, Im trying to get my game to load its levels from a file and so far its working without a problem cept im experiencing slowdowns from my loading code.
here is what I have for the actual file loading.
[SOURCE]
void io_file_load(const std::string & filename)
{
int temp_int;
char temp_char[30];
SDL_Surface *temp_sur = NULL;
SDL_Surface *temp_backsur = NULL;
std::string temp_text;
std::ifstream infile(filename.c_str());
if (infile)
{
infile >>temp_text;
infile >> temp_char;
if (temp_text != gmp_backgroundimage)
{
temp_backsur = gfx_load_image(temp_char,0);
//if (Background.graphic != NULL) {gmp_fadeoutandin(Background.graphic,temp_backsur);};
Background.setGraphic(temp_backsur);
gmp_backgroundimage = temp_text;
}
infile >> NumberofUsedBlocks;
for(int i = 1;i<=NumberofUsedBlocks;i++)
{
infile >> temp_char;
temp_sur = gfx_load_image(temp_char,0);
VerticalBlue.setGraphic(temp_sur);
infile >> temp_int;
VerticalBlue.setX(118+(40*temp_int));
infile >> temp_int;
VerticalBlue.setY(13+(40*temp_int));
infile >> VerticalBlue.selected;
infile >> VerticalBlue.direction;
}
}
}
[/SOURCE]
[/source]
like i said, it works without a problem, cept there are slowdowns. Its extremely noticable if I use the gmp_fadeoutandin function. Im thinking it has to deal with how im loading my images from the file, but im not sure. any help would be great.
here is the gmp_fadeoutandin code
[SOURCE]
void gmp_fadeoutandin(SDL_Surface *fadeouttemp1, SDL_Surface *fadeouttemp2)
{
for(int i = 255, b = 0;i>0;i = i-2,b = b+2)
{
SDL_SetAlpha(fadeouttemp1, SDL_SRCALPHA, i);
gfx_apply_surface(0,0,fadeouttemp1,gfx_screen);
SDL_SetAlpha(fadeouttemp2, SDL_SRCALPHA, b);
gfx_apply_surface(0,0,fadeouttemp2,gfx_screen);
gfx_flipscreen();
}
}
[/SOURCE]
[/source]
and again the code works and doesnt slow down here, but after the game slows down to a crawl.
any help would be great.
thanks
ok I think i know that the problem is. I believe i may have a memory leak thats caysing my game to run so slow. But it seems like everytime I call SDL_FreeSurface, the game crashes.
any advice?
[Edited by - psiko_scweek on October 8, 2006 11:42:50 AM]