From 7256fb9d62b86f96edc757247f1d8c5604239ada Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 15:55:06 +0200 Subject: [PATCH 01/44] port srb2s patch refactor still needs all the new purge tags then we should hopefully be free of use after frees and everything --- src/d_main.c | 2 +- src/hardware/hw_cache.c | 255 ++++++++++++++++++++++------------------ src/hardware/hw_data.h | 15 +-- src/hardware/hw_draw.c | 79 +++++++------ src/hardware/hw_glob.h | 33 ++++-- src/hardware/hw_main.c | 68 +++++------ src/hardware/hw_main.h | 10 +- src/hardware/hw_md2.c | 174 ++++++++++++++++----------- src/p_setup.c | 17 ++- src/r_data.c | 33 ++++-- src/r_defs.h | 20 +++- src/r_patch.c | 159 ++++++++++++++++++++----- src/r_patch.h | 9 ++ src/r_segs.c | 2 +- src/r_things.c | 16 +-- src/v_video.c | 10 +- src/w_wad.c | 118 +++++++++++++------ src/w_wad.h | 19 ++- src/y_inter.c | 2 +- 19 files changed, 645 insertions(+), 396 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 39f354ba5..8c986a24e 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -733,7 +733,7 @@ void D_SRB2Loop(void) COM_ImmedExecute("cls;version"); if (rendermode == render_soft) - V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, (patch_t *)W_CacheLumpNum(W_GetNumForName("KARTKREW"), PU_CACHE), NULL); + V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, W_CachePatchNum(W_GetNumForName("KARTKREW"), PU_CACHE), NULL); I_FinishUpdate(); // page flip or blit buffer for (;;) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 5ba8655b8..6fef6d0a9 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -191,7 +191,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, // Draw each column to the block cache for (; ncols--; block += bpp, xfrac += xfracstep) { - patchcol = (const column_t *)((const UINT8 *)realpatch + LONG(realpatch->columnofs[xfrac>>FRACBITS])); + patchcol = (const column_t *)((const UINT8 *)realpatch->columns + (realpatch->columnofs[xfrac>>FRACBITS])); HWR_DrawColumnInCache(patchcol, block, mipmap, pblockheight, blockmodulo, @@ -205,7 +205,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 pblockheight, texture_t *texture, texpatch_t *patch, - const patch_t *realpatch) + const softwarepatch_t *realpatch) { INT32 x, x1, x2; INT32 col, ncols; @@ -313,7 +313,8 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe UINT8 *block; texture_t *texture; texpatch_t *patch; - patch_t *realpatch; + softwarepatch_t *realpatch; + UINT8 *pdata; INT32 blockwidth, blockheight, blocksize; INT32 i, idx; @@ -371,12 +372,12 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - realpatch = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + realpatch = (softwarepatch_t *)pdata; if (realpatch != NULL) { HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch); - //Z_ChangeTag(realpatch, PU_HWRCACHE_UNLOCKED); } } @@ -400,20 +401,11 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe // patch may be NULL if glMipmap has been initialised already and makebitmap is false void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap) { - // don't do it twice (like a cache) if (glMipmap->width == 0) { - // save the original patch header so that the GLPatch can be casted - // into a standard patch_t struct and the existing code can get the - // orginal patch dimensions and offsets. - glPatch->width = SHORT(patch->width); - glPatch->height = SHORT(patch->height); - glPatch->leftoffset = SHORT(patch->leftoffset); - glPatch->topoffset = SHORT(patch->topoffset); - glMipmap->width = glMipmap->height = 1; - while (glMipmap->width < glPatch->width) glMipmap->width <<= 1; - while (glMipmap->height < glPatch->height) glMipmap->height <<= 1; + while (glMipmap->width < patch->width) glMipmap->width <<= 1; + while (glMipmap->height < patch->height) glMipmap->height <<= 1; // no wrap around, no chroma key glMipmap->flags = 0; @@ -421,9 +413,8 @@ void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, bo // setup the texture info glMipmap->format = patchformat; - //glPatch->max_s = glPatch->max_t = 1.0f; - glPatch->max_s = (float)glPatch->width / (float)glMipmap->width; - glPatch->max_t = (float)glPatch->height / (float)glMipmap->height; + glPatch->max_s = (float)patch->width / (float)glMipmap->width; + glPatch->max_t = (float)patch->height / (float)glMipmap->height; } Z_Free(glMipmap->data); @@ -435,7 +426,7 @@ void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, bo HWR_DrawPatchInCache(glMipmap, glMipmap->width, glMipmap->height, - glPatch->width, glPatch->height, + patch->width, patch->height, patch); } } @@ -444,22 +435,58 @@ void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, bo // CACHING HANDLING // ================================================= -static size_t gl_numtextures; +static size_t gl_numtextures = 0; // Texture count static GLMapTexture_t *gl_textures; // For all textures -void HWR_InitTextureCache(void) +void HWR_FreeTextureData(patch_t *patch) { - gl_numtextures = 0; - gl_textures = NULL; + GLPatch_t *grPatch; + + if (!patch || !patch->hardware) + return; + + grPatch = patch->hardware; + + if (vid.glstate == VID_GL_LIBRARY_LOADED) + GL_DeleteTexture(grPatch->mipmap); + if (grPatch->mipmap->data) + Z_Free(grPatch->mipmap->data); } -// Callback function for HWR_FreeTextureCache. -static void FreeMipmapColormap(INT32 patchnum, void *patch) +void HWR_FreeTexture(patch_t *patch) { - GLPatch_t* const pat = patch; - (void)patchnum; //unused + if (!patch) + return; + + if (patch->hardware) + { + GLPatch_t *glPatch = patch->hardware; + + HWR_FreeTextureColormaps(patch); + + if (glPatch->mipmap) + { + HWR_FreeTextureData(patch); + Z_Free(glPatch->mipmap); + } + + Z_Free(patch->hardware); + } + + patch->hardware = NULL; +} + +// Called by HWR_FreePatchCache. +void HWR_FreeTextureColormaps(patch_t *patch) +{ + GLPatch_t *pat; // The patch must be valid, obviously + if (!patch) + return; + + pat = patch->hardware; + if (!pat) return; @@ -481,9 +508,6 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) // Set the first colormap to the one that comes after it. next = pat->mipmap->nextcolormap; - if (!next) - break; - pat->mipmap->nextcolormap = next->nextcolormap; // Free image data from memory. @@ -497,28 +521,51 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) } } -void HWR_FreeMipmapCache(void) +static void HWR_FreePatchCache(boolean freeall) { INT32 i; - // free references to the textures - GL_ClearMipMapCache(); - // free all hardware-converted graphics cached in the heap - // our gool is only the textures since user of the texture is the texture cache - Z_FreeTags(PU_HWRCACHE, PU_HWRCACHE); - Z_FreeTags(PU_HWRCACHE_UNLOCKED, PU_HWRCACHE_UNLOCKED); - - // Alam: free the Z_Blocks before freeing it's users - - // free all patch colormaps after each level: must be done after ClearMipMapCache! for (i = 0; i < numwadfiles; i++) - M_AATreeIterate(wadfiles[i]->hwrcache, FreeMipmapColormap); + { + INT32 j = 0; + for (; j < wadfiles[i]->numlumps; j++) + (freeall ? HWR_FreeTexture : HWR_FreeTextureColormaps)(wadfiles[i]->patchcache[j]); + } } -void HWR_FreeTextureCache(void) +// free all textures after each level +void HWR_ClearAllTextures(void) { // free references to the textures - HWR_FreeMipmapCache(); + GL_ClearMipMapCache(); + HWR_FreePatchCache(true); +} + +void HWR_FreeColormapCache(void) +{ + HWR_FreePatchCache(false); +} + +void HWR_InitMapTextures(void) +{ + gl_textures = NULL; +} + +static void FreeMapTexture(GLMapTexture_t *tex) +{ + GL_DeleteTexture(&tex->mipmap); + if (tex->mipmap.data) + Z_Free(tex->mipmap.data); +} + +void HWR_FreeMapTextures(void) +{ + size_t i; + + for (i = 0; i < gl_numtextures; i++) + { + FreeMapTexture(&gl_textures[i]); + } // now the heap don't have any 'user' pointing to our // texturecache info, we can free it @@ -702,7 +749,7 @@ static void HWR_PrecacheLevelTextures(void) static void HWR_PrecacheLevelSprites(void) { - GLPatch_t *spritepatch; + patch_t *spritepatch; char *spritepresent; size_t i, j, k; lumpnum_t lump; @@ -741,7 +788,7 @@ static void HWR_PrecacheLevelSprites(void) #define cacheang(a) {\ lump = sf->lumppat[a];\ - spritepatch = (GLPatch_t *)W_CachePatchNum(lump, PU_CACHE);\ + spritepatch = (patch_t *)W_CachePatchNum(lump, PU_CACHE);\ if (spritepatch != NULL)\ HWR_GetPatch(spritepatch);\ } @@ -782,11 +829,12 @@ void HWR_PrecacheLevel(void) HWR_PrecacheLevelSprites(); } -void HWR_LoadTextures(size_t pnumtextures) +void HWR_LoadMapTextures(size_t pnumtextures) { // we must free it since numtextures changed - HWR_FreeTextureCache(); + HWR_FreeMapTextures(); + // Why not Z_Malloc? gl_numtextures = pnumtextures; #ifdef GLENCORE gl_textures = calloc(pnumtextures, sizeof (*gl_textures)*2); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore) @@ -794,7 +842,7 @@ void HWR_LoadTextures(size_t pnumtextures) gl_textures = calloc(pnumtextures, sizeof (*gl_textures)); #endif if (gl_textures == NULL) - I_Error("HWR_LoadTextures: ran out of memory for OpenGL textures. Sad!"); + I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!"); } // -------------------------------------------------------------------------- @@ -812,15 +860,20 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) tex = 0; #endif } + + // Every texture in memory, stored in the + // hardware renderer's bit depth format. Wow! #ifdef GLENCORE gltex = &gl_textures[tex*2 + (encoremap && !noencore ? 0 : 1)]; #else gltex = &gl_textures[tex]; #endif + + // Generate texture if missing from the cache if (!gltex->mipmap.data && !gltex->mipmap.downloaded) HWR_GenerateTexture(tex, gltex, noencore); - // If hardware does not have the texture, then call pfnSetTexture to upload it + // If hardware does not have the texture, then call GL_SetTexture to upload it if (!gltex->mipmap.downloaded) GL_SetTexture(&gltex->mipmap); HWR_SetCurrentTexture(&gltex->mipmap); @@ -869,6 +922,7 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) pflatsize = 64; break; } + glMipmap->width = (UINT16)pflatsize; glMipmap->height = (UINT16)pflatsize; @@ -891,11 +945,13 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) { GLMipmap_t *glMipmap; + patch_t *patch; if (flatlumpnum == LUMPERROR) return; - glMipmap = HWR_GetCachedGLPatch(flatlumpnum)->mipmap; + patch = HWR_GetCachedGLPatch(flatlumpnum); + glMipmap = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap; glMipmap->colormap = colormaps; @@ -916,27 +972,16 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); } -// -// HWR_LoadMappedPatch(): replace the skin color of the sprite in cache -// : load it first in doom cache if not already -// -static void HWR_LoadMappedPatch(GLMipmap_t *glMipmap, GLPatch_t *glPatch) +// --------------------+ +// HWR_LoadPatchMipmap : Generates a patch into a mipmap, usually the mipmap inside the patch itself +// --------------------+ +static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) { + GLPatch_t *glPatch = patch->hardware; + if (!glMipmap->downloaded && !glMipmap->data) - { - patch_t *patch = glPatch->rawpatch; - if (!patch) - patch = W_CacheLumpNumPwad(glPatch->wadnum, glPatch->lumpnum, PU_STATIC); - HWR_MakePatch(patch, glPatch, glMipmap, true); - // You can't free rawpatch for some reason? - // (Obviously I can't, sprite rotation needs that...) - - if (!glPatch->rawpatch) - Z_Free(patch); - } - // If hardware does not have the texture, then call pfnSetTexture to upload it if (!glMipmap->downloaded) GL_SetTexture(glMipmap); @@ -949,46 +994,29 @@ static void HWR_LoadMappedPatch(GLMipmap_t *glMipmap, GLPatch_t *glPatch) // -----------------+ // HWR_GetPatch : Downloads a patch to the hardware cache and make it ready for use // -----------------+ -void HWR_GetPatch(GLPatch_t *glPatch) +void HWR_GetPatch(patch_t *patch) { - // is it in hardware cache - if (!glPatch->mipmap->downloaded && !glPatch->mipmap->data) - { - // load the software patch, PU_STATIC or the Z_Malloc for hardware patch will - // flush the software patch before the conversion! oh yeah I suffered - patch_t *ptr = glPatch->rawpatch; - if (!ptr) - ptr = W_CacheLumpNumPwad(glPatch->wadnum, glPatch->lumpnum, PU_STATIC); - - HWR_MakePatch(ptr, glPatch, glPatch->mipmap, true); - - // this is inefficient.. but the hardware patch in heap is purgeable so it should - // not fragment memory, and besides the REAL cache here is the hardware memory - if (!glPatch->rawpatch) - Z_Free(ptr); - } - - // If hardware does not have the texture, then call pfnSetTexture to upload it - if (!glPatch->mipmap->downloaded) - GL_SetTexture(glPatch->mipmap); - HWR_SetCurrentTexture(glPatch->mipmap); - - // The system-memory patch data can be purged now. - Z_ChangeTag(glPatch->mipmap->data, PU_HWRCACHE_UNLOCKED); + if (!patch->hardware) + Patch_CreateGL(patch); + HWR_LoadPatchMipmap(patch, ((GLPatch_t *)patch->hardware)->mipmap); } - // -------------------+ // HWR_GetMappedPatch : Same as HWR_GetPatch for sprite color // -------------------+ -void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap) +void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) { + GLPatch_t *glPatch; GLMipmap_t *glMipmap, *newMipmap; + if (!patch->hardware) + Patch_CreateGL(patch); + glPatch = patch->hardware; + if (colormap == colormaps || colormap == NULL) { - // Load the default (green) color in doom cache (temporary?) AND hardware cache - HWR_GetPatch(glPatch); + // Load the default (green) color in hardware cache + HWR_GetPatch(patch); return; } @@ -1000,7 +1028,7 @@ void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap) if (UNLIKELY(glMipmap->colormap == colormap)) { - HWR_LoadMappedPatch(glMipmap, glPatch); + HWR_LoadPatchMipmap(patch, glMipmap); return; } } @@ -1009,7 +1037,7 @@ void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap) //BP: WARNING: don't free it manually without clearing the cache of harware renderer // (it have a liste of mipmap) - // this malloc is cleared in HWR_FreeTextureCache + // this malloc is cleared in HWR_FreeColormapCache // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better newMipmap = calloc(1, sizeof (*newMipmap)); if (newMipmap == NULL) @@ -1017,7 +1045,7 @@ void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap) glMipmap->nextcolormap = newMipmap; newMipmap->colormap = colormap; - HWR_LoadMappedPatch(newMipmap, glPatch); + HWR_LoadPatchMipmap(patch, newMipmap); } void HWR_UnlockCachedPatch(GLPatch_t *glPatch) @@ -1028,24 +1056,20 @@ void HWR_UnlockCachedPatch(GLPatch_t *glPatch) Z_ChangeTag(glPatch->mipmap->data, PU_HWRCACHE_UNLOCKED); } -GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum) +patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum) { - aatree_t *hwrcache = wadfiles[wadnum]->hwrcache; - GLPatch_t *glPatch; - - if (!(glPatch = M_AATreeGet(hwrcache, lumpnum))) + lumpcache_t *lumpcache = wadfiles[wadnum]->patchcache; + if (!lumpcache[lumpnum]) { - glPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL); - glPatch->wadnum = wadnum; - glPatch->lumpnum = lumpnum; - glPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, NULL); - M_AATreeSet(hwrcache, lumpnum, glPatch); + void *ptr = Z_Calloc(sizeof(patch_t), PU_CACHE, &lumpcache[lumpnum]); + Patch_Create(NULL, 0, ptr); + Patch_AllocateHardwarePatch(ptr); } - return glPatch; + return (patch_t *)(lumpcache[lumpnum]); } -GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum) +patch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum) { return HWR_GetCachedGLPatchPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum)); } @@ -1139,8 +1163,11 @@ static void HWR_CacheFadeMask(GLMipmap_t *glMipmap, lumpnum_t fademasklumpnum) void HWR_GetFadeMask(lumpnum_t fademasklumpnum) { GLMipmap_t *glMipmap; + patch_t *patch; + + patch = HWR_GetCachedGLPatch(fademasklumpnum); + glMipmap = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap; - glMipmap = HWR_GetCachedGLPatch(fademasklumpnum)->mipmap; if (!glMipmap->downloaded && !glMipmap->data) HWR_CacheFadeMask(glMipmap, fademasklumpnum); diff --git a/src/hardware/hw_data.h b/src/hardware/hw_data.h index 1f16ebf2a..d7c11b2c2 100644 --- a/src/hardware/hw_data.h +++ b/src/hardware/hw_data.h @@ -62,24 +62,11 @@ struct GLMapTexture_s }; typedef struct GLMapTexture_s GLMapTexture_t; -// a cached patch as converted to hardware format, holding the original patch_t -// header so that the existing code can retrieve ->width, ->height as usual -// This is returned by W_CachePatchNum()/W_CachePatchName(), when rendermode -// is 'render_opengl'. Else it returns the normal patch_t data. +// a cached patch as converted to hardware format struct GLPatch_s { - // the 4 first fields come right away from the original patch_t - INT16 width; - INT16 height; - INT16 leftoffset; // pixels to the left of origin - INT16 topoffset; // pixels below the origin - // float max_s,max_t; - UINT16 wadnum; // the software patch lump num for when the hardware patch - UINT16 lumpnum; // was flushed, and we need to re-create it - void *rawpatch; // :^) GLMipmap_t *mipmap; - boolean notfound; // if the texture file was not found, mark it here (used in model texture loading) }; typedef struct GLPatch_s GLPatch_t; diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 70a2e6cc8..9a7f19995 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -71,10 +71,11 @@ static const float FLOATBASEVIDHEIGHT = (float)BASEVIDHEIGHT; // Notes : x,y : positions relative to the original Doom resolution // : textes(console+score) + menus + status bar // -----------------+ -void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) +void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) { FOutVector v[4]; FBITFIELD flags; + GLPatch_t *hwrPatch; // 3--2 // | /| @@ -87,6 +88,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) // make patch ready in hardware cache HWR_GetPatch(gpatch); + hwrPatch = ((GLPatch_t *)gpatch->hardware); switch (option & V_SCALEPATCHMASK) { @@ -106,17 +108,17 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) if (option & V_NOSCALESTART) sdupx = sdupy = 2.0f; - v[0].x = v[3].x = (x*sdupx-SHORT(gpatch->leftoffset)*pdupx)/vid.width - 1; - v[2].x = v[1].x = (x*sdupx+(SHORT(gpatch->width)-SHORT(gpatch->leftoffset))*pdupx)/vid.width - 1; - v[0].y = v[1].y = 1-(y*sdupy-SHORT(gpatch->topoffset)*pdupy)/vid.height; - v[2].y = v[3].y = 1-(y*sdupy+(SHORT(gpatch->height)-SHORT(gpatch->topoffset))*pdupy)/vid.height; + v[0].x = v[3].x = (x*sdupx-(gpatch->leftoffset)*pdupx)/vid.width - 1; + v[2].x = v[1].x = (x*sdupx+((gpatch->width)-(gpatch->leftoffset))*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdupy-(gpatch->topoffset)*pdupy)/vid.height; + v[2].y = v[3].y = 1-(y*sdupy+((gpatch->height)-(gpatch->topoffset))*pdupy)/vid.height; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; v[0].s = v[3].s = 0.0f; - v[2].s = v[1].s = gpatch->max_s; + v[2].s = v[1].s = hwrPatch->max_s; v[0].t = v[1].t = 0.0f; - v[2].t = v[3].t = gpatch->max_t; + v[2].t = v[3].t = hwrPatch->max_t; flags = PF_Translucent|PF_NoDepthTest; @@ -129,7 +131,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) GL_DrawPolygon(NULL, v, 4, flags); } -void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags) +void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags) { FOutVector v[4]; FBITFIELD flags; @@ -137,6 +139,7 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t float cy = FIXED_TO_FLOAT(y); UINT8 alphalevel = ((option & V_ALPHAMASK) >> V_ALPHASHIFT); UINT8 blendmode = ((bflags & V_BLENDMASK) >> V_BLENDSHIFT); + GLPatch_t *hwrPatch; // 3--2 // | /| @@ -156,6 +159,8 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t else HWR_GetMappedPatch(gpatch, colormap); + hwrPatch = ((GLPatch_t *)gpatch->hardware); + dupx = (float)vid.dupx; dupy = (float)vid.dupy; @@ -186,13 +191,13 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t // left offset if (option & V_FLIP) - offsetx = (float)(SHORT(gpatch->width) - SHORT(gpatch->leftoffset)) * fscalew; + offsetx = (float)((gpatch->width) - (gpatch->leftoffset)) * fscalew; else - offsetx = (float)SHORT(gpatch->leftoffset) * fscalew; + offsetx = (float)(gpatch->leftoffset) * fscalew; // top offset // TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!? - offsety = (float)SHORT(gpatch->topoffset) * fscaleh; + offsety = (float)(gpatch->topoffset) * fscaleh; if ((option & (V_NOSCALESTART|V_OFFSET)) == (V_NOSCALESTART|V_OFFSET)) // Multiply by dupx/dupy for crosshairs { @@ -220,17 +225,15 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t // if it's meant to cover the whole screen, black out the rest // cx and cy are possibly *slightly* off from float maths // This is done before here compared to software because we directly alter cx and cy to centre - if (cx >= -0.1f && cx <= 0.1f && SHORT(gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && SHORT(gpatch->height) == BASEVIDHEIGHT) + if (cx >= -0.1f && cx <= 0.1f && (gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && (gpatch->height) == BASEVIDHEIGHT) { - // Need to temporarily cache the real patch to get the colour of the top left pixel - patch_t *realpatch = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC); - const column_t *column = (const column_t *)((const UINT8 *)(realpatch) + LONG((realpatch)->columnofs[0])); + const column_t *column = (const column_t *)((const UINT8 *)(gpatch->columns) + (gpatch->columnofs[0])); + if (!column->topdelta) { const UINT8 *source = (const UINT8 *)(column) + 3; HWR_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0])); } - Z_Free(realpatch); } // centre screen if (fabsf(fvw - FLOATBASEVIDWIDTH * dupx) > 1.0E-36f) @@ -252,8 +255,8 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t } } - fwidth = (float)SHORT(gpatch->width) * fscalew * dupx; - fheight = (float)SHORT(gpatch->height) * fscaleh * dupy; + fwidth = (float)(gpatch->width) * fscalew * dupx; + fheight = (float)(gpatch->height) * fscaleh * dupy; // positions of the cx, cy, are between 0 and vid.width/vid.height now, we need them to be between -1 and 1 cx = -1.0f + (cx / (fvw / 2.0f)); @@ -274,17 +277,17 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t if (option & V_FLIP) { - v[0].s = v[3].s = gpatch->max_s; + v[0].s = v[3].s = hwrPatch->max_s; v[2].s = v[1].s = 0.0f; } else { v[0].s = v[3].s = 0.0f; - v[2].s = v[1].s = gpatch->max_s; + v[2].s = v[1].s = hwrPatch->max_s; } v[0].t = v[1].t = 0.0f; - v[2].t = v[3].t = gpatch->max_t; + v[2].t = v[3].t = hwrPatch->max_t; // clip it since it is used for bunny scroll in doom I if (blendmode) @@ -314,13 +317,14 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t GL_DrawPolygon(NULL, v, 4, flags); } -void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h) +void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h) { FOutVector v[4]; FBITFIELD flags; float cx = FIXED_TO_FLOAT(x); float cy = FIXED_TO_FLOAT(y); UINT8 alphalevel = ((option & V_ALPHAMASK) >> V_ALPHASHIFT); + GLPatch_t *hwrPatch; // 3--2 // | /| @@ -336,6 +340,7 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal // make patch ready in hardware cache HWR_GetPatch(gpatch); + hwrPatch = ((GLPatch_t *)gpatch->hardware); dupx = (float)vid.dupx; dupy = (float)vid.dupy; @@ -358,8 +363,8 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal dupx = dupy = (dupx < dupy ? dupx : dupy); fscale = FIXED_TO_FLOAT(pscale); - cy -= (float)SHORT(gpatch->topoffset) * fscale; - cx -= (float)SHORT(gpatch->leftoffset) * fscale; + cy -= (float)(gpatch->topoffset) * fscale; + cx -= (float)(gpatch->leftoffset) * fscale; if (!(option & V_NOSCALESTART)) { @@ -371,17 +376,15 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal // if it's meant to cover the whole screen, black out the rest // cx and cy are possibly *slightly* off from float maths // This is done before here compared to software because we directly alter cx and cy to centre - if (cx >= -0.1f && cx <= 0.1f && SHORT(gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && SHORT(gpatch->height) == BASEVIDHEIGHT) + if (cx >= -0.1f && cx <= 0.1f && (gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && (gpatch->height) == BASEVIDHEIGHT) { - // Need to temporarily cache the real patch to get the colour of the top left pixel - patch_t *realpatch = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC); - const column_t *column = (const column_t *)((const UINT8 *)(realpatch) + LONG((realpatch)->columnofs[0])); + const column_t *column = (const column_t *)((const UINT8 *)(gpatch->columns) + (gpatch->columnofs[0])); + if (!column->topdelta) { const UINT8 *source = (const UINT8 *)(column) + 3; HWR_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0])); } - Z_Free(realpatch); } // centre screen if (fabsf(fvw - FLOATBASEVIDWIDTH * dupx) > 1.0E-36f) @@ -412,11 +415,11 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal if (fheight > h - sy) fheight = h - sy; - if (fwidth > SHORT(gpatch->width)) - fwidth = SHORT(gpatch->width); + if (fwidth > (gpatch->width)) + fwidth = (gpatch->width); - if (fheight > SHORT(gpatch->height)) - fheight = SHORT(gpatch->height); + if (fheight > (gpatch->height)) + fheight = (gpatch->height); if (pscale != FRACUNIT) { @@ -446,10 +449,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].s = v[3].s = ((sx)/(float)SHORT(gpatch->width) )*gpatch->max_s; - v[2].s = v[1].s = ((w )/(float)SHORT(gpatch->width) )*gpatch->max_s; - v[0].t = v[1].t = ((sy)/(float)SHORT(gpatch->height))*gpatch->max_t; - v[2].t = v[3].t = ((h )/(float)SHORT(gpatch->height))*gpatch->max_t; + v[0].s = v[3].s = ((sx)/(float)(gpatch->width) )*hwrPatch->max_s; + v[2].s = v[1].s = ((w )/(float)(gpatch->width) )*hwrPatch->max_s; + v[0].t = v[1].t = ((sy)/(float)(gpatch->height))*hwrPatch->max_t; + v[2].t = v[3].t = ((h )/(float)(gpatch->height))*hwrPatch->max_t; flags = PF_Translucent|PF_NoDepthTest; @@ -660,7 +663,7 @@ void HWR_DrawViewBorder(INT32 clearlines) INT32 top, side; INT32 baseviewwidth, baseviewheight; INT32 basewindowx, basewindowy; - GLPatch_t *patch; + patch_t *patch; // if (gl_viewwidth == vid.width) // return; diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index e4659c0e6..31ecc7792 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -32,7 +32,7 @@ typedef struct gl_vissprite_s float scale; float spritexscale, spriteyscale; float spritexoffset, spriteyoffset; - GLPatch_t *gpatch; + patch_t *gpatch; boolean flip; UINT8 translucency; //alpha level 0-255 mobj_t *mobj; @@ -56,29 +56,38 @@ void HWR_FreeExtraSubsectors(void); // -------- // hw_cache.c // -------- -void HWR_InitTextureCache(void); -void HWR_FreeTextureCache(void); -void HWR_FreeMipmapCache(void); +void HWR_InitMapTextures(void); +void HWR_LoadMapTextures(size_t pnumtextures); +void HWR_FreeMapTextures(void); + +patch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump); +patch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum); + +void HWR_GetPatch(patch_t *gpatch); +void HWR_GetMappedPatch(patch_t *gpatch, const UINT8 *colormap); +void HWR_MakePatch(patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap); +void HWR_GetFadeMask(lumpnum_t fademasklumpnum); void HWR_PrecacheLevel(void); +GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore); void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap); // ^ some flats must NOT be remapped to encore, since we remap them as we cache them for ease, adding a toggle here seems wise. -GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore); -void HWR_GetPatch(GLPatch_t *gpatch); -void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap); -void HWR_MakePatch(patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap); +void HWR_FreeTexture(patch_t *patch); +void HWR_FreeTextureData(patch_t *patch); +void HWR_FreeTextureColormaps(patch_t *patch); +void HWR_ClearAllTextures(void); +void HWR_FreeColormapCache(void); void HWR_UnlockCachedPatch(GLPatch_t *gpatch); -void HWR_SetPalette(RGBA_t *palette); +RGBA_t *HWR_GetTexturePalette(void); +void HWR_SetPalette(RGBA_t *palette); void HWR_SetMapPalette(void); UINT32 HWR_CreateLightTable(UINT8 *lighttable); UINT32 HWR_GetLightTableID(extracolormap_t *colormap); void HWR_ClearLightTables(void); -GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump); -GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum); -void HWR_GetFadeMask(lumpnum_t fademasklumpnum); + // -------- // hw_draw.c diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 4e6f352ef..77e9e598a 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -821,7 +821,7 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) { FOutVector wallVerts[4]; wallsplat_t *splat; - GLPatch_t *gpatch; + patch_t *gpatch; fixed_t i; // seg bbox fixed_t segbbox[4]; @@ -3314,7 +3314,7 @@ static fixed_t HWR_OpaqueFloorAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t hei return floorz; } -static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, GLPatch_t *gpatch) +static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch) { float this_scale = 1.0f; FOutVector swallVerts[4]; @@ -3574,7 +3574,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) { FOutVector wallVerts[4]; FOutVector baseWallVerts[4]; // This is what the verts should end up as - GLPatch_t *gpatch; + patch_t *gpatch; + GLPatch_t *hwrpatch; FSurfaceInfo Surf; extracolormap_t *colormap; INT32 lightlevel; @@ -3596,7 +3597,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) fixed_t v1x, v1y, v2x, v2y; INT32 shader = SHADER_NONE; - gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE); + gpatch = spr->gpatch; + hwrpatch = (GLPatch_t *)(gpatch->hardware); // cache the patch in the graphics card memory //12/12/99: Hurdler: same comment as above (for md2) @@ -3630,25 +3632,25 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) if (spr->flip) { - baseWallVerts[0].s = baseWallVerts[3].s = gpatch->max_s; + baseWallVerts[0].s = baseWallVerts[3].s = hwrpatch->max_s; baseWallVerts[2].s = baseWallVerts[1].s = 0; } else { baseWallVerts[0].s = baseWallVerts[3].s = 0; - baseWallVerts[2].s = baseWallVerts[1].s = gpatch->max_s; + baseWallVerts[2].s = baseWallVerts[1].s = hwrpatch->max_s; } // flip the texture coords (look familiar?) if (spr->vflip) { - baseWallVerts[3].t = baseWallVerts[2].t = gpatch->max_t; + baseWallVerts[3].t = baseWallVerts[2].t = hwrpatch->max_t; baseWallVerts[0].t = baseWallVerts[1].t = 0; } else { baseWallVerts[3].t = baseWallVerts[2].t = 0; - baseWallVerts[0].t = baseWallVerts[1].t = gpatch->max_t; + baseWallVerts[0].t = baseWallVerts[1].t = hwrpatch->max_t; } // push it toward the camera to mitigate floor-clipping sprites @@ -3847,7 +3849,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) static void HWR_DrawSprite(gl_vissprite_t *spr) { FOutVector wallVerts[4]; - GLPatch_t *gpatch; // sprite patch converted to hardware + patch_t *gpatch; // sprite patch converted to hardware + GLPatch_t *hwrpatch; FSurfaceInfo Surf; FBITFIELD blend = 0; @@ -3871,7 +3874,8 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) // sure to do it the right way. So actually, we keep normal sprite // in memory and we add the md2 model if it exists for that sprite - gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE); + gpatch = spr->gpatch; + hwrpatch = (GLPatch_t *)(gpatch->hardware); // create the sprite billboard // @@ -3893,25 +3897,25 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) if (spr->flip) { - wallVerts[0].s = wallVerts[3].s = gpatch->max_s; + wallVerts[0].s = wallVerts[3].s = hwrpatch->max_s; wallVerts[2].s = wallVerts[1].s = 0; } else { wallVerts[0].s = wallVerts[3].s = 0; - wallVerts[2].s = wallVerts[1].s = gpatch->max_s; + wallVerts[2].s = wallVerts[1].s = hwrpatch->max_s; } // flip the texture coords (look familiar?) if (spr->vflip) { - wallVerts[3].t = wallVerts[2].t = gpatch->max_t; + wallVerts[3].t = wallVerts[2].t = hwrpatch->max_t; wallVerts[0].t = wallVerts[1].t = 0; } else { wallVerts[3].t = wallVerts[2].t = 0; - wallVerts[0].t = wallVerts[1].t = gpatch->max_t; + wallVerts[0].t = wallVerts[1].t = hwrpatch->max_t; } // cache the patch in the graphics card memory @@ -3997,7 +4001,8 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) { FBITFIELD blend = 0; FOutVector wallVerts[4]; - GLPatch_t *gpatch; // sprite patch converted to hardware + patch_t *gpatch; // sprite patch converted to hardware + GLPatch_t *hwrpatch; FSurfaceInfo Surf; INT32 shader = SHADER_NONE; @@ -4006,7 +4011,8 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) return; // cache sprite graphics - gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE); + gpatch = spr->gpatch; + hwrpatch = (GLPatch_t *)(gpatch->hardware); // create the sprite billboard // @@ -4027,10 +4033,10 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) HWR_RotateSpritePolyToAim(spr, wallVerts, true, false); wallVerts[0].s = wallVerts[3].s = 0; - wallVerts[2].s = wallVerts[1].s = gpatch->max_s; + wallVerts[2].s = wallVerts[1].s = hwrpatch->max_s; wallVerts[3].t = wallVerts[2].t = 0; - wallVerts[0].t = wallVerts[1].t = gpatch->max_t; + wallVerts[0].t = wallVerts[1].t = hwrpatch->max_t; // cache the patch in the graphics card memory //12/12/99: Hurdler: same comment as above (for md2) @@ -4894,10 +4900,10 @@ static void HWR_ProjectSprite(mobj_t *thing) #ifdef ROTSPRITE if (rotsprite != NULL) - vis->gpatch = (GLPatch_t *)rotsprite; + vis->gpatch = (patch_t *)rotsprite; else #endif - vis->gpatch = (GLPatch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE); + vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE); vis->mobj = thing; @@ -5065,7 +5071,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) vis->z2 = z2; vis->tz = tz; vis->dispoffset = 0; // Monster Iestyn: 23/11/15: HARDWARE SUPPORT AT LAST - vis->gpatch = (GLPatch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE); + vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE); vis->flip = flip; vis->mobj = (mobj_t *)thing; @@ -5542,9 +5548,9 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) if (splitscreen == 2 && player == &players[displayplayers[2]]) { // V_DrawPatchFill, but for the fourth screen only - GLPatch_t *gpatch = W_CachePatchName("SRB2BACK", PU_CACHE); + patch_t *gpatch = W_CachePatchName("SRB2BACK", PU_CACHE); INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - INT32 x, y, pw = SHORT(gpatch->width) * dupz, ph = SHORT(gpatch->height) * dupz; + INT32 x, y, pw = (gpatch->width) * dupz, ph = (gpatch->height) * dupz; for (x = vid.width>>1; x < vid.width; x += pw) { @@ -5697,17 +5703,6 @@ static void HWR_CheckForHorizonLines(void) void HWR_LoadLevel(void) { - // Lactozilla (December 8, 2019) - // Level setup used to free EVERY mipmap from memory. - // Even mipmaps that aren't related to level textures. - // Presumably, the hardware render code used to store textures as level data. - // Meaning, they had memory allocated and marked with the PU_LEVEL tag. - // Level textures are only reloaded after R_LoadTextures, which is - // when the texture list is loaded. - - // Sal: Unfortunately, NOT freeing them causes the dreaded Color Bug. - HWR_FreeMipmapCache(); - HWR_CreatePlanePolygons((INT32)numnodes - 1); // Build the sky dome @@ -5818,7 +5813,7 @@ void HWR_Startup(void) CONS_Printf("HWR_Startup()...\n"); textureformat = patchformat = GL_TEXFMT_RGBA; - HWR_InitTextureCache(); + HWR_InitMapTextures(); HWR_InitMD2(); gl_shadersavailable = HWR_InitShaders(); @@ -5910,8 +5905,7 @@ void HWR_Shutdown(void) { CONS_Printf("HWR_Shutdown()\n"); HWR_FreeExtraSubsectors(); - HWR_FreeMipmapCache(); - HWR_FreeTextureCache(); + HWR_FreeMapTextures(); GL_FlushScreenTextures(); #ifdef USE_FBO_OGL GL_Framebuffer_Disable(); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index ba093c6ca..b8d6ef939 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -85,9 +85,9 @@ extern ps_metric_t ps_hw_batchdrawtime; extern boolean gl_shadersavailable; // hw_draw.c -void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option); -void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags); -void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h); +void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option); +void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags); +void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h); void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color); void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 options); // Lat: separate flags from color since color needs to be an uint to work right. void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color); @@ -171,10 +171,6 @@ void HWR_ProcessSeg(void); // Sort of like GLWall::Process in GZDoom void HWR_CreatePlanePolygons(INT32 bspnum); extern boolean gl_maphasportals; -// hw_cache.c -void HWR_LoadTextures(size_t pnumtextures); -RGBA_t *HWR_GetTexturePalette(void); - // Console variables extern CV_PossibleValue_t glanisotropicmode_cons_t[]; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index f109ddd41..2a5643d53 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -366,43 +366,49 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h, // -----------------+ static void md2_loadTexture(md2_t *model) { - GLPatch_t *glpatch; + patch_t *patch; + GLPatch_t *glPatch = NULL; + const char *filename = model->filename; if (model->glpatch) { - glpatch = model->glpatch; - Z_Free(glpatch->mipmap->data); + patch = model->glpatch; + glPatch = (GLPatch_t *)(patch->hardware); + if (glPatch) + Z_Free(glPatch->mipmap->data); } else - { - glpatch = Z_Calloc(sizeof *glpatch, PU_HWRPATCHINFO, - &(model->glpatch)); - glpatch->mipmap = Z_Calloc(sizeof (GLMipmap_t), PU_HWRPATCHINFO, NULL); - } + model->glpatch = patch = Patch_Create(NULL, 0, NULL); - if (!glpatch->mipmap->downloaded && !glpatch->mipmap->data) + if (!patch->hardware) + Patch_AllocateHardwarePatch(patch); + + if (glPatch == NULL) + glPatch = (GLPatch_t *)(patch->hardware); + + if (!glPatch->mipmap->downloaded && !glPatch->mipmap->data) { int w = 0, h = 0; #ifdef HAVE_PNG - glpatch->mipmap->format = PNG_Load(filename, &w, &h, glpatch); - if (glpatch->mipmap->format == 0) + glPatch->mipmap->format = PNG_Load(filename, &w, &h, glPatch); + if (glPatch->mipmap->format == 0) #endif - glpatch->mipmap->format = PCX_Load(filename, &w, &h, glpatch); - if (glpatch->mipmap->format == 0) + glPatch->mipmap->format = PCX_Load(filename, &w, &h, glPatch); + if (glPatch->mipmap->format == 0) { - glpatch->notfound = true;// mark it so its not searched for again repeatedly + glPatch->notfound = true;// mark it so its not searched for again repeatedly return; } - glpatch->mipmap->downloaded = 0; - glpatch->mipmap->flags = 0; + glPatch->mipmap->downloaded = 0; + glPatch->mipmap->flags = 0; - glpatch->width = (INT16)w; - glpatch->height = (INT16)h; - glpatch->mipmap->width = (UINT16)w; - glpatch->mipmap->height = (UINT16)h; + patch->width = (INT16)w; + patch->height = (INT16)h; + glPatch->mipmap->width = (UINT16)w; + glPatch->mipmap->height = (UINT16)h; // for palette rendering, color cube is applied in post-processing instead of here if (!HWR_ShouldUsePaletteRendering()) @@ -410,7 +416,7 @@ static void md2_loadTexture(md2_t *model) UINT32 size; RGBA_t *image; // Lactozilla: Apply colour cube - image = glpatch->mipmap->data; + image = glPatch->mipmap->data; size = w*h; while (size--) { @@ -419,8 +425,8 @@ static void md2_loadTexture(md2_t *model) } } } - GL_SetTexture(glpatch->mipmap); - HWR_UnlockCachedPatch(glpatch); + GL_SetTexture(glPatch->mipmap); + HWR_UnlockCachedPatch(glPatch); } // -----------------+ @@ -428,49 +434,56 @@ static void md2_loadTexture(md2_t *model) // -----------------+ static void md2_loadBlendTexture(md2_t *model) { - GLPatch_t *glpatch; + patch_t *patch; + GLPatch_t *glPatch = NULL; + char *filename = Z_Malloc(strlen(model->filename)+7, PU_STATIC, NULL); + strcpy(filename, model->filename); FIL_ForceExtension(filename, "_blend.png"); if (model->blendglpatch) { - glpatch = model->blendglpatch; - Z_Free(glpatch->mipmap->data); + patch = model->blendglpatch; + glPatch = (GLPatch_t *)(patch->hardware); + if (glPatch) + Z_Free(glPatch->mipmap->data); } else - { - glpatch = Z_Calloc(sizeof *glpatch, PU_HWRPATCHINFO, - &(model->blendglpatch)); - glpatch->mipmap = Z_Calloc(sizeof (GLMipmap_t), PU_HWRPATCHINFO, NULL); - } + model->blendglpatch = patch = Patch_Create(NULL, 0, NULL); - if (!glpatch->mipmap->downloaded && !glpatch->mipmap->data) + if (!patch->hardware) + Patch_AllocateHardwarePatch(patch); + + if (glPatch == NULL) + glPatch = (GLPatch_t *)(patch->hardware); + + if (!glPatch->mipmap->downloaded && !glPatch->mipmap->data) { int w = 0, h = 0; #ifdef HAVE_PNG - glpatch->mipmap->format = PNG_Load(filename, &w, &h, glpatch); - if (glpatch->mipmap->format == 0) + glPatch->mipmap->format = PNG_Load(filename, &w, &h, glPatch); + if (glPatch->mipmap->format == 0) #endif - glpatch->mipmap->format = PCX_Load(filename, &w, &h, glpatch); - if (glpatch->mipmap->format == 0) + glPatch->mipmap->format = PCX_Load(filename, &w, &h, glPatch); + if (glPatch->mipmap->format == 0) { - glpatch->notfound = true;// mark it so its not searched for again repeatedly + glPatch->notfound = true;// mark it so its not searched for again repeatedly Z_Free(filename); return; } - glpatch->mipmap->downloaded = 0; - glpatch->mipmap->flags = 0; + glPatch->mipmap->downloaded = 0; + glPatch->mipmap->flags = 0; - glpatch->width = (INT16)w; - glpatch->height = (INT16)h; - glpatch->mipmap->width = (UINT16)w; - glpatch->mipmap->height = (UINT16)h; + patch->width = (INT16)w; + patch->height = (INT16)h; + glPatch->mipmap->width = (UINT16)w; + glPatch->mipmap->height = (UINT16)h; } - GL_SetTexture(glpatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary - HWR_UnlockCachedPatch(glpatch); + GL_SetTexture(glPatch->mipmap); // We do need to do this so that it can be cleared and knows to recreate it when necessary + HWR_UnlockCachedPatch(glPatch); Z_Free(filename); } @@ -682,8 +695,10 @@ spritemd2found: #define SETBRIGHTNESS(brightness,r,g,b) \ brightness = (UINT8)(((1063*(UINT32)(r))/5000) + ((3576*(UINT32)(g))/5000) + ((361*(UINT32)(b))/5000)) -static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, GLMipmap_t *glMipmap, INT32 skinnum, skincolors_t color) +static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMipmap_t *glMipmap, INT32 skinnum, skincolors_t color) { + GLPatch_t *hwrPatch = gpatch->hardware; + GLPatch_t *hwrBlendPatch = blendgpatch->hardware; UINT16 w = gpatch->width, h = gpatch->height; UINT32 size = w*h; RGBA_t *image, *blendimage, *cur, blendcolor; @@ -718,8 +733,8 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, cur = Z_Malloc(size*4, PU_HWRCACHE, &glMipmap->data); memset(cur, 0x00, size*4); - image = gpatch->mipmap->data; - blendimage = blendgpatch->mipmap->data; + image = hwrPatch->mipmap->data; + blendimage = hwrBlendPatch->mipmap->data; // TC_METALSONIC includes an actual skincolor translation, on top of its flashing. if (skinnum == TC_METALSONIC) @@ -1042,21 +1057,32 @@ skippixel: #undef SETBRIGHTNESS -static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT32 skinnum, const UINT8 *colormap, skincolors_t color) +static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 skinnum, const UINT8 *colormap, skincolors_t color) { // mostly copied from HWR_GetMappedPatch, hence the similarities and comment + GLPatch_t *glPatch = patch->hardware; + GLPatch_t *glBlendPatch = NULL; GLMipmap_t *glMipmap, *newMipmap; - if (colormap == colormaps || colormap == NULL) + + if (blendgpatch == NULL || colormap == colormaps || colormap == NULL) { // Don't do any blending - GL_SetTexture(gpatch->mipmap); + GL_SetTexture(glPatch->mipmap); + return; + } + + if ((blendgpatch && (glBlendPatch = blendgpatch->hardware) && glBlendPatch->mipmap->format) + && (patch->width != blendgpatch->width || patch->height != blendgpatch->height)) + { + // Blend image exists, but it's bad. + GL_SetTexture(glPatch->mipmap); return; } // search for the Mipmap // skip the first (no colormap translated) - for (glMipmap = gpatch->mipmap; glMipmap->nextcolormap; ) + for (glMipmap = glPatch->mipmap; glMipmap->nextcolormap; ) { glMipmap = glMipmap->nextcolormap; @@ -1084,7 +1110,7 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT glMipmap->nextcolormap = newMipmap; newMipmap->colormap = colormap; - HWR_CreateBlendedTexture(gpatch, blendgpatch, newMipmap, skinnum, color); + HWR_CreateBlendedTexture(patch, blendgpatch, newMipmap, skinnum, color); GL_SetTexture(newMipmap); Z_ChangeTag(newMipmap->data, PU_HWRCACHE_UNLOCKED); @@ -1154,7 +1180,8 @@ void HWR_DrawMD2(gl_vissprite_t *spr) // Look at HWR_ProjectSprite for more { - GLPatch_t *gpatch; + patch_t *gpatch, *blendgpatch; + GLPatch_t *hwrPatch = NULL, *hwrBlendPatch = NULL; INT32 durs = spr->mobj->state->tics; INT32 tics = spr->mobj->tics; //mdlframe_t *next = NULL; @@ -1264,21 +1291,33 @@ void HWR_DrawMD2(gl_vissprite_t *spr) } //Hurdler: arf, I don't like that implementation at all... too much crappy gpatch = md2->glpatch; - if (!gpatch || ((!gpatch->mipmap->format || !gpatch->mipmap->downloaded) && !gpatch->notfound)) - md2_loadTexture(md2); - gpatch = md2->glpatch; // Load it again, because it isn't being loaded into gpatch after md2_loadtexture... + if (gpatch) + hwrPatch = ((GLPatch_t *)gpatch->hardware); - if ((gpatch && gpatch->mipmap->format) // don't load the blend texture if the base texture isn't available - && (!md2->blendglpatch - || ((!((GLPatch_t *)md2->blendglpatch)->mipmap->format || !((GLPatch_t *)md2->blendglpatch)->mipmap->downloaded) - && !((GLPatch_t *)md2->blendglpatch)->notfound))) + if (!gpatch || !hwrPatch + || ((!hwrPatch->mipmap->format || !hwrPatch->mipmap->downloaded) && !hwrPatch->notfound)) + md2_loadTexture(md2); + + // Load it again, because it isn't being loaded into gpatch after md2_loadtexture... + gpatch = md2->glpatch; + if (gpatch) + hwrPatch = ((GLPatch_t *)gpatch->hardware); + + // Load blend texture + blendgpatch = md2->blendglpatch; + if (blendgpatch) + hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware); + + if ((gpatch && hwrPatch && hwrPatch->mipmap->format) // don't load the blend texture if the base texture isn't available + && (!blendgpatch || !hwrBlendPatch + || ((!hwrBlendPatch->mipmap->format || !hwrBlendPatch->mipmap->downloaded) && !hwrPatch->notfound))) md2_loadBlendTexture(md2); - if (gpatch && gpatch->mipmap->format) // else if meant that if a texture couldn't be loaded, it would just end up using something else's texture + if (gpatch && hwrPatch && hwrPatch->mipmap->format) // else if meant that if a texture couldn't be loaded, it would just end up using something else's texture { if ((skincolors_t)spr->mobj->color != SKINCOLOR_NONE && - md2->blendglpatch && ((GLPatch_t *)md2->blendglpatch)->mipmap->format - && gpatch->width == ((GLPatch_t *)md2->blendglpatch)->width && gpatch->height == ((GLPatch_t *)md2->blendglpatch)->height) + md2->blendglpatch && (hwrBlendPatch->mipmap->format + && gpatch->width == (blendgpatch->width && gpatch->height == (blendgpatch->height)))) { INT32 tcskinnum = TC_DEFAULT; if ((spr->mobj->flags & MF_BOSS) && (spr->mobj->flags2 & MF2_FRET) && (leveltime & 1)) // Bosses "flash" @@ -1303,19 +1342,18 @@ void HWR_DrawMD2(gl_vissprite_t *spr) } else tcskinnum = TC_DEFAULT; } - HWR_GetBlendedTexture(gpatch, (GLPatch_t *)md2->blendglpatch, tcskinnum, spr->colormap, (skincolors_t)spr->mobj->color); + HWR_GetBlendedTexture(gpatch, blendgpatch, tcskinnum, spr->colormap, (skincolors_t)spr->mobj->color); } else { // This is safe, since we know the texture has been downloaded - GL_SetTexture(gpatch->mipmap); + GL_SetTexture(hwrPatch->mipmap); } } else { // Sprite - gpatch = spr->gpatch; //gpatch = W_CachePatchNum(spr->patchlumpnum, PU_CACHE); - HWR_GetMappedPatch(gpatch, spr->colormap); + HWR_GetMappedPatch(spr->gpatch, spr->colormap); } if (spr->mobj->frame & FF_ANIMATE) diff --git a/src/p_setup.c b/src/p_setup.c index e6e46edd6..5d944e5e2 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3048,6 +3048,10 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) R_FlushTranslationColormapCache(); #ifdef HWRENDER + // Free GPU textures before freeing patches. + if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED)) + HWR_ClearAllTextures(); + // Delete light table textures HWR_ClearLightTables(); #endif @@ -3122,7 +3126,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) { HWR_FreeExtraSubsectors(); - // stuff like HWR_CreatePlanePolygons is called there + // Create plane polygons. HWR_LoadLevel(); } #endif @@ -3334,11 +3338,22 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (!devparm && digmreplaces) CONS_Printf(M_GetText("%s digital musics replaced\n"), sizeu1(digmreplaces)); +#ifdef HWRENDER + // Free GPU textures before freeing patches. + if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED)) + HWR_ClearAllTextures(); +#endif + // // search for sprite replacements // R_AddSpriteDefs(wadnum); + // Reload it all anyway, just in case they + // added some textures but didn't insert a + // TEXTURES/etc. list. + R_LoadTexturesPwad(wadnum); + // everything from MultiSetupWadFile until ST_Start was here originally // diff --git a/src/r_data.c b/src/r_data.c index 6b4bef3d0..ec84cf3bf 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -302,8 +302,8 @@ static UINT8 *R_GenerateTexture(size_t texnum) UINT8 *blocktex; texture_t *texture; texpatch_t *patch; - patch_t *realpatch; - int x, x1, x2, i; + softwarepatch_t *realpatch; + int x, x1, x2, i, width, height; size_t blocksize; column_t *patchcol; UINT8 *colofs; @@ -322,16 +322,21 @@ static UINT8 *R_GenerateTexture(size_t texnum) { boolean holey = false; patch = texture->patches; - realpatch = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + + realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); // Check the patch for holes. if (texture->width > SHORT(realpatch->width) || texture->height > SHORT(realpatch->height)) holey = true; + colofs = (UINT8 *)realpatch->columnofs; + for (x = 0; x < texture->width && !holey; x++) { column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2])); + INT32 topdelta, prevdelta = -1, y = 0; + while (col->topdelta != 0xff) { topdelta = col->topdelta; @@ -343,6 +348,7 @@ static UINT8 *R_GenerateTexture(size_t texnum) y = topdelta + col->length + 1; col = (column_t *)((UINT8 *)col + col->length + 4); } + if (y < texture->height) holey = true; // this texture is HOLEy! D: } @@ -375,7 +381,7 @@ static UINT8 *R_GenerateTexture(size_t texnum) texturememory += blocksize; block = Z_Malloc(blocksize+1, PU_STATIC, &texturecache[texnum]); - memset(block, 0xF7, blocksize+1); // Transparency hack + memset(block, TRANSPARENTPIXEL, blocksize+1); // Transparency hack // columns lookup table colofs = block; @@ -387,20 +393,33 @@ static UINT8 *R_GenerateTexture(size_t texnum) // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - realpatch = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); // Well, it's not valid... if (realpatch == NULL) continue; x1 = patch->originx; - x2 = x1 + SHORT(realpatch->width); + width = SHORT(realpatch->width); + height = SHORT(realpatch->height); + x2 = x1 + width; + if (x1 > texture->width || x2 < 0) + continue; // patch not located within texture's x bounds, ignore + + if (patch->originy > texture->height || (patch->originy + height) < 0) + continue; // patch not located within texture's y bounds, ignore + + // patch is actually inside the texture! + // now check if texture is partly off-screen and adjust accordingly + + // left edge if (x1 < 0) x = 0; else x = x1; + // right edge if (x2 > texture->width) x2 = texture->width; @@ -649,7 +668,7 @@ void R_LoadTextures(void) #ifdef HWRENDER if (rendermode == render_opengl) - HWR_LoadTextures(numtextures); + HWR_LoadMapTextures(numtextures); #endif } diff --git a/src/r_defs.h b/src/r_defs.h index a1706289f..a168b9c50 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -642,7 +642,23 @@ typedef struct // Patches are used for sprites and all masked pictures, and we compose // textures from the TEXTURE1 list of patches. // -// WARNING: this structure is cloned in GLPatch_t + +typedef struct +{ + INT16 width, height; + INT16 leftoffset, topoffset; + + INT32 *columnofs; // Column offsets. This is relative to patch->columns + UINT8 *columns; // Software column data + + void *hardware; // OpenGL patch, allocated whenever necessary + +#ifdef ROTSPRITE + rotsprite_t *rotated; // Rotated patches +#endif + +} patch_t; + #if defined(_MSC_VER) #pragma pack(1) #endif @@ -655,7 +671,7 @@ typedef struct INT16 topoffset; // pixels below the origin INT32 columnofs[8]; // only [width] used // the [0] is &columnofs[width] -} patch_t; +} ATTRPACK softwarepatch_t; #ifdef _MSC_VER #pragma warning(disable : 4200) diff --git a/src/r_patch.c b/src/r_patch.c index ed8d5962d..2320b9e52 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -329,6 +329,113 @@ void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps) static unsigned char imgbuf[1<<26]; +// +// 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, size_t srcsize, void *dest) +{ + patch_t *patch = (dest == NULL) ? Z_Calloc(sizeof(patch_t), PU_CACHE, NULL) : (patch_t *)(dest); + + if (source) + { + INT32 col, colsize; + size_t size = sizeof(INT32) * source->width; + size_t offs = (sizeof(INT16) * 4) + size; + + patch->width = source->width; + patch->height = source->height; + patch->leftoffset = source->leftoffset; + patch->topoffset = source->topoffset; + patch->columnofs = Z_Calloc(size, PU_CACHE, NULL); + + for (col = 0; col < source->width; col++) + { + // This makes the column offsets relative to the column data itself, + // instead of the entire patch data + patch->columnofs[col] = LONG(source->columnofs[col]) - offs; + } + + if (!srcsize) + I_Error("Patch_Create: no source size!"); + + colsize = (INT32)(srcsize) - (INT32)offs; + if (colsize <= 0) + I_Error("Patch_Create: no column data!"); + + patch->columns = Z_Calloc(colsize, PU_CACHE, NULL); + M_Memcpy(patch->columns, ((UINT8 *)source + LONG(source->columnofs[0])), colsize); + } + + return patch; +} + +// +// Frees a patch from memory. +// + +void Patch_Free(patch_t *patch) +{ +#ifdef HWRENDER + if (patch->hardware) + HWR_FreeTexture(patch); +#endif + +#ifdef ROTSPRITE + if (patch->rotated) + { + rotsprite_t *rotsprite = patch->rotated; + INT32 i = 0; + + for (; i < rotsprite->angles; i++) + { + if (rotsprite->patches[i]) + Patch_Free(rotsprite->patches[i]); + } + + Z_Free(rotsprite->patches); + Z_Free(rotsprite); + } +#endif + + if (patch->columnofs) + Z_Free(patch->columnofs); + if (patch->columns) + Z_Free(patch->columns); + + Z_Free(patch); +} + +#ifdef HWRENDER +// +// Allocates a hardware patch. +// + +void *Patch_AllocateHardwarePatch(patch_t *patch) +{ + if (!patch->hardware) + { + GLPatch_t *grPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, &patch->hardware); + grPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, &grPatch->mipmap); + } + return (void *)(patch->hardware); +} + +// +// Creates a hardware patch. +// + +void *Patch_CreateGL(patch_t *patch) +{ + GLPatch_t *grPatch = (GLPatch_t *)Patch_AllocateHardwarePatch(patch); + if (!grPatch->mipmap->data) // Run HWR_MakePatch in all cases, to recalculate some things + HWR_MakePatch(patch, grPatch, grPatch->mipmap, false); + return grPatch; +} +#endif // HWRENDER + + // // R_MaskedFlatToPatch // @@ -440,7 +547,14 @@ static void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 l if (destsize != NULL) *destsize = size; - return img; + + patch_t *converted = Patch_Create((softwarepatch_t *)img, size, NULL); +#ifdef HWRENDER + Patch_CreateGL(converted); +#endif + Z_Free(img); + + return converted; } static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) @@ -453,14 +567,14 @@ static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) if (patch == NULL) I_Error("GetPatchPixel: patch == NULL"); - width = SHORT(patch->width); + width = patch->width; if (x >= 0 && x < width) { INT32 colx = flip ? (width-1)-x : x; INT32 topdelta, prevdelta = -1; - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[colx])); + column = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[colx])); while (column->topdelta != 0xff) { @@ -486,17 +600,6 @@ static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) return 0xFF00; } -#ifdef HWRENDER -static patch_t *R_CreateHardwarePatch(patch_t *patch) -{ - GLPatch_t *glPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, NULL); - glPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, NULL); - glPatch->rawpatch = patch; - HWR_MakePatch(patch, glPatch, glPatch->mipmap, false); - return (patch_t *)glPatch; -} -#endif - #ifdef ROTSPRITE // // R_GetRollAngle @@ -554,7 +657,8 @@ patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spri if (lump == LUMPERROR) return NULL; - patch = (patch_t *)W_CacheLumpNum(lump, PU_CACHE); // PU_LEVEL + patch = W_CachePatchNum(lump, PU_CACHE); // PU_SPRITE + //patch = W_CachePatchNum(lump, PU_SPRITE); if (sprinfo->available) { @@ -563,8 +667,8 @@ patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spri } else { - xpivot = SHORT(patch->leftoffset); - ypivot = SHORT(patch->height) / 2; + xpivot = patch->leftoffset; + ypivot = patch->height / 2; } RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip); @@ -581,7 +685,6 @@ rotsprite_t *RotatedPatch_Create(INT32 numangles) return rotsprite; } - static void RotatedPatch_CalculateDimensions( INT32 width, INT32 height, fixed_t ca, fixed_t sa, @@ -607,16 +710,15 @@ static void RotatedPatch_CalculateDimensions( void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip) { UINT32 i; - patch_t *rotated; UINT16 *rawdst, *rawconv; size_t size; INT32 bflip = (flip != 0x00); - INT32 width = SHORT(patch->width); - INT32 height = SHORT(patch->height); - INT32 leftoffset = SHORT(patch->leftoffset); + INT32 width = patch->width; + INT32 height = patch->height; + INT32 leftoffset = patch->leftoffset; INT32 newwidth, newheight; fixed_t ca = rollcosang[angle]; @@ -735,18 +837,11 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle // make patch rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); - rotated->leftoffset = ox; - rotated->topoffset = oy; - -#ifdef HWRENDER - if (rendermode == render_opengl) - { - rotated = R_CreateHardwarePatch(rotated); - } -#endif // HWRENDER - //Z_ChangeTag(rotated, PU_LEVEL); Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); Z_Free(rawconv); + + rotated->leftoffset = ox; + rotated->topoffset = oy; } #endif diff --git a/src/r_patch.h b/src/r_patch.h index 75347df3c..38df76b05 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -38,6 +38,15 @@ typedef struct boolean available; } spriteinfo_t; +// Patch functions +patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest); +void Patch_Free(patch_t *patch); + +#ifdef HWRENDER +void *Patch_AllocateHardwarePatch(patch_t *patch); +void *Patch_CreateGL(patch_t *patch); +#endif + // Conversions between patches / flats / textures... boolean R_CheckIfPatch(lumpnum_t lump); diff --git a/src/r_segs.c b/src/r_segs.c index 8a9f0dc29..313bae9b5 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -229,7 +229,7 @@ static void R_DrawWallSplats(void) continue; // draw the texture - col = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); + col = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[texturecolumn])); R_DrawSplatColumn(col); } } // next splat diff --git a/src/r_things.c b/src/r_things.c index c3a83880c..164e56814 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -254,7 +254,7 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT8 frame; UINT8 rotation; lumpinfo_t *lumpinfo; - patch_t patch; + softwarepatch_t patch; UINT8 numadded = 0; memset(sprtemp,0xFF, sizeof (sprtemp)); @@ -297,10 +297,10 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, // store sprite info in lookup tables //FIXME : numspritelumps do not duplicate sprite replacements W_ReadLumpHeaderPwad(wadnum, l, &patch, sizeof (patch_t), 0); - spritecachedinfo[numspritelumps].width = SHORT(patch.width)<columnofs[texturecolumn])); + column = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[texturecolumn])); localcolfunc (column); } @@ -893,7 +893,7 @@ static void R_DrawVisSprite(vissprite_t *vis) for (dc_x = vis->x1; dc_x <= vis->x2 && (frac>>FRACBITS) < pwidth; dc_x++, frac += vis->xiscale) { texturecolumn = CLAMP(frac >> FRACBITS, 0, pwidth - 1); - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); + column = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[texturecolumn])); localcolfunc (column); } @@ -961,7 +961,7 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) break; } - column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); + column = (column_t *)((UINT8 *)patch->columns + (patch->columnofs[texturecolumn])); R_DrawMaskedColumn(column); } diff --git a/src/v_video.c b/src/v_video.c index 1d0b7ddfb..e46acb14e 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -635,7 +635,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca //if (rendermode != render_soft && !con_startup) // Why? if (rendermode == render_opengl) { - HWR_DrawStretchyFixedPatch((GLPatch_t *)patch, x, y, pscale, vscale, scrn, colormap, bflags); + HWR_DrawStretchyFixedPatch(patch, x, y, pscale, vscale, scrn, colormap, bflags); return; } #endif @@ -761,7 +761,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca // if it's meant to cover the whole screen, black out the rest (ONLY IF TOP LEFT ISN'T TRANSPARENT) if (x == 0 && SHORT(patch->width) == BASEVIDWIDTH && y == 0 && SHORT(patch->height) == BASEVIDHEIGHT) { - column = (const column_t *)((const UINT8 *)(patch) + LONG(patch->columnofs[0])); + column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[0])); if (!column->topdelta) { source = (const UINT8 *)(column) + 3; @@ -825,7 +825,7 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca if (x+offx >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION) break; } - column = (const column_t *)((const UINT8 *)(patch) + LONG(patch->columnofs[col>>FRACBITS])); + column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[col>>FRACBITS])); while (column->topdelta != 0xff) { @@ -872,7 +872,7 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ #ifdef HWRENDER if (rendermode == render_opengl) { - HWR_DrawCroppedPatch((GLPatch_t*)patch,x,y,pscale,scrn,sx,sy,w,h); + HWR_DrawCroppedPatch(patch, x, y, pscale, scrn, sx, sy, w, h); return; } #endif @@ -963,7 +963,7 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ continue; if (x >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION) break; - column = (const column_t *)((const UINT8 *)(patch) + LONG(patch->columnofs[col>>FRACBITS])); + column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[col>>FRACBITS])); while (column->topdelta != 0xff) { diff --git a/src/w_wad.c b/src/w_wad.c index 6432c3223..3642efe2f 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -821,11 +821,7 @@ UINT16 W_InitFile(const char *filename, boolean local) // set up caching // Z_Calloc(numlumps * sizeof (*wadfile->lumpcache), PU_STATIC, &wadfile->lumpcache); - -#ifdef HWRENDER - // allocates GLPatch info structures and store them in a tree - wadfile->hwrcache = M_AATreeAlloc(AATREE_ZUSER); -#endif + Z_Calloc(numlumps * sizeof (*wadfile->patchcache), PU_STATIC, &wadfile->patchcache); #ifdef ROTSPRITE // allocates rotsprite structures and store them in a tree @@ -1312,15 +1308,15 @@ UINT8 W_LumpExists(const char *name) return false; } -UINT8 W_CheckMultipleLumps(const char* lump, ...) +UINT8 W_CheckMultipleLumps(const char* lump, ...) { va_list lumps; va_start(lumps, lump); const char* lumpname = lump; - while (lumpname != NULL) + while (lumpname != NULL) { - if (!W_LumpExists(lumpname)) + if (!W_LumpExists(lumpname)) { va_end(lumps); return false; @@ -1629,7 +1625,6 @@ void *W_CacheLumpNumPwad(UINT16 wad, UINT16 lump, INT32 tag) void *W_CacheLumpNum(lumpnum_t lumpnum, INT32 tag) { - return W_CacheLumpNumPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum),tag); } @@ -1687,6 +1682,39 @@ boolean W_IsLumpCached(lumpnum_t lumpnum, void *ptr) return W_IsLumpCachedPWAD(WADFILENUM(lumpnum),LUMPNUM(lumpnum), ptr); } +// +// W_IsPatchCached +// +// If a patch is already cached return true, otherwise +// return false. +// +// no outside code uses the PWAD form, for now +static inline boolean W_IsPatchCachedPWAD(UINT16 wad, UINT16 lump, void *ptr) +{ + void *lcache; + + if (!TestValidLump(wad, lump)) + return false; + + lcache = wadfiles[wad]->patchcache[lump]; + + if (ptr) + { + if (ptr == lcache) + return true; + } + else if (lcache) + return true; + + return false; +} + +boolean W_IsPatchCached(lumpnum_t lumpnum, void *ptr) +{ + return W_IsPatchCachedPWAD(WADFILENUM(lumpnum),LUMPNUM(lumpnum), ptr); +} + + // ========================================================================== // W_CacheLumpName // ========================================================================== @@ -1711,40 +1739,59 @@ void *W_CacheLumpName(const char *name, INT32 tag) // // Software-only compile cache the data without conversion -#ifdef HWRENDER -FUNCINLINE static ATTRINLINE void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag) +void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag) { - GLPatch_t *glPatch; - - if (rendermode == render_soft || rendermode == render_none) - return W_CacheLumpNumPwad(wad, lump, tag); + lumpcache_t *lumpcache = NULL; if (!TestValidLump(wad, lump)) return NULL; - glPatch = HWR_GetCachedGLPatchPwad(wad, lump); + lumpcache = wadfiles[wad]->patchcache; - if (glPatch->mipmap->data) + if (!lumpcache[lump]) { - if (tag == PU_CACHE) - tag = PU_HWRCACHE; - Z_ChangeTag(glPatch->mipmap->data, tag); - } - else - { - patch_t *ptr = NULL; + size_t len = W_LumpLengthPwad(wad, lump); + void *ptr, *dest, *lumpdata = Z_Malloc(len, PU_STATIC, NULL); - // Only load the patch if we haven't initialised the glPatch yet - if (glPatch->mipmap->width == 0) - ptr = W_CacheLumpNumPwad(glPatch->wadnum, glPatch->lumpnum, PU_STATIC); + // read the lump in full + W_ReadLumpHeaderPwad(wad, lump, lumpdata, 0, 0); + ptr = lumpdata; + + dest = Z_Calloc(sizeof(patch_t), tag, &lumpcache[lump]); + Patch_Create(ptr, len, dest); - // Run HWR_MakePatch in all cases, to recalculate some things - HWR_MakePatch(ptr, glPatch, glPatch->mipmap, false); Z_Free(ptr); } + else + Z_ChangeTag(lumpcache[lump], tag); - // return GLPatch_t, which can be casted to (patch_t) with valid patch header info - return (void *)glPatch; + return lumpcache[lump]; +} + +void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag) +{ + return W_CacheSoftwarePatchNumPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum),tag); +} + +void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag) +{ + patch_t *patch; + + if (!TestValidLump(wad, lump)) + return NULL; + + patch = W_CacheSoftwarePatchNumPwad(wad, lump, tag); + +#ifdef HWRENDER + // Software-only compile cache the data without conversion + if (rendermode == render_soft || rendermode == render_none) +#endif + return (void *)patch; + +#ifdef HWRENDER + Patch_CreateGL(patch); + return (void *)patch; +#endif } void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag) @@ -1752,8 +1799,6 @@ void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag) return W_CachePatchNumPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum),tag); } -#endif // HWRENDER - #ifdef ROTSPRITE // Caches a rotsprite for patch rotation. void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum) @@ -1781,7 +1826,7 @@ void W_UnlockCachedPatch(void *patch) // have different lifetimes from software's. #ifdef HWRENDER if (rendermode == render_opengl) - HWR_UnlockCachedPatch((GLPatch_t*)patch); + HWR_UnlockCachedPatch((GLPatch_t *)((patch_t *)patch)->hardware); else #endif Z_ChangeTag(patch, PU_LEVEL); @@ -1826,7 +1871,7 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) { INT32 xpivot = 0, ypivot = 0; - ptr = (patch_t *)(W_CacheLumpNum(num, PU_STATIC)); + ptr = W_CachePatchNum(num, PU_STATIC); // PU_PATCH // >y pivot centered // >x pivot not centered @@ -1835,9 +1880,6 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) ypivot = SHORT(ptr->height) / 2; RotatedPatch_DoRotation(rspr, ptr, rotationangle, xpivot, ypivot, false); - - // free image data - Z_Free(ptr); } return rspr->patches[idx]; diff --git a/src/w_wad.h b/src/w_wad.h index d0eb28f2f..0de9057b6 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -125,9 +125,7 @@ typedef struct wadfile_s restype_t type; lumpinfo_t *lumpinfo; lumpcache_t *lumpcache; -#ifdef HWRENDER - aatree_t *hwrcache; // patches are cached in renderer's native format -#endif + lumpcache_t *patchcache; #ifdef ROTSPRITE aatree_t *rotcache; // Cache rotsprites for rotating patches. #endif @@ -208,18 +206,19 @@ void *W_CacheLumpNumPwad(UINT16 wad, UINT16 lump, INT32 tag); void *W_CacheLumpNum(lumpnum_t lump, INT32 tag); void *W_CacheLumpNumForce(lumpnum_t lumpnum, INT32 tag); +boolean W_IsPatchCached(lumpnum_t lump, void *ptr); boolean W_IsLumpCached(lumpnum_t lump, void *ptr); void *W_CacheLumpName(const char *name, INT32 tag); void *W_CachePatchName(const char *name, INT32 tag); -#ifdef HWRENDER -//void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag); // return a patch_t -void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag); // return a patch_t -#else -//#define W_CachePatchNumPwad(wad, lump, tag) W_CacheLumpNumPwad(wad, lump, tag) -#define W_CachePatchNum(lumpnum, tag) W_CacheLumpNum(lumpnum, tag) -#endif +// Returns either a Software patch, or an OpenGL patch. +void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag); +void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag); + +// Returns a Software patch. +void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag); +void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag); #ifdef ROTSPRITE void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum); // Get patch-based rotsprites from the cache. diff --git a/src/y_inter.c b/src/y_inter.c index 444df52d4..213bf90d8 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -887,7 +887,7 @@ static void Y_FollowIntermission(void) G_AfterIntermission(); } -#define UNLOAD(x) Z_ChangeTag(x, PU_CACHE); x = NULL +#define UNLOAD(x) if (x) {Patch_Free(x);} x = NULL; // // Y_UnloadData From fe1579e960b1ae297b4fcd09e0438612e897a831 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 15:56:13 +0200 Subject: [PATCH 02/44] fuckit *unshortens your patch dimensions* --- src/console.c | 14 +++---- src/d_main.c | 2 +- src/f_finale.c | 12 +++--- src/hardware/hw_cache.c | 6 +-- src/hardware/hw_draw.c | 22 +++++------ src/hardware/hw_main.c | 8 ++-- src/hu_stuff.c | 18 +++------ src/k_kart.c | 40 ++++++++++---------- src/lua_hudlib.c | 26 ++++++------- src/m_menu.c | 30 +++++++-------- src/r_data.c | 4 +- src/r_patch.c | 10 ++--- src/r_segs.c | 4 +- src/r_things.c | 26 ++++++------- src/v_video.c | 82 ++++++++++++++++++++--------------------- src/w_wad.c | 1 - src/y_inter.c | 8 ++-- 17 files changed, 153 insertions(+), 160 deletions(-) diff --git a/src/console.c b/src/console.c index 3212521b0..8cc04fe93 100644 --- a/src/console.c +++ b/src/console.c @@ -621,11 +621,11 @@ static void CON_MoveConsole(void) con_curlines -= FixedInt(fracmovement); if (con_curlines < con_destlines) con_curlines = con_destlines; - + if (con_destlines == 0) // If the console is being closed, not just moved up... con_tick = 0; // ...don't show the blinking cursor } - + fracmovement %= FRACUNIT; // Reset fracmovement's integer value, but keep the fraction Unlock_state(); @@ -635,7 +635,7 @@ INT32 CON_ShiftChar(INT32 ch) { if (I_UseNativeKeyboard()) return ch; - + if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { if (cv_keyboardlayout.value == 3) @@ -1244,7 +1244,7 @@ void CONS_Printf(const char *fmt, ...) if (con_started) CON_Print(txt); - + CON_LogMessage(txt); Lock_state(); @@ -1474,7 +1474,7 @@ static void CON_DrawHudlines(void) ;//charwidth = 4 * con_scalefactor; else { - //charwidth = SHORT(hu_font['A'-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = hu_font['A'-HU_FONTSTART]->width * con_scalefactor; V_DrawCharacter(x, y, (INT32)(*p) | charflags | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); } } @@ -1577,11 +1577,11 @@ void CON_Drawer(void) if (con_recalc) { CON_RecalcSize(); - + if (con_curlines <= 0) CON_ClearHUD(); } - + // console movement if (con_curlines != con_destlines) CON_MoveConsole(); diff --git a/src/d_main.c b/src/d_main.c index 8c986a24e..6f281421a 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -604,7 +604,7 @@ static boolean D_Display(void) else py = viewwindowy + 4; patch = W_CachePatchName("M_PAUSE", PU_CACHE); - V_DrawScaledPatch(viewwindowx + (BASEVIDWIDTH - SHORT(patch->width))/2, py, V_SNAPTOTOP, patch); + V_DrawScaledPatch(viewwindowx + (BASEVIDWIDTH - patch->width)/2, py, V_SNAPTOTOP, patch); } if (rendermode == render_soft && demo.rewinding) diff --git a/src/f_finale.c b/src/f_finale.c index 1b8d236fe..a534eee68 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -170,8 +170,8 @@ static void F_SkyScroll(INT32 scrollspeed) w = (vid.width / vid.dupx)<width)*16))<width)<width)*16))<width*16))<width<width*16))<width)<width<height))<height)<width)<width<width))/2, 32, 0, contsonic); + V_DrawScaledPatch((BASEVIDWIDTH - contsonic->width)/2, 32, 0, contsonic); // Draw the continue markers! Show continues minus one. x -= ncontinues * 6; diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 6fef6d0a9..836d3adac 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -1090,15 +1090,15 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 W_ReadLump(fademasklumpnum, Z_Malloc(W_LumpLength(fademasklumpnum), PU_HWRCACHE, &flat)); - stepy = ((INT32)SHORT(fmheight)<width)]; // 1bpp - src = &flat[(posy>>FRACBITS)*SHORT(fmwidth)]; + src = &flat[(posy>>FRACBITS)*fmwidth]; for (i = 0; i < pblockwidth;i++) { // fademask bpp is always 1, and is used just for alpha diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 9a7f19995..d47d58841 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -108,10 +108,10 @@ void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) if (option & V_NOSCALESTART) sdupx = sdupy = 2.0f; - v[0].x = v[3].x = (x*sdupx-(gpatch->leftoffset)*pdupx)/vid.width - 1; - v[2].x = v[1].x = (x*sdupx+((gpatch->width)-(gpatch->leftoffset))*pdupx)/vid.width - 1; - v[0].y = v[1].y = 1-(y*sdupy-(gpatch->topoffset)*pdupy)/vid.height; - v[2].y = v[3].y = 1-(y*sdupy+((gpatch->height)-(gpatch->topoffset))*pdupy)/vid.height; + v[0].x = v[3].x = (x*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; + v[2].x = v[1].x = (x*sdupx+(gpatch->width - gpatch->leftoffset)*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdupy-gpatch->topoffset*pdupy)/vid.height; + v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height - gpatch->topoffset)*pdupy)/vid.height; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; @@ -191,7 +191,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p // left offset if (option & V_FLIP) - offsetx = (float)((gpatch->width) - (gpatch->leftoffset)) * fscalew; + offsetx = (float)(gpatch->width - gpatch->leftoffset) * fscalew; else offsetx = (float)(gpatch->leftoffset) * fscalew; @@ -225,7 +225,7 @@ void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t p // if it's meant to cover the whole screen, black out the rest // cx and cy are possibly *slightly* off from float maths // This is done before here compared to software because we directly alter cx and cy to centre - if (cx >= -0.1f && cx <= 0.1f && (gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && (gpatch->height) == BASEVIDHEIGHT) + if (cx >= -0.1f && cx <= 0.1f && gpatch->width == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && gpatch->height == BASEVIDHEIGHT) { const column_t *column = (const column_t *)((const UINT8 *)(gpatch->columns) + (gpatch->columnofs[0])); @@ -376,7 +376,7 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, // if it's meant to cover the whole screen, black out the rest // cx and cy are possibly *slightly* off from float maths // This is done before here compared to software because we directly alter cx and cy to centre - if (cx >= -0.1f && cx <= 0.1f && (gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && (gpatch->height) == BASEVIDHEIGHT) + if (cx >= -0.1f && cx <= 0.1f && gpatch->width == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && gpatch->height == BASEVIDHEIGHT) { const column_t *column = (const column_t *)((const UINT8 *)(gpatch->columns) + (gpatch->columnofs[0])); @@ -415,11 +415,11 @@ void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, if (fheight > h - sy) fheight = h - sy; - if (fwidth > (gpatch->width)) - fwidth = (gpatch->width); + if (fwidth > gpatch->width) + fwidth = gpatch->width; - if (fheight > (gpatch->height)) - fheight = (gpatch->height); + if (fheight > gpatch->height) + fheight = gpatch->height; if (pscale != FRACUNIT) { diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 77e9e598a..8e877a044 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4797,10 +4797,10 @@ static void HWR_ProjectSprite(mobj_t *thing) if (rotsprite != NULL) { - spr_width = SHORT(rotsprite->width) << FRACBITS; - spr_height = SHORT(rotsprite->height) << FRACBITS; - spr_offset = SHORT(rotsprite->leftoffset) << FRACBITS; - spr_topoffset = SHORT(rotsprite->topoffset) << FRACBITS; + spr_width = rotsprite->width << FRACBITS; + spr_height = rotsprite->height << FRACBITS; + spr_offset = rotsprite->leftoffset << FRACBITS; + spr_topoffset = rotsprite->topoffset << FRACBITS; spr_topoffset += FEETADJUST; // flip -> rotate, not rotate -> flip diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 268059d06..b7984c1e5 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1949,17 +1949,11 @@ static void HU_DrawChat_Old(void) const char *ntalk = "Say: ", *ttalk = "Say-Team: "; const char *talk = ntalk; size_t select_start = 0, select_end = 0; - INT32 charwidth = 8 * con_scalefactor; //SHORT(hu_font['A'-HU_FONTSTART]->width) * con_scalefactor; - INT32 charheight = 8 * con_scalefactor; //SHORT(hu_font['A'-HU_FONTSTART]->height) * con_scalefactor; + INT32 charwidth = 8 * con_scalefactor; //hu_font['A'-HU_FONTSTART]->width * con_scalefactor; + INT32 charheight = 8 * con_scalefactor; //hu_font['A'-HU_FONTSTART]->height * con_scalefactor; if (teamtalk) { talk = ttalk; -#if 0 - if (players[consoleplayer].ctfteam == 1) - t = 0x500; // Red - else if (players[consoleplayer].ctfteam == 2) - t = 0x400; // Blue -#endif } while (talk[i]) @@ -1971,7 +1965,7 @@ static void HU_DrawChat_Old(void) } else { - //charwidth = SHORT(hu_font[talk[i]-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = hu_font[talk[i]-HU_FONTSTART]->width * con_scalefactor; V_DrawCharacter(HU_INPUTX + c, y, talk[i++] | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); } c += charwidth; @@ -1999,7 +1993,7 @@ static void HU_DrawChat_Old(void) //Hurdler: isn't it better like that? if (w_chat_buf[i] >= HU_FONTSTART) { - //charwidth = SHORT(hu_font[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; + //charwidth = hu_font[w_chat[i]-HU_FONTSTART]->width * con_scalefactor; V_DrawCharacter(HU_INPUTX + c, y, w_chat_buf[i] | cv_constextsize.value | V_NOSCALESTART | t, !cv_allcaps.value); } @@ -2638,7 +2632,7 @@ static void HU_DrawRankings(void) else p = bmatcico; - V_DrawSmallScaledPatch(128 - SHORT(p->width)/4, 4, 0, p); + V_DrawSmallScaledPatch(128 - p->width/4, 4, 0, p); V_DrawCenteredString(128, 16, 0, va("%u", bluescore)); if (gametype == GT_CTF) @@ -2646,7 +2640,7 @@ static void HU_DrawRankings(void) else p = rmatcico; - V_DrawSmallScaledPatch(192 - SHORT(p->width)/4, 4, 0, p); + V_DrawSmallScaledPatch(192 - p->width/4, 4, 0, p); V_DrawCenteredString(192, 16, 0, va("%u", redscore)); } diff --git a/src/k_kart.c b/src/k_kart.c index 1d2bde533..fb14741cc 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9045,7 +9045,7 @@ static void K_DrawKartPositionNum(INT32 num) const boolean wheeloffs = (cv_showinput.value && cv_posi_xoffset.value == 0 && cv_posi_yoffset.value == 0 && cv_wheel_xoffset.value == 0 && cv_wheel_yoffset.value == 0); boolean win = (stplyr->exiting && num == 1); //INT32 X = POSI_X; - INT32 W = SHORT(kp_positionnum[0][0]->width); + INT32 W = kp_positionnum[0][0]->width; fixed_t scale = FRACUNIT; patch_t *localpatch = kp_positionnum[0][0]; //INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTORIGHT); @@ -9159,7 +9159,7 @@ static void K_DrawKartPositionNum(INT32 num) localpatch = kp_positionnum[num % 10][0]; } - V_DrawFixedPatch((fx<width)*scale/2) : 0), (fy<height)*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL); + V_DrawFixedPatch((fx<width*scale/2) : 0), (fy<height*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL); // ^ if we overtake as p1 or p3 in splitscren, we shift it so that it doesn't go off screen. // ^ if we overtake as p1 in 2p splits, shift vertically so that this doesn't happen either. @@ -9493,9 +9493,9 @@ static void K_DrawDialNum(INT32 x, INT32 y, boolean colorized, INT32 flags, INT3 INT32 w; if (colorized) - w = SHORT(skp_dialnumclr[0]->width); + w = skp_dialnumclr[0]->width; else - w = SHORT(skp_dialnum[0]->width); + w = skp_dialnum[0]->width; if (flags & V_NOSCALESTART) w *= vid.dupx; @@ -10436,7 +10436,7 @@ static void K_drawKartWanted(void) } else if (splitscreen == 3) // 4P splitscreen... { - basex = BASEVIDWIDTH/2 - (SHORT(kp_wantedsplit->width)/2); // center on screen + basex = BASEVIDWIDTH/2 - (kp_wantedsplit->width/2); // center on screen basey = BASEVIDHEIGHT - 55; //basey2 = 4; } @@ -10559,8 +10559,8 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags) if (encoremode) amnumxpos = -amnumxpos; - amxpos = amnumxpos + ((x + (SHORT(minimapinfo.minimap_pic->width)-SHORT(minimaphead->width)) / 2)<height)-SHORT(minimaphead->height)) / 2)<width-minimaphead->width) / 2)<height-minimaphead->height) / 2)<width) / 4)<height) / 4)<width / 4)<height / 4)<width)/2); - y = info.y - (SHORT(minimapinfo.minimap_pic->height)/2); + x = info.x - (minimapinfo.minimap_pic->width/2); + y = info.y - (minimapinfo.minimap_pic->height/2); splitflags = info.flags; splitflags |= minimaptrans; if (encoremode) - V_DrawScaledPatch(x+SHORT(minimapinfo.minimap_pic->width), y, splitflags|V_FLIP, minimapinfo.minimap_pic); + V_DrawScaledPatch(x+minimapinfo.minimap_pic->width, y, splitflags|V_FLIP, minimapinfo.minimap_pic); else V_DrawScaledPatch(x, y, splitflags, minimapinfo.minimap_pic); @@ -10665,10 +10665,10 @@ static void K_drawKartMinimap(void) // let offsets transfer to the heads, too! if (encoremode) - x += SHORT(minimapinfo.minimap_pic->leftoffset); + x += minimapinfo.minimap_pic->leftoffset; else - x -= SHORT(minimapinfo.minimap_pic->leftoffset); - y -= SHORT(minimapinfo.minimap_pic->topoffset); + x -= minimapinfo.minimap_pic->leftoffset; + y -= minimapinfo.minimap_pic->topoffset; // initialize for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) @@ -10749,7 +10749,7 @@ static void K_drawKartStartCountdown(void) if (splitscreen) // splitscreen pnum += 8; - V_DrawScaledPatch(STCD_X - (SHORT(kp_startcountdown[pnum]->width)/2), STCD_Y - (SHORT(kp_startcountdown[pnum]->height)/2), splitflags, kp_startcountdown[pnum]); + V_DrawScaledPatch(STCD_X - (kp_startcountdown[pnum]->width/2), STCD_Y - (kp_startcountdown[pnum]->height/2), splitflags, kp_startcountdown[pnum]); } static void K_drawKartFinish(void) @@ -10765,7 +10765,7 @@ static void K_drawKartFinish(void) if (splitscreen > 1) // 3/4p, stationary FIN { pnum += 2; - V_DrawScaledPatch(STCD_X - (SHORT(kp_racefinish[pnum]->width)/2), STCD_Y - (SHORT(kp_racefinish[pnum]->height)/2), splitflags, kp_racefinish[pnum]); + V_DrawScaledPatch(STCD_X - (kp_racefinish[pnum]->width/2), STCD_Y - (kp_racefinish[pnum]->height/2), splitflags, kp_racefinish[pnum]); return; } @@ -10777,14 +10777,14 @@ static void K_drawKartFinish(void) pnum += 4; x = ((vid.width<width)<width<kartstuff[k_cardanimation])< x ? xval : x))/TICRATE; if (splitscreen && stplyrnum == 1) x = -x; V_DrawFixedPatch(x + (STCD_X<>1), - (STCD_Y<height)<<(FRACBITS-1)), + (STCD_Y<height<<(FRACBITS-1)), FRACUNIT, splitflags, kp_racefinish[pnum], NULL); } @@ -11705,7 +11705,7 @@ void K_drawKartHUD(void) return; if (G_BattleGametype() && !splitscreen && (stplyr->kartstuff[k_yougotem] % 2)) // * YOU GOT EM * - V_DrawScaledPatch(BASEVIDWIDTH/2 - (SHORT(kp_yougotem->width)/2), 32, V_HUDTRANS, kp_yougotem); + V_DrawScaledPatch(BASEVIDWIDTH/2 - (kp_yougotem->width/2), 32, V_HUDTRANS, kp_yougotem); // Draw FREE PLAY. if (isfreeplay && !stplyr->spectator && timeinmap > 113) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index dc2e8f824..5bfb21e2e 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -303,16 +303,16 @@ static int patch_get(lua_State *L) lua_pushboolean(L, patch != NULL); break; case patch_width: - lua_pushinteger(L, SHORT(patch->width)); + lua_pushinteger(L, patch->width); break; case patch_height: - lua_pushinteger(L, SHORT(patch->height)); + lua_pushinteger(L, patch->height); break; case patch_leftoffset: - lua_pushinteger(L, SHORT(patch->leftoffset)); + lua_pushinteger(L, patch->leftoffset); break; case patch_topoffset: - lua_pushinteger(L, SHORT(patch->topoffset)); + lua_pushinteger(L, patch->topoffset); break; } return 1; @@ -657,27 +657,27 @@ static int libd_drawOnMinimap(lua_State *L) splitflags |= V_HUDTRANS; // Handle offsets and stuff. - mm_x = info.x - (SHORT(AutomapPic->width)/2); - mm_y = info.y - (SHORT(AutomapPic->height)/2); + mm_x = info.x - (AutomapPic->width/2); + mm_y = info.y - (AutomapPic->height/2); // let offsets transfer to the heads, too! if (encoremode) { - mm_x += SHORT(AutomapPic->leftoffset); + mm_x += AutomapPic->leftoffset; } else { - mm_x -= SHORT(AutomapPic->leftoffset); + mm_x -= AutomapPic->leftoffset; } - mm_y -= SHORT(AutomapPic->topoffset); + mm_y -= AutomapPic->topoffset; // patch is supposedly already centered, don't butt in. if (!centered) { // scale patch coords - patchw = (SHORT(patch->width) * scale / 2); - patchh = (SHORT(patch->height) * scale / 2); + patchw = (patch->width * scale / 2); + patchh = (patch->height * scale / 2); } amnumxpos = (FixedMul(x, minimapinfo.zoom) - minimapinfo.offs_x); @@ -688,8 +688,8 @@ static int libd_drawOnMinimap(lua_State *L) amnumxpos = -amnumxpos; } - amxpos = amnumxpos + ((mm_x + SHORT(AutomapPic->width) / 2)<height) / 2)<width / 2)<height / 2)<width) - SHORT(p->leftoffset); + xx += p->width - p->leftoffset; for (i = 0; i < 16; i++) { V_DrawScaledPatch(xx, y, V_WRAPX, W_CachePatchNum(centerlump[i & 1], PU_CACHE)); @@ -5192,8 +5192,8 @@ static void M_DrawMenuTitle(void) if (p->height > 24) // title is larger than normal { - INT32 xtitle = (BASEVIDWIDTH - (SHORT(p->width)/2))/2; - INT32 ytitle = (30 - (SHORT(p->height)/2))/2; + INT32 xtitle = (BASEVIDWIDTH - (p->width/2))/2; + INT32 ytitle = (30 - (p->height/2))/2; if (xtitle < 0) xtitle = 0; @@ -5204,8 +5204,8 @@ static void M_DrawMenuTitle(void) } else { - INT32 xtitle = (BASEVIDWIDTH - SHORT(p->width))/2; - INT32 ytitle = (30 - SHORT(p->height))/2; + INT32 xtitle = (BASEVIDWIDTH - p->width)/2; + INT32 ytitle = (30 - p->height)/2; if (xtitle < 0) xtitle = 0; @@ -5293,7 +5293,7 @@ static void M_DrawGenericMenu(void) { patch_t *p; p = W_CachePatchName(currentMenu->menuitems[i].patch, PU_CACHE); - V_DrawScaledPatch((BASEVIDWIDTH - SHORT(p->width))/2, y, 0, p); + V_DrawScaledPatch((BASEVIDWIDTH - p->width)/2, y, 0, p); } else { @@ -5621,7 +5621,7 @@ static void M_DrawCenteredMenu(void) if (currentMenu->menuitems[i].status & IT_CENTER) { - V_DrawScaledPatch((BASEVIDWIDTH - SHORT(p->width))/2, y, 0, p); + V_DrawScaledPatch((BASEVIDWIDTH - p->width)/2, y, 0, p); } else { @@ -6052,7 +6052,7 @@ static void M_DrawMessageMenu(void) } V_DrawString((BASEVIDWIDTH - V_StringWidth(string, 0))/2,y,V_ALLOWLOWERCASE,string); - y += 8; //SHORT(hu_font[0]->height); + y += 8; //hu_font[0]->height; } } @@ -7222,8 +7222,8 @@ static void DrawReplayHutReplayInfo(void) V_DrawSmallScaledPatch(x, y, V_SNAPTOTOP, patch); else { - w = SHORT(patch->width); - h = SHORT(patch->height); + w = patch->width; + h = patch->height; V_DrawSmallScaledPatch(x+(w>>1), y, V_SNAPTOTOP|V_FLIP, patch); { @@ -7314,7 +7314,7 @@ static void DrawReplayHutReplayInfo(void) GTC_MENUCACHE); } - V_DrawMappedPatch(BASEVIDWIDTH-15 - SHORT(patch->width), y+20, V_SNAPTOTOP, patch, colormap); + V_DrawMappedPatch(BASEVIDWIDTH-15 - patch->width, y+20, V_SNAPTOTOP, patch, colormap); break; } @@ -7533,7 +7533,7 @@ static void M_DrawReplayStartMenu(void) GTC_MENUCACHE); } - V_DrawMappedPatch(BASEVIDWIDTH-5 - SHORT(patch->width), STARTY + i*20, V_SNAPTOTOP, patch, colormap); + V_DrawMappedPatch(BASEVIDWIDTH-5 - patch->width, STARTY + i*20, V_SNAPTOTOP, patch, colormap); } #undef STARTY @@ -9132,7 +9132,7 @@ void M_DrawTimeAttackMenu(void) if (W_CheckNumForName(skins[cv_chooseskin.value-1].facewant) != LUMPERROR) { UINT8 *colormap = R_GetTranslationColormap(cv_chooseskin.value-1, cv_playercolor.value, GTC_MENUCACHE); - V_DrawMappedPatch(BASEVIDWIDTH-x - SHORT(facewantprefix[cv_chooseskin.value-1]->width), y, 0, facewantprefix[cv_chooseskin.value-1], colormap); + V_DrawMappedPatch(BASEVIDWIDTH-x - facewantprefix[cv_chooseskin.value-1]->width, y, 0, facewantprefix[cv_chooseskin.value-1], colormap); } for (i = 0; i < currentMenu->numitems; ++i) @@ -10254,8 +10254,8 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) else PictureOfLevel = W_CachePatchName("RANDOMLV", PU_CACHE); - w = SHORT(PictureOfLevel->width)/2; - i = SHORT(PictureOfLevel->height)/2; + w = PictureOfLevel->width/2; + i = PictureOfLevel->height/2; x = BASEVIDWIDTH/2 - w/2; y = currentMenu->y + 130 + 8 - i; diff --git a/src/r_data.c b/src/r_data.c index ec84cf3bf..de4d239fa 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -642,8 +642,8 @@ void R_LoadTextures(void) // Set texture properties. M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); - texture->width = SHORT(patchlump->width); - texture->height = SHORT(patchlump->height); + texture->width = patchlump->width; + texture->height = patchlump->height; texture->patchcount = 1; texture->holes = false; diff --git a/src/r_patch.c b/src/r_patch.c index 2320b9e52..665b50122 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -344,10 +344,10 @@ patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest) size_t size = sizeof(INT32) * source->width; size_t offs = (sizeof(INT16) * 4) + size; - patch->width = source->width; - patch->height = source->height; - patch->leftoffset = source->leftoffset; - patch->topoffset = source->topoffset; + patch->width = SHORT(source->width); + patch->height = SHORT(source->height); + patch->leftoffset = SHORT(source->leftoffset); + patch->topoffset = SHORT(source->topoffset); patch->columnofs = Z_Calloc(size, PU_CACHE, NULL); for (col = 0; col < source->width; col++) @@ -800,7 +800,7 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle } ox = (newwidth / 2) + (leftoffset - xpivot); - oy = (newheight / 2) + (SHORT(patch->topoffset) - ypivot); + oy = (newheight / 2) + (patch->topoffset - ypivot); width = (maxx - minx); height = (maxy - miny); diff --git a/src/r_segs.c b/src/r_segs.c index 313bae9b5..d1f46b6e8 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -173,7 +173,7 @@ static void R_DrawWallSplats(void) patch = W_CachePatchNum(splat->patch, PU_CACHE); - dc_texturemid = splat->top + (SHORT(patch->height)<<(FRACBITS-1)) - viewz; + dc_texturemid = splat->top + (patch->height<<(FRACBITS-1)) - viewz; if (splat->yoffset) dc_texturemid += *splat->yoffset; @@ -225,7 +225,7 @@ static void R_DrawWallSplats(void) // FIXME! texturecolumn >>= FRACBITS; - if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width)) + if (texturecolumn < 0 || texturecolumn >= patch->width) continue; // draw the texture diff --git a/src/r_things.c b/src/r_things.c index 164e56814..57ec53e5e 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -297,10 +297,10 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, // store sprite info in lookup tables //FIXME : numspritelumps do not duplicate sprite replacements W_ReadLumpHeaderPwad(wadnum, l, &patch, sizeof (patch_t), 0); - spritecachedinfo[numspritelumps].width = (patch.width)<startfrac < 0 || vis->startfrac > (SHORT(patch->width) << FRACBITS)) + if (vis->startfrac < 0 || vis->startfrac > (patch->width << FRACBITS)) { // never draw vissprites with startfrac out of patch range return; @@ -814,7 +814,7 @@ static void R_DrawVisSprite(vissprite_t *vis) dc_colormap += COLORMAP_REMAPOFFSET; dc_texturemid = vis->texturemid; - dc_texheight = SHORT(patch->height); + dc_texheight = patch->height; frac = vis->startfrac; windowtop = windowbottom = sprbotscreen = INT32_MAX; @@ -858,8 +858,8 @@ static void R_DrawVisSprite(vissprite_t *vis) vis->x2 = vid.width-1; localcolfunc = (vis->vflip) ? R_DrawFlippedMaskedColumn : R_DrawMaskedColumn; - lengthcol = SHORT(patch->height); - pwidth = SHORT(patch->width); + lengthcol = patch->height; + pwidth = patch->width; // Split drawing loops for paper and non-paper to reduce conditional checks per sprite if (vis->scalestep) @@ -938,7 +938,7 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) dc_iscale = FixedDiv(FRACUNIT, vis->scale); dc_texturemid = FixedDiv(vis->texturemid, this_scale); - dc_texheight = SHORT(patch->height); + dc_texheight = patch->height; frac = vis->startfrac; spryscale = vis->scale; @@ -1391,10 +1391,10 @@ static void R_ProjectSprite(mobj_t *thing) if (rotsprite != NULL) { - spr_width = SHORT(rotsprite->width) << FRACBITS; - spr_height = SHORT(rotsprite->height) << FRACBITS; - spr_offset = SHORT(rotsprite->leftoffset) << FRACBITS; - spr_topoffset = SHORT(rotsprite->topoffset) << FRACBITS; + spr_width = rotsprite->width << FRACBITS; + spr_height = rotsprite->height << FRACBITS; + spr_offset = rotsprite->leftoffset << FRACBITS; + spr_topoffset = rotsprite->topoffset << FRACBITS; spr_topoffset += FEETADJUST; // flip -> rotate, not rotate -> flip diff --git a/src/v_video.c b/src/v_video.c index e46acb14e..413829a8b 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -710,13 +710,13 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca // left offset if (scrn & V_FLIP) - offsetx = FixedMul((SHORT(patch->width) - SHORT(patch->leftoffset))<width - patch->leftoffset)<leftoffset)<leftoffset<topoffset)<topoffset<width) == BASEVIDWIDTH && y == 0 && SHORT(patch->height) == BASEVIDHEIGHT) + if (x == 0 && patch->width == BASEVIDWIDTH && y == 0 && patch->height == BASEVIDHEIGHT) { column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[0])); if (!column->topdelta) @@ -797,18 +797,18 @@ void V_DrawStretchyFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, fixed_t vsca if (pscale != FRACUNIT) // scale width properly { - pwidth = SHORT(patch->width)<width<>= FRACBITS; } else - pwidth = SHORT(patch->width) * dupx; + pwidth = patch->width * dupx; deststart = desttop; destend = desttop + pwidth; - for (col = 0; (col>>FRACBITS) < SHORT(patch->width); col += colfrac, ++offx, desttop++) + for (col = 0; (col>>FRACBITS) < patch->width; col += colfrac, ++offx, desttop++) { INT32 topdelta, prevdelta = -1; if (scrn & V_FLIP) // offx is measured from right edge instead of left @@ -905,8 +905,8 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ colfrac = FixedDiv(FRACUNIT, fdup); rowfrac = FixedDiv(FRACUNIT, fdup); - y -= FixedMul(SHORT(patch->topoffset)<leftoffset)<topoffset<leftoffset<>FRACBITS) < SHORT(patch->width) && ((col>>FRACBITS) - sx) < w; col += colfrac, ++x, desttop++) + for (col = sx<>FRACBITS) < patch->width && ((col>>FRACBITS) - sx) < w; col += colfrac, ++x, desttop++) { INT32 topdelta, prevdelta = -1; if (x < 0) // don't draw off the left of the screen (WRAP PREVENTION) @@ -1505,7 +1505,7 @@ void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum) void V_DrawPatchFill(patch_t *pat) { INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - INT32 x, y, pw = SHORT(pat->width) * dupz, ph = SHORT(pat->height) * dupz; + INT32 x, y, pw = pat->width * dupz, ph = pat->height * dupz; for (x = 0; x < vid.width; x += pw) { @@ -1706,7 +1706,7 @@ void V_DrawCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed) if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) return; - w = SHORT(hu_font[c]->width); + w = hu_font[c]->width; if (x + w > vid.width) return; @@ -1733,7 +1733,7 @@ void V_DrawChatCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, UI if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) return; - w = SHORT(hu_font[c]->width)/2; + w = hu_font[c]->width/2; if (x + w > vid.width) return; @@ -1899,10 +1899,10 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(hu_font[c]->width)*dupx/2; + center = w/2 - hu_font[c]->width*dupx/2; } else - w = SHORT(hu_font[c]->width) * dupx; + w = hu_font[c]->width * dupx; if (cx > scrwidth) break; @@ -2001,10 +2001,10 @@ void V_DrawKartString(INT32 x, INT32 y, INT32 option, const char *string) if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(kart_font[c]->width)*dupx/2; + center = w/2 - kart_font[c]->width*dupx/2; } else - w = SHORT(kart_font[c]->width) * dupx; + w = kart_font[c]->width * dupx; if (cx > scrwidth) break; @@ -2119,10 +2119,10 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(hu_font[c]->width)*dupx/4; + center = w/2 - hu_font[c]->width*dupx/4; } else - w = SHORT(hu_font[c]->width) * dupx / 2; + w = hu_font[c]->width * dupx / 2; if (cx > scrwidth) break; if (cx+left + w < 0) //left boundary check @@ -2236,8 +2236,8 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) if (charwidth) w = charwidth * dupx; else - w = ((option & V_6WIDTHSPACE ? max(1, SHORT(tny_font[c]->width)-1) // Reuse this flag for the alternate bunched-up spacing - : SHORT(tny_font[c]->width)) * dupx); + w = ((option & V_6WIDTHSPACE ? max(1, tny_font[c]->width-1) // Reuse this flag for the alternate bunched-up spacing + : tny_font[c]->width) * dupx); if (cx > scrwidth) break; @@ -2337,10 +2337,10 @@ void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(hu_font[c]->width)*(dupx/2); + center = w/2 - hu_font[c]->width*(dupx/2); } else - w = SHORT(hu_font[c]->width) * dupx; + w = hu_font[c]->width * dupx; if ((cx>>FRACBITS) > scrwidth) break; @@ -2535,10 +2535,10 @@ void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *str if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(tny_font[c]->width)*(dupx/2); + center = w/2 - tny_font[c]->width*(dupx/2); } else - w = SHORT(tny_font[c]->width) * dupx; + w = tny_font[c]->width * dupx; if ((cx>>FRACBITS) > scrwidth) break; @@ -2558,7 +2558,7 @@ void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *str // Draws a tallnum. Replaces two functions in y_inter and st_stuff void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num) { - INT32 w = SHORT(tallnum[0]->width); + INT32 w = tallnum[0]->width; boolean neg; if (flags & V_NOSCALESTART) @@ -2584,7 +2584,7 @@ void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num) // Does not handle negative numbers in a special way, don't try to feed it any. void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits) { - INT32 w = SHORT(tallnum[0]->width); + INT32 w = tallnum[0]->width; if (flags & V_NOSCALESTART) w *= vid.dupx; @@ -2605,7 +2605,7 @@ void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits) // Does not handle negative numbers in a special way, don't try to feed it any. void V_DrawPaddedTallColorNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits, const UINT8 *colormap) { - INT32 w = SHORT(tallnum[0]->width); + INT32 w = tallnum[0]->width; if (flags & V_NOSCALESTART) w *= vid.dupx; @@ -2627,7 +2627,7 @@ void V_DrawPaddedTallColorNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 di INT32 V_DrawPingNum(INT32 x, INT32 y, INT32 flags, INT32 num, const UINT8 *colormap) { - INT32 w = SHORT(pingnum[0]->width); // this SHOULD always be 5 but I guess custom graphics exist. + INT32 w = pingnum[0]->width; // this SHOULD always be 5 but I guess custom graphics exist. if (flags & V_NOSCALESTART) w *= vid.dupx; @@ -2650,7 +2650,7 @@ INT32 V_DrawPingNum(INT32 x, INT32 y, INT32 flags, INT32 num, const UINT8 *color // void V_DrawRankNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits, const UINT8 *colormap) { - INT32 w = SHORT(ranknum[0]->width) - 1; + INT32 w = ranknum[0]->width - 1; if (flags & V_NOSCALESTART) w *= vid.dupx; @@ -2709,7 +2709,7 @@ void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string) continue; } - w = SHORT(cred_font[c]->width) * dupx; + w = cred_font[c]->width * dupx; if ((cx>>FRACBITS) > scrwidth) break; @@ -2735,7 +2735,7 @@ INT32 V_CreditStringWidth(const char *string) if (c < 0 || c >= CRED_FONTSIZE) w += 16; else - w += SHORT(cred_font[c]->width); + w += cred_font[c]->width; } return w; @@ -2782,7 +2782,7 @@ void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) continue; } - w = SHORT(lt_font[c]->width) * dupx; + w = lt_font[c]->width * dupx; if (cx > scrwidth) break; if (cx+left + w < 0) //left boundary check @@ -2809,7 +2809,7 @@ INT32 V_LevelNameWidth(const char *string) if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) w += 12; else - w += SHORT(lt_font[c]->width); + w += lt_font[c]->width; } return w; @@ -2828,8 +2828,8 @@ INT32 V_LevelNameHeight(const char *string) if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) continue; - if (SHORT(lt_font[c]->height) > w) - w = SHORT(lt_font[c]->height); + if (lt_font[c]->height > w) + w = lt_font[c]->height; } return w; @@ -2871,7 +2871,7 @@ INT32 V_SubStringWidth(const char *string, INT32 length, INT32 option) if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) w += spacewidth; else - w += (charwidth ? charwidth : SHORT(hu_font[c]->width)); + w += (charwidth ? charwidth : hu_font[c]->width); } return w; @@ -2913,7 +2913,7 @@ INT32 V_SmallSubStringWidth(const char *string, INT32 length, INT32 option) if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) w += spacewidth; else - w += (charwidth ? charwidth : SHORT(hu_font[c]->width)/2); + w += (charwidth ? charwidth : hu_font[c]->width/2); } return w; @@ -2965,8 +2965,8 @@ INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option) else { w += (charwidth ? charwidth - : ((option & V_6WIDTHSPACE && i < length-1) ? max(1, SHORT(tny_font[c]->width)-1) // Reuse this flag for the alternate bunched-up spacing - : SHORT(tny_font[c]->width))); + : ((option & V_6WIDTHSPACE && i < length-1) ? max(1, tny_font[c]->width-1) // Reuse this flag for the alternate bunched-up spacing + : tny_font[c]->width)); } } @@ -3007,7 +3007,7 @@ INT32 V_SubStringLengthToFit(const char *string, INT32 width, INT32 option) if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) w += spacewidth; else - w += (charwidth ? charwidth : SHORT(hu_font[c]->width)); + w += (charwidth ? charwidth : hu_font[c]->width); } return max(i-1, 0); diff --git a/src/w_wad.c b/src/w_wad.c index 3642efe2f..0f298067d 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1814,7 +1814,6 @@ void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum) return (void *)rspr; } - #endif // ROTSPRITE void W_UnlockCachedPatch(void *patch) diff --git a/src/y_inter.c b/src/y_inter.c index 213bf90d8..68ad7365a 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -923,8 +923,8 @@ static void Y_DrawAnimatedVoteScreenPatch(boolean widePatch) currentAnimFrame = 0; patch_t *background = W_CachePatchName(va("%s%d", tempAnimPrefix, currentAnimFrame + 1), PU_CACHE); - V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (SHORT(background->width)/2), // Keep the width/height adjustments, for screens that are less wide than 320(?) - (vid.height / vid.dupy) - SHORT(background->height), + V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (background->width/2), // Keep the width/height adjustments, for screens that are less wide than 320(?) + (vid.height / vid.dupy) - background->height, V_SNAPTOTOP|V_SNAPTOLEFT, background); if (renderisnewtic && votetic % 2 == 0 && !paused) @@ -954,8 +954,8 @@ static void Y_DrawVoteScreenPatch(void) votebg = widebgpatch; } - V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (SHORT(votebg->width)/2), - (vid.height / vid.dupy) - SHORT(votebg->height), + V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (votebg->width/2), + (vid.height / vid.dupy) - votebg->height, V_SNAPTOTOP|V_SNAPTOLEFT, votebg); } From 39f8fa8d34205e80755b98177004cb1291cda78a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 15:56:41 +0200 Subject: [PATCH 03/44] add more purge tags refactor patch freeing and stuff currently dies when adding a wad midgame and the loading into another map --- src/console.c | 2 +- src/d_main.c | 4 +- src/f_finale.c | 43 +++--- src/hardware/hw_bsp.c | 6 +- src/hardware/hw_cache.c | 135 ++++++++++++----- src/hardware/hw_data.h | 36 +++-- src/hardware/hw_draw.c | 16 +- src/hardware/hw_gl.h | 1 + src/hardware/hw_glob.h | 2 +- src/hardware/hw_main.c | 14 +- src/hardware/hw_md2.c | 27 +++- src/hardware/r_opengl/r_opengl.c | 44 +++--- src/k_kart.c | 14 +- src/lua_hudlib.c | 6 +- src/m_menu.c | 246 +++++++++++++++---------------- src/p_setup.c | 6 +- src/r_data.c | 9 +- src/r_patch.c | 39 +++-- src/r_patch.h | 3 + src/r_segs.c | 2 +- src/r_splats.c | 2 +- src/r_things.c | 4 +- src/st_stuff.c | 10 +- src/v_video.c | 4 +- src/w_wad.c | 16 +- src/w_wad.h | 2 + src/y_inter.c | 30 ++-- src/z_zone.c | 31 ++-- src/z_zone.h | 7 +- 29 files changed, 447 insertions(+), 314 deletions(-) diff --git a/src/console.c b/src/console.c index 8cc04fe93..e99ea959b 100644 --- a/src/console.c +++ b/src/console.c @@ -1509,7 +1509,7 @@ static void CON_DrawConsole(void) // draw console background if (cons_backpic.value || con_forcepic) { - patch_t *con_backpic = W_CachePatchName("KARTKREW", PU_CACHE); + patch_t *con_backpic = W_CachePatchName("KARTKREW", PU_PATCH_LOWPRIORITY); // Jimita: CON_DrawBackpic just called V_DrawScaledPatch V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, con_backpic, NULL); diff --git a/src/d_main.c b/src/d_main.c index 6f281421a..fd57583d4 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -603,7 +603,7 @@ static boolean D_Display(void) py = 4; else py = viewwindowy + 4; - patch = W_CachePatchName("M_PAUSE", PU_CACHE); + patch = W_CachePatchName("M_PAUSE", PU_PATCH); V_DrawScaledPatch(viewwindowx + (BASEVIDWIDTH - patch->width)/2, py, V_SNAPTOTOP, patch); } @@ -733,7 +733,7 @@ void D_SRB2Loop(void) COM_ImmedExecute("cls;version"); if (rendermode == render_soft) - V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, W_CachePatchNum(W_GetNumForName("KARTKREW"), PU_CACHE), NULL); + V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, W_CachePatchNum(W_GetNumForName("KARTKREW"), PU_PATCH_LOWPRIORITY), NULL); I_FinishUpdate(); // page flip or blit buffer for (;;) diff --git a/src/f_finale.c b/src/f_finale.c index a534eee68..b92291467 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -164,8 +164,8 @@ static void F_SkyScroll(INT32 scrollspeed) patch_t *pat, *pat2; INT32 anim2 = 0; - pat = W_CachePatchName("TITLEBG1", PU_CACHE); - pat2 = W_CachePatchName("TITLEBG2", PU_CACHE); + pat = W_CachePatchName("TITLEBG1", PU_PATCH_LOWPRIORITY); + pat2 = W_CachePatchName("TITLEBG2", PU_PATCH_LOWPRIORITY); w = (vid.width / vid.dupx)<= 5*TICRATE) { if (drawemblem) - V_DrawScaledPatch(120, 192, 0, W_CachePatchName("NWNGA0", PU_CACHE)); + V_DrawScaledPatch(120, 192, 0, W_CachePatchName("NWNGA0", PU_PATCH_LOWPRIORITY)); if (drawchaosemblem) - V_DrawScaledPatch(200, 192, 0, W_CachePatchName("NWNGA0", PU_CACHE)); + V_DrawScaledPatch(200, 192, 0, W_CachePatchName("NWNGA0", PU_PATCH_LOWPRIORITY)); V_DrawString(8, 16, V_YELLOWMAP, "Unlocked:"); @@ -975,10 +972,10 @@ void F_StartTitleScreen(void) demoDelayLeft = demoDelayTime; demoIdleLeft = demoIdleTime; - ttbanner = W_CachePatchName("TTKBANNR", PU_LEVEL); - ttkart = W_CachePatchName("TTKART", PU_LEVEL); - ttcheckers = W_CachePatchName("TTCHECK", PU_LEVEL); - ttkflash = W_CachePatchName("TTKFLASH", PU_LEVEL); + ttbanner = W_CachePatchName("TTKBANNR", PU_PATCH_LOWPRIORITY); + ttkart = W_CachePatchName("TTKART", PU_PATCH_LOWPRIORITY); + ttcheckers = W_CachePatchName("TTCHECK", PU_PATCH_LOWPRIORITY); + ttkflash = W_CachePatchName("TTKFLASH", PU_PATCH_LOWPRIORITY); } // (no longer) De-Demo'd Title Screen @@ -1193,7 +1190,7 @@ void F_StartWaitingPlayers(void) for (i = 0; i < 2; i++) { sprframe = &skins[randskin].spritedef.spriteframes[(6+(i*3)) & FF_FRAMEMASK]; - driver[i] = W_CachePatchNum(sprframe->lumppat[1], PU_LEVEL); + driver[i] = W_CachePatchNum(sprframe->lumppat[1], PU_SPRITE); } } @@ -1262,9 +1259,9 @@ void F_ContinueDrawer(void) ncontinues = 20; if (imcontinuing) - contsonic = W_CachePatchName("CONT2", PU_CACHE); + contsonic = W_CachePatchName("CONT2", PU_PATCH_LOWPRIORITY); else - contsonic = W_CachePatchName("CONT1", PU_CACHE); + contsonic = W_CachePatchName("CONT1", PU_PATCH_LOWPRIORITY); V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); V_DrawCenteredString(BASEVIDWIDTH/2, 100, 0, "CONTINUE?"); @@ -1489,10 +1486,10 @@ void F_CutsceneDrawer(void) { if (cutscenes[cutnum]->scene[scenenum].pichires[picnum]) V_DrawSmallScaledPatch(picxpos, picypos, 0, - W_CachePatchName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_CACHE)); + W_CachePatchName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY)); else V_DrawScaledPatch(picxpos,picypos, 0, - W_CachePatchName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_CACHE)); + W_CachePatchName(cutscenes[cutnum]->scene[scenenum].picname[picnum], PU_PATCH_LOWPRIORITY)); } if (dofadenow && rendermode != render_none) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 88ef77320..934f13a14 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -369,7 +369,7 @@ static poly_t *CutOutSubsecPoly(seg_t *lseg, INT32 count, poly_t *poly) { //x,y,dx,dy (like a divline) line_t *line = lseg->linedef; - + // portal check if (!gl_maphasportals && line->special == 40 && lseg->side == 0) { @@ -380,7 +380,7 @@ static poly_t *CutOutSubsecPoly(seg_t *lseg, INT32 count, poly_t *poly) if (line2 >= 0) // found it! gl_maphasportals = 1; } - + p1.x = FIXED_TO_FLOAT(lseg->side ? line->v2->x : line->v1->x); p1.y = FIXED_TO_FLOAT(lseg->side ? line->v2->y : line->v1->y); p2.x = FIXED_TO_FLOAT(lseg->side ? line->v1->x : line->v2->x); @@ -523,7 +523,7 @@ static void loading_status(void) x = BASEVIDWIDTH/2; y = BASEVIDHEIGHT/2; V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // Black background to match fade in effect - //V_DrawPatchFill(W_CachePatchName("SRB2BACK",PU_CACHE)); // SRB2 background, ehhh too bright. + //V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); // SRB2 background, ehhh too bright. M_DrawTextBox(x-58, y-8, 13, 1); V_DrawString(x-50, y, V_YELLOWMAP, "Loading..."); V_DrawRightAlignedString(x+50, y, V_YELLOWMAP, s); diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 836d3adac..83a3a2d6b 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -117,7 +117,7 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm //Hurdler: 25/04/2000: now support colormap in hardware mode if (mipmap->colormap) - texel = mipmap->colormap[texel]; + texel = mipmap->colormap->data[texel]; // hope compiler will get this switch out of the loops (dreams...) // gcc do it ! but vcc not ! (why don't use cygwin gcc for win32 ?) @@ -314,9 +314,10 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe texture_t *texture; texpatch_t *patch; softwarepatch_t *realpatch; - UINT8 *pdata; INT32 blockwidth, blockheight, blocksize; + UINT8 *colormap = colormaps; + INT32 i, idx; boolean skyspecial = false; // poor hack for Legacy large skies.. @@ -326,9 +327,6 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe texture = textures[texnum]; gltex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY; - gltex->mipmap.width = (UINT16)(texture->width); - gltex->mipmap.height = (UINT16)(texture->height); - gltex->mipmap.colormap = colormaps; gltex->mipmap.format = textureformat; // hack the Legacy skies.. @@ -340,11 +338,18 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe gltex->mipmap.format = GL_TEXFMT_RGBA; // that skyspecial code below assumes this format ... } + gltex->mipmap.width = (UINT16)(texture->width); + gltex->mipmap.height = (UINT16)(texture->height); + #ifdef GLENCORE if (encoremap && !noencore) - gltex->mipmap.colormap += COLORMAP_REMAPOFFSET; + colormap += COLORMAP_REMAPOFFSET; #endif + gltex->mipmap.colormap = Z_Calloc(sizeof(*gltex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); + gltex->mipmap.colormap->source = colormap; + M_Memcpy(gltex->mipmap.colormap->data, colormap, 256 * sizeof(UINT8)); + blockwidth = texture->width; blockheight = texture->height; blocksize = (blockwidth * blockheight); @@ -372,8 +377,12 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); - realpatch = (softwarepatch_t *)pdata; + // If this patch has already been loaded, we just use it from the cache. + realpatch = (softwarepatch_t *)W_GetCachedPatchNumPwad(patch->wad, patch->lump); + + // Otherwise, we load it here. + if (realpatch == NULL) + realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); if (realpatch != NULL) { @@ -399,7 +408,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe } // patch may be NULL if glMipmap has been initialised already and makebitmap is false -void HWR_MakePatch (patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap) +void HWR_MakePatch(const patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap) { if (glMipmap->width == 0) { @@ -440,17 +449,17 @@ static GLMapTexture_t *gl_textures; // For all textures void HWR_FreeTextureData(patch_t *patch) { - GLPatch_t *grPatch; + GLPatch_t *glPatch; if (!patch || !patch->hardware) return; - grPatch = patch->hardware; + glPatch = patch->hardware; if (vid.glstate == VID_GL_LIBRARY_LOADED) - GL_DeleteTexture(grPatch->mipmap); - if (grPatch->mipmap->data) - Z_Free(grPatch->mipmap->data); + GL_DeleteTexture(glPatch->mipmap); + if (glPatch->mipmap->data) + Z_Free(glPatch->mipmap->data); } void HWR_FreeTexture(patch_t *patch) @@ -486,7 +495,6 @@ void HWR_FreeTextureColormaps(patch_t *patch) return; pat = patch->hardware; - if (!pat) return; @@ -508,12 +516,19 @@ void HWR_FreeTextureColormaps(patch_t *patch) // Set the first colormap to the one that comes after it. next = pat->mipmap->nextcolormap; + + if (!next) + break; + pat->mipmap->nextcolormap = next->nextcolormap; // Free image data from memory. if (next->data) Z_Free(next->data); + if (next->colormap) + Z_Free(next->colormap); next->data = NULL; + next->colormap = NULL; GL_DeleteTexture(next); // Free the old colormap mipmap from memory. @@ -521,16 +536,30 @@ void HWR_FreeTextureColormaps(patch_t *patch) } } +static boolean FreeTextureCallback(void *mem) +{ + patch_t *patch = (patch_t *)mem; + HWR_FreeTexture(patch); + return false; +} + +static boolean FreeColormapsCallback(void *mem) +{ + patch_t *patch = (patch_t *)mem; + HWR_FreeTextureColormaps(patch); + return false; +} + static void HWR_FreePatchCache(boolean freeall) { - INT32 i; + boolean (*callback)(void *mem) = FreeTextureCallback; - for (i = 0; i < numwadfiles; i++) - { - INT32 j = 0; - for (; j < wadfiles[i]->numlumps; j++) - (freeall ? HWR_FreeTexture : HWR_FreeTextureColormaps)(wadfiles[i]->patchcache[j]); - } + if (!freeall) + callback = FreeColormapsCallback; + + Z_IterateTags(PU_PATCH, PU_PATCH_ROTATED, callback); + //Z_IterateTags(PU_SPRITE, PU_HUDGFX, callback); // why would we want to free our hudgfx? + Z_IterateTags(PU_SPRITE, PU_SPRITE, callback); } // free all textures after each level @@ -556,6 +585,7 @@ static void FreeMapTexture(GLMapTexture_t *tex) GL_DeleteTexture(&tex->mipmap); if (tex->mipmap.data) Z_Free(tex->mipmap.data); + tex->mipmap.data = NULL; } void HWR_FreeMapTextures(void) @@ -788,7 +818,7 @@ static void HWR_PrecacheLevelSprites(void) #define cacheang(a) {\ lump = sf->lumppat[a];\ - spritepatch = (patch_t *)W_CachePatchNum(lump, PU_CACHE);\ + spritepatch = (patch_t *)W_CachePatchNum(lump, PU_SPRITE);\ if (spritepatch != NULL)\ HWR_GetPatch(spritepatch);\ } @@ -831,10 +861,9 @@ void HWR_PrecacheLevel(void) void HWR_LoadMapTextures(size_t pnumtextures) { - // we must free it since numtextures changed + // we must free it since numtextures may have changed HWR_FreeMapTextures(); - // Why not Z_Malloc? gl_numtextures = pnumtextures; #ifdef GLENCORE gl_textures = calloc(pnumtextures, sizeof (*gl_textures)*2); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore) @@ -936,7 +965,7 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) if (flat[steppy] == HWR_PATCHES_CHROMAKEY_COLORINDEX) continue; - flat[steppy] = glMipmap->colormap[flat[steppy]]; + flat[steppy] = glMipmap->colormap->source[flat[steppy]]; } #endif } @@ -946,6 +975,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) { GLMipmap_t *glMipmap; patch_t *patch; + UINT8 *colormap = colormaps; if (flatlumpnum == LUMPERROR) return; @@ -953,12 +983,16 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) patch = HWR_GetCachedGLPatch(flatlumpnum); glMipmap = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap; - glMipmap->colormap = colormaps; - + if (!glMipmap->colormap) + { #ifdef GLENCORE - if (!noencoremap && encoremap) - glMipmap->colormap += COLORMAP_REMAPOFFSET; + if (!noencoremap && encoremap) + colormap += COLORMAP_REMAPOFFSET; #endif + glMipmap->colormap = Z_Calloc(sizeof(*glMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + glMipmap->colormap->source = colormap; + M_Memcpy(glMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); + } if (!glMipmap->downloaded && !glMipmap->data) HWR_CacheFlat(glMipmap, flatlumpnum); @@ -991,6 +1025,26 @@ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); } +// ----------------------+ +// HWR_UpdatePatchMipmap : Updates a mipmap. +// ----------------------+ +static void HWR_UpdatePatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) +{ + GLPatch_t *grPatch = patch->hardware; + HWR_MakePatch(patch, grPatch, glMipmap, true); + + // If hardware does not have the texture, then call pfnSetTexture to upload it + // If it does have the texture, then call pfnUpdateTexture to update it + if (!glMipmap->downloaded) + GL_SetTexture(glMipmap); + else + GL_UpdateTexture(glMipmap); + HWR_SetCurrentTexture(glMipmap); + + // The system-memory data can be purged now. + Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); +} + // -----------------+ // HWR_GetPatch : Downloads a patch to the hardware cache and make it ready for use // -----------------+ @@ -1013,7 +1067,8 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) Patch_CreateGL(patch); glPatch = patch->hardware; - if (colormap == colormaps || colormap == NULL) + // Blatant hack for encore colormapping aside... + if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET)) { // Load the default (green) color in hardware cache HWR_GetPatch(patch); @@ -1026,9 +1081,16 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) { glMipmap = glMipmap->nextcolormap; - if (UNLIKELY(glMipmap->colormap == colormap)) + if (UNLIKELY(glMipmap->colormap && glMipmap->colormap->source == colormap)) { - HWR_LoadPatchMipmap(patch, glMipmap); + if (memcmp(glMipmap->colormap->data, colormap, 256 * sizeof(UINT8))) + { + M_Memcpy(glMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); + HWR_UpdatePatchMipmap(patch, glMipmap); + } + else + HWR_LoadPatchMipmap(patch, glMipmap); + return; } } @@ -1044,7 +1106,10 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) I_Error("%s: Out of memory", "HWR_GetMappedPatch"); glMipmap->nextcolormap = newMipmap; - newMipmap->colormap = colormap; + newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + newMipmap->colormap->source = colormap; + M_Memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); + HWR_LoadPatchMipmap(patch, newMipmap); } @@ -1061,7 +1126,7 @@ patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum) lumpcache_t *lumpcache = wadfiles[wadnum]->patchcache; if (!lumpcache[lumpnum]) { - void *ptr = Z_Calloc(sizeof(patch_t), PU_CACHE, &lumpcache[lumpnum]); + void *ptr = Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]); Patch_Create(NULL, 0, ptr); Patch_AllocateHardwarePatch(ptr); } diff --git a/src/hardware/hw_data.h b/src/hardware/hw_data.h index d7c11b2c2..f253eccb8 100644 --- a/src/hardware/hw_data.h +++ b/src/hardware/hw_data.h @@ -23,31 +23,39 @@ typedef enum GLTextureFormat_e { - GL_TEXFMT_P_8 = 0x01, /* 8-bit palette */ - GL_TEXFMT_AP_88 = 0x02, /* 8-bit alpha, 8-bit palette */ + GL_TEXFMT_P_8 = 0x01, /* 8-bit palette */ + GL_TEXFMT_AP_88 = 0x02, /* 8-bit alpha, 8-bit palette */ - GL_TEXFMT_RGBA = 0x10, /* 32 bit RGBA! */ + GL_TEXFMT_RGBA = 0x10, /* 32 bit RGBA! */ - GL_TEXFMT_ALPHA_8 = 0x20, /* (0..0xFF) alpha */ - GL_TEXFMT_INTENSITY_8 = 0x21, /* (0..0xFF) intensity */ - GL_TEXFMT_ALPHA_INTENSITY_88 = 0x22, + GL_TEXFMT_ALPHA_8 = 0x20, /* (0..0xFF) alpha */ + GL_TEXFMT_INTENSITY_8 = 0x21, /* (0..0xFF) intensity */ + GL_TEXFMT_ALPHA_INTENSITY_88 = 0x22, } GLTextureFormat_t; +// Colormap structure for mipmaps. +struct GLColormap_s +{ + const UINT8 *source; + UINT8 data[256]; +}; +typedef struct GLColormap_s GLColormap_t; + // Texture information (misleadingly named "mipmap" all over the code.) // The *data pointer holds the address of the graphics data cached in heap memory. // NULL if the texture is not in SRB2's heap cache. struct GLMipmap_s { // for UpdateTexture - GLTextureFormat_t format; - void *data; + GLTextureFormat_t format; + void *data; - UINT32 flags; - UINT16 width, height; + UINT32 flags; + UINT16 width, height; UINT32 downloaded; // The GPU has this texture. - struct GLMipmap_s *nextcolormap; - const UINT8 *colormap; + struct GLMipmap_s *nextcolormap; + struct GLColormap_s *colormap; }; typedef struct GLMipmap_s GLMipmap_t; @@ -62,11 +70,11 @@ struct GLMapTexture_s }; typedef struct GLMapTexture_s GLMapTexture_t; -// a cached patch as converted to hardware format +// Patch information for the hardware renderer. struct GLPatch_s { - float max_s,max_t; GLMipmap_t *mipmap; + float max_s,max_t; boolean notfound; // if the texture file was not found, mark it here (used in model texture loading) }; typedef struct GLPatch_s GLPatch_t; diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index d47d58841..9fd90fb09 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -712,7 +712,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // top edge if (clearlines > basewindowy - 8) { - patch = W_CachePatchNum(viewborderlump[BRDR_T], PU_CACHE); + patch = W_CachePatchNum(viewborderlump[BRDR_T], PU_PATCH); for (x = 0; x < baseviewwidth; x += 8) HWR_DrawPatch(patch, basewindowx + x, basewindowy - 8, 0); @@ -721,7 +721,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // bottom edge if (clearlines > basewindowy + baseviewheight) { - patch = W_CachePatchNum(viewborderlump[BRDR_B], PU_CACHE); + patch = W_CachePatchNum(viewborderlump[BRDR_B], PU_PATCH); for (x = 0; x < baseviewwidth; x += 8) HWR_DrawPatch(patch, basewindowx + x, basewindowy + baseviewheight, 0); @@ -730,7 +730,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // left edge if (clearlines > basewindowy) { - patch = W_CachePatchNum(viewborderlump[BRDR_L], PU_CACHE); + patch = W_CachePatchNum(viewborderlump[BRDR_L], PU_PATCH); for (y = 0; y < baseviewheight && basewindowy + y < clearlines; y += 8) { @@ -742,7 +742,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // right edge if (clearlines > basewindowy) { - patch = W_CachePatchNum(viewborderlump[BRDR_R], PU_CACHE); + patch = W_CachePatchNum(viewborderlump[BRDR_R], PU_PATCH); for (y = 0; y < baseviewheight && basewindowy+y < clearlines; y += 8) { @@ -754,22 +754,22 @@ void HWR_DrawViewBorder(INT32 clearlines) // Draw beveled corners. if (clearlines > basewindowy - 8) HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TL], - PU_CACHE), + PU_PATCH), basewindowx - 8, basewindowy - 8, 0); if (clearlines > basewindowy - 8) HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TR], - PU_CACHE), + PU_PATCH), basewindowx + baseviewwidth, basewindowy - 8, 0); if (clearlines > basewindowy+baseviewheight) HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BL], - PU_CACHE), + PU_PATCH), basewindowx - 8, basewindowy + baseviewheight, 0); if (clearlines > basewindowy + baseviewheight) HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BR], - PU_CACHE), + PU_PATCH), basewindowx + baseviewwidth, basewindowy + baseviewheight, 0); } diff --git a/src/hardware/hw_gl.h b/src/hardware/hw_gl.h index c2a88854f..44fa28bf2 100644 --- a/src/hardware/hw_gl.h +++ b/src/hardware/hw_gl.h @@ -40,6 +40,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics void GL_RenderSkyDome(gl_sky_t *sky); +void GL_UpdateTexture(GLMipmap_t *pTexInfo); void GL_SetTexture(GLMipmap_t *pTexInfo); void GL_DeleteTexture(GLMipmap_t *pTexInfo); diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 31ecc7792..0589ba1d2 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -65,7 +65,7 @@ patch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum); void HWR_GetPatch(patch_t *gpatch); void HWR_GetMappedPatch(patch_t *gpatch, const UINT8 *colormap); -void HWR_MakePatch(patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap); +void HWR_MakePatch(const patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipmap, boolean makebitmap); void HWR_GetFadeMask(lumpnum_t fademasklumpnum); void HWR_PrecacheLevel(void); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 8e877a044..1ec415292 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -844,7 +844,7 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) if (!M_PointInBox(segbbox,splat->v1.x,splat->v1.y) && !M_PointInBox(segbbox,splat->v2.x,splat->v2.y)) continue; - gpatch = W_CachePatchNum(splat->patch, PU_CACHE); + gpatch = W_CachePatchNum(splat->patch, PU_SPRITE); HWR_GetPatch(gpatch); wallVerts[0].x = wallVerts[3].x = FIXED_TO_FLOAT(splat->v1.x); @@ -4903,7 +4903,7 @@ static void HWR_ProjectSprite(mobj_t *thing) vis->gpatch = (patch_t *)rotsprite; else #endif - vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE); + vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE); vis->mobj = thing; @@ -5071,15 +5071,15 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) vis->z2 = z2; vis->tz = tz; vis->dispoffset = 0; // Monster Iestyn: 23/11/15: HARDWARE SUPPORT AT LAST - vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE); + vis->gpatch = (patch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE); vis->flip = flip; vis->mobj = (mobj_t *)thing; - vis->colormap = colormaps; + vis->colormap = NULL; #ifdef GLENCORE - if (encoremap && !(thing->flags & MF_DONTENCOREMAP)) - vis->colormap += COLORMAP_REMAPOFFSET; + //if (encoremap && !(thing->flags & MF_DONTENCOREMAP)) + //vis->colormap += COLORMAP_REMAPOFFSET; #endif // set top/bottom coords @@ -5548,7 +5548,7 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) if (splitscreen == 2 && player == &players[displayplayers[2]]) { // V_DrawPatchFill, but for the fourth screen only - patch_t *gpatch = W_CachePatchName("SRB2BACK", PU_CACHE); + patch_t *gpatch = W_CachePatchName("SRB2BACK", PU_PATCH); INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); INT32 x, y, pw = (gpatch->width) * dupz, ph = (gpatch->height) * dupz; diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 2a5643d53..d74486ac4 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1086,14 +1086,22 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 sk { glMipmap = glMipmap->nextcolormap; - if (glMipmap->colormap != colormap) - continue; - - if (glMipmap->downloaded && glMipmap->data) + if (glMipmap->colormap && glMipmap->colormap->source == colormap) { - GL_SetTexture(glMipmap); // found the colormap, set it to the correct texture - Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); - return; + if (glMipmap->downloaded && glMipmap->data) + { + if (memcmp(glMipmap->colormap->data, colormap, 256 * sizeof(UINT8))) + { + M_Memcpy(glMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); + HWR_CreateBlendedTexture(patch, blendgpatch, glMipmap, skinnum, color); + GL_UpdateTexture(glMipmap); + } + else + GL_SetTexture(glMipmap); // found the colormap, set it to the correct texture + + Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); + return; + } } } @@ -1108,7 +1116,10 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 sk if (newMipmap == NULL) I_Error("%s: Out of memory", "HWR_GetMappedPatch"); glMipmap->nextcolormap = newMipmap; - newMipmap->colormap = colormap; + + newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + newMipmap->colormap->source = colormap; + M_Memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); HWR_CreateBlendedTexture(patch, blendgpatch, newMipmap, skinnum, color); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index b5bb031e0..5c81db186 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -191,7 +191,7 @@ FUNCPRINTF void GL_DBG_Printf(const char *format, ...) if (!gllogstream) gllogstream = fopen("ogllog.txt", "w"); - + va_start(arglist, format); vsnprintf(str, 4096, format, arglist); va_end(arglist); @@ -673,7 +673,7 @@ typedef enum gluniform_light_dir, gluniform_light_contrast, gluniform_light_backlight, - + // palette rendering gluniform_palette_tex, // 1d texture containing a palette gluniform_palette_lookup_tex, // 3d texture containing the rgb->index lookup table @@ -743,7 +743,7 @@ void SetupGLFunc4(void) pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); pglMultiTexCoord2fv = GetGLFunc("glMultiTexCoord2fv"); - + /* 1.5 funcs */ pglGenBuffers = GetGLFunc("glGenBuffers"); pglBindBuffer = GetGLFunc("glBindBuffer"); @@ -753,7 +753,7 @@ void SetupGLFunc4(void) /* 2.0 funcs */ pglBlendEquation = GetGLFunc("glBlendEquation"); - + pglStencilFuncSeparate = GetGLFunc("glStencilFuncSeparate"); pglStencilOpSeparate = GetGLFunc("glStencilOpSeparate"); @@ -809,7 +809,7 @@ boolean GL_InitShaders(void) { if (!pglUseProgram) return false; - + gl_fallback_shader.vertex_shader = Z_StrDup(GLSL_FALLBACK_VERTEX_SHADER); gl_fallback_shader.fragment_shader = Z_StrDup(GLSL_FALLBACK_FRAGMENT_SHADER); @@ -1643,7 +1643,7 @@ static void GL_AllocTextureBuffer(GLMipmap_t *pTexInfo) // -----------------+ // UpdateTexture : Updates texture data. // -----------------+ -static void GL_UpdateTexture(GLMipmap_t *pTexInfo) +void GL_UpdateTexture(GLMipmap_t *pTexInfo) { // Upload a texture GLuint num = pTexInfo->downloaded; @@ -2024,7 +2024,7 @@ static boolean GL_Shader_CompileProgram(gl_shader_t *shader, GLint i) pglDeleteShader(gl_vertShader); if (frag_shader) pglDeleteShader(gl_fragShader); - + // couldn't link? if (result != GL_TRUE) { @@ -2313,7 +2313,7 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) gltexformat = (Value == 32) ? GL_RGBA : GL_RGB5_A1; GL_Flush(); break; - + case HWD_SET_MSAA: if (Value) { @@ -2623,7 +2623,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics scalex = hscale; scaley = vscale; scalez = hscale; - + if (duration > 0.0 && tics >= 0.0) // don't interpolate if instantaneous or infinite in length { float newtime = (duration - tics); // + 1; @@ -2692,7 +2692,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics pglRotatef(pos->anglez, 0.0f, 0.0f, -1.0f); pglRotatef(pos->anglex, 1.0f, 0.0f, 0.0f); pglRotatef(pos->angley, 0.0f, -1.0f, 0.0f); - + if (pos->roll) { pglTranslatef(pos->centerx, pos->centery, 0); @@ -2895,7 +2895,7 @@ INT32 GL_GetTextureUsed(void) res += tmp->height*tmp->width*bpp; tmp = tmp->next; } - + return res; } @@ -2913,8 +2913,8 @@ void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]) 16.0f, 16.0f, 6.0f, 16.0f, -16.0f, 6.0f }; - - if (gl_enable_screen_textures != 2) + + if (gl_enable_screen_textures != 2) return; // look for power of two that is large enough for the screen @@ -3010,8 +3010,8 @@ void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags) }; float fix[8]; - - if (gl_enable_screen_textures != 2) + + if (gl_enable_screen_textures != 2) return; // look for power of two that is large enough for the screen @@ -3039,7 +3039,7 @@ void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags) pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); pglBindTexture(GL_TEXTURE_2D, screenTextures[tex]); - + GL_PreparePolygon(surf, surf ? polyflags : (PF_NoDepthTest)); if (!surf) pglColor4ubv(white); @@ -3078,7 +3078,7 @@ void GL_DoScreenWipe(int wipeStart, int wipeEnd) 1.0f, 1.0f }; - if (!gl_enable_screen_textures) + if (!gl_enable_screen_textures) return; // look for power of two that is large enough for the screen @@ -3164,7 +3164,7 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 1.0f, -1.0f, 1.0f }; - if (gl_enable_screen_textures != 2) + if (gl_enable_screen_textures != 2) return; // look for power of two that is large enough for the screen @@ -3261,7 +3261,7 @@ void GL_MakeScreenTexture(int tex) { INT32 texsizew = 512, texsizey = 512; boolean firstTime = (screenTextures[tex] == 0); - + if (!gl_enable_screen_textures) return; @@ -3301,7 +3301,7 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh float off[12]; float fix[8]; - + if (gl_enable_screen_textures != 2) return; @@ -3392,7 +3392,7 @@ void GL_SetPaletteLookup(UINT8 *lut) { internalFormat = GL_R8; } - + if (!paletteLookupTex) pglGenTextures(1, &paletteLookupTex); pglActiveTexture(GL_TEXTURE1); @@ -3441,7 +3441,7 @@ void GL_ClearLightTables(void) } LightTablesTail = NULL; - + // we no longer have a bound light table (if we had one), we just deleted it! lt_downloaded = 0; } diff --git a/src/k_kart.c b/src/k_kart.c index fb14741cc..7fdd8351b 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -8982,7 +8982,7 @@ void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UI if (emblem->collected) { - emblempic[curemb] = W_CachePatchName(M_GetEmblemPatch(emblem), PU_CACHE); + emblempic[curemb] = W_CachePatchName(M_GetEmblemPatch(emblem), PU_PATCH); emblemcol[curemb] = R_GetTranslationColormap(TC_DEFAULT, M_GetEmblemColor(emblem), GTC_CACHE); if (++curemb == 3) break; @@ -9018,7 +9018,7 @@ void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UI V_DrawRightAlignedString(workx, worky, splitflags, targettext); workx -= 67; - V_DrawSmallScaledPatch(workx + 4, worky, splitflags, W_CachePatchName("NEEDIT", PU_CACHE)); + V_DrawSmallScaledPatch(workx + 4, worky, splitflags, W_CachePatchName("NEEDIT", PU_PATCH)); break; @@ -9546,11 +9546,11 @@ static void K_DrawDialSpeedometer(fixed_t speed, if (rot) { - dialpatch = W_CachePatchNameRotated("K_DSDIAL", rot, PU_STATIC); + dialpatch = W_CachePatchNameRotated("K_DSDIAL", rot, PU_PATCH); } else { - dialpatch = W_CachePatchName("K_DSDIAL", PU_STATIC); + dialpatch = W_CachePatchName("K_DSDIAL", PU_PATCH); } if (colorized) // Colourized hud @@ -10587,7 +10587,7 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags) if (rot) { - minimaphead = W_CachePatchNameRotated(skin->facemmap, rot, PU_STATIC); + minimaphead = W_CachePatchNameRotated(skin->facemmap, rot, PU_PATCH); } } #endif @@ -11629,8 +11629,8 @@ void K_drawKartHUD(void) x += offs - frac; } - V_DrawSciencePatch(x - (54*FRACUNIT), y, logoflags, W_CachePatchName("TTKBANNR", PU_CACHE), FRACUNIT/4); - V_DrawSciencePatch(x - (54*FRACUNIT), y + (25*FRACUNIT), logoflags, W_CachePatchName("TTKART", PU_CACHE), FRACUNIT/4); + V_DrawSciencePatch(x - (54*FRACUNIT), y, logoflags, W_CachePatchName("TTKBANNR", PU_PATCH), FRACUNIT/4); + V_DrawSciencePatch(x - (54*FRACUNIT), y + (25*FRACUNIT), logoflags, W_CachePatchName("TTKART", PU_PATCH), FRACUNIT/4); } else if (G_RaceGametype()) // Race-only elements { diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 5bfb21e2e..b2425ec0a 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -396,7 +396,7 @@ static int libd_patchExists(lua_State *L) static int libd_cachePatch(lua_State *L) { HUDONLY - LUA_PushUserdata(L, W_CachePatchName(luaL_checkstring(L, 1), PU_STATIC), META_PATCH); + LUA_PushUserdata(L, W_CachePatchName(luaL_checkstring(L, 1), PU_PATCH), META_PATCH); return 1; } @@ -406,7 +406,7 @@ static int libd_cachePatchRotated(lua_State *L) HUDONLY angle_t rollangle = luaL_checkangle(L, 2); INT32 rot = R_GetRollAngle(rollangle); - LUA_PushUserdata(L, W_CachePatchNameRotated(luaL_checkstring(L, 1), rot, PU_STATIC), META_PATCH); + LUA_PushUserdata(L, W_CachePatchNameRotated(luaL_checkstring(L, 1), rot, PU_PATCH), META_PATCH); return 1; } @@ -526,7 +526,7 @@ static int libd_getSpritePatch(lua_State *L) #endif // push both the patch and its "flip" value - LUA_PushUserdata(L, W_CachePatchNum(sprframe->lumppat[angle], PU_STATIC), META_PATCH); + LUA_PushUserdata(L, W_CachePatchNum(sprframe->lumppat[angle], PU_SPRITE), META_PATCH); lua_pushboolean(L, (sprframe->flip & (1<width - p->leftoffset; for (i = 0; i < 16; i++) { - V_DrawScaledPatch(xx, y, V_WRAPX, W_CachePatchNum(centerlump[i & 1], PU_CACHE)); + V_DrawScaledPatch(xx, y, V_WRAPX, W_CachePatchNum(centerlump[i & 1], PU_PATCH)); xx += 8; } - V_DrawScaledPatch(xx, y, 0, W_CachePatchNum(rightlump, PU_CACHE)); + V_DrawScaledPatch(xx, y, 0, W_CachePatchNum(rightlump, PU_PATCH)); xx = (cv->value - cv->PossibleValue[0].value) * (15*8) / (cv->PossibleValue[1].value - cv->PossibleValue[0].value); - V_DrawScaledPatch((x + 8) + xx, y, 0, W_CachePatchNum(cursorlump, PU_CACHE)); + V_DrawScaledPatch((x + 8) + xx, y, 0, W_CachePatchNum(cursorlump, PU_PATCH)); } // A smaller 'Thermo', with range given as percents (0-100) @@ -5067,18 +5067,18 @@ static void M_DrawSlider(INT32 x, INT32 y, const consvar_t *cv, boolean ontop) x = BASEVIDWIDTH - x - SLIDER_WIDTH; - p = W_CachePatchName("M_SLIDEL", PU_CACHE); + p = W_CachePatchName("M_SLIDEL", PU_PATCH); V_DrawScaledPatch(x - 8, y, 0, p); - p = W_CachePatchName("M_SLIDEM", PU_CACHE); + p = W_CachePatchName("M_SLIDEM", PU_PATCH); for (i = 0; i < SLIDER_RANGE; i++) V_DrawScaledPatch (x+i*8, y, 0,p); - p = W_CachePatchName("M_SLIDER", PU_CACHE); + p = W_CachePatchName("M_SLIDER", PU_PATCH); V_DrawScaledPatch(x+i*8, y, 0, p); // draw the slider cursor - p = W_CachePatchName("M_SLIDEC", PU_CACHE); + p = W_CachePatchName("M_SLIDEC", PU_PATCH); for (i = 0; cv->PossibleValue[i+1].strvalue; i++); @@ -5174,10 +5174,10 @@ static void M_DrawMapEmblems(INT32 mapnum, INT32 x, INT32 y) lasttype = curtype; if (emblem->collected) - V_DrawSmallMappedPatch(x, y, 0, W_CachePatchName(M_GetEmblemPatch(emblem), PU_CACHE), + V_DrawSmallMappedPatch(x, y, 0, W_CachePatchName(M_GetEmblemPatch(emblem), PU_PATCH), R_GetTranslationColormap(TC_DEFAULT, M_GetEmblemColor(emblem), GTC_MENUCACHE)); else - V_DrawSmallScaledPatch(x, y, 0, W_CachePatchName("NEEDIT", PU_CACHE)); + V_DrawSmallScaledPatch(x, y, 0, W_CachePatchName("NEEDIT", PU_PATCH)); emblem = M_GetLevelEmblems(-1); x -= 8; @@ -5188,7 +5188,7 @@ static void M_DrawMenuTitle(void) { if (currentMenu->menutitlepic) { - patch_t *p = W_CachePatchName(currentMenu->menutitlepic, PU_CACHE); + patch_t *p = W_CachePatchName(currentMenu->menutitlepic, PU_PATCH); if (p->height > 24) // title is larger than normal { @@ -5292,13 +5292,13 @@ static void M_DrawGenericMenu(void) if (currentMenu->menuitems[i].status & IT_CENTER) { patch_t *p; - p = W_CachePatchName(currentMenu->menuitems[i].patch, PU_CACHE); + p = W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); V_DrawScaledPatch((BASEVIDWIDTH - p->width)/2, y, 0, p); } else { V_DrawScaledPatch(x, y, 0, - W_CachePatchName(currentMenu->menuitems[i].patch, PU_CACHE)); + W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH)); } } /* FALLTHRU */ @@ -5370,7 +5370,7 @@ static void M_DrawGenericMenu(void) case IT_GRAYPATCH: if (currentMenu->menuitems[i].patch && currentMenu->menuitems[i].patch[0]) V_DrawMappedPatch(x, y, 0, - W_CachePatchName(currentMenu->menuitems[i].patch,PU_CACHE), graymap); + W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH), graymap); y += LINEHEIGHT; break; case IT_TRANSTEXT: @@ -5403,12 +5403,12 @@ static void M_DrawGenericMenu(void) || ((currentMenu->menuitems[itemOn].status & IT_DISPLAY) == IT_NOTHING)) { V_DrawScaledPatch(currentMenu->x + SKULLXOFF, cursory - 5, 0, - W_CachePatchName("M_CURSOR", PU_CACHE)); + W_CachePatchName("M_CURSOR", PU_PATCH)); } else { V_DrawScaledPatch(currentMenu->x - 24, cursory, 0, - W_CachePatchName("M_CURSOR", PU_CACHE)); + W_CachePatchName("M_CURSOR", PU_PATCH)); V_DrawString(currentMenu->x, cursory, MENUCAPS|highlightflags, currentMenu->menuitems[itemOn].text); } @@ -5435,7 +5435,7 @@ static void M_DrawGenericMenu(void) static void M_DrawGenericBackgroundMenu(void) { - V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_CACHE)); + V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); M_DrawGenericMenu(); } @@ -5557,7 +5557,7 @@ static void M_DrawGenericScrollMenu(void) // DRAW THE SKULL CURSOR V_DrawScaledPatch(currentMenu->x - 24, cursory, 0, - W_CachePatchName("M_CURSOR", PU_CACHE)); + W_CachePatchName("M_CURSOR", PU_PATCH)); // dumb hack // tooltips @@ -5587,7 +5587,7 @@ static void M_DrawPauseMenu(void) (currentMenu->y + MPauseMenu[mpause_discordrequests].alphaKey - 1) * FRACUNIT, FRACUNIT, 0, - W_CachePatchName("K_REQUE2", PU_CACHE), + W_CachePatchName("K_REQUE2", PU_PATCH), NULL ); } @@ -5617,7 +5617,7 @@ static void M_DrawCenteredMenu(void) case IT_PATCH: if (currentMenu->menuitems[i].patch && currentMenu->menuitems[i].patch[0]) { - patch_t *p = W_CachePatchName(currentMenu->menuitems[i].patch, PU_CACHE); + patch_t *p = W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); if (currentMenu->menuitems[i].status & IT_CENTER) { @@ -5695,7 +5695,7 @@ static void M_DrawCenteredMenu(void) case IT_GRAYPATCH: if (currentMenu->menuitems[i].patch && currentMenu->menuitems[i].patch[0]) V_DrawMappedPatch(x, y, 0, - W_CachePatchName(currentMenu->menuitems[i].patch,PU_CACHE), graymap); + W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH), graymap); y += LINEHEIGHT; break; } @@ -5706,12 +5706,12 @@ static void M_DrawCenteredMenu(void) || ((currentMenu->menuitems[itemOn].status & IT_DISPLAY) == IT_NOTHING)) { V_DrawScaledPatch(x + SKULLXOFF, cursory - 5, 0, - W_CachePatchName("M_CURSOR", PU_CACHE)); + W_CachePatchName("M_CURSOR", PU_PATCH)); } else { V_DrawScaledPatch(x - V_StringWidth(currentMenu->menuitems[itemOn].text, 0)/2 - 24, cursory, 0, - W_CachePatchName("M_CURSOR", PU_CACHE)); + W_CachePatchName("M_CURSOR", PU_PATCH)); V_DrawCenteredString(x, cursory, highlightflags|MENUCAPS, currentMenu->menuitems[itemOn].text); } } @@ -6007,7 +6007,7 @@ static void M_DrawMessageMenu(void) // hack: draw RA background in RA menus if (gamestate == GS_TIMEATTACK) - V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_CACHE)); + V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); M_DrawTextBox(currentMenu->x, y - 8, (max+7)>>3, mlines); @@ -6073,7 +6073,7 @@ static void M_StopMessage(INT32 choice) // You can even put multiple images in one menu! static void M_DrawImageDef(void) { - patch_t *patch = W_CachePatchName(currentMenu->menuitems[itemOn].text,PU_CACHE); + patch_t *patch = W_CachePatchName(currentMenu->menuitems[itemOn].text, PU_PATCH); if (patch->width <= BASEVIDWIDTH) V_DrawScaledPatch(0,0,0,patch); else @@ -6189,23 +6189,23 @@ static void M_AddonsInternal(void) W_UnlockCachedPatch(addonsp[i]); } - addonsp[EXT_FOLDER] = W_CachePatchName("M_FFLDR", PU_STATIC); - addonsp[EXT_UP] = W_CachePatchName("M_FBACK", PU_STATIC); - addonsp[EXT_NORESULTS] = W_CachePatchName("M_FNOPE", PU_STATIC); - addonsp[EXT_TXT] = W_CachePatchName("M_FTXT", PU_STATIC); - addonsp[EXT_CFG] = W_CachePatchName("M_FCFG", PU_STATIC); - addonsp[EXT_WAD] = W_CachePatchName("M_FWAD", PU_STATIC); + addonsp[EXT_FOLDER] = W_CachePatchName("M_FFLDR", PU_PATCH); + addonsp[EXT_UP] = W_CachePatchName("M_FBACK", PU_PATCH); + addonsp[EXT_NORESULTS] = W_CachePatchName("M_FNOPE", PU_PATCH); + addonsp[EXT_TXT] = W_CachePatchName("M_FTXT", PU_PATCH); + addonsp[EXT_CFG] = W_CachePatchName("M_FCFG", PU_PATCH); + addonsp[EXT_WAD] = W_CachePatchName("M_FWAD", PU_PATCH); #ifdef USE_KART - addonsp[EXT_KART] = W_CachePatchName("M_FKART", PU_STATIC); + addonsp[EXT_KART] = W_CachePatchName("M_FKART", PU_PATCH); #endif - addonsp[EXT_PK3] = W_CachePatchName("M_FPK3", PU_STATIC); - addonsp[EXT_SOC] = W_CachePatchName("M_FSOC", PU_STATIC); - addonsp[EXT_LUA] = W_CachePatchName("M_FLUA", PU_STATIC); - addonsp[NUM_EXT] = W_CachePatchName("M_FUNKN", PU_STATIC); - addonsp[NUM_EXT+1] = W_CachePatchName("M_FSEL", PU_STATIC); - addonsp[NUM_EXT+2] = W_CachePatchName("M_FLOAD", PU_STATIC); - addonsp[NUM_EXT+3] = W_CachePatchName("M_FSRCH", PU_STATIC); - addonsp[NUM_EXT+4] = W_CachePatchName("M_FSAVE", PU_STATIC); + addonsp[EXT_PK3] = W_CachePatchName("M_FPK3", PU_PATCH); + addonsp[EXT_SOC] = W_CachePatchName("M_FSOC", PU_PATCH); + addonsp[EXT_LUA] = W_CachePatchName("M_FLUA", PU_PATCH); + addonsp[NUM_EXT] = W_CachePatchName("M_FUNKN", PU_PATCH); + addonsp[NUM_EXT+1] = W_CachePatchName("M_FSEL", PU_PATCH); + addonsp[NUM_EXT+2] = W_CachePatchName("M_FLOAD", PU_PATCH); + addonsp[NUM_EXT+3] = W_CachePatchName("M_FSRCH", PU_PATCH); + addonsp[NUM_EXT+4] = W_CachePatchName("M_FSAVE", PU_PATCH); MISC_AddonsDef.prevMenu = currentMenu; M_SetupNextMenu(&MISC_AddonsDef); @@ -7214,9 +7214,9 @@ static void DrawReplayHutReplayInfo(void) //CONS_Printf("%d %s\n", demolist[dir_on[menudepthleft]].map, G_BuildMapName(demolist[dir_on[menudepthleft]].map)); lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(demolist[dir_on[menudepthleft]].map))); if (lumpnum != LUMPERROR) - patch = W_CachePatchNum(lumpnum, PU_CACHE); + patch = W_CachePatchNum(lumpnum, PU_PATCH); else - patch = W_CachePatchName("M_NOLVL", PU_CACHE); + patch = W_CachePatchName("M_NOLVL", PU_PATCH); if (!(demolist[dir_on[menudepthleft]].kartspeed & DF_ENCORE)) V_DrawSmallScaledPatch(x, y, V_SNAPTOTOP, patch); @@ -7229,7 +7229,7 @@ static void DrawReplayHutReplayInfo(void) { static angle_t rubyfloattime = 0; const fixed_t rubyheight = FINESINE(rubyfloattime>>ANGLETOFINESHIFT); - V_DrawFixedPatch((x+(w>>2))<>2))<>2))<>2))<x - 24, cursory, V_SNAPTOTOP|V_SNAPTOLEFT, - W_CachePatchName("M_CURSOR", PU_CACHE)); + W_CachePatchName("M_CURSOR", PU_PATCH)); V_DrawString(currentMenu->x, cursory, V_SNAPTOTOP|V_SNAPTOLEFT|highlightflags, currentMenu->menuitems[itemOn].text); // Now draw some replay info! @@ -7526,7 +7526,7 @@ static void M_DrawReplayStartMenu(void) } else { - patch = W_CachePatchName("M_NORANK", PU_CACHE); + patch = W_CachePatchName("M_NORANK", PU_PATCH); colormap = R_GetTranslationColormap( TC_RAINBOW, demolist[dir_on[menudepthleft]].standings[i].color, @@ -7700,16 +7700,16 @@ static void M_DrawPlaybackMenu(void) inactivemap = R_GetTranslationColormap(players[ply].skin, players[ply].skincolor, GTC_MENUCACHE); } else if (currentMenu->menuitems[i].patch && W_CheckNumForName(currentMenu->menuitems[i].patch) != LUMPERROR) - icon = W_CachePatchName(currentMenu->menuitems[i].patch, PU_CACHE); + icon = W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); else - icon = W_CachePatchName("PLAYRANK", PU_CACHE); // temp + icon = W_CachePatchName("PLAYRANK", PU_PATCH); // temp } else if (currentMenu->menuitems[i].status == IT_DISABLED) continue; else if (currentMenu->menuitems[i].patch && W_CheckNumForName(currentMenu->menuitems[i].patch) != LUMPERROR) - icon = W_CachePatchName(currentMenu->menuitems[i].patch, PU_CACHE); + icon = W_CachePatchName(currentMenu->menuitems[i].patch, PU_PATCH); else - icon = W_CachePatchName("PLAYRANK", PU_CACHE); // temp + icon = W_CachePatchName("PLAYRANK", PU_PATCH); // temp if ((i == playback_fastforward && cv_playbackspeed.value > 1) || (i == playback_rewind && demo.rewinding)) V_DrawMappedPatch(currentMenu->x + currentMenu->menuitems[i].alphaKey, currentMenu->y, transmap|V_SNAPTOTOP, icon, R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_JAWZ, GTC_MENUCACHE)); @@ -8344,13 +8344,13 @@ static void M_DrawEmblemHints(void) if (emblem->collected) { collected = recommendedflags; - V_DrawMappedPatch(12, 12+(28*j), 0, W_CachePatchName(M_GetEmblemPatch(emblem), PU_CACHE), + V_DrawMappedPatch(12, 12+(28*j), 0, W_CachePatchName(M_GetEmblemPatch(emblem), PU_PATCH), R_GetTranslationColormap(TC_DEFAULT, M_GetEmblemColor(emblem), GTC_MENUCACHE)); } else { collected = 0; - V_DrawScaledPatch(12, 12+(28*j), 0, W_CachePatchName("NEEDIT", PU_CACHE)); + V_DrawScaledPatch(12, 12+(28*j), 0, W_CachePatchName("NEEDIT", PU_PATCH)); } if (emblem->hint[0]) @@ -8874,7 +8874,7 @@ static void M_DrawStatsMaps(void) V_DrawRightAlignedString(BASEVIDWIDTH-16, 50, recommendedflags|MENUCAPS, "(complete)"); V_DrawString(32, 50, MENUCAPS, va("x %d/%d", M_CountEmblems(), numemblems+numextraemblems)); - V_DrawSmallScaledPatch(20, 50, 0, W_CachePatchName("GOTITA", PU_STATIC)); + V_DrawSmallScaledPatch(20, 50, 0, W_CachePatchName("GOTITA", PU_PATCH)); if (location) V_DrawCharacter(10, y-(skullAnimCounter/5), @@ -8945,10 +8945,10 @@ static void M_DrawStatsMaps(void) exemblem = &extraemblems[i]; if (exemblem->collected) - V_DrawSmallMappedPatch(295, y, 0, W_CachePatchName(M_GetExtraEmblemPatch(exemblem), PU_CACHE), + V_DrawSmallMappedPatch(295, y, 0, W_CachePatchName(M_GetExtraEmblemPatch(exemblem), PU_PATCH), R_GetTranslationColormap(TC_DEFAULT, M_GetExtraEmblemColor(exemblem), GTC_MENUCACHE)); else - V_DrawSmallScaledPatch(295, y, 0, W_CachePatchName("NEEDIT", PU_CACHE)); + V_DrawSmallScaledPatch(295, y, 0, W_CachePatchName("NEEDIT", PU_PATCH)); V_DrawString(20, y, MENUCAPS, va("%s", exemblem->description)); } @@ -9115,7 +9115,7 @@ void M_DrawTimeAttackMenu(void) //S_ChangeMusicInternal("racent", true); // Eww, but needed for when user hits escape during demo playback - V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_CACHE)); + V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); M_DrawMenuTitle(); if (currentMenu == &SP_TimeAttackDef) @@ -9199,7 +9199,7 @@ void M_DrawTimeAttackMenu(void) y = currentMenu->y; // DRAW THE SKULL CURSOR - V_DrawScaledPatch(x - 24, cursory, 0, W_CachePatchName("M_CURSOR", PU_CACHE)); + V_DrawScaledPatch(x - 24, cursory, 0, W_CachePatchName("M_CURSOR", PU_PATCH)); V_DrawString(x, cursory, highlightflags|MENUCAPS, currentMenu->menuitems[itemOn].text); // Level record list @@ -10247,12 +10247,12 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) { lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(cv_nextmap.value))); if (lumpnum != LUMPERROR) - PictureOfLevel = W_CachePatchNum(lumpnum, PU_CACHE); + PictureOfLevel = W_CachePatchNum(lumpnum, PU_PATCH); else - PictureOfLevel = W_CachePatchName("BLANKLVL", PU_CACHE); + PictureOfLevel = W_CachePatchName("BLANKLVL", PU_PATCH); } else - PictureOfLevel = W_CachePatchName("RANDOMLV", PU_CACHE); + PictureOfLevel = W_CachePatchName("RANDOMLV", PU_PATCH); w = PictureOfLevel->width/2; i = PictureOfLevel->height/2; @@ -10287,14 +10287,14 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) { /*UINT8 *mappingforencore = NULL; if ((lumpnum = W_CheckNumForName(va("%sE", mapname))) != LUMPERROR) - mappingforencore = W_CachePatchNum(lumpnum, PU_CACHE);*/ + mappingforencore = W_CachePatchNum(lumpnum, PU_PATCH);*/ V_DrawFixedPatch((x+w)<>ANGLETOFINESHIFT); - V_DrawFixedPatch((x+w/2)< 7 * FRACUNIT; cursorframe -= 7 * FRACUNIT) {} - V_DrawFixedPatch(x<> FRACBITS) + 1), PU_CACHE), NULL); + V_DrawFixedPatch(x<> FRACBITS) + 1), PU_PATCH), NULL); } x += incrwidth; @@ -10776,10 +10776,10 @@ static void M_DrawSetupMultiPlayerMenu(void) INT32 tw = 0; spritedef_t *sprdef; spriteframe_t *sprframe; - patch_t *statbg = W_CachePatchName("K_STATBG", PU_CACHE); - patch_t *statlr = W_CachePatchName("K_STATLR", PU_CACHE); - patch_t *statud = W_CachePatchName("K_STATUD", PU_CACHE); - patch_t *statdot = W_CachePatchName("K_SDOT0", PU_CACHE); + patch_t *statbg = W_CachePatchName("K_STATBG", PU_PATCH); + patch_t *statlr = W_CachePatchName("K_STATLR", PU_PATCH); + patch_t *statud = W_CachePatchName("K_STATUD", PU_PATCH); + patch_t *statdot = W_CachePatchName("K_SDOT0", PU_PATCH); patch_t *patch; UINT8 frame; UINT8 speed; @@ -10957,17 +10957,17 @@ static void M_DrawSetupMultiPlayerMenu(void) if (statdp == true) { //Background - V_DrawScaledPatch(statx - 50, staty + 4, 0, W_CachePatchName("K_STATNB", PU_CACHE)); + V_DrawScaledPatch(statx - 50, staty + 4, 0, W_CachePatchName("K_STATNB", PU_PATCH)); //Speed for (i = 0; i < GETSELECTEDSPEED; i++) // draw the stat bars { if (i == 0) - V_DrawScaledPatch(statx - 45, staty + 63, 0, W_CachePatchName("K_STATN1", PU_CACHE)); + V_DrawScaledPatch(statx - 45, staty + 63, 0, W_CachePatchName("K_STATN1", PU_PATCH)); else if (i == GETSELECTEDSPEED -1 ) - V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN3", PU_CACHE)); + V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN3", PU_PATCH)); else - V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN2", PU_CACHE)); + V_DrawScaledPatch(statx - 45, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN2", PU_PATCH)); } //Weight @@ -10975,11 +10975,11 @@ static void M_DrawSetupMultiPlayerMenu(void) { if (i == 0) - V_DrawScaledPatch(statx - 30, staty + 63, 0, W_CachePatchName("K_STATN4", PU_CACHE)); + V_DrawScaledPatch(statx - 30, staty + 63, 0, W_CachePatchName("K_STATN4", PU_PATCH)); else if (i == GETSELECTEDWEIGHT -1) - V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN6", PU_CACHE)); + V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN6", PU_PATCH)); else - V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN5", PU_CACHE)); + V_DrawScaledPatch(statx - 30, staty + 63 -(5 *i), 0, W_CachePatchName("K_STATN5", PU_PATCH)); } } @@ -11109,7 +11109,7 @@ static void M_DrawSetupMultiPlayerMenu(void) UINT8 cursorframe = (I_GetTime() / 4) % 7; - cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_CACHE); + cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); } @@ -11157,7 +11157,7 @@ static void M_DrawSetupMultiPlayerMenu(void) { UINT8 cursorframe = (I_GetTime() / 4) % 7; - cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_CACHE); + cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); } } @@ -11166,13 +11166,13 @@ static void M_DrawSetupMultiPlayerMenu(void) INT32 selectedskin = (itemOn == 1 && setupm_skinselect < numskins ? skinsorted[setupm_skinselect] : setupm_fakeskin); speed = skins[selectedskin].kartspeed; weight = skins[selectedskin].kartweight; - statdot = W_CachePatchName("K_SDOT1", PU_CACHE); + statdot = W_CachePatchName("K_SDOT1", PU_PATCH); if (skullAnimCounter < 4) // SRB2Kart: we draw this dot later so that it's not covered if there's multiple skins with the same stats V_DrawFixedPatch((((statx+46+GRIDSTATOFFSET) + (speed*4))<>1), (((staty+71) + (weight*4))<>1, 0, statdot, flashcol); else V_DrawFixedPatch((((statx+46+GRIDSTATOFFSET) + (speed*4))<>1), (((staty+71) + (weight*4))<>1, 0, statdot, NULL); - statdot = W_CachePatchName("K_SDOT2", PU_CACHE); // coloured center + statdot = W_CachePatchName("K_SDOT2", PU_PATCH); // coloured center if (setupm_fakecolor) V_DrawFixedPatch((((statx+46+GRIDSTATOFFSET) + (speed*4))<>1), (((staty+71) + (weight*4))<>1, 0, statdot, R_GetTranslationColormap(0, setupm_fakecolor, GTC_MENUCACHE)); } @@ -11221,7 +11221,7 @@ static void M_DrawSetupMultiPlayerMenu(void) { UINT8 cursorframe = (I_GetTime() / 4) % 7; - cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_CACHE); + cursor = W_CachePatchName(va("K_CHILI%d", cursorframe + 1), PU_PATCH); V_DrawFixedPatch((curx << FRACBITS) - (FRACUNIT), (cury << FRACBITS) - (FRACUNIT), FRACUNIT+(FRACUNIT>>3), 0, cursor, NULL); } } @@ -11232,13 +11232,13 @@ static void M_DrawSetupMultiPlayerMenu(void) speed = skins[setupm_fakeskin].kartspeed; weight = skins[setupm_fakeskin].kartweight; - statdot = W_CachePatchName("K_SDOT1", PU_CACHE); + statdot = W_CachePatchName("K_SDOT1", PU_PATCH); if (skullAnimCounter < 4) // SRB2Kart: we draw this dot later so that it's not covered if there's multiple skins with the same stats V_DrawFixedPatch(((BASEVIDWIDTH - mx - 80) + ((speed-1)*8))< 7 * FRACUNIT; cursorframe -= 7 * FRACUNIT) {} - cursor = W_CachePatchName(va("K_BHILI%d", (cursorframe >> FRACBITS) + 1), PU_CACHE); + cursor = W_CachePatchName(va("K_BHILI%d", (cursorframe >> FRACBITS) + 1), PU_PATCH); if (col < 0) col += numskins; @@ -11388,7 +11388,7 @@ static void M_DrawSetupMultiPlayerMenu(void) sprframe = &sprdef->spriteframes[frame]; //minenice's speen css, it's a piece of shit but hey - //patch = W_CachePatchNum(sprframe->lumppat[1], PU_CACHE); + //patch = W_CachePatchNum(sprframe->lumppat[1], PU_PATCH); speenframe = (I_GetTime()*cv_skinselectspin.value/TICRATE + 1)%8; //this is a very shitty solution for checking if a sprite needs flipping @@ -11396,7 +11396,7 @@ static void M_DrawSetupMultiPlayerMenu(void) if ((sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe]) && (speenframe > 4)) flags = V_FLIP; // This sprite is left/right flipped! - patch = W_CachePatchNum(sprframe->lumppat[speenframe], PU_CACHE); + patch = W_CachePatchNum(sprframe->lumppat[speenframe], PU_PATCH); // draw box around guy V_DrawFill(mx + 36 - (charw/2), my+65, charw, 84, 239); @@ -12521,7 +12521,7 @@ static void M_DrawControl(void) } V_DrawScaledPatch(currentMenu->x - 20, cursory, 0, - W_CachePatchName("M_CURSOR", PU_CACHE)); + W_CachePatchName("M_CURSOR", PU_PATCH)); } #undef controlheight @@ -12916,7 +12916,7 @@ static void M_DrawLocalSkinMenu(void) sprframe = &sprdef->spriteframes[frame]; //minenice's speen css, it's a piece of shit but hey - //patch = W_CachePatchNum(sprframe->lumppat[1], PU_CACHE); + //patch = W_CachePatchNum(sprframe->lumppat[1], PU_PATCH); speenframe = (I_GetTime()*cv_skinselectspin.value/TICRATE + 1)%8; //this is a very shitty solution for checking if a sprite needs flipping @@ -12924,7 +12924,7 @@ static void M_DrawLocalSkinMenu(void) if ((sprframe->lumppat[speenframe] == sprframe->lumppat[8-speenframe]) && (speenframe > 4)) { flags = V_FLIP; // This sprite is left/right flipped! } - patch = W_CachePatchNum(sprframe->lumppat[speenframe], PU_CACHE); + patch = W_CachePatchNum(sprframe->lumppat[speenframe], PU_PATCH); // draw box around guy V_DrawFill(mx + 220 - (charw/2), my+54, charw, 84, 239); @@ -12933,8 +12933,8 @@ static void M_DrawLocalSkinMenu(void) UINT8 *colormap = R_GetTranslationColormap(skintodisplay, cv_playercolor.value, GTC_MENUCACHE); colormap = R_GetLocalTranslationColormap(&skins[allskins[skintodisplay].localnum], (allskins[skintodisplay].localskin ? &localskins[allskins[skintodisplay].localnum] : NULL), cv_playercolor.value, GTC_MENUCACHE, allskins[skintodisplay].localskin); - V_DrawMappedPatch(mx, my+50, 0, W_CachePatchName(allskins[skintodisplay].facewant, PU_CACHE), colormap); - V_DrawMappedPatch(mx+8, my+85, 0, W_CachePatchName(allskins[skintodisplay].facerank, PU_CACHE), colormap); + V_DrawMappedPatch(mx, my+50, 0, W_CachePatchName(allskins[skintodisplay].facewant, PU_PATCH), colormap); + V_DrawMappedPatch(mx+8, my+85, 0, W_CachePatchName(allskins[skintodisplay].facerank, PU_PATCH), colormap); V_DrawString(mx, my+108, V_ALLOWLOWERCASE, "Character"); if (strlen(allskins[skintodisplay].realname) > 10) V_DrawThinString(mx+20, my+118, V_ALLOWLOWERCASE|highlightflags, allskins[skintodisplay].realname); @@ -13022,7 +13022,7 @@ static void M_DrawVideoMode(void) j = OP_VideoModeDef.y + 14 + ((vidm_selected % vidm_column_size)*8); V_DrawScaledPatch(i - 8, j, 0, - W_CachePatchName("M_CURSOR", PU_CACHE)); + W_CachePatchName("M_CURSOR", PU_PATCH)); } // Just M_DrawGenericScrollMenu but showing a backing behind the headers. @@ -13135,7 +13135,7 @@ static void M_DrawColorMenu(void) // DRAW THE SKULL CURSOR V_DrawScaledPatch(currentMenu->x - 24, cursory, 0, - W_CachePatchName("M_CURSOR", PU_CACHE)); + W_CachePatchName("M_CURSOR", PU_PATCH)); } @@ -13296,14 +13296,14 @@ static void M_DrawMonitorToggles(void) #ifdef ITEMTOGGLEBOTTOMRIGHT if (currentMenu->menuitems[thisitem].alphaKey == 255) { - V_DrawScaledPatch(x, y, V_TRANSLUCENT, W_CachePatchName("K_ISBG", PU_CACHE)); + V_DrawScaledPatch(x, y, V_TRANSLUCENT, W_CachePatchName("K_ISBG", PU_PATCH)); continue; } #endif if (currentMenu->menuitems[thisitem].alphaKey == 0) { - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISBG", PU_CACHE)); - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISTOGL", PU_CACHE)); + V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISBG", PU_PATCH)); + V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISTOGL", PU_PATCH)); continue; } @@ -13332,18 +13332,18 @@ static void M_DrawMonitorToggles(void) } if (cv->value) - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISBG", PU_CACHE)); + V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISBG", PU_PATCH)); else - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISBGD", PU_CACHE)); + V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISBGD", PU_PATCH)); if (drawnum != 0) { - V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISMUL", PU_CACHE)); - V_DrawScaledPatch(x, y, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[thisitem].alphaKey, true), PU_CACHE)); + V_DrawScaledPatch(x, y, 0, W_CachePatchName("K_ISMUL", PU_PATCH)); + V_DrawScaledPatch(x, y, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[thisitem].alphaKey, true), PU_PATCH)); V_DrawString(x+24, y+31, V_ALLOWLOWERCASE|translucent, va("x%d", drawnum)); } else - V_DrawScaledPatch(x, y, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[thisitem].alphaKey, true), PU_CACHE)); + V_DrawScaledPatch(x, y, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[thisitem].alphaKey, true), PU_PATCH)); y += spacing; } @@ -13356,7 +13356,7 @@ static void M_DrawMonitorToggles(void) #ifdef ITEMTOGGLEBOTTOMRIGHT if (currentMenu->menuitems[itemOn].alphaKey == 255) { - V_DrawScaledPatch(onx-1, ony-2, V_TRANSLUCENT, W_CachePatchName("K_ITBG", PU_CACHE)); + V_DrawScaledPatch(onx-1, ony-2, V_TRANSLUCENT, W_CachePatchName("K_ITBG", PU_PATCH)); if (shitsfree) { INT32 trans = V_TRANSLUCENT; @@ -13364,15 +13364,15 @@ static void M_DrawMonitorToggles(void) trans = ((10-TICRATE)+shitsfree-1)<menuitems[itemOn].alphaKey == 0) { - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITBG", PU_CACHE)); - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITTOGL", PU_CACHE)); + V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITBG", PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITTOGL", PU_PATCH)); } else { @@ -13397,19 +13397,19 @@ static void M_DrawMonitorToggles(void) } if (cv->value) - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITBG", PU_CACHE)); + V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITBG", PU_PATCH)); else - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITBGD", PU_CACHE)); + V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITBGD", PU_PATCH)); if (drawnum != 0) { - V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITMUL", PU_CACHE)); - V_DrawScaledPatch(onx-1, ony-2, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[itemOn].alphaKey, false), PU_CACHE)); - V_DrawScaledPatch(onx+27, ony+39, translucent, W_CachePatchName("K_ITX", PU_CACHE)); + V_DrawScaledPatch(onx-1, ony-2, 0, W_CachePatchName("K_ITMUL", PU_PATCH)); + V_DrawScaledPatch(onx-1, ony-2, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[itemOn].alphaKey, false), PU_PATCH)); + V_DrawScaledPatch(onx+27, ony+39, translucent, W_CachePatchName("K_ITX", PU_PATCH)); V_DrawKartString(onx+37, ony+34, translucent, va("%d", drawnum)); } else - V_DrawScaledPatch(onx-1, ony-2, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[itemOn].alphaKey, false), PU_CACHE)); + V_DrawScaledPatch(onx-1, ony-2, translucent, W_CachePatchName(K_GetItemPatch(currentMenu->menuitems[itemOn].alphaKey, false), PU_PATCH)); } } @@ -13571,7 +13571,7 @@ void M_QuitResponse(INT32 ch) while (ptime > I_GetTime()) { V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); - V_DrawSmallScaledPatch(0, 0, 0, W_CachePatchName("GAMEQUIT", PU_CACHE)); // Demo 3 Quit Screen Tails 06-16-2001 + V_DrawSmallScaledPatch(0, 0, 0, W_CachePatchName("GAMEQUIT", PU_PATCH)); // Demo 3 Quit Screen Tails 06-16-2001 I_FinishUpdate(); // Update the screen with the image Tails 06-19-2001 I_Sleep(cv_sleep.value); I_UpdateTime(cv_timescale.value); @@ -13641,12 +13641,12 @@ static void M_DrawSticker(INT32 x, INT32 y, INT32 width, INT32 flags, boolean is if (isSmall == true) { - stickerEnd = W_CachePatchName("K_STIKE2", PU_CACHE); + stickerEnd = W_CachePatchName("K_STIKE2", PU_PATCH); height = 6; } else { - stickerEnd = W_CachePatchName("K_STIKEN", PU_CACHE); + stickerEnd = W_CachePatchName("K_STIKEN", PU_PATCH); height = 11; } @@ -13676,12 +13676,12 @@ static void M_DrawDiscordRequests(void) if (confirmAccept == true) { colormap = R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_GREEN, GTC_MENUCACHE); - hand = W_CachePatchName("K_LAPH02", PU_CACHE); + hand = W_CachePatchName("K_LAPH02", PU_PATCH); } else { colormap = R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_RED, GTC_MENUCACHE); - hand = W_CachePatchName("K_LAPH03", PU_CACHE); + hand = W_CachePatchName("K_LAPH03", PU_PATCH); } slide = confirmLength - confirmDelay; @@ -13696,7 +13696,7 @@ static void M_DrawDiscordRequests(void) colormap = R_GetTranslationColormap(TC_DEFAULT, SKINCOLOR_GREY, GTC_MENUCACHE); } - V_DrawFixedPatch(56*FRACUNIT, 150*FRACUNIT, FRACUNIT, 0, W_CachePatchName("K_LAPE01", PU_CACHE), colormap); + V_DrawFixedPatch(56*FRACUNIT, 150*FRACUNIT, FRACUNIT, 0, W_CachePatchName("K_LAPE01", PU_PATCH), colormap); if (hand != NULL) { diff --git a/src/p_setup.c b/src/p_setup.c index 5d944e5e2..8eddd2a72 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3056,6 +3056,8 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) HWR_ClearLightTables(); #endif + Patch_FreeTag(PU_PATCH_LOWPRIORITY); + //Patch_FreeTag(PU_PATCH_ROTATED); // we keep those ty! Z_FreeTags(PU_LEVEL, PU_PURGELEVEL - 1); #if defined (WALLSPLATS) || defined (FLOORSPLATS) @@ -3347,6 +3349,8 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // // search for sprite replacements // + Patch_FreeTag(PU_SPRITE); + Patch_FreeTag(PU_PATCH_ROTATED); R_AddSpriteDefs(wadnum); // Reload it all anyway, just in case they @@ -3461,7 +3465,7 @@ boolean P_MultiSetupWadFiles(boolean fullsetup) if (partadd_stage == 0) { // Flush and reload HUD graphics - ST_UnloadGraphics(); + //ST_UnloadGraphics(); HU_LoadGraphics(); ST_LoadGraphics(); ST_ReloadSkinFaceGraphics(); diff --git a/src/r_data.c b/src/r_data.c index de4d239fa..c35aea0d9 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -393,7 +393,12 @@ static UINT8 *R_GenerateTexture(size_t texnum) // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + // If this patch has already been loaded, we just use it from the cache. + realpatch = (softwarepatch_t *)W_GetCachedPatchNumPwad(patch->wad, patch->lump); + + // Otherwise, we load it here. + if (realpatch == NULL) + realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); // Well, it's not valid... if (realpatch == NULL) @@ -1834,7 +1839,7 @@ static void R_PrecacheLevelSprites(void) lump = sf->lumppat[a];\ if (devparm)\ spritememory += W_LumpLength(lump);\ - W_CachePatchNum(lump, PU_CACHE);\ + W_CachePatchNum(lump, PU_SPRITE);\ } // see R_InitSprites for more about lumppat,lumpid switch (sf->rotate) diff --git a/src/r_patch.c b/src/r_patch.c index 665b50122..20444d9b4 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -375,7 +375,7 @@ patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest) // Frees a patch from memory. // -void Patch_Free(patch_t *patch) +static void Patch_FreeData(patch_t *patch) { #ifdef HWRENDER if (patch->hardware) @@ -403,10 +403,30 @@ void Patch_Free(patch_t *patch) Z_Free(patch->columnofs); if (patch->columns) Z_Free(patch->columns); +} +void Patch_Free(patch_t *patch) +{ + Patch_FreeData(patch); Z_Free(patch); } +// +// Frees patches with a tag range. +// + +static boolean Patch_FreeTagsCallback(void *mem) +{ + patch_t *patch = (patch_t *)mem; + Patch_FreeData(patch); + return true; +} + +void Patch_FreeTags(INT32 lowtag, INT32 hightag) +{ + Z_IterateTags(lowtag, hightag, Patch_FreeTagsCallback); +} + #ifdef HWRENDER // // Allocates a hardware patch. @@ -416,8 +436,8 @@ void *Patch_AllocateHardwarePatch(patch_t *patch) { if (!patch->hardware) { - GLPatch_t *grPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, &patch->hardware); - grPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, &grPatch->mipmap); + GLPatch_t *glPatch = Z_Calloc(sizeof(GLPatch_t), PU_HWRPATCHINFO, &patch->hardware); + glPatch->mipmap = Z_Calloc(sizeof(GLMipmap_t), PU_HWRPATCHINFO, &glPatch->mipmap); } return (void *)(patch->hardware); } @@ -428,10 +448,10 @@ void *Patch_AllocateHardwarePatch(patch_t *patch) void *Patch_CreateGL(patch_t *patch) { - GLPatch_t *grPatch = (GLPatch_t *)Patch_AllocateHardwarePatch(patch); - if (!grPatch->mipmap->data) // Run HWR_MakePatch in all cases, to recalculate some things - HWR_MakePatch(patch, grPatch, grPatch->mipmap, false); - return grPatch; + GLPatch_t *glPatch = (GLPatch_t *)Patch_AllocateHardwarePatch(patch); + if (!glPatch->mipmap->data) // Run HWR_MakePatch in all cases, to recalculate some things + HWR_MakePatch(patch, glPatch, glPatch->mipmap, false); + return glPatch; } #endif // HWRENDER @@ -657,8 +677,7 @@ patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spri if (lump == LUMPERROR) return NULL; - patch = W_CachePatchNum(lump, PU_CACHE); // PU_SPRITE - //patch = W_CachePatchNum(lump, PU_SPRITE); + patch = W_CachePatchNum(lump, PU_SPRITE); if (sprinfo->available) { @@ -837,7 +856,7 @@ void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle // make patch rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); - //Z_ChangeTag(rotated, PU_LEVEL); + Z_ChangeTag(rotated, PU_PATCH_ROTATED); Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); Z_Free(rawconv); diff --git a/src/r_patch.h b/src/r_patch.h index 38df76b05..bde624ead 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -42,6 +42,9 @@ typedef struct patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest); void Patch_Free(patch_t *patch); +#define Patch_FreeTag(tagnum) Patch_FreeTags(tagnum, tagnum) +void Patch_FreeTags(INT32 lowtag, INT32 hightag); + #ifdef HWRENDER void *Patch_AllocateHardwarePatch(patch_t *patch); void *Patch_CreateGL(patch_t *patch); diff --git a/src/r_segs.c b/src/r_segs.c index d1f46b6e8..9a2af70ba 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -171,7 +171,7 @@ static void R_DrawWallSplats(void) mfloorclip = floorclip; mceilingclip = ceilingclip; - patch = W_CachePatchNum(splat->patch, PU_CACHE); + patch = W_CachePatchNum(splat->patch, PU_SPRITE); dc_texturemid = splat->top + (patch->height<<(FRACBITS-1)) - viewz; if (splat->yoffset) diff --git a/src/r_splats.c b/src/r_splats.c index f86f16860..13b092ad0 100644 --- a/src/r_splats.c +++ b/src/r_splats.c @@ -142,7 +142,7 @@ void R_AddWallSplat(line_t *wallline, INT16 sectorside, const char *patchname, f splat->flags = flags; // bad.. but will be needed for drawing anyway.. - patch = W_CachePatchNum(splat->patch, PU_CACHE); + patch = W_CachePatchNum(splat->patch, PU_SPRITE); // idk? // offset needed by draw code for texture mapping linelength = P_SegLength((seg_t *)wallline); diff --git a/src/r_things.c b/src/r_things.c index 57ec53e5e..caa9085b9 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1800,7 +1800,7 @@ static void R_ProjectSprite(mobj_t *thing) vis->patch = rotsprite; else #endif - vis->patch = W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE); + vis->patch = W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE); vis->precip = false; @@ -1985,7 +1985,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) //Fab: lumppat is the lump number of the patch to use, this is different // than lumpid for sprites-in-pwad : the graphics are patched - vis->patch = W_CachePatchNum(sprframe->lumppat[0], PU_CACHE); + vis->patch = W_CachePatchNum(sprframe->lumppat[0], PU_SPRITE); // specific translucency if ((thing->blendmode != AST_COPY) && cv_translucency.value) diff --git a/src/st_stuff.c b/src/st_stuff.c index 6e39661e7..7660fbd3b 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -211,7 +211,7 @@ void ST_doPaletteStuff(void) void ST_UnloadGraphics(void) { - Z_FreeTags(PU_HUDGFX, PU_HUDGFX); + Patch_FreeTag(PU_HUDGFX); } void ST_LoadGraphics(void) @@ -249,7 +249,7 @@ void ST_LoadFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 skin facerankprefix[skinnum] = W_CachePatchName(rankstr, PU_HUDGFX); facewantprefix[skinnum] = W_CachePatchName(wantstr, PU_HUDGFX); facemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); - + /*facerankprefix_name[skinnum] = rankstr; facewantprefix_name[skinnum] = wantstr; facemmapprefix_name[skinnum] = mmapstr;*/ @@ -260,7 +260,7 @@ void ST_LoadLocalFaceGraphics(char *rankstr, char *wantstr, char *mmapstr, INT32 localfacerankprefix[skinnum] = W_CachePatchName(rankstr, PU_HUDGFX); localfacewantprefix[skinnum] = W_CachePatchName(wantstr, PU_HUDGFX); localfacemmapprefix[skinnum] = W_CachePatchName(mmapstr, PU_HUDGFX); - + /*localfacerankprefix_name[skinnum] = rankstr; localfacewantprefix_name[skinnum] = wantstr; localfacemmapprefix_name[skinnum] = mmapstr;*/ @@ -276,7 +276,7 @@ void ST_ReloadSkinFaceGraphics(void) for (i = 0; i < numskins; i++) ST_LoadFaceGraphics(skins[i].facerank, skins[i].facewant, skins[i].facemmap, i); - + for (i = 0; i < numlocalskins; i++) ST_LoadLocalFaceGraphics(localskins[i].facerank, localskins[i].facewant, localskins[i].facemmap, i); } @@ -432,7 +432,7 @@ static void ST_drawLevelTitle(void) ? BASEVIDHEIGHT/2 : 163; INT32 lvlw; - + if (!cv_stagetitle.value) return; diff --git a/src/v_video.c b/src/v_video.c index 413829a8b..93d12800a 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -999,11 +999,11 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ void V_DrawContinueIcon(INT32 x, INT32 y, INT32 flags, INT32 skinnum, UINT8 skincolor) { if (skinnum < 0 || skinnum >= numskins || (skins[skinnum].flags & SF_HIRES)) - V_DrawScaledPatch(x - 10, y - 14, flags, W_CachePatchName("CONTINS", PU_CACHE)); // Draw a star + V_DrawScaledPatch(x - 10, y - 14, flags, W_CachePatchName("CONTINS", PU_PATCH)); // Draw a star else { // Find front angle of the first waiting frame of the character's actual sprites spriteframe_t *sprframe = &skins[skinnum].spritedef.spriteframes[2 & FF_FRAMEMASK]; - patch_t *patch = W_CachePatchNum(sprframe->lumppat[0], PU_CACHE); + patch_t *patch = W_CachePatchNum(sprframe->lumppat[0], PU_PATCH); const UINT8 *colormap = R_GetTranslationColormap(skinnum, skincolor, GTC_CACHE); // No variant for translucency diff --git a/src/w_wad.c b/src/w_wad.c index 0f298067d..4d8e24a93 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1799,6 +1799,14 @@ void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag) return W_CachePatchNumPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum),tag); } +void *W_GetCachedPatchNumPwad(UINT16 wad, UINT16 lump) +{ + if (!TestValidLump(wad, lump)) + return NULL; + + return wadfiles[wad]->patchcache[lump]; +} + #ifdef ROTSPRITE // Caches a rotsprite for patch rotation. void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum) @@ -1828,7 +1836,7 @@ void W_UnlockCachedPatch(void *patch) HWR_UnlockCachedPatch((GLPatch_t *)((patch_t *)patch)->hardware); else #endif - Z_ChangeTag(patch, PU_LEVEL); + Z_ChangeTag(patch, PU_PATCH); } void *W_CachePatchName(const char *name, INT32 tag) @@ -1870,13 +1878,13 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) { INT32 xpivot = 0, ypivot = 0; - ptr = W_CachePatchNum(num, PU_STATIC); // PU_PATCH + ptr = W_CachePatchNum(num, PU_PATCH); // >y pivot centered // >x pivot not centered // Why? - xpivot = SHORT(ptr->width) / 2; - ypivot = SHORT(ptr->height) / 2; + xpivot = ptr->width / 2; + ypivot = ptr->height / 2; RotatedPatch_DoRotation(rspr, ptr, rotationangle, xpivot, ypivot, false); } diff --git a/src/w_wad.h b/src/w_wad.h index 0de9057b6..79cad44e9 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -216,6 +216,8 @@ void *W_CachePatchName(const char *name, INT32 tag); void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag); void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag); +void *W_GetCachedPatchNumPwad(UINT16 wad, UINT16 lump); + // Returns a Software patch. void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag); void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag); diff --git a/src/y_inter.c b/src/y_inter.c index 68ad7365a..65871cc78 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -420,7 +420,7 @@ static void Y_PlayerStandingsDrawer(y_data_t *standings, INT32 x, INT32 hilicol) if (pnum == whiteplayer) { UINT8 cursorframe = (intertic / 4) % 8; - V_DrawScaledPatch(x+16, y-4, 0, W_CachePatchName(va("K_CHILI%d", cursorframe+1), PU_CACHE)); + V_DrawScaledPatch(x+16, y-4, 0, W_CachePatchName(va("K_CHILI%d", cursorframe+1), PU_PATCH)); } STRBUFCPY(strtime, standings->name[i]); @@ -856,7 +856,7 @@ void Y_StartIntermission(void) break; } - bgtile = W_CachePatchName("SRB2BACK", PU_STATIC); + bgtile = W_CachePatchName("SRB2BACK", PU_PATCH); LUA_HUD_DestroyDrawList(luahuddrawlist_intermission); luahuddrawlist_intermission = LUA_HUD_CreateDrawList(); @@ -922,7 +922,7 @@ static void Y_DrawAnimatedVoteScreenPatch(boolean widePatch) if (currentAnimFrame > tempFoundAnimVoteFrames - 1) currentAnimFrame = 0; - patch_t *background = W_CachePatchName(va("%s%d", tempAnimPrefix, currentAnimFrame + 1), PU_CACHE); + patch_t *background = W_CachePatchName(va("%s%d", tempAnimPrefix, currentAnimFrame + 1), PU_PATCH); V_DrawScaledPatch(((vid.width/2) / vid.dupx) - (background->width/2), // Keep the width/height adjustments, for screens that are less wide than 320(?) (vid.height / vid.dupy) - background->height, V_SNAPTOTOP|V_SNAPTOLEFT, background); @@ -1187,7 +1187,7 @@ void Y_VoteDrawer(void) if (!splitscreen && i == consoleplayer) { UINT8 cursorframe = (votetic / 4) % 8; - V_DrawScaledPatch(x+24, y+9, V_SNAPTOLEFT, W_CachePatchName(va("K_CHILI%d", cursorframe+1), PU_CACHE)); + V_DrawScaledPatch(x+24, y+9, V_SNAPTOLEFT, W_CachePatchName(va("K_CHILI%d", cursorframe+1), PU_PATCH)); } } @@ -1466,15 +1466,15 @@ void Y_StartVote(void) Y_AnimatedVoteScreenCheck(); - widebgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCW" : "INTERSCW"), PU_STATIC); - bgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCR" : "INTERSCR"), PU_STATIC); - cursor = W_CachePatchName("M_CURSOR", PU_STATIC); - cursor1 = W_CachePatchName("P1CURSOR", PU_STATIC); - cursor2 = W_CachePatchName("P2CURSOR", PU_STATIC); - cursor3 = W_CachePatchName("P3CURSOR", PU_STATIC); - cursor4 = W_CachePatchName("P4CURSOR", PU_STATIC); - randomlvl = W_CachePatchName("RANDOMLV", PU_STATIC); - rubyicon = W_CachePatchName("RUBYICON", PU_STATIC); + widebgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCW" : "INTERSCW"), PU_PATCH); + bgpatch = W_CachePatchName(((prefgametype == GT_MATCH) ? "BATTLSCR" : "INTERSCR"), PU_PATCH); + cursor = W_CachePatchName("M_CURSOR", PU_PATCH); + cursor1 = W_CachePatchName("P1CURSOR", PU_PATCH); + cursor2 = W_CachePatchName("P2CURSOR", PU_PATCH); + cursor3 = W_CachePatchName("P3CURSOR", PU_PATCH); + cursor4 = W_CachePatchName("P4CURSOR", PU_PATCH); + randomlvl = W_CachePatchName("RANDOMLV", PU_PATCH); + rubyicon = W_CachePatchName("RUBYICON", PU_PATCH); timer = cv_votetime.value*TICRATE; pickedvote = -1; @@ -1542,9 +1542,9 @@ void Y_StartVote(void) // set up the pic lumpnum = W_CheckNumForName(va("%sP", G_BuildMapName(votelevels[i][0]+1))); if (lumpnum != LUMPERROR) - levelinfo[i].pic = W_CachePatchName(va("%sP", G_BuildMapName(votelevels[i][0]+1)), PU_STATIC); + levelinfo[i].pic = W_CachePatchName(va("%sP", G_BuildMapName(votelevels[i][0]+1)), PU_PATCH); else - levelinfo[i].pic = W_CachePatchName("BLANKLVL", PU_STATIC); + levelinfo[i].pic = W_CachePatchName("BLANKLVL", PU_PATCH); } voteclient.loaded = true; diff --git a/src/z_zone.c b/src/z_zone.c index dd10f36e3..f72afa29d 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -656,24 +656,29 @@ static void Command_Memfree_f(void) Z_CheckHeap(-1); CONS_Printf("\x82%s", M_GetText("Memory Info\n")); - CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TagsUsage(0, INT32_MAX)>>10)); - CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); - CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(Z_TagUsage(PU_LUA)>>10)); - CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); - CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10)); - CONS_Printf(M_GetText("Locked cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_CACHE)>>10)); - CONS_Printf(M_GetText("Level : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVEL)>>10)); - CONS_Printf(M_GetText("Special thinker : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVSPEC)>>10)); - CONS_Printf(M_GetText("All purgable : %7s KB\n"), + CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TagsUsage(0, INT32_MAX)>>10)); + CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); + CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(Z_TagUsage(PU_LUA)>>10)); + CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); + CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10)); + CONS_Printf(M_GetText("Patches : %7s KB\n"), sizeu1(Z_TagUsage(PU_PATCH)>>10)); + CONS_Printf(M_GetText("Patches (low priority) : %7s KB\n"), sizeu1(Z_TagUsage(PU_PATCH_LOWPRIORITY)>>10)); + CONS_Printf(M_GetText("Patches (rotated) : %7s KB\n"), sizeu1(Z_TagUsage(PU_PATCH_ROTATED)>>10)); + CONS_Printf(M_GetText("Sprites : %7s KB\n"), sizeu1(Z_TagUsage(PU_SPRITE)>>10)); + CONS_Printf(M_GetText("HUD graphics : %7s KB\n"), sizeu1(Z_TagUsage(PU_HUDGFX)>>10)); + CONS_Printf(M_GetText("Locked cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_CACHE)>>10)); + CONS_Printf(M_GetText("Level : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVEL)>>10)); + CONS_Printf(M_GetText("Special thinker : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVSPEC)>>10)); + CONS_Printf(M_GetText("All purgable : %7s KB\n"), sizeu1(Z_TagsUsage(PU_PURGELEVEL, INT32_MAX)>>10)); #ifdef HWRENDER if (rendermode != render_soft && rendermode != render_none) { - CONS_Printf(M_GetText("Patch info headers: %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); - CONS_Printf(M_GetText("Mipmap patches : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10)); - CONS_Printf(M_GetText("HW Texture cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); - CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); + CONS_Printf(M_GetText("Patch info headers : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); + CONS_Printf(M_GetText("Cached textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); + CONS_Printf(M_GetText("Texture colormaps : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10)); + CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); CONS_Printf(M_GetText("All GPU textures : %7d KB\n"), HWR_GetTextureUsed()>>10); } #endif diff --git a/src/z_zone.h b/src/z_zone.h index e4ee811f2..1c5bdffd5 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -44,7 +44,12 @@ enum PU_SOUND = 11, // static while playing PU_MUSIC = 12, // static while playing - PU_HUDGFX = 13, // static until WAD added + + PU_PATCH = 13, // static entire execution time + PU_PATCH_LOWPRIORITY = 14, // lower priority patch, static until level exited + PU_PATCH_ROTATED = 15, // rotated patch, static until level exited or WAD added + PU_SPRITE = 16, // sprite patch, static until WAD added + PU_HUDGFX = 17, // HUD patch, static until WAD added PU_HWRPATCHINFO = 21, // Hardware GLPatch_t struct for OpenGL texture cache PU_HWRPATCHCOLMIPMAP = 22, // Hardware GLMipmap_t struct colormap variation of patch From b0ba261e149a94e33fa3f29586f163d828dc008e Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 15 Apr 2025 14:32:42 +0200 Subject: [PATCH 04/44] change those tags also add PU_PATCH_DATA --- src/r_patch.c | 6 +++--- src/z_zone.h | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/r_patch.c b/src/r_patch.c index 20444d9b4..c10a8cd95 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -336,7 +336,7 @@ static unsigned char imgbuf[1<<26]; patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest) { - patch_t *patch = (dest == NULL) ? Z_Calloc(sizeof(patch_t), PU_CACHE, NULL) : (patch_t *)(dest); + patch_t *patch = (dest == NULL) ? Z_Calloc(sizeof(patch_t), PU_PATCH, NULL) : (patch_t *)(dest); if (source) { @@ -348,7 +348,7 @@ patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest) patch->height = SHORT(source->height); patch->leftoffset = SHORT(source->leftoffset); patch->topoffset = SHORT(source->topoffset); - patch->columnofs = Z_Calloc(size, PU_CACHE, NULL); + patch->columnofs = Z_Calloc(size, PU_PATCH_DATA, NULL); for (col = 0; col < source->width; col++) { @@ -364,7 +364,7 @@ patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest) if (colsize <= 0) I_Error("Patch_Create: no column data!"); - patch->columns = Z_Calloc(colsize, PU_CACHE, NULL); + patch->columns = Z_Calloc(colsize, PU_PATCH_DATA, NULL); M_Memcpy(patch->columns, ((UINT8 *)source + LONG(source->columnofs[0])), colsize); } diff --git a/src/z_zone.h b/src/z_zone.h index 1c5bdffd5..bb4597ac5 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -45,11 +45,12 @@ enum PU_SOUND = 11, // static while playing PU_MUSIC = 12, // static while playing - PU_PATCH = 13, // static entire execution time - PU_PATCH_LOWPRIORITY = 14, // lower priority patch, static until level exited - PU_PATCH_ROTATED = 15, // rotated patch, static until level exited or WAD added - PU_SPRITE = 16, // sprite patch, static until WAD added - PU_HUDGFX = 17, // HUD patch, static until WAD added + PU_PATCH = 14, // static entire execution time + PU_PATCH_LOWPRIORITY = 15, // lower priority patch, static until level exited + PU_PATCH_ROTATED = 16, // rotated patch, static until level exited or WAD added + PU_PATCH_DATA = 17, // patch data, lifetime depends on the patch that owns it + PU_SPRITE = 18, // sprite patch, static until WAD added + PU_HUDGFX = 19, // HUD patch, static until WAD added PU_HWRPATCHINFO = 21, // Hardware GLPatch_t struct for OpenGL texture cache PU_HWRPATCHCOLMIPMAP = 22, // Hardware GLMipmap_t struct colormap variation of patch From 1c95b2e464dd95c1848a9a9ebb412b0195044481 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 15:57:22 +0200 Subject: [PATCH 05/44] idk anymore lel --- src/hardware/hw_cache.c | 14 +++----------- src/r_data.c | 23 ++++++++++------------- src/st_stuff.c | 4 ++-- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 83a3a2d6b..7393caa47 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -314,6 +314,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe texture_t *texture; texpatch_t *patch; softwarepatch_t *realpatch; + UINT8 *pdata; INT32 blockwidth, blockheight, blocksize; UINT8 *colormap = colormaps; @@ -377,12 +378,8 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - // If this patch has already been loaded, we just use it from the cache. - realpatch = (softwarepatch_t *)W_GetCachedPatchNumPwad(patch->wad, patch->lump); - - // Otherwise, we load it here. - if (realpatch == NULL) - realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + realpatch = (softwarepatch_t *)pdata; if (realpatch != NULL) { @@ -516,10 +513,6 @@ void HWR_FreeTextureColormaps(patch_t *patch) // Set the first colormap to the one that comes after it. next = pat->mipmap->nextcolormap; - - if (!next) - break; - pat->mipmap->nextcolormap = next->nextcolormap; // Free image data from memory. @@ -1233,7 +1226,6 @@ void HWR_GetFadeMask(lumpnum_t fademasklumpnum) patch = HWR_GetCachedGLPatch(fademasklumpnum); glMipmap = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap; - if (!glMipmap->downloaded && !glMipmap->data) HWR_CacheFadeMask(glMipmap, fademasklumpnum); diff --git a/src/r_data.c b/src/r_data.c index c35aea0d9..bf11ce79d 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -303,6 +303,7 @@ static UINT8 *R_GenerateTexture(size_t texnum) texture_t *texture; texpatch_t *patch; softwarepatch_t *realpatch; + UINT8 *pdata; int x, x1, x2, i, width, height; size_t blocksize; column_t *patchcol; @@ -322,8 +323,8 @@ static UINT8 *R_GenerateTexture(size_t texnum) { boolean holey = false; patch = texture->patches; - - realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + realpatch = (softwarepatch_t *)pdata; // Check the patch for holes. if (texture->width > SHORT(realpatch->width) || texture->height > SHORT(realpatch->height)) @@ -393,12 +394,8 @@ static UINT8 *R_GenerateTexture(size_t texnum) // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - // If this patch has already been loaded, we just use it from the cache. - realpatch = (softwarepatch_t *)W_GetCachedPatchNumPwad(patch->wad, patch->lump); - - // Otherwise, we load it here. - if (realpatch == NULL) - realpatch = (softwarepatch_t *)W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + realpatch = (softwarepatch_t *)pdata; // Well, it's not valid... if (realpatch == NULL) @@ -520,7 +517,7 @@ void R_LoadTextures(void) INT32 i, k, w; UINT16 j; UINT16 texstart, texend, texturesLumpPos; - patch_t *patchlump; + softwarepatch_t patchlump; texpatch_t *patch; texture_t *texture; @@ -642,13 +639,15 @@ void R_LoadTextures(void) } patchlump = W_CacheLumpNumPwad((UINT16)w, texstart + j, PU_CACHE); + W_ReadLumpHeaderPwad(wadnum, lumpnum, &patchlump, 8, 0); + //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); // Set texture properties. M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); - texture->width = patchlump->width; - texture->height = patchlump->height; + texture->width = SHORT(patchlump.width); + texture->height = SHORT(patchlump.height); texture->patchcount = 1; texture->holes = false; @@ -659,8 +658,6 @@ void R_LoadTextures(void) patch->wad = (UINT16)w; patch->lump = texstart + j; - Z_Free(patchlump); - k = 1; while (k << 1 <= texture->width) k <<= 1; diff --git a/src/st_stuff.c b/src/st_stuff.c index 7660fbd3b..5a09f61e8 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -217,8 +217,8 @@ void ST_UnloadGraphics(void) void ST_LoadGraphics(void) { // SRB2 border patch - st_borderpatchnum = W_GetNumForName("GFZFLR01"); - scr_borderpatch = W_CacheLumpNum(st_borderpatchnum, PU_HUDGFX); + //st_borderpatchnum = W_GetNumForName("GFZFLR01"); + //scr_borderpatch = W_CacheLumpNum(st_borderpatchnum, PU_HUDGFX); // the original Doom uses 'STF' as base name for all face graphics // Graue 04-08-2004: face/name graphics are now indexed by skins From 6b44ac922efdb371ece609c837d7a62a2103e71c Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 15:57:44 +0200 Subject: [PATCH 06/44] revert this part --- src/r_data.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index bf11ce79d..0c582054b 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -517,7 +517,7 @@ void R_LoadTextures(void) INT32 i, k, w; UINT16 j; UINT16 texstart, texend, texturesLumpPos; - softwarepatch_t patchlump; + softwarepatch_t *patchlump; texpatch_t *patch; texture_t *texture; @@ -639,15 +639,15 @@ void R_LoadTextures(void) } patchlump = W_CacheLumpNumPwad((UINT16)w, texstart + j, PU_CACHE); - W_ReadLumpHeaderPwad(wadnum, lumpnum, &patchlump, 8, 0); + patchlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_STATIC); //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); // Set texture properties. M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); - texture->width = SHORT(patchlump.width); - texture->height = SHORT(patchlump.height); + texture->width = SHORT(patchlump->width); + texture->height = SHORT(patchlump->height); texture->patchcount = 1; texture->holes = false; From 2e7ae45fdbe89ed6baf7d4be96a6f9c0e4173120 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 15 Apr 2025 15:34:30 +0200 Subject: [PATCH 07/44] cast Zzz... --- src/r_data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_data.c b/src/r_data.c index 0c582054b..c91910a32 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -639,7 +639,7 @@ void R_LoadTextures(void) } patchlump = W_CacheLumpNumPwad((UINT16)w, texstart + j, PU_CACHE); - patchlump = W_CacheLumpNumPwad(wadnum, lumpnum, PU_STATIC); + patchlump = (softwarepatch_t *)W_CacheLumpNumPwad(wadnum, lumpnum, PU_STATIC); //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); From 123fe48cad3e09e9fc129a95773492883604dfe8 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 15 Apr 2025 16:27:03 +0200 Subject: [PATCH 08/44] simplify this --- src/w_wad.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 4d8e24a93..2e7f2cee4 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1780,7 +1780,7 @@ void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag) if (!TestValidLump(wad, lump)) return NULL; - patch = W_CacheSoftwarePatchNumPwad(wad, lump, tag); + patch = (patch_t *)W_CacheSoftwarePatchNumPwad(wad, lump, tag); #ifdef HWRENDER // Software-only compile cache the data without conversion @@ -1843,9 +1843,7 @@ void *W_CachePatchName(const char *name, INT32 tag) { lumpnum_t num; - const char *finalname = name; - - num = W_CheckNumForName(finalname); + num = W_CheckNumForName(name); if (num == LUMPERROR) return W_CachePatchNum(W_GetNumForName("MISSING"), tag); From 804d9e2e8eefc7dc3ef3f10181312dde34f1d5b5 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 15 Apr 2025 17:49:52 +0300 Subject: [PATCH 09/44] If GLENCORE is enabled, free both encore and noencore textures --- src/hardware/hw_cache.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 7393caa47..aa995de85 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -585,7 +585,11 @@ void HWR_FreeMapTextures(void) { size_t i; +#ifdef GLENCORE + for (i = 0; i < gl_numtextures*2; i++) +#else for (i = 0; i < gl_numtextures; i++) +#endif { FreeMapTexture(&gl_textures[i]); } From 70f1a6bf48e8a01980d62dcde4ea9ecf9f95ff76 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 15 Apr 2025 16:55:04 +0200 Subject: [PATCH 10/44] readd hud gfx flushing now that stuff doesent completely die lmao --- src/hardware/hw_cache.c | 3 +-- src/p_setup.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index aa995de85..c4720450d 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -551,8 +551,7 @@ static void HWR_FreePatchCache(boolean freeall) callback = FreeColormapsCallback; Z_IterateTags(PU_PATCH, PU_PATCH_ROTATED, callback); - //Z_IterateTags(PU_SPRITE, PU_HUDGFX, callback); // why would we want to free our hudgfx? - Z_IterateTags(PU_SPRITE, PU_SPRITE, callback); + Z_IterateTags(PU_SPRITE, PU_HUDGFX, callback); } // free all textures after each level diff --git a/src/p_setup.c b/src/p_setup.c index 8eddd2a72..a984121aa 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3465,7 +3465,7 @@ boolean P_MultiSetupWadFiles(boolean fullsetup) if (partadd_stage == 0) { // Flush and reload HUD graphics - //ST_UnloadGraphics(); + ST_UnloadGraphics(); HU_LoadGraphics(); ST_LoadGraphics(); ST_ReloadSkinFaceGraphics(); From 41cb3e932a5d2a71927eeba81b8f22be7f09c11f Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 15:58:30 +0200 Subject: [PATCH 11/44] readd freeing those dont want kart to use like 4gbs of memory for no reason lel --- src/r_data.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index c91910a32..015cc626f 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -323,7 +323,7 @@ static UINT8 *R_GenerateTexture(size_t texnum) { boolean holey = false; patch = texture->patches; - pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); realpatch = (softwarepatch_t *)pdata; // Check the patch for holes. @@ -359,7 +359,7 @@ static UINT8 *R_GenerateTexture(size_t texnum) { texture->holes = true; blocksize = W_LumpLengthPwad(patch->wad, patch->lump); - block = Z_Calloc(blocksize, PU_STATIC, // will change tag at end of this function + block = Z_Calloc(blocksize, PU_LEVEL, // will change tag at end of this function &texturecache[texnum]); M_Memcpy(block, realpatch, blocksize); texturememory += blocksize; @@ -380,7 +380,7 @@ static UINT8 *R_GenerateTexture(size_t texnum) texture->holes = false; blocksize = (texture->width * 4) + (texture->width * texture->height); texturememory += blocksize; - block = Z_Malloc(blocksize+1, PU_STATIC, &texturecache[texnum]); + block = Z_Malloc(blocksize+1, PU_LEVEL, &texturecache[texnum]); memset(block, TRANSPARENTPIXEL, blocksize+1); // Transparency hack @@ -394,7 +394,7 @@ static UINT8 *R_GenerateTexture(size_t texnum) // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); realpatch = (softwarepatch_t *)pdata; // Well, it's not valid... @@ -436,8 +436,6 @@ static UINT8 *R_GenerateTexture(size_t texnum) } done: - // Now that the texture has been built in column cache, it is purgable from zone memory. - Z_ChangeTag(block, PU_CACHE); return blocktex; } @@ -487,7 +485,7 @@ UINT8 *R_GetColumn(fixed_t tex, INT32 col) // UINT8 *R_GetFlat(lumpnum_t flatlumpnum) { - return W_CacheLumpNum(flatlumpnum, PU_CACHE); + return W_CacheLumpNum(flatlumpnum, PU_LEVEL); } // From 8ab097f166e6d963e19e3554b1b261aa0977da24 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 15 Apr 2025 18:37:33 +0200 Subject: [PATCH 12/44] dont free our rotsprites aa --- src/hardware/hw_cache.c | 3 ++- src/r_defs.h | 1 - src/r_patch.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index c4720450d..afba914a3 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -550,7 +550,8 @@ static void HWR_FreePatchCache(boolean freeall) if (!freeall) callback = FreeColormapsCallback; - Z_IterateTags(PU_PATCH, PU_PATCH_ROTATED, callback); + //Z_IterateTags(PU_PATCH, PU_PATCH_ROTATED, callback); + Z_IterateTags(PU_PATCH, PU_PATCH, callback); Z_IterateTags(PU_SPRITE, PU_HUDGFX, callback); } diff --git a/src/r_defs.h b/src/r_defs.h index a168b9c50..95f8a796d 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -656,7 +656,6 @@ typedef struct #ifdef ROTSPRITE rotsprite_t *rotated; // Rotated patches #endif - } patch_t; #if defined(_MSC_VER) diff --git a/src/r_patch.c b/src/r_patch.c index c10a8cd95..e35563fe6 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -383,7 +383,7 @@ static void Patch_FreeData(patch_t *patch) #endif #ifdef ROTSPRITE - if (patch->rotated) + /*if (patch->rotated) { rotsprite_t *rotsprite = patch->rotated; INT32 i = 0; @@ -396,7 +396,7 @@ static void Patch_FreeData(patch_t *patch) Z_Free(rotsprite->patches); Z_Free(rotsprite); - } + }*/ #endif if (patch->columnofs) From 14a1c391a68f1f4e1df62139ceba4fb3b33eeaac Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 15 Apr 2025 19:14:20 +0200 Subject: [PATCH 13/44] fix models lel --- src/hardware/hw_md2.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index d74486ac4..a3413f90f 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -368,7 +368,6 @@ static void md2_loadTexture(md2_t *model) { patch_t *patch; GLPatch_t *glPatch = NULL; - const char *filename = model->filename; if (model->glpatch) @@ -1324,10 +1323,15 @@ void HWR_DrawMD2(gl_vissprite_t *spr) || ((!hwrBlendPatch->mipmap->format || !hwrBlendPatch->mipmap->downloaded) && !hwrPatch->notfound))) md2_loadBlendTexture(md2); + // Load it again, because it isn't being loaded into blendgpatch after md2_loadblendtexture... + blendgpatch = md2->blendglpatch; + if (blendgpatch) + hwrBlendPatch = ((GLPatch_t *)blendgpatch->hardware); + if (gpatch && hwrPatch && hwrPatch->mipmap->format) // else if meant that if a texture couldn't be loaded, it would just end up using something else's texture { if ((skincolors_t)spr->mobj->color != SKINCOLOR_NONE && - md2->blendglpatch && (hwrBlendPatch->mipmap->format + blendgpatch && (hwrBlendPatch->mipmap->format && gpatch->width == (blendgpatch->width && gpatch->height == (blendgpatch->height)))) { INT32 tcskinnum = TC_DEFAULT; @@ -1353,6 +1357,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) } else tcskinnum = TC_DEFAULT; } + HWR_GetBlendedTexture(gpatch, blendgpatch, tcskinnum, spr->colormap, (skincolors_t)spr->mobj->color); } else From 50caffd70f977f465964a12a1b19e4aeccdabcaa Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 15 Apr 2025 19:23:53 +0200 Subject: [PATCH 14/44] add tags for model textures --- src/hardware/hw_md2.c | 12 ++++++------ src/z_zone.c | 3 ++- src/z_zone.h | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index a3413f90f..d50a30354 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -244,7 +244,7 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ { png_uint_32 i, pitch = png_get_rowbytes(png_ptr, png_info_ptr); - png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRCACHE, &glpatch->mipmap->data); + png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRMODELTEXTURE, &glpatch->mipmap->data); png_bytepp row_pointers = png_malloc(png_ptr, height * sizeof (png_bytep)); for (i = 0; i < height; i++) row_pointers[i] = PNG_image + i*pitch; @@ -324,7 +324,7 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h, pw = *w = header.xmax - header.xmin + 1; ph = *h = header.ymax - header.ymin + 1; - image = Z_Malloc(pw*ph*4, PU_HWRCACHE, &glpatch->mipmap->data); + image = Z_Malloc(pw*ph*4, PU_HWRMODELTEXTURE, &glpatch->mipmap->data); if (fread(palette, sizeof (UINT8), PALSIZE, file) != PALSIZE) { @@ -729,7 +729,7 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi glMipmap->data = NULL; } - cur = Z_Malloc(size*4, PU_HWRCACHE, &glMipmap->data); + cur = Z_Malloc(size*4, PU_HWRMODELTEXTURE, &glMipmap->data); memset(cur, 0x00, size*4); image = hwrPatch->mipmap->data; @@ -1098,7 +1098,7 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 sk else GL_SetTexture(glMipmap); // found the colormap, set it to the correct texture - Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(glMipmap->data, PU_HWRMODELTEXTURE_UNLOCKED); return; } } @@ -1113,7 +1113,7 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 sk // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better newMipmap = calloc(1, sizeof (*newMipmap)); if (newMipmap == NULL) - I_Error("%s: Out of memory", "HWR_GetMappedPatch"); + I_Error("%s: Out of memory", "HWR_GetBlendedTexture"); glMipmap->nextcolormap = newMipmap; newMipmap->colormap = Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL); @@ -1123,7 +1123,7 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 sk HWR_CreateBlendedTexture(patch, blendgpatch, newMipmap, skinnum, color); GL_SetTexture(newMipmap); - Z_ChangeTag(newMipmap->data, PU_HWRCACHE_UNLOCKED); + Z_ChangeTag(newMipmap->data, PU_HWRMODELTEXTURE_UNLOCKED); } // -----------------+ diff --git a/src/z_zone.c b/src/z_zone.c index f72afa29d..698861dfb 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -657,8 +657,8 @@ static void Command_Memfree_f(void) Z_CheckHeap(-1); CONS_Printf("\x82%s", M_GetText("Memory Info\n")); CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TagsUsage(0, INT32_MAX)>>10)); - CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(Z_TagUsage(PU_LUA)>>10)); + CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10)); CONS_Printf(M_GetText("Patches : %7s KB\n"), sizeu1(Z_TagUsage(PU_PATCH)>>10)); @@ -678,6 +678,7 @@ static void Command_Memfree_f(void) CONS_Printf(M_GetText("Patch info headers : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); CONS_Printf(M_GetText("Cached textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); CONS_Printf(M_GetText("Texture colormaps : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10)); + CONS_Printf(M_GetText("Model textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRMODELTEXTURE)>>10)); CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); CONS_Printf(M_GetText("All GPU textures : %7d KB\n"), HWR_GetTextureUsed()>>10); } diff --git a/src/z_zone.h b/src/z_zone.h index bb4597ac5..41ea1d669 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -54,6 +54,7 @@ enum PU_HWRPATCHINFO = 21, // Hardware GLPatch_t struct for OpenGL texture cache PU_HWRPATCHCOLMIPMAP = 22, // Hardware GLMipmap_t struct colormap variation of patch + PU_HWRMODELTEXTURE = 23, // Hardware model texture PU_HWRCACHE = 48, // static until unlocked PU_CACHE = 49, // static until unlocked @@ -69,6 +70,7 @@ enum PU_HWRCACHE_UNLOCKED = 102, // 'unlocked' PU_HWRCACHE memory: // 'second-level' cache for graphics // stored in hardware format and downloaded as needed + PU_HWRMODELTEXTURE_UNLOCKED = 103, // 'unlocked' PU_HWRMODELTEXTURE memory }; // From fccfcd12fd67610d4cdbe23c2c37ccf6bb5e0baa Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 15 Apr 2025 20:27:21 +0200 Subject: [PATCH 15/44] fix model blendpatches we already have a functional check in HWR_GetBlendedTexture anyways --- src/hardware/hw_md2.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index d50a30354..de78808e6 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1330,9 +1330,7 @@ void HWR_DrawMD2(gl_vissprite_t *spr) if (gpatch && hwrPatch && hwrPatch->mipmap->format) // else if meant that if a texture couldn't be loaded, it would just end up using something else's texture { - if ((skincolors_t)spr->mobj->color != SKINCOLOR_NONE && - blendgpatch && (hwrBlendPatch->mipmap->format - && gpatch->width == (blendgpatch->width && gpatch->height == (blendgpatch->height)))) + if ((skincolors_t)spr->mobj->color != SKINCOLOR_NONE) { INT32 tcskinnum = TC_DEFAULT; if ((spr->mobj->flags & MF_BOSS) && (spr->mobj->flags2 & MF2_FRET) && (leveltime & 1)) // Bosses "flash" From 962b68c5c3e13d75f748717dd7d61912daea313b Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 02:46:40 +0200 Subject: [PATCH 16/44] smol opitmizations and cleanup --- src/hardware/hw_cache.c | 13 +++++------ src/r_data.c | 51 +++++++++++++++++++++-------------------- src/r_plane.c | 6 ++--- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index afba914a3..545be088d 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -378,13 +378,10 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); realpatch = (softwarepatch_t *)pdata; - if (realpatch != NULL) - { - HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch); - } + HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch); } //Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :( @@ -863,9 +860,9 @@ void HWR_LoadMapTextures(size_t pnumtextures) gl_numtextures = pnumtextures; #ifdef GLENCORE - gl_textures = calloc(pnumtextures, sizeof (*gl_textures)*2); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore) + gl_textures = calloc(gl_numtextures, sizeof (*gl_textures)*2); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore) #else - gl_textures = calloc(pnumtextures, sizeof (*gl_textures)); + gl_textures = calloc(gl_numtextures, sizeof (*gl_textures)); #endif if (gl_textures == NULL) I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!"); @@ -1121,6 +1118,7 @@ void HWR_UnlockCachedPatch(GLPatch_t *glPatch) patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum) { lumpcache_t *lumpcache = wadfiles[wadnum]->patchcache; + if (!lumpcache[lumpnum]) { void *ptr = Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]); @@ -1393,6 +1391,7 @@ UINT32 HWR_CreateLightTable(UINT8 *lighttable) UINT32 HWR_GetLightTableID(extracolormap_t *colormap) { boolean default_colormap = false; + if (!colormap) { colormap = &extra_colormaps[num_extra_colormaps]; // a place to store the hw lighttable id diff --git a/src/r_data.c b/src/r_data.c index 015cc626f..2a2a0bd1d 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -329,29 +329,31 @@ static UINT8 *R_GenerateTexture(size_t texnum) // Check the patch for holes. if (texture->width > SHORT(realpatch->width) || texture->height > SHORT(realpatch->height)) holey = true; - - colofs = (UINT8 *)realpatch->columnofs; - - for (x = 0; x < texture->width && !holey; x++) + else { - column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2])); + colofs = (UINT8 *)realpatch->columnofs; - INT32 topdelta, prevdelta = -1, y = 0; - - while (col->topdelta != 0xff) + for (x = 0; x < texture->width; x++) { - topdelta = col->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - if (topdelta > y) - break; - y = topdelta + col->length + 1; - col = (column_t *)((UINT8 *)col + col->length + 4); - } + column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2])); - if (y < texture->height) - holey = true; // this texture is HOLEy! D: + INT32 topdelta, prevdelta = -1, y = 0; + + while (col->topdelta != 0xff) + { + topdelta = col->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + if (topdelta > y) + break; + y = topdelta + col->length + 1; + col = (column_t *)((UINT8 *)col + col->length + 4); + } + + if (y < texture->height) + holey = true; // this texture is HOLEy! D: + } } // If the patch uses transparency, we have to save it this way. @@ -359,8 +361,7 @@ static UINT8 *R_GenerateTexture(size_t texnum) { texture->holes = true; blocksize = W_LumpLengthPwad(patch->wad, patch->lump); - block = Z_Calloc(blocksize, PU_LEVEL, // will change tag at end of this function - &texturecache[texnum]); + block = Z_Calloc(blocksize, PU_LEVEL, &texturecache[texnum]); M_Memcpy(block, realpatch, blocksize); texturememory += blocksize; @@ -368,8 +369,12 @@ static UINT8 *R_GenerateTexture(size_t texnum) colofs = (block + 8); texturecolumnofs[texnum] = (UINT32 *)colofs; blocktex = block; + for (x = 0; x < texture->width; x++) + { *(UINT32 *)&colofs[x<<2] = LONG(LONG(*(UINT32 *)&colofs[x<<2]) + 3); + } + goto done; } @@ -397,10 +402,6 @@ static UINT8 *R_GenerateTexture(size_t texnum) pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); realpatch = (softwarepatch_t *)pdata; - // Well, it's not valid... - if (realpatch == NULL) - continue; - x1 = patch->originx; width = SHORT(realpatch->width); height = SHORT(realpatch->height); diff --git a/src/r_plane.c b/src/r_plane.c index 807baca5c..aaf8d519b 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -128,7 +128,7 @@ static void R_CalculatePlaneRipple(visplane_t *plane, INT32 y, fixed_t plheight, { fixed_t distance = FixedMul(plheight, yslope[y]); const INT32 yay = (planeripple.offset + (distance>>9)) & 8191; - + // ripples da water texture ds_bgofs = FixedDiv(FINESINE(yay), (1<<12) + (distance>>11))>>FRACBITS; @@ -630,7 +630,7 @@ void R_DrawPlanes(void) R_DrawSinglePlane(pl); } } - + #ifndef NOWATER R_UpdatePlaneRipple(); #endif @@ -1050,7 +1050,7 @@ void R_DrawSinglePlane(visplane_t *pl) xoffs = (fixed_t)(xoffs*fudgecanyon); yoffs = (fixed_t)(yoffs/fudgecanyon); - + #ifndef NOWATER if (planeripple.active) { From 46e10f67b2353c5043eb8680ac6583ad07be438d Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 16:21:13 +0200 Subject: [PATCH 17/44] more smol fixes --- src/hardware/hw_cache.c | 8 ++++---- src/p_setup.c | 4 ++-- src/r_data.c | 20 ++++++++++++-------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 545be088d..ae9436ac0 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -991,7 +991,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) if (!glMipmap->downloaded && !glMipmap->data) HWR_CacheFlat(glMipmap, flatlumpnum); - // If hardware does not have the texture, then call pfnSetTexture to upload it + // If hardware does not have the texture, then call GL_SetTexture to upload it if (!glMipmap->downloaded) GL_SetTexture(glMipmap); HWR_SetCurrentTexture(glMipmap); @@ -1010,7 +1010,7 @@ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) if (!glMipmap->downloaded && !glMipmap->data) HWR_MakePatch(patch, glPatch, glMipmap, true); - // If hardware does not have the texture, then call pfnSetTexture to upload it + // If hardware does not have the texture, then call GL_SetTexture to upload it if (!glMipmap->downloaded) GL_SetTexture(glMipmap); HWR_SetCurrentTexture(glMipmap); @@ -1027,8 +1027,8 @@ static void HWR_UpdatePatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) GLPatch_t *grPatch = patch->hardware; HWR_MakePatch(patch, grPatch, glMipmap, true); - // If hardware does not have the texture, then call pfnSetTexture to upload it - // If it does have the texture, then call pfnUpdateTexture to update it + // If hardware does not have the texture, then call GL_SetTexture to upload it + // If it does have the texture, then call GL_UpdateTexture to update it if (!glMipmap->downloaded) GL_SetTexture(glMipmap); else diff --git a/src/p_setup.c b/src/p_setup.c index a984121aa..d1657a153 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3350,13 +3350,13 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // search for sprite replacements // Patch_FreeTag(PU_SPRITE); - Patch_FreeTag(PU_PATCH_ROTATED); + //Patch_FreeTag(PU_PATCH_ROTATED); R_AddSpriteDefs(wadnum); // Reload it all anyway, just in case they // added some textures but didn't insert a // TEXTURES/etc. list. - R_LoadTexturesPwad(wadnum); + //R_LoadTexturesPwad(wadnum); // everything from MultiSetupWadFile until ST_Start was here originally diff --git a/src/r_data.c b/src/r_data.c index 2a2a0bd1d..b01b12ba5 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -541,7 +541,7 @@ void R_LoadTextures(void) // but the alternative is to spend a ton of time checking and re-checking all previous entries just to skip any potentially patched textures. for (w = 0, numtextures = 0; w < numwadfiles; w++) { - if (wadfiles[w]->type == RET_PK3) + if (W_FileHasFolders(wadfiles[w])) { texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); @@ -605,7 +605,7 @@ void R_LoadTextures(void) for (i = 0, w = 0; w < numwadfiles; w++) { // Get the lump numbers for the markers in the WAD, if they exist. - if (wadfiles[w]->type == RET_PK3) + if (W_FileHasFolders(wadfiles[w])) { texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); @@ -618,7 +618,7 @@ void R_LoadTextures(void) } else { - texstart = W_CheckNumForNamePwad(TX_START, (UINT16)w, 0) + 1; + texstart = W_CheckNumForMarkerStartPwad(TX_START, (UINT16)w, 0); texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); if (texturesLumpPos != INT16_MAX) @@ -631,20 +631,22 @@ void R_LoadTextures(void) // Work through each lump between the markers in the WAD. for (j = 0; j < (texend - texstart); j++) { + UINT16 wadnum = (UINT16)w; + lumpnum_t lumpnum = texstart + j; + if (W_FileHasFolders(wadfiles[w])) { - if (W_IsLumpFolder(w, texstart + j)) // Check if lump is a folder + if (W_IsLumpFolder(wadnum, lumpnum)) // Check if lump is a folder continue; // If it is then SKIP IT } - patchlump = W_CacheLumpNumPwad((UINT16)w, texstart + j, PU_CACHE); patchlump = (softwarepatch_t *)W_CacheLumpNumPwad(wadnum, lumpnum, PU_STATIC); - //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height); + //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad(wadnum, lumpnum), patchlump->width, patchlump->height); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); // Set texture properties. - M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); + M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name)); texture->width = SHORT(patchlump->width); texture->height = SHORT(patchlump->height); texture->patchcount = 1; @@ -654,9 +656,11 @@ void R_LoadTextures(void) patch = &texture->patches[0]; patch->originx = patch->originy = 0; - patch->wad = (UINT16)w; + patch->wad = wadnum; patch->lump = texstart + j; + Z_Free(patchlump); + k = 1; while (k << 1 <= texture->width) k <<= 1; From 2c8d5f2625970a6569285a33c6fdcc485002335f Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 16:25:58 +0200 Subject: [PATCH 18/44] dont clear all our textures if we dont intend to reload em the multipart addfile stuff is awkward asf --- src/p_setup.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index d1657a153..6e8ea237c 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3340,12 +3340,6 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (!devparm && digmreplaces) CONS_Printf(M_GetText("%s digital musics replaced\n"), sizeu1(digmreplaces)); -#ifdef HWRENDER - // Free GPU textures before freeing patches. - if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED)) - HWR_ClearAllTextures(); -#endif - // // search for sprite replacements // @@ -3482,6 +3476,11 @@ boolean P_MultiSetupWadFiles(boolean fullsetup) if (partadd_stage == 1) { +#ifdef HWRENDER + // Free GPU textures before freeing patches. + if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED)) + HWR_ClearAllTextures(); +#endif // Reload all textures, unconditionally for better or worse. R_LoadTextures(); From 8e6633d0bc7b1cf52d0121693798834bc9d678bf Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 16:36:41 +0200 Subject: [PATCH 19/44] fix the sprite shadows Zzz... --- src/hardware/hw_main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 1ec415292..3e964db9e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3324,6 +3324,9 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch) pslope_t *floorslope; fixed_t slopez; float offset = 0; + GLPatch_t *hwrpatch; + + hwrpatch = (GLPatch_t *)(gpatch->hardware); // technically this_scale gets multiplied and added to sprite y/x scale, but this thing needs it for some crap so ill just throw it in here again const boolean hires = (spr->mobj && spr->mobj->skin && K_GetMobjSkin(spr->mobj)->flags & SF_HIRES); @@ -3439,25 +3442,25 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch) if (spr->flip) { - swallVerts[0].s = swallVerts[3].s = gpatch->max_s; + swallVerts[0].s = swallVerts[3].s = hwrpatch->max_s; swallVerts[2].s = swallVerts[1].s = 0; } else { swallVerts[0].s = swallVerts[3].s = 0; - swallVerts[2].s = swallVerts[1].s = gpatch->max_s; + swallVerts[2].s = swallVerts[1].s = hwrpatch->max_s; } // flip the texture coords (look familiar?) if (spr->vflip) { - swallVerts[3].t = swallVerts[2].t = gpatch->max_t; + swallVerts[3].t = swallVerts[2].t = hwrpatch->max_t; swallVerts[0].t = swallVerts[1].t = 0; } else { swallVerts[3].t = swallVerts[2].t = 0; - swallVerts[0].t = swallVerts[1].t = gpatch->max_t; + swallVerts[0].t = swallVerts[1].t = hwrpatch->max_t; } sSurf.PolyColor.s.red = 0x01; From a0062060eb59ad82fd38e558e05e38d4e915b24f Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 16:50:09 +0200 Subject: [PATCH 20/44] oop --- src/r_data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_data.c b/src/r_data.c index b01b12ba5..53f58de27 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -618,7 +618,7 @@ void R_LoadTextures(void) } else { - texstart = W_CheckNumForMarkerStartPwad(TX_START, (UINT16)w, 0); + texstart = W_CheckNumForNamePwad(TX_START, (UINT16)w, 0) + 1; texend = W_CheckNumForNamePwad(TX_END, (UINT16)w, 0); texturesLumpPos = W_CheckNumForNamePwad("TEXTURES", (UINT16)w, 0); if (texturesLumpPos != INT16_MAX) From 88dc5f25adb5e987eae169e0aa63add7be6d2899 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 18:46:55 +0200 Subject: [PATCH 21/44] smol cleanup W_CachePatchNumPwad --- src/w_wad.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 2e7f2cee4..98ab1488a 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1738,7 +1738,6 @@ void *W_CacheLumpName(const char *name, INT32 tag) // Cache a patch into heap memory, convert the patch format as necessary // -// Software-only compile cache the data without conversion void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag) { lumpcache_t *lumpcache = NULL; @@ -1784,14 +1783,11 @@ void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag) #ifdef HWRENDER // Software-only compile cache the data without conversion - if (rendermode == render_soft || rendermode == render_none) + if (rendermode == render_opengl) + Patch_CreateGL(patch); #endif - return (void *)patch; -#ifdef HWRENDER - Patch_CreateGL(patch); return (void *)patch; -#endif } void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag) From b28593dba7457ea34bba1958e57b042ed86ce40b Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 19:22:28 +0200 Subject: [PATCH 22/44] turn rotcache into a lumpcache_t aswell no need for slow aatrees --- src/w_wad.c | 14 ++++++-------- src/w_wad.h | 4 +--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 98ab1488a..5e2e2e94b 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -824,8 +824,7 @@ UINT16 W_InitFile(const char *filename, boolean local) Z_Calloc(numlumps * sizeof (*wadfile->patchcache), PU_STATIC, &wadfile->patchcache); #ifdef ROTSPRITE - // allocates rotsprite structures and store them in a tree - wadfile->rotcache = M_AATreeAlloc(AATREE_ZUSER); + Z_Calloc(numlumps * sizeof (*wadfile->rotcache), PU_STATIC, &wadfile->rotcache); #endif // @@ -1807,16 +1806,15 @@ void *W_GetCachedPatchNumPwad(UINT16 wad, UINT16 lump) // Caches a rotsprite for patch rotation. void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum) { - aatree_t *rotcache = wadfiles[wadnum]->rotcache; - rotsprite_t *rspr; + lumpcache_t *rotcache = wadfiles[wadnum]->rotcache; - if (!(rspr = M_AATreeGet(rotcache, lumpnum))) + if (!rotcache[lumpnum]) { - rspr = RotatedPatch_Create(ROTANGLES); - M_AATreeSet(rotcache, lumpnum, rspr); + rotsprite_t *rspr = RotatedPatch_Create(ROTANGLES); + Z_SetUser(rspr, (void **)(&rotcache[lumpnum])); } - return (void *)rspr; + return (void *)(rotcache[lumpnum]); } #endif // ROTSPRITE diff --git a/src/w_wad.h b/src/w_wad.h index 79cad44e9..12ad8cea7 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -106,8 +106,6 @@ virtlump_t* vres_Find(const virtres_t*, const char*); #define lumpcache_t void * -#include "m_aatree.h" - // Resource type of the WAD. Yeah, I know this sounds dumb, but I'll leave it like this until I clean up the code further. typedef enum restype { @@ -127,7 +125,7 @@ typedef struct wadfile_s lumpcache_t *lumpcache; lumpcache_t *patchcache; #ifdef ROTSPRITE - aatree_t *rotcache; // Cache rotsprites for rotating patches. + lumpcache_t *rotcache; // Cache rotsprites for rotating patches. #endif UINT16 numlumps; // this wad's number of resources FILE *handle; From f4fc185f5b729951fdf9bd0cdcb7af8325528bec Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 20:25:56 +0200 Subject: [PATCH 23/44] move patch rotation stuff into their own files --- src/CMakeLists.txt | 4 +- src/Makefile | 1 + src/dehacked.c | 2 +- src/hardware/hw_cache.c | 2 +- src/hardware/hw_main.c | 7 +- src/k_kart.c | 4 + src/lua_hudlib.c | 4 + src/r_bsp.c | 5 +- src/r_patch.c | 254 +------------------------------------- src/r_patch.h | 16 +-- src/r_patchrotation.c | 262 ++++++++++++++++++++++++++++++++++++++++ src/r_patchrotation.h | 30 +++++ src/r_things.c | 34 +++--- src/sdl/Srb2SDL.dsp | 8 ++ src/w_wad.c | 3 +- 15 files changed, 347 insertions(+), 289 deletions(-) create mode 100644 src/r_patchrotation.c create mode 100644 src/r_patchrotation.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 121cb9925..729b5896a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -129,6 +129,7 @@ set(SRB2_CORE_RENDER_SOURCES r_fps.c r_main.c r_patch.c + r_patchrotation.c r_plane.c r_segs.c r_sky.c @@ -143,7 +144,8 @@ set(SRB2_CORE_RENDER_SOURCES r_fps.h r_local.h r_main.h - r_patch + r_patch.h + r_patchrotation.h r_plane.h r_segs.h r_sky.h diff --git a/src/Makefile b/src/Makefile index 9244c30fd..ebc2c683b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -552,6 +552,7 @@ OBJS:=$(i_main_o) \ $(OBJDIR)/r_sky.o \ $(OBJDIR)/r_splats.o \ $(OBJDIR)/r_patch.o \ + $(OBJDIR)/r_patchrotation.o \ $(OBJDIR)/r_things.o \ $(OBJDIR)/r_portal.o \ $(OBJDIR)/screen.o \ diff --git a/src/dehacked.c b/src/dehacked.c index fd90c380e..f0e2583d8 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -28,7 +28,7 @@ #include "p_local.h" // for var1 and var2, and some constants #include "p_setup.h" #include "r_data.h" -#include "r_patch.h" +#include "r_fps.h" #include "r_sky.h" #include "r_draw.h" // translation colormap consts (for lua) #include "fastcmp.h" diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index ae9436ac0..554c2297a 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -28,7 +28,7 @@ #include "../v_video.h" #include "../r_draw.h" #include "../r_main.h" -#include "../r_patch.h" // patch rotation +#include "../r_patch.h" #include "../p_setup.h" // levelflats #include "../p_spec.h" // anim_t #include "../r_sky.h" diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3e964db9e..66809d19e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -39,7 +39,6 @@ #include "../r_fps.h" #include "../r_local.h" #include "../r_main.h" // cv_fov -#include "../r_patch.h" // a mystery as to what this is for #include "../r_portal.h" #ifdef WALLSPLATS #include "../r_splats.h" @@ -56,7 +55,11 @@ #include "../w_wad.h" #include "../z_zone.h" -#include "../qs22j.h" // fast qsort +#ifdef ROTSPRITE +#include "../r_patchrotation.h" // a mystery as to what this is for +#endif + +#include "../qs22j.h" // fast qsort // ========================================================================== // Globals diff --git a/src/k_kart.c b/src/k_kart.c index 7fdd8351b..14677f18d 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -48,6 +48,10 @@ #include "hardware/hw_main.h" #endif +#ifdef ROTSPRITE +#include "r_patchrotation.h" +#endif + // Hud offset cvars #define IMPL_HUD_OFFSET_X(name)\ consvar_t cv_##name##_xoffset = {"hud_" #name "_xoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index b2425ec0a..d6b6db5c3 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -30,6 +30,10 @@ #include "lua_hud.h" #include "lua_hook.h" +#ifdef ROTSPRITE +#include "r_patchrotation.h" +#endif + #define HUDONLY if (!hud_running) return luaL_error(L, "HUD rendering code should not be called outside of rendering hooks!"); boolean hud_running = false; diff --git a/src/r_bsp.c b/src/r_bsp.c index 278bafb82..6ef40b0e6 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -13,12 +13,13 @@ #include "doomdef.h" #include "g_game.h" + +#include "r_fps.h" #include "r_local.h" #include "r_state.h" #include "r_portal.h" // Add seg portals - - #include "r_splats.h" + #include "p_local.h" // camera #include "p_slopes.h" #include "z_zone.h" // Check R_Prep3DFloors diff --git a/src/r_patch.c b/src/r_patch.c index e35563fe6..209b7e017 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -13,12 +13,7 @@ /// \brief Patch generation. #include "byteptr.h" -#include "dehacked.h" #include "doomdef.h" -#include "i_video.h" -#include "r_data.h" -#include "r_draw.h" -#include "r_fps.h" #include "r_patch.h" #include "r_things.h" #include "z_zone.h" @@ -462,7 +457,7 @@ void *Patch_CreateGL(patch_t *patch) // Convert a masked flat to a patch. // Explanation of "masked" flats in R_PatchToMaskedFlat. // -static void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffset, INT16 topoffset, size_t *destsize) +void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffset, INT16 topoffset, size_t *destsize) { INT16 x, y; UINT8 *img; @@ -577,7 +572,7 @@ static void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 l return converted; } -static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) +UINT16 R_GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) { fixed_t ofs; column_t *column; @@ -619,248 +614,3 @@ static UINT16 GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) return 0xFF00; } - -#ifdef ROTSPRITE -// -// R_GetRollAngle -// -// Angles precalculated in R_InitSprites. -// -fixed_t rollcosang[ROTANGLES]; -fixed_t rollsinang[ROTANGLES]; - -INT32 R_GetRollAngle(angle_t rollangle) -{ - INT32 ra = AngleFixed(rollangle)>>FRACBITS; -#if (ROTANGDIFF > 1) - ra += (ROTANGDIFF/2); -#endif - ra /= ROTANGDIFF; - ra %= ROTANGLES; - return ra; -} - -angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp) -{ - return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp->roll) + - FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp->pitch) + - FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp->sloperoll) + - FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp->slopepitch); -} - -patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle) -{ - rotsprite_t *rotsprite; - spriteinfo_t *sprinfo = (spriteinfo_t *)info; - INT32 idx = rotationangle; - - if (rotationangle < 1 || rotationangle >= ROTANGLES) - return NULL; - - rotsprite = sprite->rotated[spriteangle]; - - if (rotsprite == NULL) - { - rotsprite = RotatedPatch_Create(ROTANGLES); - sprite->rotated[spriteangle] = rotsprite; - } - - if (flip) - idx += rotsprite->angles; - - if (rotsprite->patches[idx] == NULL) - { - patch_t *patch; - INT32 xpivot = 0, ypivot = 0; - lumpnum_t lump = sprite->lumppat[spriteangle]; - - if (lump == LUMPERROR) - return NULL; - - patch = W_CachePatchNum(lump, PU_SPRITE); - - if (sprinfo->available) - { - xpivot = sprinfo->pivot[frame].x; - ypivot = sprinfo->pivot[frame].y; - } - else - { - xpivot = patch->leftoffset; - ypivot = patch->height / 2; - } - - RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip); - } - - return rotsprite->patches[idx]; -} - -rotsprite_t *RotatedPatch_Create(INT32 numangles) -{ - rotsprite_t *rotsprite = Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL); - rotsprite->angles = numangles; - rotsprite->patches = Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL); - return rotsprite; -} - -static void RotatedPatch_CalculateDimensions( - INT32 width, INT32 height, - fixed_t ca, fixed_t sa, - INT32 *newwidth, INT32 *newheight) -{ - fixed_t fixedwidth = (width * FRACUNIT); - fixed_t fixedheight = (height * FRACUNIT); - - fixed_t w1 = abs(FixedMul(fixedwidth, ca) - FixedMul(fixedheight, sa)); - fixed_t w2 = abs(FixedMul(-fixedwidth, ca) - FixedMul(fixedheight, sa)); - fixed_t h1 = abs(FixedMul(fixedwidth, sa) + FixedMul(fixedheight, ca)); - fixed_t h2 = abs(FixedMul(-fixedwidth, sa) + FixedMul(fixedheight, ca)); - - w1 = FixedInt(FixedCeil(w1 + (FRACUNIT/2))); - w2 = FixedInt(FixedCeil(w2 + (FRACUNIT/2))); - h1 = FixedInt(FixedCeil(h1 + (FRACUNIT/2))); - h2 = FixedInt(FixedCeil(h2 + (FRACUNIT/2))); - - *newwidth = max(width, max(w1, w2)); - *newheight = max(height, max(h1, h2)); -} - -void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip) -{ - UINT32 i; - patch_t *rotated; - - UINT16 *rawdst, *rawconv; - size_t size; - INT32 bflip = (flip != 0x00); - - INT32 width = patch->width; - INT32 height = patch->height; - INT32 leftoffset = patch->leftoffset; - INT32 newwidth, newheight; - - fixed_t ca = rollcosang[angle]; - fixed_t sa = rollsinang[angle]; - fixed_t xcenter, ycenter; - INT32 idx = angle; - INT32 x, y; - INT32 sx, sy; - INT32 dx, dy; - INT32 ox, oy; - INT32 minx, miny, maxx, maxy; - - // Don't cache angle = 0 - if (angle < 1 || angle >= ROTANGLES) - return; - - if (flip) - { - idx += rotsprite->angles; - xpivot = width - xpivot; - leftoffset = width - leftoffset; - } - - if (rotsprite->patches[idx]) - return; - - // Find the dimensions of the rotated patch. - RotatedPatch_CalculateDimensions(width, height, ca, sa, &newwidth, &newheight); - - xcenter = (xpivot * FRACUNIT); - ycenter = (ypivot * FRACUNIT); - - if (xpivot != width / 2 || ypivot != height / 2) - { - newwidth *= 2; - newheight *= 2; - } - - minx = newwidth; - miny = newheight; - maxx = 0; - maxy = 0; - - // Draw the rotated sprite to a temporary buffer. - size = (newwidth * newheight); - if (!size) - size = (width * height); - rawdst = Z_Malloc(size * sizeof(UINT16), PU_STATIC, NULL); - - for (i = 0; i < size; i++) - rawdst[i] = 0xFF00; - - for (dy = 0; dy < newheight; dy++) - { - for (dx = 0; dx < newwidth; dx++) - { - x = (dx - (newwidth / 2)) * FRACUNIT; - y = (dy - (newheight / 2)) * FRACUNIT; - sx = FixedMul(x, ca) + FixedMul(y, sa) + xcenter; - sy = -FixedMul(x, sa) + FixedMul(y, ca) + ycenter; - - sx >>= FRACBITS; - sy >>= FRACBITS; - - if (sx >= 0 && sy >= 0 && sx < width && sy < height) - { - rawdst[(dy * newwidth) + dx] = GetPatchPixel(patch, sx, sy, bflip); - - if (dx < minx) - minx = dx; - if (dy < miny) - miny = dy; - if (dx > maxx) - maxx = dx; - if (dy > maxy) - maxy = dy; - } - } - } - - ox = (newwidth / 2) + (leftoffset - xpivot); - oy = (newheight / 2) + (patch->topoffset - ypivot); - width = (maxx - minx); - height = (maxy - miny); - - if ((unsigned)(width * height) > size) - { - UINT16 *src, *dest; - - size = (width * height); - rawconv = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL); - - src = &rawdst[(miny * newwidth) + minx]; - dest = rawconv; - dy = height; - - while (dy--) - { - M_Memcpy(dest, src, width * sizeof(UINT16)); - dest += width; - src += newwidth; - } - - ox -= minx; - oy -= miny; - - Z_Free(rawdst); - } - else - { - rawconv = rawdst; - width = newwidth; - height = newheight; - } - - // make patch - rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); - - Z_ChangeTag(rotated, PU_PATCH_ROTATED); - Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); - Z_Free(rawconv); - - rotated->leftoffset = ox; - rotated->topoffset = oy; -} -#endif diff --git a/src/r_patch.h b/src/r_patch.h index bde624ead..2978ff10c 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -15,8 +15,6 @@ #define __R_PATCH__ #include "r_defs.h" -#include "r_fps.h" -#include "doomdef.h" // Structs typedef enum @@ -58,17 +56,7 @@ extern spriteinfo_t spriteinfo[NUMSPRITES]; void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps); void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum); -// Sprite rotation -#ifdef ROTSPRITE -INT32 R_GetRollAngle(angle_t rollangle); -angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp); - -patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle); -rotsprite_t *RotatedPatch_Create(INT32 numangles); -void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip); - -extern fixed_t rollcosang[ROTANGLES]; -extern fixed_t rollsinang[ROTANGLES]; -#endif +void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffset, INT16 topoffset, size_t *destsize); +UINT16 R_GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip); #endif // __R_PATCH__ diff --git a/src/r_patchrotation.c b/src/r_patchrotation.c new file mode 100644 index 000000000..3f1836ad1 --- /dev/null +++ b/src/r_patchrotation.c @@ -0,0 +1,262 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020-2023 by Lactozilla. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file r_patchrotation.c +/// \brief Patch rotation. + +#include "doomdef.h" +#include "r_fps.h" +#include "r_patch.h" +#include "r_patchrotation.h" +#include "z_zone.h" +#include "w_wad.h" + +#ifdef ROTSPRITE +// +// R_GetRollAngle +// +// Angles precalculated in R_InitSprites. +// +fixed_t rollcosang[ROTANGLES]; +fixed_t rollsinang[ROTANGLES]; + +INT32 R_GetRollAngle(angle_t rollangle) +{ + INT32 ra = AngleFixed(rollangle)>>FRACBITS; +#if (ROTANGDIFF > 1) + ra += (ROTANGDIFF/2); +#endif + ra /= ROTANGDIFF; + ra %= ROTANGLES; + return ra; +} + +angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp) +{ + return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp->roll) + + FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp->pitch) + + FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp->sloperoll) + + FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp->slopepitch); +} + +patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle) +{ + rotsprite_t *rotsprite; + spriteinfo_t *sprinfo = (spriteinfo_t *)info; + INT32 idx = rotationangle; + + if (rotationangle < 1 || rotationangle >= ROTANGLES) + return NULL; + + rotsprite = sprite->rotated[spriteangle]; + + if (rotsprite == NULL) + { + rotsprite = RotatedPatch_Create(ROTANGLES); + sprite->rotated[spriteangle] = rotsprite; + } + + if (flip) + idx += rotsprite->angles; + + if (rotsprite->patches[idx] == NULL) + { + patch_t *patch; + INT32 xpivot = 0, ypivot = 0; + lumpnum_t lump = sprite->lumppat[spriteangle]; + + if (lump == LUMPERROR) + return NULL; + + patch = W_CachePatchNum(lump, PU_SPRITE); + + if (sprinfo->available) + { + xpivot = sprinfo->pivot[frame].x; + ypivot = sprinfo->pivot[frame].y; + } + else + { + xpivot = patch->leftoffset; + ypivot = patch->height / 2; + } + + RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip); + } + + return rotsprite->patches[idx]; +} + +rotsprite_t *RotatedPatch_Create(INT32 numangles) +{ + rotsprite_t *rotsprite = Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL); + rotsprite->angles = numangles; + rotsprite->patches = Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL); + return rotsprite; +} + +static void RotatedPatch_CalculateDimensions( + INT32 width, INT32 height, + fixed_t ca, fixed_t sa, + INT32 *newwidth, INT32 *newheight) +{ + fixed_t fixedwidth = (width * FRACUNIT); + fixed_t fixedheight = (height * FRACUNIT); + + fixed_t w1 = abs(FixedMul(fixedwidth, ca) - FixedMul(fixedheight, sa)); + fixed_t w2 = abs(FixedMul(-fixedwidth, ca) - FixedMul(fixedheight, sa)); + fixed_t h1 = abs(FixedMul(fixedwidth, sa) + FixedMul(fixedheight, ca)); + fixed_t h2 = abs(FixedMul(-fixedwidth, sa) + FixedMul(fixedheight, ca)); + + w1 = FixedInt(FixedCeil(w1 + (FRACUNIT/2))); + w2 = FixedInt(FixedCeil(w2 + (FRACUNIT/2))); + h1 = FixedInt(FixedCeil(h1 + (FRACUNIT/2))); + h2 = FixedInt(FixedCeil(h2 + (FRACUNIT/2))); + + *newwidth = max(width, max(w1, w2)); + *newheight = max(height, max(h1, h2)); +} + +void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip) +{ + UINT32 i; + patch_t *rotated; + + UINT16 *rawdst, *rawconv; + size_t size; + INT32 bflip = (flip != 0x00); + + INT32 width = patch->width; + INT32 height = patch->height; + INT32 leftoffset = patch->leftoffset; + INT32 newwidth, newheight; + + fixed_t ca = rollcosang[angle]; + fixed_t sa = rollsinang[angle]; + fixed_t xcenter, ycenter; + INT32 idx = angle; + INT32 x, y; + INT32 sx, sy; + INT32 dx, dy; + INT32 ox, oy; + INT32 minx, miny, maxx, maxy; + + // Don't cache angle = 0 + if (angle < 1 || angle >= ROTANGLES) + return; + + if (flip) + { + idx += rotsprite->angles; + xpivot = width - xpivot; + leftoffset = width - leftoffset; + } + + if (rotsprite->patches[idx]) + return; + + // Find the dimensions of the rotated patch. + RotatedPatch_CalculateDimensions(width, height, ca, sa, &newwidth, &newheight); + + xcenter = (xpivot * FRACUNIT); + ycenter = (ypivot * FRACUNIT); + + if (xpivot != width / 2 || ypivot != height / 2) + { + newwidth *= 2; + newheight *= 2; + } + + minx = newwidth; + miny = newheight; + maxx = 0; + maxy = 0; + + // Draw the rotated sprite to a temporary buffer. + size = (newwidth * newheight); + if (!size) + size = (width * height); + rawdst = Z_Malloc(size * sizeof(UINT16), PU_STATIC, NULL); + + for (i = 0; i < size; i++) + rawdst[i] = 0xFF00; + + for (dy = 0; dy < newheight; dy++) + { + for (dx = 0; dx < newwidth; dx++) + { + x = (dx - (newwidth / 2)) * FRACUNIT; + y = (dy - (newheight / 2)) * FRACUNIT; + sx = FixedMul(x, ca) + FixedMul(y, sa) + xcenter; + sy = -FixedMul(x, sa) + FixedMul(y, ca) + ycenter; + + sx >>= FRACBITS; + sy >>= FRACBITS; + + if (sx >= 0 && sy >= 0 && sx < width && sy < height) + { + rawdst[(dy * newwidth) + dx] = R_GetPatchPixel(patch, sx, sy, bflip); + + if (dx < minx) + minx = dx; + if (dy < miny) + miny = dy; + if (dx > maxx) + maxx = dx; + if (dy > maxy) + maxy = dy; + } + } + } + + ox = (newwidth / 2) + (leftoffset - xpivot); + oy = (newheight / 2) + (patch->topoffset - ypivot); + width = (maxx - minx); + height = (maxy - miny); + + if ((unsigned)(width * height) > size) + { + UINT16 *src, *dest; + + size = (width * height); + rawconv = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL); + + src = &rawdst[(miny * newwidth) + minx]; + dest = rawconv; + dy = height; + + while (dy--) + { + M_Memcpy(dest, src, width * sizeof(UINT16)); + dest += width; + src += newwidth; + } + + ox -= minx; + oy -= miny; + + Z_Free(rawdst); + } + else + { + rawconv = rawdst; + width = newwidth; + height = newheight; + } + + // make patch + rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); + + Z_ChangeTag(rotated, PU_PATCH_ROTATED); + Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); + Z_Free(rawconv); + + rotated->leftoffset = ox; + rotated->topoffset = oy; +} +#endif diff --git a/src/r_patchrotation.h b/src/r_patchrotation.h new file mode 100644 index 000000000..d387ae20f --- /dev/null +++ b/src/r_patchrotation.h @@ -0,0 +1,30 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020-2023 by Lactozilla. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file r_patchrotation.h +/// \brief Patch rotation. + +#ifndef __R_PATCHROTATION__ +#define __R_PATCHROTATION__ + +#include "r_fps.h" + +// Sprite rotation +#ifdef ROTSPRITE +INT32 R_GetRollAngle(angle_t rollangle); +angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp); + +rotsprite_t *RotatedPatch_Create(INT32 numangles); +void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip); +patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle); + +extern fixed_t rollcosang[ROTANGLES]; +extern fixed_t rollsinang[ROTANGLES]; +#endif + +#endif // __R_PATCHROTATION__ diff --git a/src/r_things.c b/src/r_things.c index caa9085b9..4a24e0158 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -11,34 +11,38 @@ /// \file r_things.c /// \brief Refresh of things, i.e. objects represented by sprites -#include "doomdef.h" -#include "console.h" -#include "g_game.h" -#include "r_local.h" -#include "st_stuff.h" -#include "w_wad.h" -#include "z_zone.h" -#include "m_misc.h" -#include "i_video.h" // rendermode #include "r_main.h" // stplyr #include "r_fps.h" #include "r_things.h" -#include "r_patch.h" #include "r_plane.h" +#include "r_portal.h" +#include "r_local.h" + +#include "dehacked.h" // get_number (for thok) +#include "doomdef.h" +#include "d_netfil.h" // blargh. for nameonly(). +#include "console.h" +#include "g_game.h" +#include "k_kart.h" // SRB2kart #include "p_tick.h" #include "p_local.h" #include "p_setup.h" #include "p_slopes.h" -#include "dehacked.h" // get_number (for thok) -#include "d_netfil.h" // blargh. for nameonly(). +#include "st_stuff.h" #include "m_cheat.h" // objectplace -#include "r_portal.h" -#include "k_kart.h" // SRB2kart -#include "p_local.h" // stplyr +#include "m_misc.h" +#include "i_video.h" // rendermode +#include "w_wad.h" +#include "z_zone.h" + #ifdef HWRENDER #include "hardware/hw_md2.h" #endif +#ifdef ROTSPRITE +#include "r_patchrotation.h" +#endif + #include "qs22j.h" CV_PossibleValue_t Forceskin_cons_t[MAXSKINS+2]; diff --git a/src/sdl/Srb2SDL.dsp b/src/sdl/Srb2SDL.dsp index 35e5ec32b..67400625a 100644 --- a/src/sdl/Srb2SDL.dsp +++ b/src/sdl/Srb2SDL.dsp @@ -897,6 +897,14 @@ SOURCE=..\r_patch.h # End Source File # Begin Source File +SOURCE=..\r_patchrotation.c +# End Source File +# Begin Source File + +SOURCE=..\r_patchrotation.h +# End Source File +# Begin Source File + SOURCE=..\r_plane.c # End Source File # Begin Source File diff --git a/src/w_wad.c b/src/w_wad.c index 5e2e2e94b..292101750 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -58,6 +58,7 @@ #include "dehacked.h" #include "d_clisrv.h" #include "r_defs.h" +#include "r_patch.h" #include "i_system.h" #include "md5.h" #include "lua_script.h" @@ -72,7 +73,7 @@ #endif #ifdef ROTSPRITE -#include "r_patch.h" // RotatedPatch_Create +#include "r_patchrotation.h" // RotatedPatch_Create #endif #ifndef O_BINARY From 8ec6b2e737ca4c98ea17619e677835eb2c0215ee Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 20:27:53 +0200 Subject: [PATCH 24/44] fix compile without ROTSPRITE --- src/k_kart.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/k_kart.c b/src/k_kart.c index 14677f18d..e1127f05c 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9643,7 +9643,9 @@ static void K_drawKartSpeedometer(void) // index 0 is the raw value, index 1 is the converted value fixed_t convSpeed[2] = {0,0}; +#ifdef ROTSPRITE fixed_t dial_divisor = DIALSPDDIV; +#endif INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); @@ -9659,12 +9661,16 @@ static void K_drawKartSpeedometer(void) case 2: convSpeed[0] = FixedDiv(FixedMul(stplyr->speed, 88465), mapobjectscale); // 1.349868774 convSpeed[1] = convSpeed[0] / FRACUNIT; +#ifdef ROTSPRITE dial_divisor = MPHDIV; +#endif break; case 3: convSpeed[0] = FixedDiv(stplyr->speed, mapobjectscale); convSpeed[1] = convSpeed[0] / FRACUNIT; +#ifdef ROTSPRITE dial_divisor = MPHDIV; +#endif break; case 4: if (stplyr->mo) From 006931eaa8ab696e408724903f86019b955bb0a9 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 22:37:22 +0200 Subject: [PATCH 25/44] why are these even seperated like that lel --- src/m_menu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 397a850c9..6d54e44d8 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2432,17 +2432,17 @@ static menuitem_t OP_SaturnHudMenu[] = {IT_STRING | IT_CVAR, NULL, "Show Names on Minimap", &cv_showminimapnames, 135}, {IT_STRING | IT_CVAR, NULL, "Small Minimap Players", &cv_minihead, 140}, - {IT_STRING | IT_CVAR, NULL, "Spin Minimap Icons", &cv_spinoutroll, 150}, - {IT_STRING | IT_CVAR, NULL, "Player Angle Dot", &cv_showminimapangle, 160}, + {IT_STRING | IT_CVAR, NULL, "Spin Minimap Icons", &cv_spinoutroll, 145}, + {IT_STRING | IT_CVAR, NULL, "Player Angle Dot", &cv_showminimapangle, 150}, - {IT_STRING | IT_CVAR, NULL, "Beta Intermissionscreen", &cv_betainterscreen, 170}, + {IT_STRING | IT_CVAR, NULL, "Beta Intermissionscreen", &cv_betainterscreen, 160}, - {IT_STRING | IT_CVAR, NULL, "Show Director Prompt", &cv_showdirectorhud, 180}, + {IT_STRING | IT_CVAR, NULL, "Show Director Prompt", &cv_showdirectorhud, 170}, - {IT_STRING | IT_SUBMENU, NULL, "Nametags...", &OP_NametagDef, 190}, - {IT_STRING | IT_SUBMENU, NULL, "Driftgauge...", &OP_DriftGaugeDef, 195}, + {IT_STRING | IT_SUBMENU, NULL, "Nametags...", &OP_NametagDef, 180}, + {IT_STRING | IT_SUBMENU, NULL, "Driftgauge...", &OP_DriftGaugeDef, 185}, - {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 205}, + {IT_SUBMENU|IT_STRING, NULL, "Hud Offsets...", &OP_HudOffsetDef, 195}, }; static const char* OP_SaturnHudTooltips[] = From 3b4ffa20bc0f461d9f15e7d17702a5aac5d3a7f1 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Apr 2025 23:21:33 +0200 Subject: [PATCH 26/44] why? --- src/w_wad.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 292101750..241693324 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1854,9 +1854,7 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) rotsprite_t *rspr; INT32 idx = rotationangle; - const char *finalname = name; - - num = W_CheckNumForName(finalname); + num = W_CheckNumForName(name); if (num == LUMPERROR) num = W_GetNumForName("MISSING"); From da5aaa7ebfb1ab464276492aa59389513c5d24b2 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 17 Apr 2025 19:37:17 +0100 Subject: [PATCH 27/44] Revert "SHORT ma balls" This reverts commit 5401cb58bdfbbeedc148eea0922aab1801099350. --- src/k_kart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 36d3e90c2..da484841a 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -10575,13 +10575,13 @@ static void K_drawKartMinimapIcon(fixed_t objx, fixed_t objy, INT32 hudx, INT32 if (encoremode) amnumxpos = -amnumxpos; - amxpos = amnumxpos + ((hudx + (SHORT(AutomapPic->width)-SHORT(icon->width))/2)<height)-SHORT(icon->height))/2)<width-icon->width)/2)<height-icon->height)/2)<width) / 4)<height) / 4)<width / 4)<height / 4)< Date: Fri, 18 Apr 2025 21:59:24 +0200 Subject: [PATCH 28/44] readd missing SHORT macro for patch_create --- src/r_patch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_patch.c b/src/r_patch.c index 209b7e017..21f59401c 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -336,7 +336,7 @@ patch_t *Patch_Create(softwarepatch_t *source, size_t srcsize, void *dest) if (source) { INT32 col, colsize; - size_t size = sizeof(INT32) * source->width; + size_t size = sizeof(INT32) * SHORT(source->width); size_t offs = (sizeof(INT16) * 4) + size; patch->width = SHORT(source->width); From f03a12241d6bdd2419faee320b2b4c348f11bf57 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 18 Apr 2025 22:03:55 +0200 Subject: [PATCH 29/44] fix hwrpatch grabbing the wrong patch getmapped patch needs to be called before this is referenced to avoid potential issues --- src/hardware/hw_main.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 66809d19e..5b1b3a48e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3329,7 +3329,7 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch) float offset = 0; GLPatch_t *hwrpatch; - hwrpatch = (GLPatch_t *)(gpatch->hardware); + hwrpatch = ((GLPatch_t *)gpatch->hardware); // technically this_scale gets multiplied and added to sprite y/x scale, but this thing needs it for some crap so ill just throw it in here again const boolean hires = (spr->mobj && spr->mobj->skin && K_GetMobjSkin(spr->mobj)->flags & SF_HIRES); @@ -3604,13 +3604,14 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) INT32 shader = SHADER_NONE; gpatch = spr->gpatch; - hwrpatch = (GLPatch_t *)(gpatch->hardware); // cache the patch in the graphics card memory //12/12/99: Hurdler: same comment as above (for md2) //Hurdler: 25/04/2000: now support colormap in hardware mode HWR_GetMappedPatch(gpatch, spr->colormap); + hwrpatch = ((GLPatch_t *)gpatch->hardware); + // Draw shadow BEFORE sprite if (cv_shadow.value // Shadows enabled && (spr->mobj->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. @@ -3881,7 +3882,13 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) // in memory and we add the md2 model if it exists for that sprite gpatch = spr->gpatch; - hwrpatch = (GLPatch_t *)(gpatch->hardware); + + // cache the patch in the graphics card memory + //12/12/99: Hurdler: same comment as above (for md2) + //Hurdler: 25/04/2000: now support colormap in hardware mode + HWR_GetMappedPatch(gpatch, spr->colormap); + + hwrpatch = ((GLPatch_t *)gpatch->hardware); // create the sprite billboard // @@ -3924,11 +3931,6 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) wallVerts[0].t = wallVerts[1].t = hwrpatch->max_t; } - // cache the patch in the graphics card memory - //12/12/99: Hurdler: same comment as above (for md2) - //Hurdler: 25/04/2000: now support colormap in hardware mode - HWR_GetMappedPatch(gpatch, spr->colormap); - // Draw shadow BEFORE sprite if (cv_shadow.value // Shadows enabled && (spr->mobj->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. @@ -4018,7 +4020,13 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) // cache sprite graphics gpatch = spr->gpatch; - hwrpatch = (GLPatch_t *)(gpatch->hardware); + + // cache the patch in the graphics card memory + //12/12/99: Hurdler: same comment as above (for md2) + //Hurdler: 25/04/2000: now support colormap in hardware mode + HWR_GetMappedPatch(gpatch, spr->colormap); + + hwrpatch = ((GLPatch_t *)gpatch->hardware); // create the sprite billboard // @@ -4044,11 +4052,6 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) wallVerts[3].t = wallVerts[2].t = 0; wallVerts[0].t = wallVerts[1].t = hwrpatch->max_t; - // cache the patch in the graphics card memory - //12/12/99: Hurdler: same comment as above (for md2) - //Hurdler: 25/04/2000: now support colormap in hardware mode - HWR_GetMappedPatch(gpatch, spr->colormap); - // colormap test sector_t *sector = spr->mobj->subsector->sector; UINT8 lightlevel = 255; From dc4950288475f5ae13ada5d7a2e6ce88d8748346 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 18 Apr 2025 23:28:53 +0200 Subject: [PATCH 30/44] smol fix for R_AddSingleSpriteDef --- src/r_things.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 4a24e0158..d37107ca7 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -282,7 +282,7 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, for (l = startlump; l < endlump; l++) { - if (memcmp(lumpinfo[l].name,sprname,4)) + if (memcmp(lumpinfo[l].name, sprname, 4)) continue; frame = R_Char2Frame(lumpinfo[l].name[4]); @@ -295,12 +295,12 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, } // skip NULL sprites from very old dmadds pwads - if (W_LumpLengthPwad(wadnum,l)<=8) + if (W_LumpLengthPwad(wadnum, l) <= 8) continue; // store sprite info in lookup tables //FIXME : numspritelumps do not duplicate sprite replacements - W_ReadLumpHeaderPwad(wadnum, l, &patch, sizeof (patch_t), 0); + W_ReadLumpHeaderPwad(wadnum, l, &patch, (sizeof(INT16) *4), 0); spritecachedinfo[numspritelumps].width = (INT32)(SHORT(patch.width))< Date: Sat, 19 Apr 2025 01:25:37 +0200 Subject: [PATCH 31/44] a --- src/r_things.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/r_things.c b/src/r_things.c index 44720585c..31fddc550 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1522,7 +1522,11 @@ static void R_ProjectSprite(mobj_t *thing) } // Compatibility with MSVC - SSNTails - scalestep = ((yscale2 - yscale)/range) ?: 1; + scalestep = ((yscale2 - yscale)/range); + + if (scalestep == 0) + scalestep = 1; + xscale = FixedDiv(range< Date: Sun, 20 Apr 2025 16:40:35 +0200 Subject: [PATCH 32/44] pass hardware patch to HWR_DrawSpriteShadow --- src/hardware/hw_main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5b1b3a48e..9001b4c5c 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3317,7 +3317,7 @@ static fixed_t HWR_OpaqueFloorAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t hei return floorz; } -static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch) +static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t *hwrpatch) { float this_scale = 1.0f; FOutVector swallVerts[4]; @@ -3327,9 +3327,6 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch) pslope_t *floorslope; fixed_t slopez; float offset = 0; - GLPatch_t *hwrpatch; - - hwrpatch = ((GLPatch_t *)gpatch->hardware); // technically this_scale gets multiplied and added to sprite y/x scale, but this thing needs it for some crap so ill just throw it in here again const boolean hires = (spr->mobj && spr->mobj->skin && K_GetMobjSkin(spr->mobj)->flags & SF_HIRES); @@ -3538,6 +3535,7 @@ static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts { basey = FIXED_TO_FLOAT(interp.z); } + lowy = wallVerts[0].y; // Rotate sprites to fully billboard with the camera @@ -3621,7 +3619,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) //////////////////// // SHADOW SPRITE! // //////////////////// - HWR_DrawSpriteShadow(spr, gpatch); + HWR_DrawSpriteShadow(spr, gpatch, hwrpatch); } baseWallVerts[0].x = baseWallVerts[3].x = spr->x1; @@ -3940,7 +3938,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) //////////////////// // SHADOW SPRITE! // //////////////////// - HWR_DrawSpriteShadow(spr, gpatch); + HWR_DrawSpriteShadow(spr, gpatch, hwrpatch); } // push it toward the camera to mitigate floor-clipping sprites @@ -5879,6 +5877,7 @@ static void COM_HWR_glinfo(void) CONS_Printf("Vendor: %s\n", gl_vendor); CONS_Printf("%u GL extensions present.\n", gl_num_extensions); + if (list_extensions) { // We need this strtok loop because we cannot write the extensions list directly From 5ba6021010bfac6a8fb7c3dee4e79f35c004d189 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Apr 2025 22:59:55 +0200 Subject: [PATCH 33/44] dont let postload free our waitingplayer spritepatches --- src/f_finale.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/f_finale.c b/src/f_finale.c index b92291467..4bbf4d991 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1190,7 +1190,7 @@ void F_StartWaitingPlayers(void) for (i = 0; i < 2; i++) { sprframe = &skins[randskin].spritedef.spriteframes[(6+(i*3)) & FF_FRAMEMASK]; - driver[i] = W_CachePatchNum(sprframe->lumppat[1], PU_SPRITE); + driver[i] = W_CachePatchNum(sprframe->lumppat[1], PU_CACHE); } } From f838ff528e56edd7ee7b44b5d13e7cb7bf05a0e0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Apr 2025 06:22:58 +0200 Subject: [PATCH 34/44] dont need this anymore --- src/hardware/hw_clip.c | 2 -- src/hardware/hw_main.c | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 7d0179dfc..0329ebc0e 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -314,8 +314,6 @@ void gld_clipper_Clear(void) cliphead = NULL; } -#define RMUL (1.6f/1.333333f) - angle_t gld_FrustumAngle(angle_t tiltangle) { double clipfov; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 9001b4c5c..b6fc25b4f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5557,11 +5557,11 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) // V_DrawPatchFill, but for the fourth screen only patch_t *gpatch = W_CachePatchName("SRB2BACK", PU_PATCH); INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - INT32 x, y, pw = (gpatch->width) * dupz, ph = (gpatch->height) * dupz; + INT32 x, y, pw = (gpatch->width * dupz), ph = (gpatch->height * dupz); - for (x = vid.width>>1; x < vid.width; x += pw) + for (x = vid.width >> 1; x < vid.width; x += pw) { - for (y = vid.height>>1; y < vid.height; y += ph) + for (y = vid.height >> 1; y < vid.height; y += ph) HWR_DrawStretchyFixedPatch(gpatch, (x)< Date: Mon, 21 Apr 2025 14:12:42 +0200 Subject: [PATCH 35/44] dont free our hud patches when loading an addon lel appears to work fine in RR so we do it here fixes some weird issues and crashes with certain hud elements --- src/p_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 6749a87a9..bdab7022d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3458,7 +3458,7 @@ boolean P_MultiSetupWadFiles(boolean fullsetup) if (partadd_stage == 0) { // Flush and reload HUD graphics - ST_UnloadGraphics(); + //ST_UnloadGraphics(); HU_LoadGraphics(); ST_LoadGraphics(); ST_ReloadSkinFaceGraphics(); From 7c4b93fba89ce8dfbac85a7033ff4e1832435046 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 21 Apr 2025 14:15:35 +0200 Subject: [PATCH 36/44] add some savety to the hudlib just error instead of crashing so we can track down any issues more easily --- src/k_kart.c | 8 ++--- src/lua_hudlib.c | 79 ++++++++++++++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index cb8978734..eb852f312 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7702,10 +7702,10 @@ void K_LoadKartHUDGraphics(void) kp_bumperstickerwideclr = W_CachePatchName("K_SCBALW", PU_HUDGFX); kp_karmastickerclr = W_CachePatchName("K_SCKARM", PU_HUDGFX); kp_timeoutstickerclr = W_CachePatchName("K_SCTOUT", PU_HUDGFX); - kp_itembgclr[0] = W_CachePatchName("K_ITBC", PU_HUDGFX); - kp_itembgclr[1] = W_CachePatchName("K_ITBCD", PU_HUDGFX); - kp_itembgclr[2] = W_CachePatchName("K_ISBC", PU_HUDGFX); - kp_itembgclr[3] = W_CachePatchName("K_ISBCD", PU_HUDGFX); + kp_itembgclr[0] = W_CachePatchName("K_ITBC" , PU_HUDGFX); + kp_itembgclr[1] = W_CachePatchName("K_ITBCD" , PU_HUDGFX); + kp_itembgclr[2] = W_CachePatchName("K_ISBC" , PU_HUDGFX); + kp_itembgclr[3] = W_CachePatchName("K_ISBCD" , PU_HUDGFX); kp_itemmulstickerclr[1] = W_CachePatchName("K_ISMULC", PU_HUDGFX); kp_itemmulstickerclr[0] = W_CachePatchName("K_ITMULC", PU_HUDGFX); } diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 8083807ad..d1dce0ae0 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -297,9 +297,13 @@ static int patch_get(lua_State *L) patch_t *patch = *((patch_t **)luaL_checkudata(L, 1, META_PATCH)); enum patch field = Lua_optoption(L, 2, -1, patch_fields_ref); - // patches are CURRENTLY always valid, expected to be cached with PU_STATIC - // this may change in the future, so patch.valid still exists - I_Assert(patch != NULL); + if (!patch) { + if (field == patch_valid) { + lua_pushboolean(L, 0); + return 1; + } + return LUA_ErrInvalid(L, "patch_t"); + } switch (field) { @@ -546,6 +550,8 @@ static int libd_draw(lua_State *L) x = luaL_checkinteger(L, 1); y = luaL_checkinteger(L, 2); patch = *((patch_t **)luaL_checkudata(L, 3, META_PATCH)); + if (!patch) + return LUA_ErrInvalid(L, "patch_t"); flags = luaL_optinteger(L, 4, 0); if (!lua_isnoneornil(L, 5)) colormap = *((UINT8 **)luaL_checkudata(L, 5, META_COLORMAP)); @@ -579,6 +585,8 @@ static int libd_drawScaled(lua_State *L) if (scale < 0) return luaL_error(L, "negative scale"); patch = *((patch_t **)luaL_checkudata(L, 4, META_PATCH)); + if (!patch) + return LUA_ErrInvalid(L, "patch_t"); flags = luaL_optinteger(L, 5, 0); if (!lua_isnoneornil(L, 6)) colormap = *((UINT8 **)luaL_checkudata(L, 6, META_COLORMAP)); @@ -642,6 +650,8 @@ static int libd_drawOnMinimap(lua_State *L) y = luaL_checkinteger(L, 2); scale = luaL_checkinteger(L, 3); patch = *((patch_t **)luaL_checkudata(L, 4, META_PATCH)); + if (!patch) + return LUA_ErrInvalid(L, "patch_t"); if (!lua_isnoneornil(L, 5)) colormap = *((UINT8 **)luaL_checkudata(L, 5, META_COLORMAP)); centered = lua_optboolean(L, 6); @@ -737,6 +747,8 @@ static int libd_drawStretched(lua_State *L) if (vscale < 0) return luaL_error(L, "negative vertical scale"); patch = *((patch_t **)luaL_checkudata(L, 5, META_PATCH)); + if (!patch) + return LUA_ErrInvalid(L, "patch_t"); flags = luaL_optinteger(L, 6, 0); if (!lua_isnoneornil(L, 7)) colormap = *((UINT8 **)luaL_checkudata(L, 7, META_COLORMAP)); @@ -910,35 +922,37 @@ static int libd_drawString(lua_State *L) if (LUA_HUD_IsDrawListValid(list)) LUA_HUD_AddDrawString(list, x, y, str, flags, align); else - switch(align) { - // hu_font - case align_left: - V_DrawString(x, y, flags, str); - break; - case align_center: - V_DrawCenteredString(x, y, flags, str); - break; - case align_right: - V_DrawRightAlignedString(x, y, flags, str); - break; - case align_fixed: - V_DrawStringAtFixed(x, y, flags, str); - break; - // hu_font, 0.5x scale - case align_small: - V_DrawSmallString(x, y, flags, str); - break; - case align_smallright: - V_DrawRightAlignedSmallString(x, y, flags, str); - break; - // tny_font - case align_thin: - V_DrawThinString(x, y, flags, str); - break; - case align_thinright: - V_DrawRightAlignedThinString(x, y, flags, str); - break; + switch(align) + { + // hu_font + case align_left: + V_DrawString(x, y, flags, str); + break; + case align_center: + V_DrawCenteredString(x, y, flags, str); + break; + case align_right: + V_DrawRightAlignedString(x, y, flags, str); + break; + case align_fixed: + V_DrawStringAtFixed(x, y, flags, str); + break; + // hu_font, 0.5x scale + case align_small: + V_DrawSmallString(x, y, flags, str); + break; + case align_smallright: + V_DrawRightAlignedSmallString(x, y, flags, str); + break; + // tny_font + case align_thin: + V_DrawThinString(x, y, flags, str); + break; + case align_thinright: + V_DrawRightAlignedThinString(x, y, flags, str); + break; + } } return 0; } @@ -1025,7 +1039,8 @@ static int libd_getColorHudPatch(lua_State *L) UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); boolean small, dark; - switch (option) { + switch (option) + { case hudpatch_item: small = lua_optboolean(L, 2); dark = lua_optboolean(L, 3); From 4ce111139f2c42ef47ed4ef9e2d3b60e7d626b42 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Apr 2025 02:52:48 +0200 Subject: [PATCH 37/44] add cv_palette and cv_palettenum so palettes can be changed midgame note: subpalettes do not work properly in opengl with paletterendering disabled, so palettenum will NOT work there --- src/d_netcmd.c | 4 ++++ src/p_setup.c | 3 ++- src/v_video.c | 60 +++++++++++++++++++++++++++++++++++++------------- src/v_video.h | 12 +++++----- 4 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index ebbf91736..c0a7bfb93 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -39,6 +39,7 @@ #include "d_main.h" #include "m_random.h" #include "f_finale.h" +#include "v_video.h" #include "filesrch.h" #include "mserv.h" #include "md5.h" @@ -956,6 +957,9 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_audbuffersize); + CV_RegisterVar(&cv_palette); + CV_RegisterVar(&cv_palettenum); + // m_menu.c CV_RegisterVar(&cv_chatheight); CV_RegisterVar(&cv_chatwidth); diff --git a/src/p_setup.c b/src/p_setup.c index bdab7022d..e3b012d31 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3018,7 +3018,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) // Reset the palette now all fades have been done if (rendermode != render_none) - V_SetPaletteLump(GetPalette()); // Set the level palette + V_ReloadPalette(); // Set the level palette // Print "SPEEDING OFF TO [ZONE] [ACT 1]..." /*if (rendermode != render_none) @@ -3301,6 +3301,7 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) { name = lumpinfo->name; lumpnum_t lumpnum = i|(wadnum<<16); + if (name[0] == 'D') { if (name[1] == 'S') for (j = 1; j < NUMSFX; j++) diff --git a/src/v_video.c b/src/v_video.c index 93d12800a..217bb0ae5 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -48,6 +48,9 @@ consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, fps_cons_t, NULL, 0, NULL, NUL static void CV_palette_OnChange(void); +consvar_t cv_palette = {"palette", "", CV_CALL|CV_NOINIT, NULL, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_palettenum = {"palettenum", "0", CV_CALL|CV_NOINIT, CV_Unsigned, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t gamma_cons_t[] = {{-15, "MIN"}, {4, "MAX"}, {0, NULL}}; consvar_t cv_globalgamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -91,6 +94,8 @@ consvar_t cv_menucaps = {"menucaps", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NUL // local copy of the palette for V_GetColor() RGBA_t *pLocalPalette = NULL; +static size_t currentPaletteSize; + /* The following was an extremely helpful resource when developing my Colour Cube LUT. http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html @@ -411,13 +416,19 @@ const UINT8 gammatable[5][256] = // keep a copy of the palette so that we can get the RGB value for a color index at any time. static void LoadPalette(const char *lumpname) { + UINT8 *pal; + size_t i, palsize; + lumpnum_t lumpnum; + #ifdef BACKWARDSCOMPATCORRECTION const UINT8 *usegamma = gammatable[min(max(cv_globalgamma.value, 0), 4)]; #endif Cubeapply = InitCube(); - lumpnum_t lumpnum = W_GetNumForName(lumpname); - size_t i, palsize = W_LumpLength(lumpnum)/3; - UINT8 *pal; + + lumpnum = W_GetNumForName(lumpname); + + currentPaletteSize = W_LumpLength(lumpnum); + palsize = currentPaletteSize / 3; Z_Free(pLocalPalette); @@ -505,8 +516,23 @@ const char *R_GetPalname(UINT16 num) const char *GetPalette(void) { + const char *user = cv_palette.string; + + if (user && user[0]) + { + if (W_CheckNumForName(user) == LUMPERROR) + { + CONS_Alert(CONS_WARNING, "cv_palette %s lump does not exist\n", user); + } + else + { + return cv_palette.string; + } + } + if (gamestate == GS_LEVEL) return R_GetPalname((encoremode ? mapheaderinfo[gamemap-1]->encorepal : mapheaderinfo[gamemap-1]->palette)); + return "PLAYPAL"; } @@ -524,6 +550,20 @@ void V_SetPalette(INT32 palettenum) if (!pLocalPalette) V_ReloadPalette(); + if (rendermode == render_soft || (rendermode == render_opengl && HWR_ShouldUsePaletteRendering())) // opengl without paletterendering hates subpalettes + { + if (palettenum == 0) + { + palettenum = cv_palettenum.value; + + if (palettenum * 256U > currentPaletteSize - 256) + { + CONS_Alert(CONS_WARNING, "cv_palettenum %d out of range\n", palettenum); + palettenum = 0; + } + } + } + #ifdef HWRENDER if (rendermode == render_opengl) HWR_SetPalette(&pLocalPalette[palettenum*256]); @@ -538,18 +578,7 @@ void V_SetPalette(INT32 palettenum) void V_SetPaletteLump(const char *pal) { LoadPalette(pal); -#ifdef HWRENDER - if (rendermode == render_opengl) - HWR_SetPalette(pLocalPalette); -#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) - else -#endif -#endif - if (rendermode != render_none) - I_SetPalette(pLocalPalette); -#ifdef HASINVERT - R_MakeInvertmap(); -#endif + V_SetPalette(0); } static void CV_palette_OnChange(void) @@ -557,6 +586,7 @@ static void CV_palette_OnChange(void) if (loaded_config == false) return; // reload palette + // recalculate Color Cube V_ReloadPalette(); V_SetPalette(0); } diff --git a/src/v_video.h b/src/v_video.h index 85338751c..c8eca1069 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -28,12 +28,12 @@ extern UINT8 *screens[5]; -extern consvar_t cv_ticrate, cv_accuratefps, cv_allcaps, cv_constextsize, cv_menucaps,\ -cv_globalgamma, cv_globalsaturation,\ -cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue,\ -cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma, \ -cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation; - +extern consvar_t cv_ticrate, cv_accuratefps, cv_allcaps, cv_constextsize, cv_menucaps, +cv_globalgamma, cv_globalsaturation, +cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue, +cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma, +cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation, +cv_palette, cv_palettenum; // Allocates buffer screens, call before R_Init. void V_Init(void); From 1ffb655131e9cf488b5100bcc672e51e2b86c5f5 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Apr 2025 05:04:04 +0200 Subject: [PATCH 38/44] speed up ogl palette stuff doesent wipe all our gpu textures if palette hasnt changed too lol --- src/hardware/r_opengl/r_opengl.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 4621658ce..457f7fcf9 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -683,7 +683,7 @@ typedef enum gluniform_leveltime, gluniform_scr_resolution, - + gluniform_max, } gluniform_t; @@ -1328,14 +1328,13 @@ void GL_ReadScreenTexture(int tex, UINT16 *dst_data) // -----------------+ void GL_SetPalette(RGBA_t *palette) { - INT32 i; - - for (i = 0; i < 256; i++) + size_t palsize = (sizeof(RGBA_t) * 256); + // on a palette change, you have to reload all of the textures + if (memcmp(&myPaletteData, palette, palsize)) { - myPaletteData[i].s = palette[i].s; + memcpy(&myPaletteData, palette, palsize); + GL_Flush(); } - - GL_Flush(); } // -----------------+ @@ -2641,7 +2640,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics poly.green = byte2float[Surface->PolyColor.s.green]; poly.blue = byte2float[Surface->PolyColor.s.blue]; poly.alpha = byte2float[Surface->PolyColor.s.alpha]; - + pglColor4ubv((GLubyte*)&Surface->PolyColor.s); GL_SetBlend((poly.alpha < 1 ? Surface->PolyFlags : (PF_Masked|PF_Occlude))|PF_Modulated); @@ -2655,7 +2654,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics fade.green = byte2float[Surface->FadeColor.s.green]; fade.blue = byte2float[Surface->FadeColor.s.blue]; fade.alpha = byte2float[Surface->FadeColor.s.alpha]; - + if (Surface->LightTableId && Surface->LightTableId != lt_downloaded) { pglActiveTexture(GL_TEXTURE2); From 2a3e4c4c6d64e46f52acd595bd84a5f798a2a7cb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Apr 2025 20:13:28 +0200 Subject: [PATCH 39/44] smol cleanup z_zone --- src/z_zone.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/z_zone.c b/src/z_zone.c index 698861dfb..548c1e025 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -656,7 +656,7 @@ static void Command_Memfree_f(void) Z_CheckHeap(-1); CONS_Printf("\x82%s", M_GetText("Memory Info\n")); - CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TagsUsage(0, INT32_MAX)>>10)); + CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TotalUsage()>>10)); CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(Z_TagUsage(PU_LUA)>>10)); CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); @@ -673,7 +673,7 @@ static void Command_Memfree_f(void) sizeu1(Z_TagsUsage(PU_PURGELEVEL, INT32_MAX)>>10)); #ifdef HWRENDER - if (rendermode != render_soft && rendermode != render_none) + if (rendermode == render_opengl) { CONS_Printf(M_GetText("Patch info headers : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); CONS_Printf(M_GetText("Cached textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); @@ -690,8 +690,6 @@ static void Command_Memfree_f(void) CONS_Printf(M_GetText("Available physical memory: %s KB\n"), sizeu1(freebytes>>10)); } - - #ifdef ZDEBUG /** The function called by the "memdump" console command. * Prints zone memory debugging information (i.e. tag, size, location in code allocated). From 89906cf384344420ed947d2c7fefd5553270101c Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Apr 2025 18:43:19 +0100 Subject: [PATCH 40/44] Revert "speed up ogl palette stuff" why is windows like this? This reverts commit 1ffb655131e9cf488b5100bcc672e51e2b86c5f5. --- src/hardware/r_opengl/r_opengl.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 457f7fcf9..4621658ce 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -683,7 +683,7 @@ typedef enum gluniform_leveltime, gluniform_scr_resolution, - + gluniform_max, } gluniform_t; @@ -1328,13 +1328,14 @@ void GL_ReadScreenTexture(int tex, UINT16 *dst_data) // -----------------+ void GL_SetPalette(RGBA_t *palette) { - size_t palsize = (sizeof(RGBA_t) * 256); - // on a palette change, you have to reload all of the textures - if (memcmp(&myPaletteData, palette, palsize)) + INT32 i; + + for (i = 0; i < 256; i++) { - memcpy(&myPaletteData, palette, palsize); - GL_Flush(); + myPaletteData[i].s = palette[i].s; } + + GL_Flush(); } // -----------------+ @@ -2640,7 +2641,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics poly.green = byte2float[Surface->PolyColor.s.green]; poly.blue = byte2float[Surface->PolyColor.s.blue]; poly.alpha = byte2float[Surface->PolyColor.s.alpha]; - + pglColor4ubv((GLubyte*)&Surface->PolyColor.s); GL_SetBlend((poly.alpha < 1 ? Surface->PolyFlags : (PF_Masked|PF_Occlude))|PF_Modulated); @@ -2654,7 +2655,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics fade.green = byte2float[Surface->FadeColor.s.green]; fade.blue = byte2float[Surface->FadeColor.s.blue]; fade.alpha = byte2float[Surface->FadeColor.s.alpha]; - + if (Surface->LightTableId && Surface->LightTableId != lt_downloaded) { pglActiveTexture(GL_TEXTURE2); From 8edec89a36da4184d6720d9a555fa5037f5a0f08 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Apr 2025 21:52:46 +0200 Subject: [PATCH 41/44] fix cloud tops palette not applying --- src/p_setup.c | 2 +- src/v_video.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index e3b012d31..32f77658d 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3018,7 +3018,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) // Reset the palette now all fades have been done if (rendermode != render_none) - V_ReloadPalette(); // Set the level palette + V_SetPaletteLump(GetPalette()); // Set the level palette // Print "SPEEDING OFF TO [ZONE] [ACT 1]..." /*if (rendermode != render_none) diff --git a/src/v_video.c b/src/v_video.c index 217bb0ae5..2552244c4 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -579,6 +579,9 @@ void V_SetPaletteLump(const char *pal) { LoadPalette(pal); V_SetPalette(0); +#ifdef HASINVERT + R_MakeInvertmap(); +#endif } static void CV_palette_OnChange(void) From db9435f81021d063ef4713f6d0ef34f33b5ed07c Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Apr 2025 22:10:49 +0200 Subject: [PATCH 42/44] reset palette cvars when toggling paletterendering everything gets wiped anyways, so this would be just confusing --- src/hardware/hw_main.c | 2 ++ src/p_setup.c | 3 +++ src/sdl/ogl_sdl.c | 8 ++++---- src/v_video.c | 17 +++++++++++++++-- src/v_video.h | 2 ++ 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b7ece1f81..75a62f596 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5721,6 +5721,8 @@ void HWR_LoadLevel(void) // shader recompilation is done in the cvar callback static void HWR_TogglePaletteRendering(void) { + V_ResetPaletteCVars(); // dont carry over changed palettes + // which state should we go to? if (HWR_ShouldUsePaletteRendering()) { diff --git a/src/p_setup.c b/src/p_setup.c index 32f77658d..2582261e9 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3018,7 +3018,10 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) // Reset the palette now all fades have been done if (rendermode != render_none) + { + //V_ResetPaletteCVars(); // dont carry over changed palettes V_SetPaletteLump(GetPalette()); // Set the level palette + } // Print "SPEEDING OFF TO [ZONE] [ACT 1]..." /*if (rendermode != render_none) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 73f6635e3..d6805cf21 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -134,7 +134,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) if (!first_init) { - if (!gllogstream) + if (!gllogstream) { gllogdir = D_Home(); @@ -147,7 +147,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) gllogstream = fopen("./ogllog.txt", "wt"); #endif } - + gl_version = pglGetString(GL_VERSION); gl_renderer = pglGetString(GL_RENDERER); gl_extensions = pglGetString(GL_EXTENSIONS); @@ -220,7 +220,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) } SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); - + // The screen textures need to be flushed if the width or height change so that they be remade for the correct size if (screen_width != w || screen_height != h) { @@ -310,7 +310,7 @@ void OglSdlFinishUpdate(boolean waitvbl) #if defined (__unix__) #ifdef USE_FBO_OGL - if (loaded_config == true) + if (loaded_config) xwaylandcrap = false; #endif #endif diff --git a/src/v_video.c b/src/v_video.c index 2552244c4..34bc9f296 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -139,7 +139,7 @@ static boolean InitCube(void) float globalgammamul, globalgammaoffs; boolean doinggamma; - if (loaded_config == false) + if (!loaded_config) return false; #define diffcons(cv) (strcmp(cv.string, cv.defaultvalue)) @@ -586,7 +586,7 @@ void V_SetPaletteLump(const char *pal) static void CV_palette_OnChange(void) { - if (loaded_config == false) + if (!loaded_config) return; // reload palette // recalculate Color Cube @@ -594,6 +594,19 @@ static void CV_palette_OnChange(void) V_SetPalette(0); } +void V_ResetPaletteCVars(void) +{ + if (!loaded_config) + return; + +#define diffcons(cv) (strcmp(cv.string, cv.defaultvalue)) + if diffcons(cv_palette) + CV_StealthSetValue(&cv_palette, atoi(cv_palette.defaultvalue)); + if diffcons(cv_palettenum) + CV_StealthSetValue(&cv_palettenum, atoi(cv_palettenum.defaultvalue)); +#undef diffcons +} + static void CV_constextsize_OnChange(void) { con_recalc = true; diff --git a/src/v_video.h b/src/v_video.h index c8eca1069..c8f614afc 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -60,6 +60,8 @@ void V_SetPalette(INT32 palettenum); void V_SetPaletteLump(const char *pal); +void V_ResetPaletteCVars(void); + const char *R_GetPalname(UINT16 num); const char *GetPalette(void); From 97093dbeb9b85890143d3373fd07cd14c8d41ceb Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 25 Apr 2025 12:15:57 +0300 Subject: [PATCH 43/44] Don't free PU_SPRITE memory, since it invalidates some lua patches if they are using sprite frames --- src/p_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index 4c6a76ef1..b229cabdc 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3342,7 +3342,7 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // // search for sprite replacements // - Patch_FreeTag(PU_SPRITE); + //Patch_FreeTag(PU_SPRITE); //Patch_FreeTag(PU_PATCH_ROTATED); R_AddSpriteDefs(wadnum); From 79d440d398156bf4118a9ad6066b833cf262f6cc Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 28 Apr 2025 13:25:30 +0100 Subject: [PATCH 44/44] quick and dirty gcc 15 compile fix need to fix this properly --- src/dehacked.c | 4 ++++ src/info.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/dehacked.c b/src/dehacked.c index f0e2583d8..a453715a7 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -1414,6 +1414,9 @@ static void readhuditem(MYFILE *f, INT32 num) // IMPORTANT! // DO NOT FORGET TO SYNC THIS LIST WITH THE ACTIONNUM ENUM IN INFO.H + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wincompatible-pointer-types" actionpointer_t actionpointers[] = { {{A_Explode}, "A_EXPLODE"}, @@ -1622,6 +1625,7 @@ actionpointer_t actionpointers[] = // This NULL entry must be the last in the list {{NULL}, NULL}, }; +#pragma GCC diagnostic pop static void readframe(MYFILE *f, INT32 num) { diff --git a/src/info.c b/src/info.c index 7afc76bf6..19183de52 100644 --- a/src/info.c +++ b/src/info.c @@ -69,6 +69,8 @@ char sprnames[NUMSPRITES + 1][5] = }; // Doesn't work with g++, needs actionf_p1 (don't modify this comment) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wincompatible-pointer-types" state_t states[NUMSTATES] = { // frame is masked through FF_FRAMEMASK @@ -3410,6 +3412,7 @@ state_t states[NUMSTATES] = {SPR_NULL, 0, 1, {NULL}, 0, 0, S_NULL}, // S_NAMECHECK #endif }; +#pragma GCC diagnostic pop mobjinfo_t mobjinfo[NUMMOBJTYPES] = {