Minor refactoring

This commit is contained in:
Lactozilla 2023-09-23 20:43:59 -03:00
parent 28e6b97299
commit c09305de62
8 changed files with 49 additions and 25 deletions

View file

@ -1107,8 +1107,8 @@ patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum)
lumpcache_t *lumpcache = wadfiles[wadnum]->patchcache;
if (!lumpcache[lumpnum])
{
void *ptr = Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]);
Patch_Create(NULL, ptr);
void *ptr = Patch_Create(0, 0);
Z_SetUser(ptr, &lumpcache[lumpnum]);
Patch_AllocateHardwarePatch(ptr);
}
return (patch_t *)(lumpcache[lumpnum]);

View file

@ -377,7 +377,7 @@ static void md2_loadTexture(md2_t *model)
Z_Free(grPatch->mipmap->data);
}
else
model->grpatch = patch = Patch_Create(NULL, NULL);
model->grpatch = patch = Patch_Create(0, 0);
if (!patch->hardware)
Patch_AllocateHardwarePatch(patch);
@ -442,7 +442,7 @@ static void md2_loadBlendTexture(md2_t *model)
Z_Free(grPatch->mipmap->data);
}
else
model->blendgrpatch = patch = Patch_Create(NULL, NULL);
model->blendgrpatch = patch = Patch_Create(0, 0);
if (!patch->hardware)
Patch_AllocateHardwarePatch(patch);

View file

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

View file

@ -21,12 +21,19 @@
//
// Creates a patch.
// Assumes a PU_PATCH zone memory tag and no user, but can always be set later
//
patch_t *Patch_Create(softwarepatch_t *source, void *dest)
patch_t *Patch_Create(INT16 width, INT16 height)
{
patch_t *patch = (dest == NULL) ? Z_Calloc(sizeof(patch_t), PU_PATCH, NULL) : (patch_t *)(dest);
patch_t *patch = Z_Calloc(sizeof(patch_t), PU_PATCH, NULL);
patch->width = width;
patch->height = height;
return patch;
}
patch_t *Patch_CreateFromDoomPatch(softwarepatch_t *source)
{
patch_t *patch = Patch_Create(0, 0);
if (!source)
return patch;
@ -40,16 +47,16 @@ patch_t *Patch_Create(softwarepatch_t *source, void *dest)
Patch_CalcDataSizes(source, &total_pixels, &total_posts);
patch->width_po2 = 1;
while (patch->width_po2 < patch->width)
patch->width_po2 <<= 1;
patch->width_mask = patch->width_po2 - 1;
int width_po2 = 1;
while (width_po2 < patch->width)
width_po2 <<= 1;
patch->width_mask = width_po2 - 1;
patch->columns = Z_Calloc(sizeof(column_t) * patch->width_po2, PU_PATCH_DATA, NULL);
patch->columns = Z_Calloc(sizeof(column_t) * patch->width, 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_po2, patch->width, patch->pixels, patch->columns, patch->posts, false);
Patch_MakeColumns(source, patch->width, patch->width, patch->pixels, patch->columns, patch->posts, false);
return patch;
}
@ -116,6 +123,19 @@ void Patch_MakeColumns(softwarepatch_t *source, size_t num_columns, INT16 width,
}
}
column_t *Patch_GetColumn(patch_t *patch, unsigned column)
{
if (column >= (unsigned)patch->width)
{
if (patch->width_mask + 1 == patch->width)
column &= patch->width_mask;
else
column %= patch->width;
}
return &patch->columns[column];
}
//
// Frees a patch from memory.
//

View file

@ -18,7 +18,9 @@
#include "doomdef.h"
// Patch functions
patch_t *Patch_Create(softwarepatch_t *source, void *dest);
patch_t *Patch_Create(INT16 width, INT16 height);
patch_t *Patch_CreateFromDoomPatch(softwarepatch_t *source);
column_t *Patch_GetColumn(patch_t *patch, unsigned column);
void Patch_CalcDataSizes(softwarepatch_t *source, size_t *total_pixels, size_t *total_posts);
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);

View file

@ -245,7 +245,7 @@ void *Picture_PatchConvert(
{
if (outsize != NULL)
*outsize = sizeof(patch_t);
return Patch_Create(picture, NULL);
return Patch_CreateFromDoomPatch(picture);
}
INT32 outbpp = Picture_FormatBPP(outformat);

View file

@ -943,7 +943,7 @@ static void R_DrawVisSprite(vissprite_t *vis)
sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale));
dc_iscale = (0xffffffffu / (unsigned)spryscale);
column = &patch->columns[texturecolumn];
column = Patch_GetColumn(patch, texturecolumn);
localcolfunc (column);
}
@ -957,8 +957,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)
{
texturecolumn = (frac>>FRACBITS) & patch->width_mask;
column = &patch->columns[texturecolumn];
texturecolumn = frac>>FRACBITS;
column = Patch_GetColumn(patch, texturecolumn);
sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale));
localcolfunc (column);
}
@ -972,8 +972,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)
{
texturecolumn = (frac>>FRACBITS) & patch->width_mask;
column = &patch->columns[texturecolumn];
texturecolumn = frac>>FRACBITS;
column = Patch_GetColumn(patch, texturecolumn);
localcolfunc (column);
}
}
@ -1031,8 +1031,8 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis)
for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale)
{
texturecolumn = (frac>>FRACBITS) & patch->width_mask;
column = &patch->columns[texturecolumn];
texturecolumn = frac>>FRACBITS;
column = Patch_GetColumn(patch, texturecolumn);
R_DrawMaskedColumn(column);
}

View file

@ -2064,9 +2064,11 @@ void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
}
#endif
dest = Z_Calloc(sizeof(patch_t), tag, &lumpcache[lump]);
Patch_Create(ptr, dest);
dest = Patch_CreateFromDoomPatch(ptr);
Z_Free(ptr);
Z_ChangeTag(dest, tag);
Z_SetUser(dest, &lumpcache[lump]);
}
else
Z_ChangeTag(lumpcache[lump], tag);