Wii stack size, and flood fill algorithm July 06, 2009 08:07PM | Registered: 14 years ago Posts: 17 |
5 4 4 4 4 4 4 w 5 5 5 4 3 3 3 3 3 w 4 5 5 4 w 2 2 2 2 3 4 5 5 5 w 1 1 1 2 3 4 5 6 6 w w x 1 2 3 4 5 7 7 7 w 1 1 2 w 4 5 8 8 8 w w 2 2 w 5 5 9 9 9 9 w 3 3 w 5 6 10 9 8 8 w 4 4 4 5 6 10 9 8 7 w 5 5 5 5 6 10 9 8 7 6 6 6 6 6 6
Re: Wii stack size, and flood fill algorithm July 06, 2009 09:15PM | Registered: 14 years ago Posts: 116 |
Re: Wii stack size, and flood fill algorithm July 06, 2009 11:51PM | Registered: 15 years ago Posts: 265 |
Re: Wii stack size, and flood fill algorithm July 07, 2009 01:14AM | Registered: 15 years ago Posts: 1,012 |
Re: Wii stack size, and flood fill algorithm July 07, 2009 10:18AM | Registered: 14 years ago Posts: 17 |
void flood_fill(int team, int x, int y, int value) { if(grad_grid[team][x][y] == 0) { grad_grid[team][x][y] = value +1; flood_fill(team, x+1, y,value); flood_fill(team, x-1, y,value); flood_fill(team, x, y+1,value); flood_fill(team, x, y-1,value); } }
Re: Wii stack size, and flood fill algorithm July 07, 2009 01:27PM | Registered: 15 years ago Posts: 1,012 |
Re: Wii stack size, and flood fill algorithm July 07, 2009 03:53PM | Registered: 14 years ago Posts: 17 |
void bucket_fill(int x, int y, int value) { if (grid[x, y] == 0 || (grid[x, y] - value)>0) { grid[x, y] = value; if (x < map_size-1) bucket_fill(x + 1, y, value+1); if(x>0) bucket_fill(x - 1, y, value+1); if (y < map_size-1) bucket_fill(x, y+1, value+1); if(y>0) bucket_fill(x, y-1, value+1); } }
bucket_fill(x,y, 0);
Re: Wii stack size, and flood fill algorithm July 07, 2009 08:44PM | Registered: 14 years ago Posts: 116 |
#define RANGE_CHECK(A,B) ( ( (A) < rowspr+SMALLY) && ( (A)>=SMALLY ) && ( (B)>=SMALLX ) && ( (B) < colspr+SMALLX) ) void floodf(void) { int stack[800]; // Stack for 400 Positions // This big Stack is needed because of bad floodfill algorithm done by me.. // it eats a lot of space as it goes through multiple choices, // it starts pulling of positions until it has no place to go. // Most of the positions in the stack becomes unavailable since they are covered // by previous steps and this is the weak side of the algorithm. // But it is fast enough filling 64x64 area // The algorithm is recursive but implemented with goto // to avoid stack overflow int *stackp; char cdraw,cpool; int si,sj,i,j; if (getsimplegridarea (&dg,xplace,yplace,&i,&j) >NOT_IN_CELL) { cdraw=current_col; i+=SMALLY;j+=SMALLX; cpool=getpixel(j,i); if (cpool!=cdraw) { putpixel(j,i,cdraw); save_undo_sprite(); setcolor(cdraw); stackp=stack; recurse : ; // Going Up if ( (getpixel(j,i-1)==cpool)&&RANGE_CHECK(i-1,j)) { *stackp++=i; *stackp++=j; while ((getpixel(j,i-1)==cpool)&&RANGE_CHECK(i-1,j)) { i--; putpixel(j,i,cdraw); } goto recurse; } else // Right if ((getpixel(j+1,i)==cpool)&&RANGE_CHECK(i,j+1)) { *stackp++=i; *stackp++=j; while ((getpixel(j+1,i)==cpool)&&RANGE_CHECK(i,j+1)) { j++; putpixel(j,i,cdraw); } goto recurse; } else // Down if ((getpixel(j,i+1)==cpool)&&RANGE_CHECK(i+1,j)) { *stackp++=i; *stackp++=j; while ((getpixel(j,i+1)==cpool)&&RANGE_CHECK(i+1,j)) { i++; putpixel(j,i,cdraw); } goto recurse; } // Left else if ((getpixel(j-1,i)==cpool)&&RANGE_CHECK(i,j-1)) { *stackp++=i; *stackp++=j; while ((getpixel(j-1,i)==cpool)&&RANGE_CHECK(i,j-1)) { j--; putpixel(j,i,cdraw); } goto recurse; } if (stackp!=stack) { si=*(stackp-2); // Copy top of stack to variables si,sj... sj=*(stackp-1); if (si==i&&sj==j) { stackp--; // Position Pulled out of stack.. stackp--; goto recurse; } else // Move in the direction of position { if ((si-i)>0) i++; else if ((si-i)<0) i--; if ((sj-j)>0) j++; else if ((sj-j)<0) j--; goto recurse; } } update_to_grid(); // Make grid aware of flood } // End of color control } // End of if } // End of main block...
Re: Wii stack size, and flood fill algorithm July 08, 2009 01:05AM | Registered: 14 years ago Posts: 379 |
static void map_flood_line_area(struct map_data *m, int x, int y, int areanum) { int fillL, fillR, i; int in_line = 1; /* find left side, filling along the way */ fillL = fillR = x; while( in_line ) { m->area[fillL+y*m->xs] = areanum; fillL--; in_line = (fillL < 0) ? 0 : (m->area[fillL+y*m->xs] == AREA_FILLABLE); } fillL++; /* find right side, filling along the way */ in_line = 1; while( in_line ) { m->area[fillR+y*m->xs] = areanum; fillR++; in_line = (fillR >= m->xs) ? 0 : (m->area[fillR+y*m->xs] == AREA_FILLABLE); } fillR--; /* search top and bottom */ for(i = fillL; i <= fillR; i++) { if( y > 0 && m->area[i + (y - 1) * m->xs] == AREA_FILLABLE) map_flood_line_area(m, i, y - 1, areanum); if( y < (m->ys-1) && m->area[i + (y + 1) * m->xs] == AREA_FILLABLE) map_flood_line_area(m, i, y + 1, areanum); } }