R_GetTextureFlat -> R_GetLevelFlat

This commit is contained in:
Jaime Passos 2020-01-07 13:27:59 -03:00
parent 76a6710f8b
commit 5b5f371b0c
6 changed files with 29 additions and 51 deletions

View file

@ -638,7 +638,7 @@ texturefound:
{ {
flatfound: flatfound:
/* This could be a flat, patch, or PNG. */ /* This could be a flat, patch, or PNG. */
flatpatch = W_CacheLumpNum(flatnum, PU_STATIC); flatpatch = W_CacheLumpNum(flatnum, PU_CACHE);
lumplength = W_LumpLength(flatnum); lumplength = W_LumpLength(flatnum);
if (Picture_CheckIfPatch(flatpatch, lumplength)) if (Picture_CheckIfPatch(flatpatch, lumplength))
levelflat->type = LEVELFLAT_PATCH; levelflat->type = LEVELFLAT_PATCH;

View file

@ -72,7 +72,6 @@ typedef struct
u; u;
UINT16 width, height; UINT16 width, height;
fixed_t topoffset, leftoffset;
// for flat animation // for flat animation
INT32 animseq; // start pos. in the anim sequence INT32 animseq; // start pos. in the anim sequence

View file

@ -615,7 +615,7 @@ boolean Picture_CheckIfPatch(patch_t *patch, size_t size)
width = SHORT(patch->width); width = SHORT(patch->width);
height = SHORT(patch->height); height = SHORT(patch->height);
result = (height > 0 && height <= 16384 && width > 0 && width <= 16384 && width < (INT16)(size / 4)); result = (height > 0 && height <= 16384 && width > 0 && width <= 16384);
if (result) if (result)
{ {
@ -930,6 +930,9 @@ void *Picture_PNGConvert(
png_bytep *row_pointers = PNG_Read(png, w, h, topoffset, leftoffset, insize); png_bytep *row_pointers = PNG_Read(png, w, h, topoffset, leftoffset, insize);
png_uint_32 width = *w, height = *h; png_uint_32 width = *w, height = *h;
if (png == NULL)
I_Error("Picture_PNGConvert: picture was NULL!");
// Find the output format's bits per pixel amount // Find the output format's bits per pixel amount
outbpp = Picture_FormatBPP(outformat); outbpp = Picture_FormatBPP(outformat);

View file

@ -777,12 +777,11 @@ d.z = (v1.x * v2.y) - (v1.y * v2.x)
void R_DrawSinglePlane(visplane_t *pl) void R_DrawSinglePlane(visplane_t *pl)
{ {
UINT8 *flat; levelflat_t *levelflat;
INT32 light = 0; INT32 light = 0;
INT32 x; INT32 x;
INT32 stop, angle; INT32 stop, angle;
ffloor_t *rover; ffloor_t *rover;
levelflat_t *levelflat;
int type; int type;
int spanfunctype = BASEDRAWFUNC; int spanfunctype = BASEDRAWFUNC;
@ -943,30 +942,15 @@ void R_DrawSinglePlane(visplane_t *pl)
case LEVELFLAT_NONE: case LEVELFLAT_NONE:
return; return;
case LEVELFLAT_FLAT: case LEVELFLAT_FLAT:
ds_source = R_GetFlat(levelflat->u.flat.lumpnum); ds_source = (UINT8 *)R_GetFlat(levelflat->u.flat.lumpnum);
R_CheckFlatLength(W_LumpLength(levelflat->u.flat.lumpnum)); R_CheckFlatLength(W_LumpLength(levelflat->u.flat.lumpnum));
// Raw flats always have dimensions that are powers-of-two numbers. // Raw flats always have dimensions that are powers-of-two numbers.
ds_powersoftwo = true; ds_powersoftwo = true;
break; break;
default: default:
switch (type) ds_source = (UINT8 *)R_GetLevelFlat(levelflat);
{ if (!ds_source)
case LEVELFLAT_TEXTURE: return;
/* Textures get cached differently and don't need ds_source */
ds_source = R_GetTextureFlat(levelflat, true, false);
break;
default:
ds_source = R_GetFlat(levelflat->u.flat.lumpnum);
flat = R_GetTextureFlat(levelflat, false,
#ifndef NO_PNG_LUMPS
( type == LEVELFLAT_PNG )
#else
false
#endif
);
Z_ChangeTag(ds_source, PU_CACHE);
ds_source = flat;
}
// Check if this texture or patch has power-of-two dimensions. // Check if this texture or patch has power-of-two dimensions.
if (R_CheckPowersOfTwo()) if (R_CheckPowersOfTwo())
R_CheckFlatLength(ds_flatwidth * ds_flatheight); R_CheckFlatLength(ds_flatwidth * ds_flatheight);

View file

@ -497,31 +497,29 @@ UINT8 *R_GetColumn(fixed_t tex, INT32 col)
return data + LONG(texturecolumnofs[tex][col]); return data + LONG(texturecolumnofs[tex][col]);
} }
UINT8 *R_GetFlat(lumpnum_t flatlumpnum) void *R_GetFlat(lumpnum_t flatlumpnum)
{ {
return W_CacheLumpNum(flatlumpnum, PU_CACHE); return W_CacheLumpNum(flatlumpnum, PU_CACHE);
} }
// //
// R_GetTextureFlat // R_GetLevelFlat
// //
// Convert a texture or patch to a flat. // If needed, convert a texture or patch to a flat.
// //
UINT8 *R_GetTextureFlat(levelflat_t *levelflat, boolean leveltexture, boolean ispng) void *R_GetLevelFlat(levelflat_t *levelflat)
{ {
UINT8 *flat; UINT8 *flatdata = NULL;
boolean leveltexture = (levelflat->type == LEVELFLAT_TEXTURE);
textureflat_t *texflat = &texflats[levelflat->u.texture.num]; textureflat_t *texflat = &texflats[levelflat->u.texture.num];
patch_t *patch = NULL;
boolean texturechanged = (leveltexture ? (levelflat->u.texture.num != levelflat->u.texture.lastnum) : false); boolean texturechanged = (leveltexture ? (levelflat->u.texture.num != levelflat->u.texture.lastnum) : false);
(void)ispng;
// Check if the texture changed. // Check if the texture changed.
if (leveltexture && (!texturechanged)) if (leveltexture && (!texturechanged))
{ {
if (texflat != NULL && texflat->flat) if (texflat != NULL && texflat->flat)
{ {
flat = texflat->flat; flatdata = texflat->flat;
ds_flatwidth = texflat->width; ds_flatwidth = texflat->width;
ds_flatheight = texflat->height; ds_flatheight = texflat->height;
texturechanged = false; texturechanged = false;
@ -547,23 +545,19 @@ UINT8 *R_GetTextureFlat(levelflat_t *levelflat, boolean leveltexture, boolean is
converted = (UINT8 *)Picture_TextureToFlat(levelflat->u.texture.num); converted = (UINT8 *)Picture_TextureToFlat(levelflat->u.texture.num);
M_Memcpy(texflat->flat, converted, size); M_Memcpy(texflat->flat, converted, size);
Z_Free(converted); Z_Free(converted);
flat = texflat->flat;
levelflat->flatpatch = flat; levelflat->flatpatch = texflat->flat;
levelflat->width = ds_flatwidth; levelflat->width = ds_flatwidth;
levelflat->height = ds_flatheight; levelflat->height = ds_flatheight;
} }
// Patch (never happens yet)
else else
{ {
patch = (patch_t *)ds_source;
#ifndef NO_PNG_LUMPS #ifndef NO_PNG_LUMPS
if (ispng) if (levelflat->type == LEVELFLAT_PNG)
{ {
INT32 pngwidth, pngheight; INT32 pngwidth, pngheight;
levelflat->flatpatch = Picture_PNGConvert(ds_source, PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0); levelflat->flatpatch = Picture_PNGConvert(W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_CACHE), PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0);
levelflat->topoffset = levelflat->leftoffset = 0;
levelflat->width = (UINT16)pngwidth; levelflat->width = (UINT16)pngwidth;
levelflat->height = (UINT16)pngheight; levelflat->height = (UINT16)pngheight;
@ -572,35 +566,33 @@ UINT8 *R_GetTextureFlat(levelflat_t *levelflat, boolean leveltexture, boolean is
} }
else else
#endif #endif
if (levelflat->type == LEVELFLAT_PATCH)
{ {
UINT8 *converted; UINT8 *converted;
size_t size; size_t size;
patch_t *patch = W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_CACHE);
levelflat->width = ds_flatwidth = SHORT(patch->width); levelflat->width = ds_flatwidth = SHORT(patch->width);
levelflat->height = ds_flatheight = SHORT(patch->height); 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); 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); 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); M_Memcpy(levelflat->flatpatch, converted, size);
Z_Free(converted); Z_Free(converted);
} }
flat = levelflat->flatpatch;
} }
} }
else else
{ {
flat = levelflat->flatpatch;
ds_flatwidth = levelflat->width; ds_flatwidth = levelflat->width;
ds_flatheight = levelflat->height; ds_flatheight = levelflat->height;
} }
//xoffs += levelflat->leftoffset;
//yoffs += levelflat->topoffset;
levelflat->u.texture.lastnum = levelflat->u.texture.num; levelflat->u.texture.lastnum = levelflat->u.texture.num;
return flat;
if (flatdata == NULL)
flatdata = levelflat->flatpatch;
return flatdata;
} }
// //

View file

@ -93,8 +93,8 @@ 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); void *R_GetFlat(lumpnum_t flatnum);
UINT8 *R_GetTextureFlat(levelflat_t *levelflat, boolean leveltexture, boolean ispng); void *R_GetLevelFlat(levelflat_t *levelflat);
boolean R_CheckPowersOfTwo(void); boolean R_CheckPowersOfTwo(void);
void R_CheckFlatLength(size_t size); void R_CheckFlatLength(size_t size);