WIP More work towards span filling

Antialiased edge stuff will be hard to port over :(
This commit is contained in:
Bill Kendrick 2021-11-17 00:55:30 -08:00
parent 2f912bd5d7
commit 07165fc3ae

View file

@ -74,8 +74,9 @@ typedef struct queue_s {
int x1, x2, y, yd;
} queue_t;
queue_t * queue = NULL;
queue_t * queue;
int queue_size = 0, queue_start = 0, queue_end = 0;
static unsigned char progbar_anim = 0;
#endif
@ -90,6 +91,7 @@ void init_queue(void);
void add_to_queue(int x1, int x2, int y, int yd);
int remove_from_queue(int * x1, int * x2, int * y, int * yd);
void cleanup_queue(void);
void track_extents_and_progbar(int x, int y, int * extent_x1, int * extent_y1, int * extent_x2, int * extent_y2, SDL_Surface * screen, SDL_Surface * canvas);
#endif
#ifdef USE_QUEUE
@ -98,7 +100,7 @@ void init_queue(void) {
queue_start = 0;
queue_end = 0;
queue = (queue_t *) realloc(queue, sizeof(queue_t) * QUEUE_SIZE_CHUNK);
queue = (queue_t *) malloc(sizeof(queue_t) * QUEUE_SIZE_CHUNK);
if (queue == NULL)
{
fprintf(stderr, "Fill queue cannot be malloc()'d\n");
@ -154,6 +156,25 @@ void cleanup_queue(void) {
queue_end = 0;
}
void track_extents_and_progbar(int x, int y, int * extent_x1, int * extent_y1, int * extent_x2, int * extent_y2, SDL_Surface * screen, SDL_Surface * canvas) {
if (x < *extent_x1)
*extent_x1 = x;
if (x > *extent_x2)
*extent_x2 = x;
if (y < *extent_y1)
*extent_y1 = y;
if (y > *extent_y2)
*extent_y2 = y;
progbar_anim++;
if ((progbar_anim % 4) == 0)
{
show_progress_bar(screen);
playsound(canvas, 1, SND_FILL, 1, x, SNDDIST_NEAR);
}
}
#endif
@ -221,8 +242,69 @@ Uint32 blend(SDL_Surface * canvas, Uint32 draw_colr, Uint32 old_colr, double pct
return SDL_MapRGB(canvas->format, new_r, new_g, new_b);
}
void simulate_flood_fill(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2, Uint8 * touched) {
simulate_flood_fill_outside_check(screen, last, canvas, x, y, cur_colr, old_colr, x1, y1, x2, y2, touched, 0);
void simulate_flood_fill(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * extent_x1, int * extent_y1, int * extent_x2, int * extent_y2, Uint8 * touched) {
#ifdef USE_QUEUE
int x1, x2, dy;
/* "Same" color? No need to fill */
if (!would_flood_fill(canvas, cur_colr, old_colr))
return;
if (x < 0 || x >= canvas->w || y < 0 || y >= canvas->h)
return;
/* Don't re-visit the same pixel */
if (touched && touched[(y * canvas->w) + x])
return;
/* Queue up the first things to work on: */
init_queue();
add_to_queue(x, x, y, 1);
add_to_queue(x, x, y - 1, -1);
/* Do the work (possibly queuing more, as we go) */
while (remove_from_queue(&x1, &x2, &y, &dy))
{
x = x1;
if (Inside(x, y))
{
while (Inside(x - 1, y))
{
Set(x - 1, y);
track_extents_and_progbar(x - 1, y, extent_x1, extent_y1, extent_x2, extent_y2, screen, canvas);
x = x - 1;
}
}
if (x < x1)
add_to_queue(x, x1 - 1, y - dy, -dy);
while (x1 < x2)
{
Set(x1, y);
track_extents_and_progbar(x1, y, extent_x1, extent_y1, extent_x2, extent_y2, screen, canvas);
x1 = x1 + 1;
}
add_to_queue(x, x1 - 1, y + dy, dy);
if (x1 - 1 > x2)
add_to_queue(x2 + 1, x1 - 1, y - dy, -dy);
while (x1 < x2 && !Inside(x1, y))
x1++;
x = x1;
}
cleanup_queue();
#else
simulate_flood_fill_outside_check(screen, last, canvas, x, y, cur_colr, old_colr, extent_x1, extent_y1, extent_x2, extent_y2, touched, 0);
#endif
}
void simulate_flood_fill_outside_check(SDL_Surface * screen, SDL_Surface * last, SDL_Surface * canvas, int x, int y, Uint32 cur_colr, Uint32 old_colr, int * x1, int * y1, int * x2, int * y2, Uint8 * touched, int y_outside)