Move location of R_GetTextureFlat

This commit is contained in:
Jaime Passos 2020-01-07 12:45:22 -03:00
parent 762ce146eb
commit 06d6e2e027
3 changed files with 102 additions and 101 deletions

View file

@ -765,107 +765,6 @@ void R_CheckFlatLength(size_t size)
} }
} }
//
// R_GetTextureFlat
//
// Convert a texture or patch to a flat.
//
static UINT8 *R_GetTextureFlat(levelflat_t *levelflat, boolean leveltexture, boolean ispng)
{
UINT8 *flat;
textureflat_t *texflat = &texflats[levelflat->u.texture.num];
patch_t *patch = NULL;
boolean texturechanged = (leveltexture ? (levelflat->u.texture.num != levelflat->u.texture.lastnum) : false);
(void)ispng;
// Check if the texture changed.
if (leveltexture && (!texturechanged))
{
if (texflat != NULL && texflat->flat)
{
flat = texflat->flat;
ds_flatwidth = texflat->width;
ds_flatheight = texflat->height;
texturechanged = false;
}
else
texturechanged = true;
}
// If the texture changed, or the patch doesn't exist, convert either of them to a flat.
if (levelflat->flatpatch == NULL || texturechanged)
{
// Level texture
if (leveltexture)
{
UINT8 *converted;
size_t size;
texture_t *texture = textures[levelflat->u.texture.num];
texflat->width = ds_flatwidth = texture->width;
texflat->height = ds_flatheight = texture->height;
size = (texflat->width * texflat->height);
texflat->flat = Z_Malloc(size, PU_LEVEL, NULL);
converted = (UINT8 *)Picture_TextureToFlat(levelflat->u.texture.num);
M_Memcpy(texflat->flat, converted, size);
Z_Free(converted);
flat = texflat->flat;
levelflat->flatpatch = flat;
levelflat->width = ds_flatwidth;
levelflat->height = ds_flatheight;
}
// Patch (never happens yet)
else
{
patch = (patch_t *)ds_source;
#ifndef NO_PNG_LUMPS
if (ispng)
{
INT32 pngwidth, pngheight;
levelflat->flatpatch = Picture_PNGConvert(ds_source, PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0);
levelflat->topoffset = levelflat->leftoffset = 0;
levelflat->width = (UINT16)pngwidth;
levelflat->height = (UINT16)pngheight;
ds_flatwidth = levelflat->width;
ds_flatheight = levelflat->height;
}
else
#endif
{
UINT8 *converted;
size_t size;
levelflat->width = ds_flatwidth = SHORT(patch->width);
levelflat->height = ds_flatheight = SHORT(patch->height);
levelflat->topoffset = patch->topoffset * FRACUNIT;
levelflat->leftoffset = patch->leftoffset * FRACUNIT;
levelflat->flatpatch = Z_Malloc(levelflat->width * levelflat->height, PU_LEVEL, NULL);
converted = Picture_FlatConvert(PICFMT_PATCH, patch, PICFMT_FLAT, 0, &size, levelflat->width, levelflat->height, patch->topoffset, patch->leftoffset, 0);
M_Memcpy(levelflat->flatpatch, converted, size);
Z_Free(converted);
}
flat = levelflat->flatpatch;
}
}
else
{
flat = levelflat->flatpatch;
ds_flatwidth = levelflat->width;
ds_flatheight = levelflat->height;
}
xoffs += levelflat->leftoffset;
yoffs += levelflat->topoffset;
levelflat->u.texture.lastnum = levelflat->u.texture.num;
return flat;
}
#ifdef ESLOPE #ifdef ESLOPE
static void R_SlopeVectors(visplane_t *pl, INT32 i, float fudge) static void R_SlopeVectors(visplane_t *pl, INT32 i, float fudge)
{ {

View file

@ -502,6 +502,107 @@ UINT8 *R_GetFlat(lumpnum_t flatlumpnum)
return W_CacheLumpNum(flatlumpnum, PU_CACHE); return W_CacheLumpNum(flatlumpnum, PU_CACHE);
} }
//
// R_GetTextureFlat
//
// Convert a texture or patch to a flat.
//
UINT8 *R_GetTextureFlat(levelflat_t *levelflat, boolean leveltexture, boolean ispng)
{
UINT8 *flat;
textureflat_t *texflat = &texflats[levelflat->u.texture.num];
patch_t *patch = NULL;
boolean texturechanged = (leveltexture ? (levelflat->u.texture.num != levelflat->u.texture.lastnum) : false);
(void)ispng;
// Check if the texture changed.
if (leveltexture && (!texturechanged))
{
if (texflat != NULL && texflat->flat)
{
flat = texflat->flat;
ds_flatwidth = texflat->width;
ds_flatheight = texflat->height;
texturechanged = false;
}
else
texturechanged = true;
}
// If the texture changed, or the patch doesn't exist, convert either of them to a flat.
if (levelflat->flatpatch == NULL || texturechanged)
{
// Level texture
if (leveltexture)
{
UINT8 *converted;
size_t size;
texture_t *texture = textures[levelflat->u.texture.num];
texflat->width = ds_flatwidth = texture->width;
texflat->height = ds_flatheight = texture->height;
size = (texflat->width * texflat->height);
texflat->flat = Z_Malloc(size, PU_LEVEL, NULL);
converted = (UINT8 *)Picture_TextureToFlat(levelflat->u.texture.num);
M_Memcpy(texflat->flat, converted, size);
Z_Free(converted);
flat = texflat->flat;
levelflat->flatpatch = flat;
levelflat->width = ds_flatwidth;
levelflat->height = ds_flatheight;
}
// Patch (never happens yet)
else
{
patch = (patch_t *)ds_source;
#ifndef NO_PNG_LUMPS
if (ispng)
{
INT32 pngwidth, pngheight;
levelflat->flatpatch = Picture_PNGConvert(ds_source, PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0);
levelflat->topoffset = levelflat->leftoffset = 0;
levelflat->width = (UINT16)pngwidth;
levelflat->height = (UINT16)pngheight;
ds_flatwidth = levelflat->width;
ds_flatheight = levelflat->height;
}
else
#endif
{
UINT8 *converted;
size_t size;
levelflat->width = ds_flatwidth = SHORT(patch->width);
levelflat->height = ds_flatheight = SHORT(patch->height);
levelflat->topoffset = patch->topoffset * FRACUNIT;
levelflat->leftoffset = patch->leftoffset * FRACUNIT;
levelflat->flatpatch = Z_Malloc(levelflat->width * levelflat->height, PU_LEVEL, NULL);
converted = Picture_FlatConvert(PICFMT_PATCH, patch, PICFMT_FLAT, 0, &size, levelflat->width, levelflat->height, patch->topoffset, patch->leftoffset, 0);
M_Memcpy(levelflat->flatpatch, converted, size);
Z_Free(converted);
}
flat = levelflat->flatpatch;
}
}
else
{
flat = levelflat->flatpatch;
ds_flatwidth = levelflat->width;
ds_flatheight = levelflat->height;
}
//xoffs += levelflat->leftoffset;
//yoffs += levelflat->topoffset;
levelflat->u.texture.lastnum = levelflat->u.texture.num;
return flat;
}
// //
// Empty the texture cache (used for load wad at runtime) // Empty the texture cache (used for load wad at runtime)
// //

View file

@ -94,6 +94,7 @@ void R_ClearTextureNumCache(boolean btell);
// Retrieve texture data. // Retrieve texture data.
UINT8 *R_GetColumn(fixed_t tex, INT32 col); UINT8 *R_GetColumn(fixed_t tex, INT32 col);
UINT8 *R_GetFlat(lumpnum_t flatnum); UINT8 *R_GetFlat(lumpnum_t flatnum);
UINT8 *R_GetTextureFlat(levelflat_t *levelflat, boolean leveltexture, boolean ispng);
// Returns the texture number for the texture name. // Returns the texture number for the texture name.
INT32 R_TextureNumForName(const char *name); INT32 R_TextureNumForName(const char *name);