From c7cbc27efb0f07d1ac7a089fe7ac0ed1ce6fa16e Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sat, 24 May 2025 23:36:32 -0400 Subject: [PATCH 01/11] completly borked remove flats port Completey fucked color and brightmap handling for floors. --- src/doomdef.h | 3 - src/hardware/hw_cache.c | 205 ++++++++++-------------------- src/hardware/hw_main.c | 122 +++--------------- src/p_setup.c | 99 ++++----------- src/p_setup.h | 41 +----- src/p_spec.c | 110 ++-------------- src/p_spec.h | 3 - src/r_picformats.c | 2 +- src/r_plane.cpp | 55 ++++---- src/r_textures.c | 270 +++++++++++++--------------------------- src/r_textures.h | 11 +- 11 files changed, 238 insertions(+), 683 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index da551b5b2..489302e48 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -515,9 +515,6 @@ extern int compuncommitted; #define NO_PNG_LUMPS #endif -/// Render flats on walls -#define WALLFLATS - /// Divide volume of music and sounds by this much (loudest sounds on earth) #define VOLUME_DIVIDER 4 #define USER_VOLUME_SCALE 2 diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 4b9da2616..7da9716c8 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -521,7 +521,6 @@ static void HWR_GenerateTexture(GLMapTexture_t *grtex, INT32 texnum, boolean noe realpatch = (softwarepatch_t *)Picture_PNGConvert(pdata, PICFMT_DOOMPATCH, NULL, NULL, NULL, NULL, lumplength, NULL, 0); else #endif -#ifdef WALLFLATS if (texture->type == TEXTURETYPE_FLAT) { if (doremap) @@ -529,7 +528,6 @@ static void HWR_GenerateTexture(GLMapTexture_t *grtex, INT32 texnum, boolean noe realpatch = (softwarepatch_t *)Picture_Convert(PICFMT_FLAT, pdata, PICFMT_DOOMPATCH, 0, NULL, texture->width, texture->height, 0, 0, 0); } else -#endif { dealloc = false; if (doremap) @@ -767,7 +765,7 @@ void HWR_LoadMapTextures(size_t pnumtextures) gl_textures = calloc(gl_numtextures, sizeof(*gl_textures)); gl_flats = calloc(gl_numtextures, sizeof(*gl_flats)); - if ((gl_textures == NULL) || (gl_flats == NULL)) + if (gl_textures == NULL || gl_flats == NULL) I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures"); gl_maptexturesloaded = true; @@ -896,36 +894,6 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) flat[steppy] = grMipmap->colormap->source[flat[steppy]]; } -static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum, boolean noencoremap) -{ - UINT8 *flat; - UINT8 *converted; - size_t size; - size_t i; - UINT8 *colormap = colormaps; - - if (!noencoremap && encoremap) - { - colormap += COLORMAP_REMAPOFFSET; - } - - // setup the texture info - grMipmap->format = GL_TEXFMT_P_8; - grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; - - grMipmap->width = (UINT16)textures[texturenum]->width; - grMipmap->height = (UINT16)textures[texturenum]->height; - size = (grMipmap->width * grMipmap->height); - - flat = Z_Malloc(size, PU_HWRCACHE, &grMipmap->data); - converted = (UINT8 *)Picture_TextureToFlat(texturenum); - for (i = 0; i < size; i++) - { - flat[i] = colormap[converted[i]]; - } - Z_Free(converted); -} - // Download a Doom 'flat' to the hardware cache and make it ready for use void HWR_GetRawFlat(lumpnum_t flatlumpnum, boolean noencoremap) { @@ -966,125 +934,80 @@ void HWR_GetRawFlat(lumpnum_t flatlumpnum, boolean noencoremap) void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) { - // Who knows? - if (levelflat == NULL) - return; - - if (levelflat->type == LEVELFLAT_FLAT) - HWR_GetRawFlat(levelflat->u.flat.lumpnum, noencoremap); - else if (levelflat->type == LEVELFLAT_TEXTURE) + if (levelflat->type == LEVELFLAT_NONE) { - GLMapTexture_t *grtex; - INT32 texturenum = levelflat->u.texture.num; -#ifdef PARANOIA - if ((unsigned)texturenum >= gl_numtextures) - I_Error("HWR_GetLevelFlat: texturenum >= numtextures"); -#endif + HWR_SetCurrentTexture(NULL); + return; + } - // Who knows? - if (texturenum == 0 || texturenum == -1) - return; + INT32 texturenum = texturetranslation[levelflat->texture_id]; + INT32 brightmapnum = R_GetTextureBrightmap(texturenum); + if (texturenum <= 0) + { + HWR_SetCurrentTexture(NULL); + return; + } - // Every texture in memory, stored as a 8-bit flat. Wow! - grtex = &gl_flats[texturenum]; + GLMapTexture_t *grtex = &gl_flats[texturenum]; + GLMipmap_t *grMipmap = &grtex->mipmap; - // Generate flat if missing from the cache - if (!grtex->mipmap.data && !grtex->mipmap.downloaded) + if (!grMipmap->data && !grMipmap->downloaded) + { + UINT8 *colormap = colormaps; + + if (!noencoremap && encoremap) { - HWR_CacheTextureAsFlat(&grtex->mipmap, texturenum, noencoremap); - - if (!noencoremap && encoremap) - { - grtex->mipmap.colormap = Z_Calloc(sizeof(*grtex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); - grtex->mipmap.colormap->source = colormaps + COLORMAP_REMAPOFFSET; - M_Memcpy(grtex->mipmap.colormap->data, colormaps + COLORMAP_REMAPOFFSET, 256); - } + colormap += COLORMAP_REMAPOFFSET; } - // If hardware does not have the texture, then call pfnSetTexture to upload it - if (!grtex->mipmap.downloaded) + grMipmap->format = GL_TEXFMT_P_8; + grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; + + grMipmap->width = (UINT16)textures[texturenum]->width; + grMipmap->height = (UINT16)textures[texturenum]->height; + + size_t size = grMipmap->width * grMipmap->height; + memcpy(Z_Malloc(size, PU_HWRCACHE, &grMipmap->data), R_GetFlatForTexture(texturenum), size); + + if (!noencoremap && encoremap) + { + grtex->mipmap.colormap = Z_Calloc(sizeof(*grtex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); + grtex->mipmap.colormap->source = colormaps + COLORMAP_REMAPOFFSET; + M_Memcpy(grtex->mipmap.colormap->data, colormaps + COLORMAP_REMAPOFFSET, 256); + } + } + + if (!grMipmap->downloaded) + HWD.pfnSetTexture(&grtex->mipmap); + + HWR_SetCurrentTexture(&grtex->mipmap); + + Z_ChangeTag(grMipmap->data, PU_HWRCACHE_UNLOCKED); + + if (brightmapnum) + { + grtex = &gl_flats[brightmapnum]; + grMipmap = &grtex->mipmap; + + if (!grMipmap->data && !grMipmap->downloaded) + { + grMipmap->format = GL_TEXFMT_P_8; + grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; + + grMipmap->width = (UINT16)textures[brightmapnum]->width; + grMipmap->height = (UINT16)textures[brightmapnum]->height; + + size_t size = grMipmap->width * grMipmap->height; + memcpy(Z_Malloc(size, PU_HWRCACHE, &grMipmap->data), R_GetFlatForTexture(brightmapnum), size); + } + + if (!grMipmap->downloaded) HWD.pfnSetTexture(&grtex->mipmap); + HWR_SetCurrentTexture(&grtex->mipmap); - // The system-memory data can be purged now. - Z_ChangeTag(grtex->mipmap.data, PU_HWRCACHE_UNLOCKED); - - if ((texturenum = R_GetTextureBrightmap(texturenum))) - { - // Every texture in memory, stored as a 8-bit flat. Wow! - grtex = &gl_flats[texturenum]; - - // Generate flat if missing from the cache - if (!grtex->mipmap.data && !grtex->mipmap.downloaded) - HWR_CacheTextureAsFlat(&grtex->mipmap, texturenum, true); - - grtex->mipmap.flags |= TF_BRIGHTMAP; - - // If hardware does not have the texture, then call pfnSetTexture to upload it - if (!grtex->mipmap.downloaded) - HWD.pfnSetTexture(&grtex->mipmap); - HWR_SetCurrentTexture(&grtex->mipmap); - - // The system-memory data can be purged now. - Z_ChangeTag(grtex->mipmap.data, PU_HWRCACHE_UNLOCKED); - } + Z_ChangeTag(grMipmap->data, PU_HWRCACHE_UNLOCKED); } - else if (levelflat->type == LEVELFLAT_PATCH) - { - patch_t *patch = W_CachePatchNum(levelflat->u.flat.lumpnum, PU_CACHE); - levelflat->width = (UINT16)(patch->width); - levelflat->height = (UINT16)(patch->height); - HWR_GetPatch(patch); - } -#ifndef NO_PNG_LUMPS - else if (levelflat->type == LEVELFLAT_PNG) - { - GLMipmap_t *mipmap = levelflat->mipmap; - - // Cache the picture. - if (!levelflat->mippic) - { - INT32 pngwidth = 0, pngheight = 0; - void *pic = Picture_PNGConvert(W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_CACHE), PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0); - - Z_ChangeTag(pic, PU_LEVEL); - Z_SetUser(pic, &levelflat->mippic); - - levelflat->width = (UINT16)pngwidth; - levelflat->height = (UINT16)pngheight; - } - - // Make the mipmap. - if (mipmap == NULL) - { - mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_STATIC, NULL); - mipmap->format = GL_TEXFMT_P_8; - mipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; - levelflat->mipmap = mipmap; - } - - if (!mipmap->data && !mipmap->downloaded) - { - UINT8 *flat; - size_t size; - - if (levelflat->mippic == NULL) - I_Error("HWR_GetLevelFlat: levelflat->mippic == NULL"); - - mipmap->width = levelflat->width; - mipmap->height = levelflat->height; - - size = (mipmap->width * mipmap->height); - flat = Z_Malloc(size, PU_LEVEL, &mipmap->data); - M_Memcpy(flat, levelflat->mippic, size); - } - - // Tell the hardware driver to bind the current texture to the flat's mipmap - HWR_SetCurrentTexture(mipmap); - } -#endif - else // set no texture - HWR_SetCurrentTexture(NULL); } // --------------------+ diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 24e5897fd..6a06bc4e8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -396,8 +396,6 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool INT32 i; float flatxref,flatyref; float fflatwidth = 64.0f, fflatheight = 64.0f; - INT32 flatflag = 63; - boolean texflat = false; float scrollx = 0.0f, scrolly = 0.0f, anglef = 0.0f; angle_t angle = 0; FSurfaceInfo Surf; @@ -452,34 +450,16 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool // set texture for polygon if (levelflat != NULL) { - if (levelflat->type == LEVELFLAT_FLAT) - { - size_t len = W_LumpLength(levelflat->u.flat.lumpnum); - size_t sflatsize = R_FlatDimensionsFromLumpSize(len); - fflatwidth = fflatheight = (double)sflatsize; - flatflag = sflatsize-1; - } - else - { - if (levelflat->type == LEVELFLAT_TEXTURE) - { - fflatwidth = textures[levelflat->u.texture.num]->width; - fflatheight = textures[levelflat->u.texture.num]->height; - } - else if (levelflat->type == LEVELFLAT_PATCH || levelflat->type == LEVELFLAT_PNG) - { - fflatwidth = levelflat->width; - fflatheight = levelflat->height; - } - texflat = true; - } + texture_t *texture = textures[R_GetTextureNumForFlat(levelflat)]; + fflatwidth = texture->width; + fflatheight = texture->height; } else // set no texture HWR_SetCurrentTexture(NULL); // reference point for flat texture coord for each vertex around the polygon - flatxref = (float)(((fixed_t)pv->x & (~flatflag)) / fflatwidth); - flatyref = (float)(((fixed_t)pv->y & (~flatflag)) / fflatheight); + flatxref = 0.0; + flatyref = 0.0; // transform if (FOFsector != NULL) @@ -514,30 +494,13 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool } - if (angle) // Only needs to be done if there's an altered angle - { - tempxsow = flatxref; - tempytow = flatyref; - - anglef = ANG2RAD(InvAngle(angle)); - - flatxref = (tempxsow * cos(anglef)) - (tempytow * sin(anglef)); - flatyref = (tempxsow * sin(anglef)) + (tempytow * cos(anglef)); - } + anglef = ANG2RAD(InvAngle(angle)); #define SETUP3DVERT(vert, vx, vy) {\ - /* Hurdler: add scrolling texture on floor/ceiling */\ - if (texflat)\ - {\ - vert->s = (float)((vx) / fflatwidth) + scrollx;\ - vert->t = -(float)((vy) / fflatheight) + scrolly;\ - }\ - else\ - {\ - vert->s = (float)(((vx) / fflatwidth) - flatxref + scrollx);\ - vert->t = (float)(flatyref - ((vy) / fflatheight) + scrolly);\ - }\ -\ + /* Hurdler: add scrolling texture on floor/ceiling */ \ + vert->s = (float)(((vx) / fflatwidth) - flatxref + scrollx);\ + vert->t = (float)(flatyref - ((vy) / fflatheight) + scrolly);\ + \ /* Need to rotate before translate */\ if (angle) /* Only needs to be done if there's an altered angle */\ {\ @@ -2479,9 +2442,6 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, float height = FIXED_TO_FLOAT(fixedheight); // constant y for all points on the convex flat polygon float flatxref, flatyref; float fflatwidth = 64.0f, fflatheight = 64.0f; - INT32 flatflag = 63; - - boolean texflat = false; float scrollx = 0.0f, scrolly = 0.0f; angle_t angle = 0; @@ -2509,37 +2469,16 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, // set texture for polygon if (levelflat != NULL) { - if (levelflat->type == LEVELFLAT_FLAT) - { - size_t len = W_LumpLength(levelflat->u.flat.lumpnum); - size_t sflatsize = R_FlatDimensionsFromLumpSize(len); - fflatwidth = fflatheight = (double)sflatsize; - flatflag = sflatsize-1; - } - else - { - if (levelflat->type == LEVELFLAT_TEXTURE) - { - fflatwidth = textures[levelflat->u.texture.num]->width; - fflatheight = textures[levelflat->u.texture.num]->height; - } - else if (levelflat->type == LEVELFLAT_PATCH || levelflat->type == LEVELFLAT_PNG) - { - fflatwidth = levelflat->width; - fflatheight = levelflat->height; - } - texflat = true; - } + texture_t *texture = textures[R_GetTextureNumForFlat(levelflat)]; + fflatwidth = texture->width; + fflatheight = texture->height; } else // set no texture HWR_SetCurrentTexture(NULL); // reference point for flat texture coord for each vertex around the polygon - flatxref = FIXED_TO_FLOAT(polysector->origVerts[0].x); - flatyref = FIXED_TO_FLOAT(polysector->origVerts[0].y); - - flatxref = (float)(((fixed_t)flatxref & (~flatflag)) / fflatwidth); - flatyref = (float)(((fixed_t)flatyref & (~flatflag)) / fflatheight); + flatxref = 0.0; + flatyref = 0.0; // transform v3d = planeVerts; @@ -2575,44 +2514,19 @@ static void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, } } - if (angle) // Only needs to be done if there's an altered angle - { - angle = (InvAngle(angle))>>ANGLETOFINESHIFT; - - // This needs to be done so that it scrolls in a different direction after rotation like software - /*tempxs = FLOAT_TO_FIXED(scrollx); - tempyt = FLOAT_TO_FIXED(scrolly); - scrollx = (FIXED_TO_FLOAT(FixedMul(tempxs, FINECOSINE(angle)) - FixedMul(tempyt, FINESINE(angle)))); - scrolly = (FIXED_TO_FLOAT(FixedMul(tempxs, FINESINE(angle)) + FixedMul(tempyt, FINECOSINE(angle))));*/ - - // This needs to be done so everything aligns after rotation - // It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does - tempxs = FLOAT_TO_FIXED(flatxref); - tempyt = FLOAT_TO_FIXED(flatyref); - flatxref = (FIXED_TO_FLOAT(FixedMul(tempxs, FINECOSINE(angle)) - FixedMul(tempyt, FINESINE(angle)))); - flatyref = (FIXED_TO_FLOAT(FixedMul(tempxs, FINESINE(angle)) + FixedMul(tempyt, FINECOSINE(angle)))); - } - for (i = 0; i < (INT32)nrPlaneVerts; i++,v3d++) { // Go from the polysector's original vertex locations // Means the flat is offset based on the original vertex locations - if (texflat) - { - v3d->s = (float)(FIXED_TO_FLOAT(polysector->origVerts[i].x) / fflatwidth) + scrollx; - v3d->t = -(float)(FIXED_TO_FLOAT(polysector->origVerts[i].y) / fflatheight) + scrolly; - } - else - { - v3d->s = (float)((FIXED_TO_FLOAT(polysector->origVerts[i].x) / fflatwidth) - flatxref + scrollx); - v3d->t = (float)(flatyref - (FIXED_TO_FLOAT(polysector->origVerts[i].y) / fflatheight) + scrolly); - } + v3d->s = (float)((FIXED_TO_FLOAT(polysector->origVerts[i].x) / fflatwidth) - flatxref + scrollx); + v3d->t = (float)(flatyref - (FIXED_TO_FLOAT(polysector->origVerts[i].y) / fflatheight) + scrolly); // Need to rotate before translate if (angle) // Only needs to be done if there's an altered angle { tempxs = FLOAT_TO_FIXED(v3d->s); tempyt = FLOAT_TO_FIXED(v3d->t); + angle = ANG2RAD(InvAngle(angle)); v3d->s = (FIXED_TO_FLOAT(FixedMul(tempxs, FINECOSINE(angle)) - FixedMul(tempyt, FINESINE(angle)))); v3d->t = (FIXED_TO_FLOAT(FixedMul(tempxs, FINESINE(angle)) + FixedMul(tempyt, FINECOSINE(angle)))); } diff --git a/src/p_setup.c b/src/p_setup.c index fdf2284ca..43c239f08 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -539,13 +539,8 @@ size_t P_PrecacheLevelFlats(void) flatmemory = 0; for (i = 0; i < numlevelflats; i++) { - if (levelflats[i].type == LEVELFLAT_FLAT) - { - lump = levelflats[i].u.flat.lumpnum; - if (devparm) - flatmemory += W_LumpLength(lump); - R_GetFlat(lump); - } + if (levelflats[i].type != LEVELFLAT_NONE) + R_GetFlat(&levelflats[i]); } return flatmemory; } @@ -557,18 +552,8 @@ or NULL if we want to allocate it now. static INT32 Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize) { -#ifndef NO_PNG_LUMPS - UINT8 buffer[8]; -#endif - - lumpnum_t flatnum; - int texturenum; - UINT8 *flatpatch; - size_t lumplength; - size_t i; - // Scan through the already found flats, return if it matches. - for (i = 0; i < numlevelflats; i++) + for (size_t i = 0; i < numlevelflats; i++) { if (strnicmp(levelflat[i].name, flatname, 8) == 0) return i; @@ -592,65 +577,38 @@ Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize) strlcpy(levelflat->name, flatname, sizeof (levelflat->name)); strupr(levelflat->name); - /* If we can't find a flat, try looking for a texture! */ - if (( flatnum = R_GetFlatNumForName(levelflat->name) ) == LUMPERROR) - { - if (( texturenum = R_CheckTextureNumForName(levelflat->name) ) == -1) - { - // check for REDWALL - if (( texturenum = R_CheckTextureNumForName(MISSING_TEXTURE) ) != -1) - goto texturefound; - // check for REDFLR - else if (( flatnum = R_GetFlatNumForName(MISSING_TEXTURE) ) != LUMPERROR) - goto flatfound; - // nevermind - levelflat->type = LEVELFLAT_NONE; - } - else - { -texturefound: - levelflat->type = LEVELFLAT_TEXTURE; - levelflat->u.texture. num = texturenum; - levelflat->u.texture.lastnum = texturenum; - /* start out unanimated */ - levelflat->u.texture.basenum = -1; - } - } - else - { -flatfound: - /* This could be a flat, patch, or PNG. */ - flatpatch = W_CacheLumpNum(flatnum, PU_CACHE); - lumplength = W_LumpLength(flatnum); - if (Picture_CheckIfDoomPatch((softwarepatch_t *)flatpatch, lumplength)) - levelflat->type = LEVELFLAT_PATCH; - else - { -#ifndef NO_PNG_LUMPS - /* - Only need eight bytes for PNG headers. - FIXME: Put this elsewhere. - */ - W_ReadLumpHeader(flatnum, buffer, 8, 0); - if (Picture_IsLumpPNG(buffer, lumplength)) - levelflat->type = LEVELFLAT_PNG; - else -#endif/*NO_PNG_LUMPS*/ - levelflat->type = LEVELFLAT_FLAT;/* phew */ - } - if (flatpatch) - Z_Free(flatpatch); + levelflat->type = LEVELFLAT_TEXTURE; - levelflat->u.flat. lumpnum = flatnum; - levelflat->u.flat.baselumpnum = LUMPERROR; + // Look for a flat + int texturenum = R_CheckFlatNumForName(levelflat->name); + if (texturenum <= 0) + { + // If we can't find a flat, try looking for a texture! + texturenum = R_CheckTextureNumForName(levelflat->name); + if (texturenum <= 0) + { + // Use "not found" texture + texturenum = R_CheckTextureNumForName("REDWALL"); + + // Give up? + if (texturenum <= 0) + { + levelflat->type = LEVELFLAT_NONE; + texturenum = -1; + } + } } + levelflat->texture_id = texturenum; + levelflat->terrain = K_GetTerrainForTextureName(levelflat->name); +#ifndef ZDEBUG CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name); +#endif - return ( numlevelflats++ ); + return numlevelflats++; } // Auxiliary function. Find a flat in the active wad files, @@ -3784,9 +3742,6 @@ static boolean P_LoadMapData(const virtres_t *virt) levelflats = M_Memcpy(Z_Calloc(numlevelflats * sizeof (*levelflats), PU_LEVEL, NULL), foundflats, numlevelflats * sizeof (levelflat_t)); free(foundflats); - // search for animated flats and set up - P_SetupLevelFlatAnims(); - TracyCZoneEnd(__zone); return true; } diff --git a/src/p_setup.h b/src/p_setup.h index 3b1f5ae29..c7c438d3d 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -54,9 +54,6 @@ extern mapnamespace_t mapnamespace; enum { LEVELFLAT_NONE,/* HOM time my friend */ - LEVELFLAT_FLAT, - LEVELFLAT_PATCH, - LEVELFLAT_PNG, LEVELFLAT_TEXTURE, }; @@ -66,43 +63,9 @@ enum struct levelflat_t { char name[9]; // resource name from wad - - UINT8 type; - union - { - struct - { - lumpnum_t lumpnum; // lump number of the flat - // for flat animation - lumpnum_t baselumpnum; - } - flat; - struct - { - INT32 num; - INT32 lastnum; // texture number of the flat - // for flat animation - INT32 basenum; - } - texture; - } - u; - - UINT16 width, height; - terrain_t *terrain; - - // for flat animation - INT32 animseq; // start pos. in the anim sequence - INT32 numpics; - INT32 speed; - - // for textures - UINT8 *picture; -#ifdef HWRENDER - void *mipmap; - void *mippic; -#endif + UINT8 type; + INT32 texture_id; }; extern size_t numlevelflats; diff --git a/src/p_spec.c b/src/p_spec.c index 7a9efc6b6..bce69e446 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -217,11 +217,11 @@ void P_InitPicAnims(void) } else { - if ((W_CheckNumForName(animdefs[i].startname)) == LUMPERROR) + if (R_CheckFlatNumForName(animdefs[i].startname) == -1) continue; - lastanim->picnum = R_GetFlatNumForName(animdefs[i].endname); - lastanim->basepic = R_GetFlatNumForName(animdefs[i].startname); + lastanim->picnum = R_CheckFlatNumForName(animdefs[i].endname); + lastanim->basepic = R_CheckFlatNumForName(animdefs[i].startname); } lastanim->istexture = animdefs[i].istexture; @@ -449,82 +449,13 @@ void P_ParseAnimationDefintion(SINT8 istexture) animdefs[i].speed = animSpeed; Z_Free(animdefsToken); -#ifdef WALLFLATS - // hehe... uhh..... + // Add it as a texture too if (!istexture) { GrowAnimDefs(); M_Memcpy(&animdefs[maxanims-1], &animdefs[i], sizeof(animdef_t)); animdefs[maxanims-1].istexture = 1; } -#endif -} - -/** Checks for flats in levelflats that are part of a flat animation sequence - * and sets them up for animation. - * - * \param animnum Index into ::anims to find flats for. - * \sa P_SetupLevelFlatAnims - */ -static inline void P_FindAnimatedFlat(INT32 animnum) -{ - size_t i; - lumpnum_t startflatnum, endflatnum; - levelflat_t *foundflats; - - foundflats = levelflats; - startflatnum = anims[animnum].basepic; - endflatnum = anims[animnum].picnum; - - // note: high word of lumpnum is the wad number - if ((startflatnum>>16) != (endflatnum>>16)) - I_Error("AnimatedFlat start %s not in same wad as end %s\n", - animdefs[animnum].startname, animdefs[animnum].endname); - - // - // now search through the levelflats if this anim flat sequence is used - // - for (i = 0; i < numlevelflats; i++, foundflats++) - { - // is that levelflat from the flat anim sequence ? - if ((anims[animnum].istexture) && (foundflats->type == LEVELFLAT_TEXTURE) - && ((UINT16)foundflats->u.texture.num >= startflatnum && (UINT16)foundflats->u.texture.num <= endflatnum)) - { - foundflats->u.texture.basenum = startflatnum; - foundflats->animseq = foundflats->u.texture.num - startflatnum; - foundflats->numpics = endflatnum - startflatnum + 1; - foundflats->speed = anims[animnum].speed; - - CONS_Debug(DBG_SETUP, "animflat: #%03d name:%.8s animseq:%d numpics:%d speed:%d\n", - atoi(sizeu1(i)), foundflats->name, foundflats->animseq, - foundflats->numpics,foundflats->speed); - } - else if ((!anims[animnum].istexture) && (foundflats->type == LEVELFLAT_FLAT) - && (foundflats->u.flat.lumpnum >= startflatnum && foundflats->u.flat.lumpnum <= endflatnum)) - { - foundflats->u.flat.baselumpnum = startflatnum; - foundflats->animseq = foundflats->u.flat.lumpnum - startflatnum; - foundflats->numpics = endflatnum - startflatnum + 1; - foundflats->speed = anims[animnum].speed; - - CONS_Debug(DBG_SETUP, "animflat: #%03d name:%.8s animseq:%d numpics:%d speed:%d\n", - atoi(sizeu1(i)), foundflats->name, foundflats->animseq, - foundflats->numpics,foundflats->speed); - } - } -} - -/** Sets up all flats used in a level. - * - * \sa P_InitPicAnims, P_FindAnimatedFlat - */ -void P_SetupLevelFlatAnims(void) -{ - INT32 i; - - // the original game flat anim sequences - for (i = 0; anims[i].istexture != -1; i++) - P_FindAnimatedFlat(i); } // @@ -6155,13 +6086,6 @@ void P_CheckMobjTouchingSectorActions(mobj_t *mobj, boolean continuous, boolean */ void P_UpdateSpecials(void) { - anim_t *anim; - INT32 i; - INT32 pic; - size_t j; - - levelflat_t *foundflats; // for flat animation - // LEVEL TIMER P_CheckTimeLimit(); @@ -6169,37 +6093,19 @@ void P_UpdateSpecials(void) P_CheckPointLimit(); // ANIMATE TEXTURES - for (anim = anims; anim < lastanim; anim++) + for (anim_t *anim = anims; anim < lastanim; anim++) { - for (i = 0; i < anim->numpics; i++) + for (INT32 i = 0; i < anim->numpics; i++) { - pic = anim->basepic + ((leveltime/anim->speed + i) % anim->numpics); + INT32 pic = anim->basepic + ((leveltime/anim->speed + i) % anim->numpics); if (anim->istexture) texturetranslation[anim->basepic+i] = pic; } } - - // ANIMATE FLATS - /// \todo do not check the non-animate flat.. link the animated ones? - /// \note its faster than the original anywaysince it animates only - /// flats used in the level, and there's usually very few of them - foundflats = levelflats; - for (j = 0; j < numlevelflats; j++, foundflats++) - { - if (foundflats->speed) // it is an animated flat - { - // update the levelflat texture number - if ((foundflats->type == LEVELFLAT_TEXTURE) && (foundflats->u.texture.basenum != -1)) - foundflats->u.texture.num = foundflats->u.texture.basenum + ((leveltime/foundflats->speed + foundflats->animseq) % foundflats->numpics); - // update the levelflat lump number - else if ((foundflats->type == LEVELFLAT_FLAT) && (foundflats->u.flat.baselumpnum != LUMPERROR)) - foundflats->u.flat.lumpnum = foundflats->u.flat.baselumpnum + ((leveltime/foundflats->speed + foundflats->animseq) % foundflats->numpics); - } - } } // -// Floor over floors (FOFs), 3Dfloors, 3Dblocks, fake floors (ffloors), rovers, or whatever you want to call them +// 3D floors // /** Gets the ID number for a 3Dfloor in its target sector. diff --git a/src/p_spec.h b/src/p_spec.h index 9b247ab7f..a3fba69ab 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -526,9 +526,6 @@ void P_StartQuake(fixed_t intensity, tic_t time); // at game start void P_InitPicAnims(void); -// at map load (sectors) -void P_SetupLevelFlatAnims(void); - // at map load void P_InitSpecials(void); void P_ApplyFlatAlignment(sector_t* sector, angle_t flatangle, fixed_t xoffs, fixed_t yoffs, boolean floor, boolean ceiling); diff --git a/src/r_picformats.c b/src/r_picformats.c index c382bcbc0..db33c33d6 100644 --- a/src/r_picformats.c +++ b/src/r_picformats.c @@ -764,7 +764,7 @@ void *Picture_TextureToFlat(size_t trickytex) R_CheckTextureCache(tex); // Allocate the flat - flatsize = (texture->width * texture->height); + flatsize = texture->width * texture->height; converted = Z_Malloc(flatsize, PU_STATIC, NULL); memset(converted, TRANSPARENTPIXEL, flatsize); diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 87a4fd308..61be014f9 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1118,39 +1118,32 @@ void R_DrawSinglePlane(drawspandata_t *ds, visplane_t *pl, boolean allow_paralle ds->currentplane = pl; levelflat = &levelflats[pl->picnum]; - /* :james: */ - type = levelflat->type; - switch (type) - { - case LEVELFLAT_NONE: - return; - case LEVELFLAT_FLAT: - ds->source = (UINT8 *)R_GetFlat(levelflat->u.flat.lumpnum); - R_CheckFlatLength(ds, W_LumpLength(levelflat->u.flat.lumpnum)); - // Raw flats always have dimensions that are powers-of-two numbers. - ds->powersoftwo = true; - break; - default: - ds->source = (UINT8 *)R_GetLevelFlat(ds, levelflat); - if (!ds->source) - return; - // Check if this texture or patch has power-of-two dimensions. - if (R_CheckPowersOfTwo(ds)) - R_CheckFlatLength(ds, ds->flatwidth * ds->flatheight); - } + // Get the texture + ds->source = (UINT8 *)R_GetFlat(levelflat); + if (ds->source == NULL) + return; - if (type == LEVELFLAT_TEXTURE) + texture_t *texture = textures[R_GetTextureNumForFlat(levelflat)]; + ds->flatwidth = texture->width; + ds->flatheight = texture->height; + + /*(if (R_CheckSolidColorFlat()) + ds->solidcolor = true; + else if (R_CheckPowersOfTwo()) { - // Get the span's brightmap. - // FLATS not supported, SORRY!! - INT32 bmNum = R_GetTextureBrightmap(levelflat->u.texture.num); - if (bmNum != 0) - { - // FIXME: This has the potential to read out of - // bounds if the brightmap texture is not as - // large as the flat. - ds->brightmap = (UINT8 *)R_GenerateTextureAsFlat(bmNum); - } + R_SetFlatVars(ds_flatwidth * ds_flatheight); + ds->powersoftwo = true; + }*/ + + // Get the span's brightmap. + // FLATS not supported, SORRY!! + INT32 bmNum = R_GetTextureBrightmap(levelflat->texture_id); + if (bmNum != 0) + { + // FIXME: This has the potential to read out of + // bounds if the brightmap texture is not as + // large as the flat. + ds->brightmap = (UINT8 *)R_GetFlatForTexture(bmNum); } if (!pl->slope // Don't mess with angle on slopes! We'll handle this ourselves later diff --git a/src/r_textures.c b/src/r_textures.c index 7232216d9..29f7747da 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -66,6 +66,7 @@ static struct { char name[9]; UINT32 hash; INT32 id; + UINT8 type; } *tidcache = NULL; static INT32 tidcachelen = 0; @@ -361,7 +362,8 @@ UINT8 *R_GenerateTexture(size_t texnum) texture = textures[texnum]; I_Assert(texture != NULL); - // allocate texture column offset lookup + if (texture->type == TEXTURETYPE_FLAT) + goto multipatch; // single-patch textures can have holes in them and may be used on // 2sided lines so they need to be kept in 'packed' format @@ -390,11 +392,8 @@ UINT8 *R_GenerateTexture(size_t texnum) realpatch = (softwarepatch_t *)pdata; #ifndef NO_PNG_LUMPS - if (Picture_IsLumpPNG((UINT8 *)realpatch, lumplength)) - goto multipatch; -#endif -#ifdef WALLFLATS - if (texture->type == TEXTURETYPE_FLAT) + // TODO: Is it worth converting those? + if (Picture_IsLumpPNG(pdata, lumplength)) goto multipatch; #endif @@ -495,7 +494,6 @@ UINT8 *R_GenerateTexture(size_t texnum) realpatch = (softwarepatch_t *)Picture_PNGConvert((UINT8 *)realpatch, PICFMT_DOOMPATCH, NULL, NULL, NULL, NULL, lumplength, NULL, 0); else #endif -#ifdef WALLFLATS if (texture->type == TEXTURETYPE_FLAT) { if (doremap) @@ -503,7 +501,6 @@ UINT8 *R_GenerateTexture(size_t texnum) realpatch = (softwarepatch_t *)Picture_Convert(PICFMT_FLAT, pdata, PICFMT_DOOMPATCH, 0, NULL, texture->width, texture->height, 0, 0, 0); } else -#endif { dealloc = false; if (doremap) @@ -562,29 +559,38 @@ done: return blocktex; } -// -// R_GenerateTextureAsFlat -// -// Generates a flat picture for a texture. -// -UINT8 *R_GenerateTextureAsFlat(size_t texnum) +UINT8 *R_GetFlatForTexture(size_t texnum) { texture_t *texture = textures[texnum]; - UINT8 *converted = NULL; - size_t size = (texture->width * texture->height); - // The flat picture for this texture was not generated yet. - if (!texture->flat) + if (texture->flat != NULL) + return texture->flat; + + if (texture->type == TEXTURETYPE_FLAT) { - // Well, let's do it now, then. - Z_Malloc(size, PU_LEVEL, &texture->flat); + texpatch_t *patch = &texture->patches[0]; + UINT16 wadnum = patch->wad; + lumpnum_t lumpnum = patch->lump; + UINT8 *pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); - // Picture_TextureToFlat handles everything for us. - converted = (UINT8 *)Picture_TextureToFlat(texnum); - M_Memcpy(texture->flat, converted, size); - Z_Free(converted); +#ifndef NO_PNG_LUMPS + size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum); + if (Picture_IsLumpPNG(pdata, lumplength)) + { + texture->flat = Picture_PNGConvert(pdata, PICFMT_FLAT, NULL, NULL, NULL, NULL, lumplength, NULL, 0); + Z_Free(pdata); + } + else +#endif + texture->flat = pdata; + + return texture->flat; } + texture->flat = (UINT8 *)Picture_TextureToFlat(texnum); + + flatmemory += texture->width + texture->height; + return texture->flat; } @@ -935,96 +941,26 @@ UINT8 *R_GetBrightmapColumn(fixed_t tex, INT32 col) return texturebrightmapcache[tex] + LONG(texturecolumnofs[tex][wrap_column(tex, col)]); } -void *R_GetFlat(lumpnum_t flatlumpnum) +INT32 R_GetTextureNumForFlat(levelflat_t *levelflat) { - // FIXME: checking this every time a flat is fetched for drawing is stupid... - // sadly they are not cached anywhere else so i have no choice - boolean doremap = W_NeedPaletteRemap(flatlumpnum, false); - void *flat = W_CacheLumpNum(flatlumpnum, PU_LEVEL); - if (doremap) - R_DoPaletteRemapFlat(flat, W_LumpLength(flatlumpnum)); - return flat; + return texturetranslation[levelflat->texture_id]; } -// -// R_GetLevelFlat -// -// If needed, convert a texture or patch to a flat. -// -void *R_GetLevelFlat(drawspandata_t* ds, levelflat_t *levelflat) +void *R_GetFlat(levelflat_t *levelflat) { - boolean isleveltexture = (levelflat->type == LEVELFLAT_TEXTURE); - texture_t *texture = (isleveltexture ? textures[levelflat->u.texture.num] : NULL); - boolean texturechanged = (isleveltexture ? (levelflat->u.texture.num != levelflat->u.texture.lastnum) : false); - UINT8 *flatdata = NULL; + if (levelflat->type == LEVELFLAT_NONE) + return NULL; - // Check if the texture changed. - if (isleveltexture && (!texturechanged)) - { - if (texture->flat) - { - flatdata = texture->flat; - ds->flatwidth = texture->width; - ds->flatheight = texture->height; - texturechanged = false; - } - else - texturechanged = true; - } + // FIXME: checking this every time a flat is fetched for drawing is stupid... + // sadly they are not cached anywhere else so i have no choice + /*boolean doremap = W_NeedPaletteRemap(flatlumpnum, false); + void *flat = W_CacheLumpNum(flatlumpnum, PU_LEVEL); + if (doremap) + R_DoPaletteRemapFlat(flat, W_LumpLength(levelflat->texture_id)); + return flat;*/ - // If the texture changed, or the flat wasn't generated, convert. - if (levelflat->picture == NULL || texturechanged) - { - // Level texture - if (isleveltexture) - { - levelflat->picture = R_GenerateTextureAsFlat(levelflat->u.texture.num); - ds->flatwidth = levelflat->width = texture->width; - ds->flatheight = levelflat->height = texture->height; - } - else - { -#ifndef NO_PNG_LUMPS - if (levelflat->type == LEVELFLAT_PNG) - { - INT32 pngwidth, pngheight; - - levelflat->picture = Picture_PNGConvert(W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_LEVEL), PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0); - levelflat->width = (UINT16)pngwidth; - levelflat->height = (UINT16)pngheight; - - ds->flatwidth = levelflat->width; - ds->flatheight = levelflat->height; - } - else -#endif - if (levelflat->type == LEVELFLAT_PATCH) - { - UINT8 *converted; - size_t size; - softwarepatch_t *patch = W_CacheLumpNum(levelflat->u.flat.lumpnum, PU_LEVEL); - - levelflat->width = ds->flatwidth = SHORT(patch->width); - levelflat->height = ds->flatheight = SHORT(patch->height); - - levelflat->picture = Z_Malloc(levelflat->width * levelflat->height, PU_LEVEL, NULL); - converted = Picture_FlatConvert(PICFMT_DOOMPATCH, patch, PICFMT_FLAT, 0, &size, levelflat->width, levelflat->height, SHORT(patch->topoffset), SHORT(patch->leftoffset), 0); - M_Memcpy(levelflat->picture, converted, size); - Z_Free(converted); - } - } - } - else - { - ds->flatwidth = levelflat->width; - ds->flatheight = levelflat->height; - } - - levelflat->u.texture.lastnum = levelflat->u.texture.num; - - if (flatdata == NULL) - flatdata = levelflat->picture; - return flatdata; + // FIXME: How do I convert above for new format. + return R_GetFlatForTexture(R_GetTextureNumForFlat(levelflat)); } // @@ -1178,7 +1114,6 @@ void R_FlushTextureCache(void) int R_CountTexturesInTEXTURESLump(UINT16 wadNum, UINT16 lumpNum); void R_ParseTEXTURESLump(UINT16 wadNum, UINT16 lumpNum, INT32 *index); -#ifdef WALLFLATS static INT32 Rloadflats (INT32 i, INT32 w) { @@ -1188,7 +1123,6 @@ Rloadflats (INT32 i, INT32 w) texpatch_t *patch; UINT8 header[PNG_HEADER_SIZE]; - // Yes if (wadfiles[w]->type == RET_PK3) { texstart = W_CheckNumForFolderStartPK3("flats/", (UINT16)w, 0); @@ -1207,8 +1141,6 @@ Rloadflats (INT32 i, INT32 w) { UINT16 wadnum = (UINT16)w; lumpnum_t lumpnum = texstart + j; - size_t lumplength; - size_t flatsize = 0; if (wadfiles[w]->type == RET_PK3) { @@ -1216,10 +1148,8 @@ Rloadflats (INT32 i, INT32 w) continue; // If it is then SKIP IT } - W_ReadLumpHeaderPwad(wadnum, lumpnum, header, sizeof header, 0); - lumplength = W_LumpLengthPwad(wadnum, lumpnum); - - flatsize = R_FlatDimensionsFromLumpSize(lumplength); + size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum); + size_t flatsize = R_FlatDimensionsFromLumpSize(lumplength); //CONS_Printf("\n\"%s\" is a flat, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),flatsize,flatsize); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); @@ -1229,6 +1159,8 @@ Rloadflats (INT32 i, INT32 w) texture->hash = quickncasehash(texture->name, 8); #ifndef NO_PNG_LUMPS + W_ReadLumpHeaderPwad(wadnum, lumpnum, header, sizeof header, 0); + if (Picture_IsLumpPNG(header, lumplength)) { UINT8 *flatlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); @@ -1264,7 +1196,6 @@ Rloadflats (INT32 i, INT32 w) return i; } -#endif/*WALLFLATS*/ #define TX_START "TX_START" #define TX_END "TX_END" @@ -1424,9 +1355,7 @@ static INT32 R_CountTextures(UINT16 wadnum) // This system will allocate memory for all duplicate/patched textures even if it never uses them, // but the alternative is to spend a ton of time checking and re-checking all previous entries just to skip any potentially patched textures. -#ifdef WALLFLATS count += count_range("F_START", "F_END", "flats/", wadnum); -#endif // Count the textures from TEXTURES lumps texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", wadnum, 0); @@ -1508,9 +1437,7 @@ void R_UpdateTextureBrightmap(INT32 tx, INT32 bm) static INT32 R_DefineTextures(INT32 i, UINT16 w) { -#ifdef WALLFLATS i = Rloadflats(i, w); -#endif return Rloadtextures(i, w); } @@ -2044,56 +1971,6 @@ static void PaletteTextureHack(const char **name) } } -// Search for flat name. -lumpnum_t R_GetFlatNumForName(const char *name) -{ - INT32 i; - lumpnum_t lump; - lumpnum_t start; - lumpnum_t end; - - PaletteTextureHack(&name); - - // Scan wad files backwards so patched flats take preference. - for (i = numwadfiles - 1; i >= 0; i--) - { - switch (wadfiles[i]->type) - { - case RET_WAD: - if ((start = W_CheckNumForMarkerStartPwad("F_START", (UINT16)i, 0)) == INT16_MAX) - { - if ((start = W_CheckNumForMarkerStartPwad("FF_START", (UINT16)i, 0)) == INT16_MAX) - continue; - else if ((end = W_CheckNumForNamePwad("FF_END", (UINT16)i, start)) == INT16_MAX) - continue; - } - else - if ((end = W_CheckNumForNamePwad("F_END", (UINT16)i, start)) == INT16_MAX) - continue; - break; - case RET_PK3: - if ((start = W_CheckNumForFolderStartPK3("Flats/", i, 0)) == INT16_MAX) - continue; - if ((end = W_CheckNumForFolderEndPK3("Flats/", i, start)) == INT16_MAX) - continue; - break; - default: - continue; - } - - // Now find lump with specified name in that range. - lump = W_CheckNumForNamePwad(name, (UINT16)i, start); - if (lump < end) - { - lump += (i<<16); // found it, in our constraints - break; - } - lump = LUMPERROR; - } - - return lump; -} - void R_ClearTextureNumCache(boolean btell) { if (tidcache) @@ -2104,6 +1981,20 @@ void R_ClearTextureNumCache(boolean btell) tidcachelen = 0; } +static void AddTextureToCache(const char *name, UINT32 hash, INT32 id, UINT8 type) +{ + tidcachelen++; + Z_Realloc(tidcache, tidcachelen * sizeof(*tidcache), PU_STATIC, &tidcache); + strncpy(tidcache[tidcachelen-1].name, name, 8); + tidcache[tidcachelen-1].name[8] = '\0'; +#ifndef ZDEBUG + CONS_Debug(DBG_SETUP, "texture #%s: %s\n", sizeu1(tidcachelen), tidcache[tidcachelen-1].name); +#endif + tidcache[tidcachelen-1].hash = hash; + tidcache[tidcachelen-1].id = id; + tidcache[tidcachelen-1].type = type; +} + // // R_CheckTextureNumForName // @@ -2126,18 +2017,10 @@ INT32 R_CheckTextureNumForName(const char *name) if (tidcache[i].hash == hash && !strncasecmp(tidcache[i].name, name, 8)) return tidcache[i].id; - // Need to parse the list backwards, so textures loaded more recently are used in lieu of ones loaded earlier - //for (i = 0; i < numtextures; i++) <- old - for (i = (numtextures - 1); i >= 0; i--) // <- new + for (i = numtextures - 1; i >= 0; i--) if (textures[i]->hash == hash && !strncasecmp(textures[i]->name, name, 8)) { - tidcachelen++; - Z_Realloc(tidcache, tidcachelen * sizeof(*tidcache), PU_STATIC, &tidcache); - strncpy(tidcache[tidcachelen-1].name, name, 8); - tidcache[tidcachelen-1].name[8] = '\0'; - CONS_Debug(DBG_SETUP, "texture #%s: %s\n", sizeu1(tidcachelen), tidcache[tidcachelen-1].name); - tidcache[tidcachelen-1].hash = hash; - tidcache[tidcachelen-1].id = i; + AddTextureToCache(name, hash, i, textures[i]->type); return i; } @@ -2170,3 +2053,28 @@ INT32 R_TextureNumForName(const char *name) } return i; } + +INT32 R_CheckFlatNumForName(const char *name) +{ + INT32 i; + UINT32 hash; + + // "NoTexture" marker. + if (name[0] == '-') + return 0; + + hash = quickncasehash(name, 8); + + for (i = 0; i < tidcachelen; i++) + if (tidcache[i].type == TEXTURETYPE_FLAT && tidcache[i].hash == hash && !strncasecmp(tidcache[i].name, name, 8)) + return tidcache[i].id; + + for (i = numtextures - 1; i >= 0; i--) + if (textures[i]->hash == hash && !strncasecmp(textures[i]->name, name, 8) && textures[i]->type == TEXTURETYPE_FLAT) + { + AddTextureToCache(name, hash, i, TEXTURETYPE_FLAT); + return i; + } + + return -1; +} diff --git a/src/r_textures.h b/src/r_textures.h index 44f1b3d61..650cb523c 100644 --- a/src/r_textures.h +++ b/src/r_textures.h @@ -44,9 +44,7 @@ enum TEXTURETYPE_UNKNOWN, TEXTURETYPE_SINGLEPATCH, TEXTURETYPE_COMPOSITE, -#ifdef WALLFLATS TEXTURETYPE_FLAT, -#endif }; // A texture_t describes a rectangular texture, @@ -86,7 +84,7 @@ void R_FlushTextureCache(void); // Texture generation UINT8 *R_GenerateTexture(size_t texnum); -UINT8 *R_GenerateTextureAsFlat(size_t texnum); +UINT8 *R_GetFlatForTexture(size_t texnum); UINT8 *R_GenerateTextureBrightmap(size_t texnum); INT32 R_GetTextureNum(INT32 texnum); INT32 R_GetTextureBrightmap(INT32 texnum); @@ -98,10 +96,11 @@ void R_DoPaletteRemapPatch(softwarepatch_t *patch, size_t size); void R_DoPaletteRemapFlat(UINT8 *data, size_t size); // Retrieve texture data. -void *R_GetLevelFlat(drawspandata_t* ds, levelflat_t *levelflat); UINT8 *R_GetColumn(fixed_t tex, INT32 col); UINT8 *R_GetBrightmapColumn(fixed_t tex, INT32 col); -void *R_GetFlat(lumpnum_t flatnum); +void *R_GetFlat(levelflat_t *levelflat); + +INT32 R_GetTextureNumForFlat(levelflat_t *levelflat); boolean R_CheckPowersOfTwo(drawspandata_t* ds); void R_CheckFlatLength(drawspandata_t* ds, size_t size); @@ -111,7 +110,7 @@ void R_UpdateTextureBrightmap(INT32 tx, INT32 bm); // Returns the texture number for the texture name. INT32 R_TextureNumForName(const char *name); INT32 R_CheckTextureNumForName(const char *name); -lumpnum_t R_GetFlatNumForName(const char *name); +INT32 R_CheckFlatNumForName(const char *name); extern INT32 numtextures; From 6874f7ca70f6e351403f0a4d33e22232f9f452e5 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 25 May 2025 00:48:25 -0400 Subject: [PATCH 02/11] Fix brightmap overlays being drawn instead of regular texture: --- src/hardware/hw_cache.c | 2 ++ src/r_plane.cpp | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 7da9716c8..15c726a7c 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -1001,6 +1001,8 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) memcpy(Z_Malloc(size, PU_HWRCACHE, &grMipmap->data), R_GetFlatForTexture(brightmapnum), size); } + grtex->mipmap.flags |= TF_BRIGHTMAP; + if (!grMipmap->downloaded) HWD.pfnSetTexture(&grtex->mipmap); diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 61be014f9..cc9088256 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1136,7 +1136,6 @@ void R_DrawSinglePlane(drawspandata_t *ds, visplane_t *pl, boolean allow_paralle }*/ // Get the span's brightmap. - // FLATS not supported, SORRY!! INT32 bmNum = R_GetTextureBrightmap(levelflat->texture_id); if (bmNum != 0) { From c83d5cebd4ff4672f7f4f5d8883b9c1982764bd6 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 25 May 2025 02:01:33 -0400 Subject: [PATCH 03/11] AAAAAA I'll be honest what am I doing??? --- src/hardware/hw_cache.c | 7 +++++++ src/p_setup.c | 6 ++++-- src/p_setup.h | 1 + src/r_textures.c | 9 +++++---- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 15c726a7c..2d65d6511 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -991,6 +991,13 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) if (!grMipmap->data && !grMipmap->downloaded) { + UINT8 *colormap = colormaps; + + if (!noencoremap && encoremap) + { + colormap += COLORMAP_REMAPOFFSET; + } + grMipmap->format = GL_TEXFMT_P_8; grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; diff --git a/src/p_setup.c b/src/p_setup.c index 43c239f08..4777a78d5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -532,7 +532,6 @@ levelflat_t *foundflats; //SoM: Other files want this info. size_t P_PrecacheLevelFlats(void) { - lumpnum_t lump; size_t i; //SoM: 4/18/2000: New flat code to make use of levelflats. @@ -581,6 +580,7 @@ Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize) // Look for a flat int texturenum = R_CheckFlatNumForName(levelflat->name); + lumpnum_t texturelump = W_CheckNumForName(levelflat->name); if (texturenum <= 0) { // If we can't find a flat, try looking for a texture! @@ -588,7 +588,8 @@ Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize) if (texturenum <= 0) { // Use "not found" texture - texturenum = R_CheckTextureNumForName("REDWALL"); + texturenum = R_CheckTextureNumForName(MISSING_TEXTURE); + texturelump = W_CheckNumForName(MISSING_TEXTURE); // Give up? if (texturenum <= 0) @@ -600,6 +601,7 @@ Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize) } levelflat->texture_id = texturenum; + levelflat->lump = texturelump; levelflat->terrain = K_GetTerrainForTextureName(levelflat->name); diff --git a/src/p_setup.h b/src/p_setup.h index c7c438d3d..b1cea67db 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -66,6 +66,7 @@ struct levelflat_t terrain_t *terrain; UINT8 type; INT32 texture_id; + lumpnum_t lump; }; extern size_t numlevelflats; diff --git a/src/r_textures.c b/src/r_textures.c index 29f7747da..3e99f4026 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -953,14 +953,15 @@ void *R_GetFlat(levelflat_t *levelflat) // FIXME: checking this every time a flat is fetched for drawing is stupid... // sadly they are not cached anywhere else so i have no choice - /*boolean doremap = W_NeedPaletteRemap(flatlumpnum, false); + lumpnum_t flatlumpnum = levelflat->lump; + boolean doremap = W_NeedPaletteRemap(flatlumpnum, false); void *flat = W_CacheLumpNum(flatlumpnum, PU_LEVEL); if (doremap) - R_DoPaletteRemapFlat(flat, W_LumpLength(levelflat->texture_id)); - return flat;*/ + R_DoPaletteRemapFlat(flat, W_LumpLength(flatlumpnum)); + return flat; // FIXME: How do I convert above for new format. - return R_GetFlatForTexture(R_GetTextureNumForFlat(levelflat)); + //return R_GetFlatForTexture(R_GetTextureNumForFlat(levelflat)); } // From b429a3e74cdf02f792f51cfe8f4a2249253a1264 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 25 May 2025 10:57:20 -0400 Subject: [PATCH 04/11] Repair removeflats commit to make it function correctly with colormapping --- src/hardware/hw_cache.c | 17 +++++++++-------- src/r_textures.c | 17 ++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 2d65d6511..25a950908 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -953,7 +953,9 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) if (!grMipmap->data && !grMipmap->downloaded) { + UINT8 *flat; UINT8 *colormap = colormaps; + UINT8 *converted; if (!noencoremap && encoremap) { @@ -967,7 +969,13 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) grMipmap->height = (UINT16)textures[texturenum]->height; size_t size = grMipmap->width * grMipmap->height; - memcpy(Z_Malloc(size, PU_HWRCACHE, &grMipmap->data), R_GetFlatForTexture(texturenum), size); + flat = Z_Malloc(size, PU_HWRCACHE, &grMipmap->data); + converted = (UINT8 *)Picture_TextureToFlat(texturenum); + for (size_t i = 0; i < size; i++) + { + flat[i] = colormap[converted[i]]; + } + Z_Free(converted); if (!noencoremap && encoremap) { @@ -991,13 +999,6 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) if (!grMipmap->data && !grMipmap->downloaded) { - UINT8 *colormap = colormaps; - - if (!noencoremap && encoremap) - { - colormap += COLORMAP_REMAPOFFSET; - } - grMipmap->format = GL_TEXFMT_P_8; grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; diff --git a/src/r_textures.c b/src/r_textures.c index 3e99f4026..28e60090e 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -571,7 +571,12 @@ UINT8 *R_GetFlatForTexture(size_t texnum) texpatch_t *patch = &texture->patches[0]; UINT16 wadnum = patch->wad; lumpnum_t lumpnum = patch->lump; + boolean doremap = W_NeedPaletteRemapPwad(wadnum, lumpnum, false); UINT8 *pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); + if (doremap) + { + R_DoPaletteRemapFlat(pdata, W_LumpLengthPwad(wadnum, lumpnum)); + } #ifndef NO_PNG_LUMPS size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum); @@ -951,17 +956,7 @@ void *R_GetFlat(levelflat_t *levelflat) if (levelflat->type == LEVELFLAT_NONE) return NULL; - // FIXME: checking this every time a flat is fetched for drawing is stupid... - // sadly they are not cached anywhere else so i have no choice - lumpnum_t flatlumpnum = levelflat->lump; - boolean doremap = W_NeedPaletteRemap(flatlumpnum, false); - void *flat = W_CacheLumpNum(flatlumpnum, PU_LEVEL); - if (doremap) - R_DoPaletteRemapFlat(flat, W_LumpLength(flatlumpnum)); - return flat; - - // FIXME: How do I convert above for new format. - //return R_GetFlatForTexture(R_GetTextureNumForFlat(levelflat)); + return R_GetFlatForTexture(R_GetTextureNumForFlat(levelflat)); } // From 41a62d7823a80318a20083674b60ea4ed06c6e70 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 25 May 2025 11:30:07 -0400 Subject: [PATCH 05/11] Do palette hack for flats as well --- src/r_textures.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/r_textures.c b/src/r_textures.c index 28e60090e..c9366688e 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -2059,6 +2059,8 @@ INT32 R_CheckFlatNumForName(const char *name) if (name[0] == '-') return 0; + PaletteTextureHack(&name); + hash = quickncasehash(name, 8); for (i = 0; i < tidcachelen; i++) From fbea771486e928dea2056ce9eef929cf0783981a Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Mon, 15 Jan 2024 02:47:03 -0300 Subject: [PATCH 06/11] Cleanup R_GetFlatForTexture --- src/r_textures.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/r_textures.c b/src/r_textures.c index c9366688e..c1f1f7b9d 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -561,11 +561,14 @@ done: UINT8 *R_GetFlatForTexture(size_t texnum) { - texture_t *texture = textures[texnum]; + if (texnum >= (unsigned)numtextures) + return NULL; + texture_t *texture = textures[texnum]; if (texture->flat != NULL) return texture->flat; + // Special case: Textures that are flats don't need to be converted FROM a texture INTO a flat. if (texture->type == TEXTURETYPE_FLAT) { texpatch_t *patch = &texture->patches[0]; @@ -588,13 +591,11 @@ UINT8 *R_GetFlatForTexture(size_t texnum) else #endif texture->flat = pdata; - - return texture->flat; } + else + texture->flat = (UINT8 *)Picture_TextureToFlat(texnum); - texture->flat = (UINT8 *)Picture_TextureToFlat(texnum); - - flatmemory += texture->width + texture->height; + flatmemory += texture->width * texture->height; return texture->flat; } From fc03c880fbaf285e6243188dcf5679f656d3e083 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Sun, 25 May 2025 18:07:25 +0200 Subject: [PATCH 07/11] Fix flat corruption (from lacto's feffdb37) --- src/r_textures.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/r_textures.c b/src/r_textures.c index c1f1f7b9d..eb7abc5d9 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -576,21 +576,25 @@ UINT8 *R_GetFlatForTexture(size_t texnum) lumpnum_t lumpnum = patch->lump; boolean doremap = W_NeedPaletteRemapPwad(wadnum, lumpnum, false); UINT8 *pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); + size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum); if (doremap) { R_DoPaletteRemapFlat(pdata, W_LumpLengthPwad(wadnum, lumpnum)); } #ifndef NO_PNG_LUMPS - size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum); if (Picture_IsLumpPNG(pdata, lumplength)) - { texture->flat = Picture_PNGConvert(pdata, PICFMT_FLAT, NULL, NULL, NULL, NULL, lumplength, NULL, 0); - Z_Free(pdata); - } else #endif - texture->flat = pdata; + { + texture->flat = Z_Malloc(lumplength, PU_STATIC, NULL); + memcpy(texture->flat, pdata, lumplength); + } + + Z_SetUser(texture->flat, &texture->flat); + + Z_Free(pdata); } else texture->flat = (UINT8 *)Picture_TextureToFlat(texnum); @@ -1104,7 +1108,10 @@ void R_FlushTextureCache(void) if (numtextures) for (i = 0; i < numtextures; i++) + { + Z_Free(textures[i]->flat); Z_Free(texturecache[i]); + } } // Need these prototypes for later; defining them here instead of r_textures.h so they're "private" From 2642e8d9727637633139e6346dafc2bb4c640fbf Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Sun, 25 May 2025 18:18:21 +0200 Subject: [PATCH 08/11] Get flat palremap working again --- src/p_setup.c | 3 --- src/p_setup.h | 1 - src/r_textures.c | 8 +++----- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 4777a78d5..234f8460d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -580,7 +580,6 @@ Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize) // Look for a flat int texturenum = R_CheckFlatNumForName(levelflat->name); - lumpnum_t texturelump = W_CheckNumForName(levelflat->name); if (texturenum <= 0) { // If we can't find a flat, try looking for a texture! @@ -589,7 +588,6 @@ Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize) { // Use "not found" texture texturenum = R_CheckTextureNumForName(MISSING_TEXTURE); - texturelump = W_CheckNumForName(MISSING_TEXTURE); // Give up? if (texturenum <= 0) @@ -601,7 +599,6 @@ Ploadflat (levelflat_t *levelflat, const char *flatname, boolean resize) } levelflat->texture_id = texturenum; - levelflat->lump = texturelump; levelflat->terrain = K_GetTerrainForTextureName(levelflat->name); diff --git a/src/p_setup.h b/src/p_setup.h index b1cea67db..c7c438d3d 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -66,7 +66,6 @@ struct levelflat_t terrain_t *terrain; UINT8 type; INT32 texture_id; - lumpnum_t lump; }; extern size_t numlevelflats; diff --git a/src/r_textures.c b/src/r_textures.c index eb7abc5d9..26ae8650d 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -574,13 +574,8 @@ UINT8 *R_GetFlatForTexture(size_t texnum) texpatch_t *patch = &texture->patches[0]; UINT16 wadnum = patch->wad; lumpnum_t lumpnum = patch->lump; - boolean doremap = W_NeedPaletteRemapPwad(wadnum, lumpnum, false); UINT8 *pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum); - if (doremap) - { - R_DoPaletteRemapFlat(pdata, W_LumpLengthPwad(wadnum, lumpnum)); - } #ifndef NO_PNG_LUMPS if (Picture_IsLumpPNG(pdata, lumplength)) @@ -592,6 +587,9 @@ UINT8 *R_GetFlatForTexture(size_t texnum) memcpy(texture->flat, pdata, lumplength); } + if (W_NeedPaletteRemapPwad(wadnum, lumpnum, true)) + R_DoPaletteRemapFlat(texture->flat, lumplength); + Z_SetUser(texture->flat, &texture->flat); Z_Free(pdata); From 647bc08b3f832ee4c873b33bda8eb79ad06df7fe Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Sun, 25 May 2025 19:36:37 +0200 Subject: [PATCH 09/11] Fix chromakey in encore mode (+ cleanup) --- src/hardware/hw_cache.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 25a950908..54676f2f4 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -955,12 +955,6 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) { UINT8 *flat; UINT8 *colormap = colormaps; - UINT8 *converted; - - if (!noencoremap && encoremap) - { - colormap += COLORMAP_REMAPOFFSET; - } grMipmap->format = GL_TEXFMT_P_8; grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; @@ -969,20 +963,20 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) grMipmap->height = (UINT16)textures[texturenum]->height; size_t size = grMipmap->width * grMipmap->height; - flat = Z_Malloc(size, PU_HWRCACHE, &grMipmap->data); - converted = (UINT8 *)Picture_TextureToFlat(texturenum); - for (size_t i = 0; i < size; i++) - { - flat[i] = colormap[converted[i]]; - } - Z_Free(converted); + flat = Picture_TextureToFlat(texturenum); + Z_ChangeTag(flat, PU_HWRCACHE); + Z_SetUser(flat, &grMipmap->data); if (!noencoremap && encoremap) - { - grtex->mipmap.colormap = Z_Calloc(sizeof(*grtex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); - grtex->mipmap.colormap->source = colormaps + COLORMAP_REMAPOFFSET; - M_Memcpy(grtex->mipmap.colormap->data, colormaps + COLORMAP_REMAPOFFSET, 256); - } + colormap += COLORMAP_REMAPOFFSET; + + grtex->mipmap.colormap = Z_Calloc(sizeof(*grtex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); + grtex->mipmap.colormap->source = colormap; + M_Memcpy(grtex->mipmap.colormap->data, colormap, 256); + + for (size_t steppy = 0; steppy < size; steppy++) + if (flat[steppy] != HWR_PATCHES_CHROMAKEY_COLORINDEX) + flat[steppy] = grtex->mipmap.colormap->source[flat[steppy]]; } if (!grMipmap->downloaded) From f96c9e90952da97da8994f076d8ea755d480f1d0 Mon Sep 17 00:00:00 2001 From: GenericHeroGuy Date: Sun, 25 May 2025 19:51:06 +0200 Subject: [PATCH 10/11] Forgot why this is necessary --- src/r_textures.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/r_textures.c b/src/r_textures.c index 26ae8650d..1a191828f 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -574,6 +574,7 @@ UINT8 *R_GetFlatForTexture(size_t texnum) texpatch_t *patch = &texture->patches[0]; UINT16 wadnum = patch->wad; lumpnum_t lumpnum = patch->lump; + boolean doremap = W_NeedPaletteRemapPwad(wadnum, lumpnum, false); UINT8 *pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum); @@ -587,7 +588,7 @@ UINT8 *R_GetFlatForTexture(size_t texnum) memcpy(texture->flat, pdata, lumplength); } - if (W_NeedPaletteRemapPwad(wadnum, lumpnum, true)) + if (doremap) R_DoPaletteRemapFlat(texture->flat, lumplength); Z_SetUser(texture->flat, &texture->flat); From 8cfa0fa74ff3891c2c495f20007fe869d05cfb47 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 25 May 2025 14:00:41 -0400 Subject: [PATCH 11/11] Remove leftover flat animdef code --- src/p_spec.c | 85 ++++++++++++++++++++++++------------------------ src/r_textures.c | 1 + 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index bce69e446..06cda1111 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -66,17 +66,12 @@ mobj_t *skyboxcenterpnts[16]; // array of MT_SKYBOX centerpoint mobjs */ typedef struct { - SINT8 istexture; ///< ::true for a texture, ::false for a flat INT32 picnum; ///< The end flat number INT32 basepic; ///< The start flat number INT32 numpics; ///< Number of frames in the animation tic_t speed; ///< Number of tics for which each frame is shown } anim_t; -#if defined(_MSC_VER) -#pragma pack(1) -#endif - /** Animated texture definition. * Used for loading an ANIMDEFS lump from a wad. * @@ -91,13 +86,9 @@ typedef struct SINT8 istexture; ///< True for a texture, false for a flat. char endname[9]; ///< Name of the last frame, null-terminated. char startname[9]; ///< Name of the first frame, null-terminated. - INT32 speed ; ///< Number of tics for which each frame is shown. + INT32 speed; ///< Number of tics for which each frame is shown. } ATTRPACK animdef_t; -#if defined(_MSC_VER) -#pragma pack() -#endif - typedef struct { UINT32 count; @@ -142,17 +133,32 @@ static size_t maxanims; static animdef_t *animdefs = NULL; -// Increase the size of animdefs to make room for a new animation definition -static void GrowAnimDefs(void) -{ - maxanims++; - animdefs = (animdef_t *)Z_Realloc(animdefs, sizeof(animdef_t)*(maxanims + 1), PU_STATIC, NULL); -} - // A prototype; here instead of p_spec.h, so they're "private" void P_ParseANIMDEFSLump(INT32 wadNum, UINT16 lumpnum); void P_ParseAnimationDefintion(SINT8 istexture); +static boolean P_FindTextureForAnimation(anim_t *anim, animdef_t *animdef) +{ + if (R_CheckTextureNumForName(animdef->startname) == -1) + return false; + + anim->picnum = R_TextureNumForName(animdef->endname); + anim->basepic = R_TextureNumForName(animdef->startname); + + return true; +} + +static boolean P_FindFlatForAnimation(anim_t *anim, animdef_t *animdef) +{ + if (R_CheckFlatNumForName(animdef->startname) == -1) + return false; + + anim->picnum = R_CheckFlatNumForName(animdef->endname); + anim->basepic = R_CheckFlatNumForName(animdef->startname); + + return true; +} + /** Sets up texture and flat animations. * * Converts an ::animdef_t array loaded from a lump into @@ -207,37 +213,38 @@ void P_InitPicAnims(void) lastanim = anims; for (i = 0; animdefs[i].istexture != -1; i++) { - if (animdefs[i].istexture == 1) - { - if (R_CheckTextureNumForName(animdefs[i].startname) == -1) - continue; + animdef_t *animdef = &animdefs[i]; - lastanim->picnum = R_TextureNumForName(animdefs[i].endname); - lastanim->basepic = R_TextureNumForName(animdefs[i].startname); + // If this animation is for a texture, look for one first, THEN look for a flat + if (animdefs[i].istexture) + { + if (!P_FindTextureForAnimation(lastanim, animdef)) + { + if (!P_FindFlatForAnimation(lastanim, animdef)) + continue; + } } else { - if (R_CheckFlatNumForName(animdefs[i].startname) == -1) - continue; - - lastanim->picnum = R_CheckFlatNumForName(animdefs[i].endname); - lastanim->basepic = R_CheckFlatNumForName(animdefs[i].startname); + if (!P_FindFlatForAnimation(lastanim, animdef)) + { + if (!P_FindTextureForAnimation(lastanim, animdef)) + continue; + } } - lastanim->istexture = animdefs[i].istexture; lastanim->numpics = lastanim->picnum - lastanim->basepic + 1; if (lastanim->numpics < 2) { free(anims); I_Error("P_InitPicAnims: bad cycle from %s to %s", - animdefs[i].startname, animdefs[i].endname); + animdefs->startname, animdefs->endname); } - lastanim->speed = LONG(animdefs[i].speed); + lastanim->speed = animdef->speed; lastanim++; } - lastanim->istexture = -1; R_ClearTextureNumCache(false); // Clear animdefs now that we're done with it. @@ -362,7 +369,8 @@ void P_ParseAnimationDefintion(SINT8 istexture) if (i == maxanims) { // Increase the size to make room for the new animation definition - GrowAnimDefs(); + maxanims++; + animdefs = (animdef_t *)Z_Realloc(animdefs, sizeof(animdef_t)*(maxanims + 1), PU_STATIC, NULL); strncpy(animdefs[i].startname, animdefsToken, 9); } @@ -448,14 +456,6 @@ void P_ParseAnimationDefintion(SINT8 istexture) } animdefs[i].speed = animSpeed; Z_Free(animdefsToken); - - // Add it as a texture too - if (!istexture) - { - GrowAnimDefs(); - M_Memcpy(&animdefs[maxanims-1], &animdefs[i], sizeof(animdef_t)); - animdefs[maxanims-1].istexture = 1; - } } // @@ -6098,8 +6098,7 @@ void P_UpdateSpecials(void) for (INT32 i = 0; i < anim->numpics; i++) { INT32 pic = anim->basepic + ((leveltime/anim->speed + i) % anim->numpics); - if (anim->istexture) - texturetranslation[anim->basepic+i] = pic; + texturetranslation[anim->basepic+i] = pic; } } } diff --git a/src/r_textures.c b/src/r_textures.c index 1a191828f..d8c57b49d 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -2057,6 +2057,7 @@ INT32 R_TextureNumForName(const char *name) return i; } +// Like R_CheckTextureNumForName, but only looks in the flat namespace specifically. INT32 R_CheckFlatNumForName(const char *name) { INT32 i;