Slowness?

I began coding a RPG one night. After fixing the typos I ran it…it seemed
OK, but when I added some code so I could move around the map I found that it
was SLOW. I put in timing code and it came out to be about 1FPS. What is
wrong? I’m on a Pentium I 233mhz Windows 98 Machine with a Voodoo 5. I’ve
tried both all kinds of options for the video(800x600x24) and none have any
affect. I am Blit-ing directly from the surface where tiles are stored to the
screen. It makes no sense. I can make a simple RPG Engine in QB that can run
faster than this thing. Something has to be wrong. Please help. Source code
to the drawmap function and drawtile function is included below.

void draw_tile(int x, int y, int tile)
{
SDL_Rect srect;
SDL_Rect drect;

if(x < 0)
{
    srect.x = (tile - (((int)(tile / 10)) * 10)) * 40 - x;
    //srect.x = (tile - (((int)(tile / 10)) * 10) * 40;
    srect.w = srect.x + 40 + x;
    drect.x = 0;
}
else
{
    srect.x = (tile - (((int)(tile / 10)) * 10)) * 40;
    srect.w = srect.x + 40;
    drect.x = x;
}

if(y < 0)
{
    srect.y = ((int)(tile / 10)) * 40 - y;
    //srect.y = ((int)(tile / 10)) * 40;
    srect.h = srect.y + 40 + y;
    drect.y = 0;
}
else
{
    srect.y = ((int)(tile / 10)) * 40;
    srect.h = srect.y + 40;
    drect.y = y;
}


SDL_BlitSurface(tiles, &srect, temp, &drect);

}

void draw_map()
{
int x, y, x1, y1, x2, y2, sx, sy, oldtime;

oldtime = time(NULL);
x1 = (int)(camx / 40);
y1 = (int)(camy / 40);
x2 = camx - (x1 * 40);
y2 = camy - (y1 * 40);

sx = -x2;
sy = -y2;

for(y = y1; y < y1 + 16; y++)
{
    for(x = x1; x < x1 + 21; x++)
    {
        draw_tile(sx, sy, ground[x + 1][y + 1]);
        draw_tile(sx, sy, map[x + 1][y + 1]);

        sx += 40;
    }
    sx = -x2;
    sy = sy + 40;
}

SDL_BlitSurface(temp, NULL, screen, NULL);

printf("%i\n", time(NULL) - oldtime);

}

You may have run out of memory on your video card and are blitting from
system memory to video card memory. But for 1 fps it sounds like you are
reading graphic data from your video card. Perhaps you have alpha blending
switched on and one of the surfaces is in system memory and one is in video
card memory.>From: VBillybob87 at aol.com

Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: [SDL] slowness?
Date: Mon, 31 Dec 2001 16:04:27 EST

I began coding a RPG one night. After fixing the typos I ran it…it seemed
OK, but when I added some code so I could move around the map I found that
it
was SLOW. I put in timing code and it came out to be about 1FPS. What is
wrong? I’m on a Pentium I 233mhz Windows 98 Machine with a Voodoo 5. I’ve
tried both all kinds of options for the video(800x600x24) and none have any
affect. I am Blit-ing directly from the surface where tiles are stored to
the
screen. It makes no sense. I can make a simple RPG Engine in QB that can
run
faster than this thing. Something has to be wrong. Please help. Source code
to the drawmap function and drawtile function is included below.

void draw_tile(int x, int y, int tile)
{
SDL_Rect srect;
SDL_Rect drect;

if(x < 0)
{
    srect.x = (tile - (((int)(tile / 10)) * 10)) * 40 - x;
    //srect.x = (tile - (((int)(tile / 10)) * 10) * 40;
    srect.w = srect.x + 40 + x;
    drect.x = 0;
}
else
{
    srect.x = (tile - (((int)(tile / 10)) * 10)) * 40;
    srect.w = srect.x + 40;
    drect.x = x;
}

if(y < 0)
{
    srect.y = ((int)(tile / 10)) * 40 - y;
    //srect.y = ((int)(tile / 10)) * 40;
    srect.h = srect.y + 40 + y;
    drect.y = 0;
}
else
{
    srect.y = ((int)(tile / 10)) * 40;
    srect.h = srect.y + 40;
    drect.y = y;
}


SDL_BlitSurface(tiles, &srect, temp, &drect);

}

void draw_map()
{
int x, y, x1, y1, x2, y2, sx, sy, oldtime;

oldtime = time(NULL);
x1 = (int)(camx / 40);
y1 = (int)(camy / 40);
x2 = camx - (x1 * 40);
y2 = camy - (y1 * 40);

sx = -x2;
sy = -y2;

for(y = y1; y < y1 + 16; y++)
{
    for(x = x1; x < x1 + 21; x++)
    {
        draw_tile(sx, sy, ground[x + 1][y + 1]);
        draw_tile(sx, sy, map[x + 1][y + 1]);

        sx += 40;
    }
    sx = -x2;
    sy = sy + 40;
}

SDL_BlitSurface(temp, NULL, screen, NULL);

printf("%i\n", time(NULL) - oldtime);

}


Send and receive Hotmail on your mobile device: http://mobile.msn.com