mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-23 17:51:31 +00:00
Minor refactoring
This commit is contained in:
parent
28e6b97299
commit
c09305de62
8 changed files with 49 additions and 25 deletions
|
@ -1107,8 +1107,8 @@ patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum)
|
||||||
lumpcache_t *lumpcache = wadfiles[wadnum]->patchcache;
|
lumpcache_t *lumpcache = wadfiles[wadnum]->patchcache;
|
||||||
if (!lumpcache[lumpnum])
|
if (!lumpcache[lumpnum])
|
||||||
{
|
{
|
||||||
void *ptr = Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]);
|
void *ptr = Patch_Create(0, 0);
|
||||||
Patch_Create(NULL, ptr);
|
Z_SetUser(ptr, &lumpcache[lumpnum]);
|
||||||
Patch_AllocateHardwarePatch(ptr);
|
Patch_AllocateHardwarePatch(ptr);
|
||||||
}
|
}
|
||||||
return (patch_t *)(lumpcache[lumpnum]);
|
return (patch_t *)(lumpcache[lumpnum]);
|
||||||
|
|
|
@ -377,7 +377,7 @@ static void md2_loadTexture(md2_t *model)
|
||||||
Z_Free(grPatch->mipmap->data);
|
Z_Free(grPatch->mipmap->data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
model->grpatch = patch = Patch_Create(NULL, NULL);
|
model->grpatch = patch = Patch_Create(0, 0);
|
||||||
|
|
||||||
if (!patch->hardware)
|
if (!patch->hardware)
|
||||||
Patch_AllocateHardwarePatch(patch);
|
Patch_AllocateHardwarePatch(patch);
|
||||||
|
@ -442,7 +442,7 @@ static void md2_loadBlendTexture(md2_t *model)
|
||||||
Z_Free(grPatch->mipmap->data);
|
Z_Free(grPatch->mipmap->data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
model->blendgrpatch = patch = Patch_Create(NULL, NULL);
|
model->blendgrpatch = patch = Patch_Create(0, 0);
|
||||||
|
|
||||||
if (!patch->hardware)
|
if (!patch->hardware)
|
||||||
Patch_AllocateHardwarePatch(patch);
|
Patch_AllocateHardwarePatch(patch);
|
||||||
|
|
|
@ -811,7 +811,7 @@ typedef struct
|
||||||
{
|
{
|
||||||
INT16 width, height;
|
INT16 width, height;
|
||||||
INT16 leftoffset, topoffset;
|
INT16 leftoffset, topoffset;
|
||||||
INT32 width_po2, width_mask;
|
INT32 width_mask;
|
||||||
|
|
||||||
UINT8 *pixels;
|
UINT8 *pixels;
|
||||||
column_t *columns;
|
column_t *columns;
|
||||||
|
|
|
@ -21,12 +21,19 @@
|
||||||
|
|
||||||
//
|
//
|
||||||
// Creates a patch.
|
// 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)
|
if (!source)
|
||||||
return patch;
|
return patch;
|
||||||
|
|
||||||
|
@ -40,16 +47,16 @@ patch_t *Patch_Create(softwarepatch_t *source, void *dest)
|
||||||
|
|
||||||
Patch_CalcDataSizes(source, &total_pixels, &total_posts);
|
Patch_CalcDataSizes(source, &total_pixels, &total_posts);
|
||||||
|
|
||||||
patch->width_po2 = 1;
|
int width_po2 = 1;
|
||||||
while (patch->width_po2 < patch->width)
|
while (width_po2 < patch->width)
|
||||||
patch->width_po2 <<= 1;
|
width_po2 <<= 1;
|
||||||
patch->width_mask = patch->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->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->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;
|
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.
|
// Frees a patch from memory.
|
||||||
//
|
//
|
||||||
|
|
|
@ -18,7 +18,9 @@
|
||||||
#include "doomdef.h"
|
#include "doomdef.h"
|
||||||
|
|
||||||
// Patch functions
|
// 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_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_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);
|
void Patch_Free(patch_t *patch);
|
||||||
|
|
|
@ -245,7 +245,7 @@ void *Picture_PatchConvert(
|
||||||
{
|
{
|
||||||
if (outsize != NULL)
|
if (outsize != NULL)
|
||||||
*outsize = sizeof(patch_t);
|
*outsize = sizeof(patch_t);
|
||||||
return Patch_Create(picture, NULL);
|
return Patch_CreateFromDoomPatch(picture);
|
||||||
}
|
}
|
||||||
|
|
||||||
INT32 outbpp = Picture_FormatBPP(outformat);
|
INT32 outbpp = Picture_FormatBPP(outformat);
|
||||||
|
|
|
@ -943,7 +943,7 @@ static void R_DrawVisSprite(vissprite_t *vis)
|
||||||
sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale));
|
sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale));
|
||||||
dc_iscale = (0xffffffffu / (unsigned)spryscale);
|
dc_iscale = (0xffffffffu / (unsigned)spryscale);
|
||||||
|
|
||||||
column = &patch->columns[texturecolumn];
|
column = Patch_GetColumn(patch, texturecolumn);
|
||||||
|
|
||||||
localcolfunc (column);
|
localcolfunc (column);
|
||||||
}
|
}
|
||||||
|
@ -957,8 +957,8 @@ static void R_DrawVisSprite(vissprite_t *vis)
|
||||||
// Vertically sheared sprite
|
// Vertically sheared sprite
|
||||||
for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale, dc_texturemid -= vis->shear.tan)
|
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;
|
texturecolumn = frac>>FRACBITS;
|
||||||
column = &patch->columns[texturecolumn];
|
column = Patch_GetColumn(patch, texturecolumn);
|
||||||
sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale));
|
sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale));
|
||||||
localcolfunc (column);
|
localcolfunc (column);
|
||||||
}
|
}
|
||||||
|
@ -972,8 +972,8 @@ static void R_DrawVisSprite(vissprite_t *vis)
|
||||||
// Non-paper drawing loop
|
// Non-paper drawing loop
|
||||||
for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale, sprtopscreen += vis->shear.tan)
|
for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale, sprtopscreen += vis->shear.tan)
|
||||||
{
|
{
|
||||||
texturecolumn = (frac>>FRACBITS) & patch->width_mask;
|
texturecolumn = frac>>FRACBITS;
|
||||||
column = &patch->columns[texturecolumn];
|
column = Patch_GetColumn(patch, texturecolumn);
|
||||||
localcolfunc (column);
|
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)
|
for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale)
|
||||||
{
|
{
|
||||||
texturecolumn = (frac>>FRACBITS) & patch->width_mask;
|
texturecolumn = frac>>FRACBITS;
|
||||||
column = &patch->columns[texturecolumn];
|
column = Patch_GetColumn(patch, texturecolumn);
|
||||||
R_DrawMaskedColumn(column);
|
R_DrawMaskedColumn(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2064,9 +2064,11 @@ void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dest = Z_Calloc(sizeof(patch_t), tag, &lumpcache[lump]);
|
dest = Patch_CreateFromDoomPatch(ptr);
|
||||||
Patch_Create(ptr, dest);
|
|
||||||
Z_Free(ptr);
|
Z_Free(ptr);
|
||||||
|
|
||||||
|
Z_ChangeTag(dest, tag);
|
||||||
|
Z_SetUser(dest, &lumpcache[lump]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Z_ChangeTag(lumpcache[lump], tag);
|
Z_ChangeTag(lumpcache[lump], tag);
|
||||||
|
|
Loading…
Reference in a new issue