More efficient floodfill function for gravity walls, no need for larger stacks with 64bit builds
This commit is contained in:
parent
beb0e80849
commit
822539bcdb
@ -418,15 +418,32 @@ 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)
|
||||||
|
break;
|
||||||
|
x1--;
|
||||||
|
}
|
||||||
|
while (x2 < XRES/CELL)
|
||||||
|
{
|
||||||
|
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);
|
grav_mask_r(x, y-1, checkmap, shape, shapeout);
|
||||||
if(x+1 < XRES/CELL && !checkmap[y][x+1] && bmap[y][x+1]!=WL_GRAV)
|
if(y < (YRES/CELL)-1)
|
||||||
grav_mask_r(x+1, y, checkmap, shape, shapeout);
|
for(x = x1; x <= x2; x++)
|
||||||
if(y+1 < YRES/CELL && !checkmap[y+1][x] && bmap[y+1][x]!=WL_GRAV)
|
if(!checkmap[y+1][x] && bmap[y+1][x]!=WL_GRAV)
|
||||||
grav_mask_r(x, y+1, checkmap, shape, shapeout);
|
grav_mask_r(x, y+1, checkmap, shape, shapeout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user