More efficient floodfill function for gravity walls, no need for larger stacks with 64bit builds

This commit is contained in:
Simon Robertshaw 2012-08-24 18:22:02 +01:00
parent beb0e80849
commit 822539bcdb

View File

@ -418,16 +418,33 @@ void Gravity::grav_mask_r(int x, int y, char checkmap[YRES/CELL][XRES/CELL], cha
return; return;
if(x == 0 || y ==0 || y == (YRES/CELL)-1 || x == (XRES/CELL)-1) if(x == 0 || y ==0 || y == (YRES/CELL)-1 || x == (XRES/CELL)-1)
*shapeout = 1; *shapeout = 1;
checkmap[y][x] = 1;
shape[y][x] = 1; int x1 = x, x2 = x;
if(x-1 >= 0 && !checkmap[y][x-1] && bmap[y][x-1]!=WL_GRAV) while (x1 >= 0)
grav_mask_r(x-1, y, checkmap, shape, shapeout); {
if(y-1 >= 0 && !checkmap[y-1][x] && bmap[y-1][x]!=WL_GRAV) if(checkmap[y][x1-1] || bmap[y][x1-1]==WL_GRAV)
grav_mask_r(x, y-1, checkmap, shape, shapeout); break;
if(x+1 < XRES/CELL && !checkmap[y][x+1] && bmap[y][x+1]!=WL_GRAV) x1--;
grav_mask_r(x+1, y, checkmap, shape, shapeout); }
if(y+1 < YRES/CELL && !checkmap[y+1][x] && bmap[y+1][x]!=WL_GRAV) while (x2 < XRES/CELL)
grav_mask_r(x, y+1, checkmap, shape, shapeout); {
if(checkmap[y][x2+1] || bmap[y][x2+1]==WL_GRAV)
break;
x2++;
}
// fill span
for (x = x1; x <= x2; x++)
checkmap[y][x] = shape[y][x] = 1;
if(y >= 1)
for(x = x1; x <= x2; x++)
if(!checkmap[y-1][x] && bmap[y-1][x]!=WL_GRAV)
grav_mask_r(x, y-1, checkmap, shape, shapeout);
if(y < (YRES/CELL)-1)
for(x = x1; x <= x2; x++)
if(!checkmap[y+1][x] && bmap[y+1][x]!=WL_GRAV)
grav_mask_r(x, y+1, checkmap, shape, shapeout);
return; return;
} }
void Gravity::mask_free(mask_el *c_mask_el){ void Gravity::mask_free(mask_el *c_mask_el){