From 06d6e2e027758b592221e1e4ac61ad3c60ac8a66 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Tue, 7 Jan 2020 12:45:22 -0300 Subject: [PATCH] Move location of R_GetTextureFlat --- src/r_plane.c | 101 ----------------------------------------------- src/r_textures.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++ src/r_textures.h | 1 + 3 files changed, 102 insertions(+), 101 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index cc304043e..292b5b2d4 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -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 static void R_SlopeVectors(visplane_t *pl, INT32 i, float fudge) { diff --git a/src/r_textures.c b/src/r_textures.c index 96f2590a6..9d70b9d5c 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -502,6 +502,107 @@ UINT8 *R_GetFlat(lumpnum_t flatlumpnum) 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) // diff --git a/src/r_textures.h b/src/r_textures.h index fd35926cc..d42509bdd 100644 --- a/src/r_textures.h +++ b/src/r_textures.h @@ -94,6 +94,7 @@ void R_ClearTextureNumCache(boolean btell); // Retrieve texture data. UINT8 *R_GetColumn(fixed_t tex, INT32 col); UINT8 *R_GetFlat(lumpnum_t flatnum); +UINT8 *R_GetTextureFlat(levelflat_t *levelflat, boolean leveltexture, boolean ispng); // Returns the texture number for the texture name. INT32 R_TextureNumForName(const char *name);