diff --git a/src/Makefile b/src/Makefile index dc6bfb58a..2d9ba2ecc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -453,9 +453,9 @@ else # build a normal optimised version WINDRESFLAGS = -DNDEBUG - CFLAGS+=-O3 -flto=auto - CPPFLAGS+=-O3 -flto=auto - #LDFLAGS+= + CFLAGS+=-O3 -fsanitize=address + CPPFLAGS+=-O3 -fsanitize=address + LDFLAGS+=-fsanitize=address endif CFLAGS+=-g $(OPTS) $(ARCHOPTS) $(WINDRESFLAGS) diff --git a/src/console.c b/src/console.c index 3212521b0..e99ea959b 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); } } @@ -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); @@ -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 5f778f743..d4b6c6583 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -603,8 +603,8 @@ static boolean D_Display(void) py = 4; else py = viewwindowy + 4; - patch = W_CachePatchName("M_PAUSE", PU_CACHE); - V_DrawScaledPatch(viewwindowx + (BASEVIDWIDTH - SHORT(patch->width))/2, py, V_SNAPTOTOP, patch); + patch = W_CachePatchName("M_PAUSE", PU_PATCH); + V_DrawScaledPatch(viewwindowx + (BASEVIDWIDTH - patch->width)/2, py, V_SNAPTOTOP, patch); } if (rendermode == render_soft && demo.rewinding) @@ -794,7 +794,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_PATCH_LOWPRIORITY), NULL); I_FinishUpdate(); // page flip or blit buffer for (;;) diff --git a/src/f_finale.c b/src/f_finale.c index 1b8d236fe..b92291467 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -164,14 +164,14 @@ 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)<width)*16))<width)<width)*16))<width*16))<width<width*16))<width)<width<height))<height)<width)<width<= 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,15 +1259,15 @@ 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?"); // Draw a Sonic! - V_DrawScaledPatch((BASEVIDWIDTH - SHORT(contsonic->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; @@ -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 5ba8655b8..afba914a3 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 ?) @@ -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,9 +313,12 @@ 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; + UINT8 *colormap = colormaps; + INT32 i, idx; boolean skyspecial = false; // poor hack for Legacy large skies.. @@ -325,9 +328,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.. @@ -339,11 +339,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); @@ -371,12 +378,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); } } @@ -398,22 +405,13 @@ 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) { - // 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 +419,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 +432,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 +441,57 @@ 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 *glPatch; + + if (!patch || !patch->hardware) + return; + + glPatch = patch->hardware; + + if (vid.glstate == VID_GL_LIBRARY_LOADED) + GL_DeleteTexture(glPatch->mipmap); + if (glPatch->mipmap->data) + Z_Free(glPatch->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,15 +513,15 @@ 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. 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. @@ -497,28 +529,70 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) } } -void HWR_FreeMipmapCache(void) +static boolean FreeTextureCallback(void *mem) { - 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); + patch_t *patch = (patch_t *)mem; + HWR_FreeTexture(patch); + return false; } -void HWR_FreeTextureCache(void) +static boolean FreeColormapsCallback(void *mem) +{ + patch_t *patch = (patch_t *)mem; + HWR_FreeTextureColormaps(patch); + return false; +} + +static void HWR_FreePatchCache(boolean freeall) +{ + boolean (*callback)(void *mem) = FreeTextureCallback; + + if (!freeall) + callback = FreeColormapsCallback; + + //Z_IterateTags(PU_PATCH, PU_PATCH_ROTATED, callback); + Z_IterateTags(PU_PATCH, PU_PATCH, callback); + Z_IterateTags(PU_SPRITE, PU_HUDGFX, callback); +} + +// 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); + tex->mipmap.data = NULL; +} + +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]); + } // now the heap don't have any 'user' pointing to our // texturecache info, we can free it @@ -702,7 +776,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 +815,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_SPRITE);\ if (spritepatch != NULL)\ HWR_GetPatch(spritepatch);\ } @@ -782,10 +856,10 @@ 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(); + // we must free it since numtextures may have changed + HWR_FreeMapTextures(); gl_numtextures = pnumtextures; #ifdef GLENCORE @@ -794,7 +868,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 +886,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 +948,7 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) pflatsize = 64; break; } + glMipmap->width = (UINT16)pflatsize; glMipmap->height = (UINT16)pflatsize; @@ -882,7 +962,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 } @@ -891,18 +971,25 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) { GLMipmap_t *glMipmap; + patch_t *patch; + UINT8 *colormap = colormaps; if (flatlumpnum == LUMPERROR) return; - glMipmap = HWR_GetCachedGLPatch(flatlumpnum)->mipmap; - - glMipmap->colormap = colormaps; + patch = HWR_GetCachedGLPatch(flatlumpnum); + glMipmap = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap; + 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); @@ -916,27 +1003,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); @@ -946,49 +1022,53 @@ static void HWR_LoadMappedPatch(GLMipmap_t *glMipmap, GLPatch_t *glPatch) 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 // -----------------+ -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 (colormap == colormaps || colormap == NULL) + if (!patch->hardware) + Patch_CreateGL(patch); + glPatch = patch->hardware; + + // Blatant hack for encore colormapping aside... + if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET)) { - // 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; } @@ -998,9 +1078,16 @@ void HWR_GetMappedPatch(GLPatch_t *glPatch, const UINT8 *colormap) { glMipmap = glMipmap->nextcolormap; - if (UNLIKELY(glMipmap->colormap == colormap)) + if (UNLIKELY(glMipmap->colormap && glMipmap->colormap->source == colormap)) { - HWR_LoadMappedPatch(glMipmap, glPatch); + 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; } } @@ -1009,15 +1096,18 @@ 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) I_Error("%s: Out of memory", "HWR_GetMappedPatch"); glMipmap->nextcolormap = newMipmap; - newMipmap->colormap = colormap; - HWR_LoadMappedPatch(newMipmap, glPatch); + 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); } void HWR_UnlockCachedPatch(GLPatch_t *glPatch) @@ -1028,24 +1118,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_PATCH, &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)); } @@ -1066,15 +1152,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 @@ -1139,8 +1225,10 @@ static void HWR_CacheFadeMask(GLMipmap_t *glMipmap, lumpnum_t fademasklumpnum) void HWR_GetFadeMask(lumpnum_t fademasklumpnum) { GLMipmap_t *glMipmap; + patch_t *patch; - glMipmap = HWR_GetCachedGLPatch(fademasklumpnum)->mipmap; + patch = HWR_GetCachedGLPatch(fademasklumpnum); + glMipmap = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->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..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,24 +70,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. +// Patch information for the hardware renderer. 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; - + 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 d2680b11b..800b05f3d 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; @@ -664,7 +667,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; @@ -713,7 +716,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); @@ -722,7 +725,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); @@ -731,7 +734,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) { @@ -743,7 +746,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) { @@ -755,22 +758,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 55ad5c4a2..a21fd0a3a 100644 --- a/src/hardware/hw_gl.h +++ b/src/hardware/hw_gl.h @@ -39,6 +39,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 e4659c0e6..0589ba1d2 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(const 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 5be84d89d..c1d31dacf 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -855,7 +855,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]; @@ -878,7 +878,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); @@ -3348,7 +3348,7 @@ static gl_vissprite_t *HWR_NewVisSprite(void) 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]; @@ -3608,7 +3608,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; @@ -3630,7 +3631,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) @@ -3664,25 +3666,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 @@ -3881,7 +3883,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; @@ -3905,7 +3908,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 // @@ -3927,25 +3931,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 @@ -4031,7 +4035,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; @@ -4040,7 +4045,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 // @@ -4061,10 +4067,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) @@ -4833,10 +4839,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 @@ -4936,10 +4942,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_SPRITE); vis->mobj = thing; @@ -5107,15 +5113,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 = (GLPatch_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 @@ -5584,9 +5590,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_PATCH); 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) { @@ -5739,17 +5745,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 @@ -5860,7 +5855,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(); @@ -5952,8 +5947,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 f579677b2..45415372e 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -90,9 +90,9 @@ extern boolean havepazrcst; extern boolean havefaytpad; // 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); @@ -176,10 +176,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..a3413f90f 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -366,43 +366,48 @@ 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 +415,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 +424,8 @@ static void md2_loadTexture(md2_t *model) } } } - GL_SetTexture(glpatch->mipmap); - HWR_UnlockCachedPatch(glpatch); + GL_SetTexture(glPatch->mipmap); + HWR_UnlockCachedPatch(glPatch); } // -----------------+ @@ -428,49 +433,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 +694,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 +732,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,32 +1056,51 @@ 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; - 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; + } } } @@ -1082,9 +1115,12 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT if (newMipmap == NULL) I_Error("%s: Out of memory", "HWR_GetMappedPatch"); glMipmap->nextcolormap = newMipmap; - newMipmap->colormap = colormap; - HWR_CreateBlendedTexture(gpatch, blendgpatch, newMipmap, skinnum, color); + 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); GL_SetTexture(newMipmap); Z_ChangeTag(newMipmap->data, PU_HWRCACHE_UNLOCKED); @@ -1154,7 +1190,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 +1301,38 @@ 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 + // 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 && ((GLPatch_t *)md2->blendglpatch)->mipmap->format - && gpatch->width == ((GLPatch_t *)md2->blendglpatch)->width && gpatch->height == ((GLPatch_t *)md2->blendglpatch)->height) + blendgpatch && (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 +1357,19 @@ 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/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index ac2d85371..520f7e3a2 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -158,7 +158,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); @@ -640,7 +640,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 @@ -653,7 +653,7 @@ typedef enum // supersampling crap gluniform_inv_supersamplefactor, - + gluniform_max, } gluniform_t; @@ -713,7 +713,7 @@ void SetupGLFunc4(void) pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); pglMultiTexCoord2fv = GetGLFunc("glMultiTexCoord2fv"); - + /* 1.5 funcs */ pglGenBuffers = GetGLFunc("glGenBuffers"); pglBindBuffer = GetGLFunc("glBindBuffer"); @@ -723,7 +723,7 @@ void SetupGLFunc4(void) /* 2.0 funcs */ pglBlendEquation = GetGLFunc("glBlendEquation"); - + pglStencilFuncSeparate = GetGLFunc("glStencilFuncSeparate"); pglStencilOpSeparate = GetGLFunc("glStencilOpSeparate"); @@ -779,7 +779,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); @@ -1614,7 +1614,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; @@ -1995,7 +1995,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) { @@ -2296,7 +2296,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) { @@ -2606,7 +2606,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; @@ -2624,7 +2624,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); @@ -2638,7 +2638,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); @@ -2675,7 +2675,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); @@ -2878,7 +2878,7 @@ INT32 GL_GetTextureUsed(void) res += tmp->height*tmp->width*bpp; tmp = tmp->next; } - + return res; } @@ -2896,8 +2896,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 @@ -2993,8 +2993,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 @@ -3022,7 +3022,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); @@ -3061,7 +3061,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 @@ -3147,7 +3147,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 @@ -3244,7 +3244,7 @@ void GL_MakeScreenTexture(int tex) { INT32 texsizew = 512, texsizey = 512; boolean firstTime = (screenTextures[tex] == 0); - + if (!gl_enable_screen_textures) return; @@ -3284,7 +3284,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; @@ -3384,7 +3384,7 @@ void GL_SetPaletteLookup(UINT8 *lut) { internalFormat = GL_R8; } - + if (!paletteLookupTex) pglGenTextures(1, &paletteLookupTex); pglActiveTexture(GL_TEXTURE1); @@ -3433,7 +3433,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/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 67bd83d9b..01db6c77c 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -9259,7 +9259,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; @@ -9295,7 +9295,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; @@ -9322,7 +9322,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 addOrSub = B_SUBTRACT; @@ -9448,7 +9448,7 @@ static void K_DrawKartPositionNum(INT32 num) localpatch = kp_positionnum[num % 10][0]; } - V_DrawBlendingFixedPatch((fx<width)*scale/2) : 0), (fy<height)*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL, addOrSub); + V_DrawBlendingFixedPatch((fx<width*scale/2) : 0), (fy<height*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL, addOrSub); // ^ 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. @@ -9782,9 +9782,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; @@ -9835,11 +9835,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 @@ -10725,7 +10725,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; } @@ -10848,8 +10848,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)<facemmap, rot, PU_STATIC); + minimaphead = W_CachePatchNameRotated(skin->facemmap, rot, PU_PATCH); } } #endif @@ -10935,14 +10935,14 @@ static void K_drawKartMinimap(void) drawinfo_t info; K_getMinimapDrawinfo(&info); - x = info.x - (SHORT(minimapinfo.minimap_pic->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); @@ -10954,10 +10954,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++) @@ -11038,7 +11038,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) @@ -11054,7 +11054,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; } @@ -11066,14 +11066,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); } @@ -11918,8 +11918,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 { @@ -11994,7 +11994,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 425f507dd..3a7671cb7 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; @@ -396,7 +396,7 @@ FUNCINLINE static ATTRINLINE int libd_patchExists(lua_State *L) FUNCINLINE static ATTRINLINE 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)/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); + V_DrawScaledPatch(xx, y, 0, p = W_CachePatchNum(leftlump, PU_PATCH)); + xx += p->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,12 +5188,12 @@ 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 { - 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; @@ -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); - V_DrawScaledPatch((BASEVIDWIDTH - SHORT(p->width))/2, y, 0, p); + 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,11 +5617,11 @@ 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) { - V_DrawScaledPatch((BASEVIDWIDTH - SHORT(p->width))/2, y, 0, p); + V_DrawScaledPatch((BASEVIDWIDTH - p->width)/2, y, 0, p); } else { @@ -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); @@ -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; } } @@ -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,22 +7214,22 @@ 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); 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); { static angle_t rubyfloattime = 0; const fixed_t rubyheight = FINESINE(rubyfloattime>>ANGLETOFINESHIFT); - V_DrawFixedPatch((x+(w>>2))<>2))<>2))<>2))<width), y+20, V_SNAPTOTOP, patch, colormap); + V_DrawMappedPatch(BASEVIDWIDTH-15 - patch->width, y+20, V_SNAPTOTOP, patch, colormap); break; } @@ -7329,7 +7329,7 @@ static void M_DrawReplayHut(void) static UINT16 replayhutmenuy = 0; - V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_CACHE)); + V_DrawPatchFill(W_CachePatchName("SRB2BACK", PU_PATCH)); if (cv_vhseffect.value) V_DrawVhsEffect(false); @@ -7414,7 +7414,7 @@ static void M_DrawReplayHut(void) if (demolist[i].type == MD_SUBDIR) { localx += 8; - V_DrawScaledPatch(x - 4, localy, V_SNAPTOTOP|V_SNAPTOLEFT, W_CachePatchName(dirmenu[i][DIR_TYPE] == EXT_UP ? "M_RBACK" : "M_RFLDR", PU_CACHE)); + V_DrawScaledPatch(x - 4, localy, V_SNAPTOTOP|V_SNAPTOLEFT, W_CachePatchName(dirmenu[i][DIR_TYPE] == EXT_UP ? "M_RBACK" : "M_RFLDR", PU_PATCH)); } if (itemOn == replaylistitem && i == (INT16)dir_on[menudepthleft]) @@ -7462,7 +7462,7 @@ static void M_DrawReplayHut(void) // Draw the cursor V_DrawScaledPatch(currentMenu->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,14 +7526,14 @@ 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, 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 @@ -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) @@ -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) @@ -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,15 +10247,15 @@ 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 = 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; @@ -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 2fd8b84af..381a4a061 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3040,10 +3040,16 @@ 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 + 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) @@ -3114,7 +3120,7 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) { HWR_FreeExtraSubsectors(); - // stuff like HWR_CreatePlanePolygons is called there + // Create plane polygons. HWR_LoadLevel(); } #endif @@ -3329,13 +3335,24 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (!devparm && digmreplaces) CONS_Printf(M_GetText("%s digital musics replaced\n"), sizeu1(digmreplaces)); - R_LoadTexturesPwad(wadnum); +#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 // + Patch_FreeTag(PU_SPRITE); + 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); + // everything from MultiSetupWadFile until ST_Start was here originally // diff --git a/src/r_data.c b/src/r_data.c index 0de389a73..8cc843e15 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -303,8 +303,9 @@ 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; + UINT8 *pdata; + int x, x1, x2, i, width, height; size_t blocksize; column_t *patchcol; UINT8 *colofs; @@ -323,16 +324,21 @@ static UINT8 *R_GenerateTexture(size_t texnum) { boolean holey = false; patch = texture->patches; - realpatch = 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. 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; @@ -344,6 +350,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: } @@ -353,7 +360,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; @@ -374,9 +381,9 @@ 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, 0xF7, blocksize+1); // Transparency hack + memset(block, TRANSPARENTPIXEL, blocksize+1); // Transparency hack // columns lookup table colofs = block; @@ -388,20 +395,34 @@ 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); + 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; - 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; @@ -416,8 +437,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; } @@ -467,7 +486,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); } // @@ -495,7 +514,7 @@ Rloadtextures (INT32 i, INT32 w) UINT16 j; INT32 k; UINT16 texstart, texend, texturesLumpPos; - patch_t *patchlump; + softwarepatch_t *patchlump; texpatch_t *patch; texture_t *texture; @@ -534,7 +553,7 @@ Rloadtextures (INT32 i, INT32 w) continue; // If it is then SKIP IT } - 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); @@ -680,8 +699,7 @@ static void R_AllocateTextures(INT32 add) // R_FlushTextureCache relies on the user for // Z_Free, texturecache has been reallocated so the // user is now garbage memory. - Z_SetUser(texturecache[i], - (void**)&texturecache[i]); + Z_SetUser(texturecache[i], (void**)&texturecache[i]); } while (i < newtextures) @@ -702,7 +720,7 @@ static void R_FinishLoadingTextures(INT32 add) #ifdef HWRENDER if (rendermode == render_opengl) - HWR_LoadTextures(numtextures); + HWR_LoadMapTextures(numtextures); #endif } @@ -1913,7 +1931,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_defs.h b/src/r_defs.h index a1706289f..95f8a796d 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -642,7 +642,22 @@ 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 +670,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..e35563fe6 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -329,6 +329,133 @@ 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_PATCH, 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 = SHORT(source->width); + patch->height = SHORT(source->height); + patch->leftoffset = SHORT(source->leftoffset); + patch->topoffset = SHORT(source->topoffset); + patch->columnofs = Z_Calloc(size, PU_PATCH_DATA, 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_PATCH_DATA, NULL); + M_Memcpy(patch->columns, ((UINT8 *)source + LONG(source->columnofs[0])), colsize); + } + + return patch; +} + +// +// Frees a patch from memory. +// + +static void Patch_FreeData(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); +} + +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. +// + +void *Patch_AllocateHardwarePatch(patch_t *patch) +{ + if (!patch->hardware) + { + 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); +} + +// +// Creates a hardware patch. +// + +void *Patch_CreateGL(patch_t *patch) +{ + 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 + + // // R_MaskedFlatToPatch // @@ -440,7 +567,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 +587,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 +620,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 +677,7 @@ 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_SPRITE); if (sprinfo->available) { @@ -563,8 +686,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 +704,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 +729,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]; @@ -698,7 +819,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); @@ -735,18 +856,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_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 75347df3c..bde624ead 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -38,6 +38,18 @@ 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); + +#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); +#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..9a2af70ba 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -171,9 +171,9 @@ 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 + (SHORT(patch->height)<<(FRACBITS-1)) - viewz; + dc_texturemid = splat->top + (patch->height<<(FRACBITS-1)) - viewz; if (splat->yoffset) dc_texturemid += *splat->yoffset; @@ -225,11 +225,11 @@ 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 - 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_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 d1db9400c..15103900d 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)<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) @@ -882,7 +882,7 @@ static void R_DrawVisSprite(vissprite_t *vis) sprtopscreen = (centeryfrac - FixedMul(dc_texturemid, spryscale)); dc_iscale = (0xffffffffu / (unsigned)spryscale); - column = (column_t *)((UINT8 *)patch + LONG(patch->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); } @@ -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; @@ -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); } @@ -1399,10 +1399,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 @@ -1808,7 +1808,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; @@ -1993,7 +1993,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..5a09f61e8 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -211,14 +211,14 @@ void ST_doPaletteStuff(void) void ST_UnloadGraphics(void) { - Z_FreeTags(PU_HUDGFX, PU_HUDGFX); + Patch_FreeTag(PU_HUDGFX); } 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 @@ -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 3266953ed..ce54fa53c 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 @@ -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) + LONG(patch->columnofs[0])); + column = (const column_t *)((const UINT8 *)(patch->columns) + (patch->columnofs[0])); if (!column->topdelta) { source = (const UINT8 *)(column) + 3; @@ -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 @@ -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 @@ -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) 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) { @@ -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 @@ -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) { @@ -1710,7 +1710,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; @@ -1737,7 +1737,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; @@ -1903,10 +1903,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; @@ -2005,10 +2005,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; @@ -2123,10 +2123,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 @@ -2240,8 +2240,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; @@ -2341,10 +2341,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; @@ -2539,10 +2539,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; @@ -2562,7 +2562,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) @@ -2588,7 +2588,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; @@ -2609,7 +2609,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; @@ -2631,7 +2631,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; @@ -2654,7 +2654,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; @@ -2713,7 +2713,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; @@ -2739,7 +2739,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; @@ -2786,7 +2786,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 @@ -2813,7 +2813,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; @@ -2832,8 +2832,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; @@ -2875,7 +2875,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; @@ -2917,7 +2917,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; @@ -2969,8 +2969,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)); } } @@ -3011,7 +3011,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 b770a16e8..eee3619bf 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -824,11 +824,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 @@ -1321,15 +1317,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; @@ -1638,7 +1634,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); } @@ -1696,6 +1691,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 // ========================================================================== @@ -1720,40 +1748,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 = (patch_t *)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) @@ -1761,7 +1808,13 @@ void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag) return W_CachePatchNumPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum),tag); } -#endif // HWRENDER +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. @@ -1778,7 +1831,6 @@ void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum) return (void *)rspr; } - #endif // ROTSPRITE void W_UnlockCachedPatch(void *patch) @@ -1790,19 +1842,17 @@ 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); + Z_ChangeTag(patch, PU_PATCH); } 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); @@ -1835,18 +1885,15 @@ 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_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); - - // free image data - Z_Free(ptr); } return rspr->patches[idx]; diff --git a/src/w_wad.h b/src/w_wad.h index c3292eaad..dc1680a08 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -126,9 +126,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 @@ -209,18 +207,21 @@ 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); + +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); #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..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(); @@ -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 @@ -922,9 +922,9 @@ 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); - 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), + 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); 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); } @@ -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..bb4597ac5 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -44,7 +44,13 @@ enum PU_SOUND = 11, // static while playing PU_MUSIC = 12, // static while playing - PU_HUDGFX = 13, // 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