Mask the sprite patch column in R_DrawVisSprite

This commit is contained in:
Lactozilla 2023-09-03 12:57:11 -03:00
parent 649669c217
commit 0c664681cd
5 changed files with 16 additions and 20 deletions

View file

@ -811,6 +811,7 @@ typedef struct
{
INT16 width, height;
INT16 leftoffset, topoffset;
INT32 width_po2, width_mask;
UINT8 *pixels;
column_t *columns;

View file

@ -40,11 +40,16 @@ patch_t *Patch_Create(softwarepatch_t *source, void *dest)
Patch_CalcDataSizes(source, &total_pixels, &total_posts);
patch->columns = Z_Calloc(sizeof(column_t) * patch->width, PU_PATCH_DATA, NULL);
patch->width_po2 = 1;
while (patch->width_po2 < patch->width)
patch->width_po2 <<= 1;
patch->width_mask = patch->width_po2 - 1;
patch->columns = Z_Calloc(sizeof(column_t) * patch->width_po2, PU_PATCH_DATA, NULL);
patch->posts = Z_Calloc(sizeof(post_t) * total_posts, PU_PATCH_DATA, NULL);
patch->pixels = Z_Calloc(sizeof(UINT8) * total_pixels, PU_PATCH_DATA, NULL);
Patch_MakeColumns(source, patch->width, patch->pixels, patch->columns, patch->posts, false);
Patch_MakeColumns(source, patch->width_po2, patch->width, patch->pixels, patch->columns, patch->posts, false);
return patch;
}
@ -63,7 +68,7 @@ void Patch_CalcDataSizes(softwarepatch_t *source, size_t *total_pixels, size_t *
}
}
void Patch_MakeColumns(softwarepatch_t *source, size_t num_columns, UINT8 *pixels, column_t *columns, post_t *posts, boolean flip)
void Patch_MakeColumns(softwarepatch_t *source, size_t num_columns, INT16 width, UINT8 *pixels, column_t *columns, post_t *posts, boolean flip)
{
column_t *column = flip ? columns + (num_columns - 1) : columns;
@ -76,6 +81,9 @@ void Patch_MakeColumns(softwarepatch_t *source, size_t num_columns, UINT8 *pixel
column->posts = posts;
column->num_posts = 0;
if (i >= (unsigned)width)
continue;
doompost_t *src_posts = (doompost_t*)((UINT8 *)source + LONG(source->columnofs[i]));
for (doompost_t *post = src_posts; post->topdelta != 0xff ;)

View file

@ -20,7 +20,7 @@
// Patch functions
patch_t *Patch_Create(softwarepatch_t *source, void *dest);
void Patch_CalcDataSizes(softwarepatch_t *source, size_t *total_pixels, size_t *total_posts);
void Patch_MakeColumns(softwarepatch_t *source, size_t num_columns, UINT8 *pixels, column_t *columns, post_t *posts, boolean flip);
void Patch_MakeColumns(softwarepatch_t *source, size_t num_columns, INT16 width, UINT8 *pixels, column_t *columns, post_t *posts, boolean flip);
void Patch_Free(patch_t *patch);
#define Patch_FreeTag(tagnum) Patch_FreeTags(tagnum, tagnum)

View file

@ -319,7 +319,7 @@ UINT8 *R_GenerateTexture(size_t texnum)
texturecolumns[texnum] = columns;
Patch_MakeColumns(realpatch, texture->width, pixels, columns, posts, texture->flip);
Patch_MakeColumns(realpatch, texture->width, texture->width, pixels, columns, posts, texture->flip);
goto done;
}

View file

@ -947,15 +947,8 @@ static void R_DrawVisSprite(vissprite_t *vis)
// Vertically sheared sprite
for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale, dc_texturemid -= vis->shear.tan)
{
#ifdef RANGECHECK
texturecolumn = frac>>FRACBITS;
if (texturecolumn < 0 || texturecolumn >= pwidth)
I_Error("R_DrawSpriteRange: bad texturecolumn at %d from end", vis->x2 - dc_x);
texturecolumn = (frac>>FRACBITS) & patch->width_mask;
column = &patch->columns[texturecolumn];
#else
column = &patch->columns[frac>>FRACBITS];
#endif
sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale));
localcolfunc (column);
}
@ -969,14 +962,8 @@ static void R_DrawVisSprite(vissprite_t *vis)
// Non-paper drawing loop
for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale, sprtopscreen += vis->shear.tan)
{
#ifdef RANGECHECK
texturecolumn = frac>>FRACBITS;
if (texturecolumn < 0 || texturecolumn >= pwidth)
I_Error("R_DrawSpriteRange: bad texturecolumn at %d from end", vis->x2 - dc_x);
texturecolumn = (frac>>FRACBITS) & patch->width_mask;
column = &patch->columns[texturecolumn];
#else
column = &patch->columns[frac>>FRACBITS];
#endif
localcolfunc (column);
}
}