diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 121cb9925..729b5896a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -129,6 +129,7 @@ set(SRB2_CORE_RENDER_SOURCES r_fps.c r_main.c r_patch.c + r_patchrotation.c r_plane.c r_segs.c r_sky.c @@ -143,7 +144,8 @@ set(SRB2_CORE_RENDER_SOURCES r_fps.h r_local.h r_main.h - r_patch + r_patch.h + r_patchrotation.h r_plane.h r_segs.h r_sky.h diff --git a/src/Makefile b/src/Makefile index 116595868..9dddfe7da 100644 --- a/src/Makefile +++ b/src/Makefile @@ -548,6 +548,7 @@ OBJS:=$(i_main_o) \ $(OBJDIR)/r_sky.o \ $(OBJDIR)/r_splats.o \ $(OBJDIR)/r_patch.o \ + $(OBJDIR)/r_patchrotation.o \ $(OBJDIR)/r_things.o \ $(OBJDIR)/r_portal.o \ $(OBJDIR)/screen.o \ diff --git a/src/console.c b/src/console.c index f1c8efcc2..b97ba9934 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 44511b87d..e6568030e 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) @@ -733,7 +733,7 @@ void D_SRB2Loop(void) COM_ImmedExecute("cls;version"); if (rendermode == render_soft) - V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, (patch_t *)W_CacheLumpNum(W_GetNumForName("KARTKREW"), PU_CACHE), NULL); + V_DrawFixedPatch(0, 0, FRACUNIT/2, 0, W_CachePatchNum(W_GetNumForName("KARTKREW"), PU_PATCH_LOWPRIORITY), NULL); I_FinishUpdate(); // page flip or blit buffer for (;;) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 83edad6b1..1fe582d0c 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -39,6 +39,7 @@ #include "d_main.h" #include "m_random.h" #include "f_finale.h" +#include "v_video.h" #include "filesrch.h" #include "mserv.h" #include "md5.h" @@ -955,6 +956,9 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_audbuffersize); + CV_RegisterVar(&cv_palette); + CV_RegisterVar(&cv_palettenum); + // m_menu.c CV_RegisterVar(&cv_chatheight); CV_RegisterVar(&cv_chatwidth); diff --git a/src/dehacked.c b/src/dehacked.c index 1a84108fd..a453715a7 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -28,7 +28,7 @@ #include "p_local.h" // for var1 and var2, and some constants #include "p_setup.h" #include "r_data.h" -#include "r_patch.h" +#include "r_fps.h" #include "r_sky.h" #include "r_draw.h" // translation colormap consts (for lua) #include "fastcmp.h" diff --git a/src/f_finale.c b/src/f_finale.c index 167985c24..e9ce093fc 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_CACHE); } } @@ -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 f3b4ae84f..85e50465a 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -28,7 +28,7 @@ #include "../v_video.h" #include "../r_draw.h" #include "../r_main.h" -#include "../r_patch.h" // patch rotation +#include "../r_patch.h" #include "../p_setup.h" // levelflats #include "../p_spec.h" // anim_t #include "../r_sky.h" @@ -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,13 +378,10 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe // Composite the columns together. for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { - realpatch = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); + realpatch = (softwarepatch_t *)pdata; - if (realpatch != NULL) - { - HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch); - //Z_ChangeTag(realpatch, PU_HWRCACHE_UNLOCKED); - } + HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch); } //Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :( @@ -398,22 +402,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 +416,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 +429,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 +438,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 +510,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 +526,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 +773,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 +812,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,19 +853,19 @@ 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 - gl_textures = calloc(pnumtextures, sizeof (*gl_textures)*2); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore) + gl_textures = calloc(gl_numtextures, sizeof (*gl_textures)*2); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore) #else - gl_textures = calloc(pnumtextures, sizeof (*gl_textures)); + gl_textures = calloc(gl_numtextures, sizeof (*gl_textures)); #endif if (gl_textures == NULL) - I_Error("HWR_LoadTextures: ran out of memory for OpenGL textures. Sad!"); + I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!"); } // -------------------------------------------------------------------------- @@ -812,15 +883,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 +945,7 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) pflatsize = 64; break; } + glMipmap->width = (UINT16)pflatsize; glMipmap->height = (UINT16)pflatsize; @@ -882,7 +959,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,23 +968,30 @@ 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); - // If hardware does not have the texture, then call pfnSetTexture to upload it + // If hardware does not have the texture, then call GL_SetTexture to upload it if (!glMipmap->downloaded) GL_SetTexture(glMipmap); HWR_SetCurrentTexture(glMipmap); @@ -916,28 +1000,17 @@ 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) { - if (!glMipmap->downloaded && !glMipmap->data) - { - patch_t *patch = glPatch->rawpatch; - if (!patch) - patch = W_CacheLumpNumPwad(glPatch->wadnum, glPatch->lumpnum, PU_STATIC); + GLPatch_t *glPatch = patch->hardware; + if (!glMipmap->downloaded && !glMipmap->data) 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 hardware does not have the texture, then call GL_SetTexture to upload it if (!glMipmap->downloaded) GL_SetTexture(glMipmap); HWR_SetCurrentTexture(glMipmap); @@ -946,49 +1019,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 GL_SetTexture to upload it + // If it does have the texture, then call GL_UpdateTexture to update it + if (!glMipmap->downloaded) + GL_SetTexture(glMipmap); + else + 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 +1075,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 +1093,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 +1115,21 @@ 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; + lumpcache_t *lumpcache = wadfiles[wadnum]->patchcache; - if (!(glPatch = M_AATreeGet(hwrcache, lumpnum))) + 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 +1150,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 +1223,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); @@ -1305,6 +1391,7 @@ UINT32 HWR_CreateLightTable(UINT8 *lighttable) UINT32 HWR_GetLightTableID(extracolormap_t *colormap) { boolean default_colormap = false; + if (!colormap) { colormap = &extra_colormaps[num_extra_colormaps]; // a place to store the hw lighttable id diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 7d0179dfc..0329ebc0e 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -314,8 +314,6 @@ void gld_clipper_Clear(void) cliphead = NULL; } -#define RMUL (1.6f/1.333333f) - angle_t gld_FrustumAngle(angle_t tiltangle) { double clipfov; diff --git a/src/hardware/hw_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 70a2e6cc8..9fd90fb09 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -71,10 +71,11 @@ static const float FLOATBASEVIDHEIGHT = (float)BASEVIDHEIGHT; // Notes : x,y : positions relative to the original Doom resolution // : textes(console+score) + menus + status bar // -----------------+ -void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) +void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option) { FOutVector v[4]; FBITFIELD flags; + GLPatch_t *hwrPatch; // 3--2 // | /| @@ -87,6 +88,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) // make patch ready in hardware cache HWR_GetPatch(gpatch); + hwrPatch = ((GLPatch_t *)gpatch->hardware); switch (option & V_SCALEPATCHMASK) { @@ -106,17 +108,17 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) if (option & V_NOSCALESTART) sdupx = sdupy = 2.0f; - v[0].x = v[3].x = (x*sdupx-SHORT(gpatch->leftoffset)*pdupx)/vid.width - 1; - v[2].x = v[1].x = (x*sdupx+(SHORT(gpatch->width)-SHORT(gpatch->leftoffset))*pdupx)/vid.width - 1; - v[0].y = v[1].y = 1-(y*sdupy-SHORT(gpatch->topoffset)*pdupy)/vid.height; - v[2].y = v[3].y = 1-(y*sdupy+(SHORT(gpatch->height)-SHORT(gpatch->topoffset))*pdupy)/vid.height; + v[0].x = v[3].x = (x*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; + v[2].x = v[1].x = (x*sdupx+(gpatch->width - gpatch->leftoffset)*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdupy-gpatch->topoffset*pdupy)/vid.height; + v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height - gpatch->topoffset)*pdupy)/vid.height; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; v[0].s = v[3].s = 0.0f; - v[2].s = v[1].s = gpatch->max_s; + v[2].s = v[1].s = hwrPatch->max_s; v[0].t = v[1].t = 0.0f; - v[2].t = v[3].t = gpatch->max_t; + v[2].t = v[3].t = hwrPatch->max_t; flags = PF_Translucent|PF_NoDepthTest; @@ -129,7 +131,7 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) GL_DrawPolygon(NULL, v, 4, flags); } -void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags) +void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap, INT32 bflags) { FOutVector v[4]; FBITFIELD flags; @@ -137,6 +139,7 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t float cy = FIXED_TO_FLOAT(y); UINT8 alphalevel = ((option & V_ALPHAMASK) >> V_ALPHASHIFT); UINT8 blendmode = ((bflags & V_BLENDMASK) >> V_BLENDSHIFT); + GLPatch_t *hwrPatch; // 3--2 // | /| @@ -156,6 +159,8 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t else HWR_GetMappedPatch(gpatch, colormap); + hwrPatch = ((GLPatch_t *)gpatch->hardware); + dupx = (float)vid.dupx; dupy = (float)vid.dupy; @@ -186,13 +191,13 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t // left offset if (option & V_FLIP) - offsetx = (float)(SHORT(gpatch->width) - SHORT(gpatch->leftoffset)) * fscalew; + offsetx = (float)(gpatch->width - gpatch->leftoffset) * fscalew; else - offsetx = (float)SHORT(gpatch->leftoffset) * fscalew; + offsetx = (float)(gpatch->leftoffset) * fscalew; // top offset // TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!? - offsety = (float)SHORT(gpatch->topoffset) * fscaleh; + offsety = (float)(gpatch->topoffset) * fscaleh; if ((option & (V_NOSCALESTART|V_OFFSET)) == (V_NOSCALESTART|V_OFFSET)) // Multiply by dupx/dupy for crosshairs { @@ -220,17 +225,15 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t // if it's meant to cover the whole screen, black out the rest // cx and cy are possibly *slightly* off from float maths // This is done before here compared to software because we directly alter cx and cy to centre - if (cx >= -0.1f && cx <= 0.1f && SHORT(gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && SHORT(gpatch->height) == BASEVIDHEIGHT) + if (cx >= -0.1f && cx <= 0.1f && gpatch->width == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && gpatch->height == BASEVIDHEIGHT) { - // Need to temporarily cache the real patch to get the colour of the top left pixel - patch_t *realpatch = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC); - const column_t *column = (const column_t *)((const UINT8 *)(realpatch) + LONG((realpatch)->columnofs[0])); + const column_t *column = (const column_t *)((const UINT8 *)(gpatch->columns) + (gpatch->columnofs[0])); + if (!column->topdelta) { const UINT8 *source = (const UINT8 *)(column) + 3; HWR_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0])); } - Z_Free(realpatch); } // centre screen if (fabsf(fvw - FLOATBASEVIDWIDTH * dupx) > 1.0E-36f) @@ -252,8 +255,8 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t } } - fwidth = (float)SHORT(gpatch->width) * fscalew * dupx; - fheight = (float)SHORT(gpatch->height) * fscaleh * dupy; + fwidth = (float)(gpatch->width) * fscalew * dupx; + fheight = (float)(gpatch->height) * fscaleh * dupy; // positions of the cx, cy, are between 0 and vid.width/vid.height now, we need them to be between -1 and 1 cx = -1.0f + (cx / (fvw / 2.0f)); @@ -274,17 +277,17 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t if (option & V_FLIP) { - v[0].s = v[3].s = gpatch->max_s; + v[0].s = v[3].s = hwrPatch->max_s; v[2].s = v[1].s = 0.0f; } else { v[0].s = v[3].s = 0.0f; - v[2].s = v[1].s = gpatch->max_s; + v[2].s = v[1].s = hwrPatch->max_s; } v[0].t = v[1].t = 0.0f; - v[2].t = v[3].t = gpatch->max_t; + v[2].t = v[3].t = hwrPatch->max_t; // clip it since it is used for bunny scroll in doom I if (blendmode) @@ -314,13 +317,14 @@ void HWR_DrawStretchyFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t GL_DrawPolygon(NULL, v, 4, flags); } -void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h) +void HWR_DrawCroppedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, INT32 option, fixed_t sx, fixed_t sy, fixed_t w, fixed_t h) { FOutVector v[4]; FBITFIELD flags; float cx = FIXED_TO_FLOAT(x); float cy = FIXED_TO_FLOAT(y); UINT8 alphalevel = ((option & V_ALPHAMASK) >> V_ALPHASHIFT); + GLPatch_t *hwrPatch; // 3--2 // | /| @@ -336,6 +340,7 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal // make patch ready in hardware cache HWR_GetPatch(gpatch); + hwrPatch = ((GLPatch_t *)gpatch->hardware); dupx = (float)vid.dupx; dupy = (float)vid.dupy; @@ -358,8 +363,8 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal dupx = dupy = (dupx < dupy ? dupx : dupy); fscale = FIXED_TO_FLOAT(pscale); - cy -= (float)SHORT(gpatch->topoffset) * fscale; - cx -= (float)SHORT(gpatch->leftoffset) * fscale; + cy -= (float)(gpatch->topoffset) * fscale; + cx -= (float)(gpatch->leftoffset) * fscale; if (!(option & V_NOSCALESTART)) { @@ -371,17 +376,15 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal // if it's meant to cover the whole screen, black out the rest // cx and cy are possibly *slightly* off from float maths // This is done before here compared to software because we directly alter cx and cy to centre - if (cx >= -0.1f && cx <= 0.1f && SHORT(gpatch->width) == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && SHORT(gpatch->height) == BASEVIDHEIGHT) + if (cx >= -0.1f && cx <= 0.1f && gpatch->width == BASEVIDWIDTH && cy >= -0.1f && cy <= 0.1f && gpatch->height == BASEVIDHEIGHT) { - // Need to temporarily cache the real patch to get the colour of the top left pixel - patch_t *realpatch = W_CacheLumpNumPwad(gpatch->wadnum, gpatch->lumpnum, PU_STATIC); - const column_t *column = (const column_t *)((const UINT8 *)(realpatch) + LONG((realpatch)->columnofs[0])); + const column_t *column = (const column_t *)((const UINT8 *)(gpatch->columns) + (gpatch->columnofs[0])); + if (!column->topdelta) { const UINT8 *source = (const UINT8 *)(column) + 3; HWR_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0])); } - Z_Free(realpatch); } // centre screen if (fabsf(fvw - FLOATBASEVIDWIDTH * dupx) > 1.0E-36f) @@ -412,11 +415,11 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal if (fheight > h - sy) fheight = h - sy; - if (fwidth > SHORT(gpatch->width)) - fwidth = SHORT(gpatch->width); + if (fwidth > gpatch->width) + fwidth = gpatch->width; - if (fheight > SHORT(gpatch->height)) - fheight = SHORT(gpatch->height); + if (fheight > gpatch->height) + fheight = gpatch->height; if (pscale != FRACUNIT) { @@ -446,10 +449,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].s = v[3].s = ((sx)/(float)SHORT(gpatch->width) )*gpatch->max_s; - v[2].s = v[1].s = ((w )/(float)SHORT(gpatch->width) )*gpatch->max_s; - v[0].t = v[1].t = ((sy)/(float)SHORT(gpatch->height))*gpatch->max_t; - v[2].t = v[3].t = ((h )/(float)SHORT(gpatch->height))*gpatch->max_t; + v[0].s = v[3].s = ((sx)/(float)(gpatch->width) )*hwrPatch->max_s; + v[2].s = v[1].s = ((w )/(float)(gpatch->width) )*hwrPatch->max_s; + v[0].t = v[1].t = ((sy)/(float)(gpatch->height))*hwrPatch->max_t; + v[2].t = v[3].t = ((h )/(float)(gpatch->height))*hwrPatch->max_t; flags = PF_Translucent|PF_NoDepthTest; @@ -660,7 +663,7 @@ void HWR_DrawViewBorder(INT32 clearlines) INT32 top, side; INT32 baseviewwidth, baseviewheight; INT32 basewindowx, basewindowy; - GLPatch_t *patch; + patch_t *patch; // if (gl_viewwidth == vid.width) // return; @@ -709,7 +712,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // top edge if (clearlines > basewindowy - 8) { - patch = W_CachePatchNum(viewborderlump[BRDR_T], PU_CACHE); + patch = W_CachePatchNum(viewborderlump[BRDR_T], PU_PATCH); for (x = 0; x < baseviewwidth; x += 8) HWR_DrawPatch(patch, basewindowx + x, basewindowy - 8, 0); @@ -718,7 +721,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // bottom edge if (clearlines > basewindowy + baseviewheight) { - patch = W_CachePatchNum(viewborderlump[BRDR_B], PU_CACHE); + patch = W_CachePatchNum(viewborderlump[BRDR_B], PU_PATCH); for (x = 0; x < baseviewwidth; x += 8) HWR_DrawPatch(patch, basewindowx + x, basewindowy + baseviewheight, 0); @@ -727,7 +730,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // left edge if (clearlines > basewindowy) { - patch = W_CachePatchNum(viewborderlump[BRDR_L], PU_CACHE); + patch = W_CachePatchNum(viewborderlump[BRDR_L], PU_PATCH); for (y = 0; y < baseviewheight && basewindowy + y < clearlines; y += 8) { @@ -739,7 +742,7 @@ void HWR_DrawViewBorder(INT32 clearlines) // right edge if (clearlines > basewindowy) { - patch = W_CachePatchNum(viewborderlump[BRDR_R], PU_CACHE); + patch = W_CachePatchNum(viewborderlump[BRDR_R], PU_PATCH); for (y = 0; y < baseviewheight && basewindowy+y < clearlines; y += 8) { @@ -751,22 +754,22 @@ void HWR_DrawViewBorder(INT32 clearlines) // Draw beveled corners. if (clearlines > basewindowy - 8) HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TL], - PU_CACHE), + PU_PATCH), basewindowx - 8, basewindowy - 8, 0); if (clearlines > basewindowy - 8) HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_TR], - PU_CACHE), + PU_PATCH), basewindowx + baseviewwidth, basewindowy - 8, 0); if (clearlines > basewindowy+baseviewheight) HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BL], - PU_CACHE), + PU_PATCH), basewindowx - 8, basewindowy + baseviewheight, 0); if (clearlines > basewindowy + baseviewheight) HWR_DrawPatch(W_CachePatchNum(viewborderlump[BRDR_BR], - PU_CACHE), + PU_PATCH), basewindowx + baseviewwidth, basewindowy + baseviewheight, 0); } diff --git a/src/hardware/hw_gl.h b/src/hardware/hw_gl.h index c2a88854f..44fa28bf2 100644 --- a/src/hardware/hw_gl.h +++ b/src/hardware/hw_gl.h @@ -40,6 +40,7 @@ void GL_DrawModelEx(model_t *model, INT32 frameIndex, float duration, float tics void GL_RenderSkyDome(gl_sky_t *sky); +void GL_UpdateTexture(GLMipmap_t *pTexInfo); void GL_SetTexture(GLMipmap_t *pTexInfo); void GL_DeleteTexture(GLMipmap_t *pTexInfo); diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 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 c485b5a77..ea5b9f522 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -39,7 +39,6 @@ #include "../r_fps.h" #include "../r_local.h" #include "../r_main.h" // cv_fov -#include "../r_patch.h" // a mystery as to what this is for #include "../r_portal.h" #ifdef WALLSPLATS #include "../r_splats.h" @@ -56,7 +55,11 @@ #include "../w_wad.h" #include "../z_zone.h" -#include "../qs22j.h" // fast qsort +#ifdef ROTSPRITE +#include "../r_patchrotation.h" // a mystery as to what this is for +#endif + +#include "../qs22j.h" // fast qsort // ========================================================================== // Globals @@ -821,7 +824,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]; @@ -844,7 +847,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 = FixedToFloat(splat->v1.x); @@ -3309,7 +3312,7 @@ static fixed_t HWR_OpaqueFloorAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t hei return floorz; } -static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, GLPatch_t *gpatch) +static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t *hwrpatch) { float this_scale = 1.0f; FOutVector swallVerts[4]; @@ -3434,25 +3437,25 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, GLPatch_t *gpatch) if (spr->flip) { - swallVerts[0].s = swallVerts[3].s = gpatch->max_s; + swallVerts[0].s = swallVerts[3].s = hwrpatch->max_s; swallVerts[2].s = swallVerts[1].s = 0; } else { swallVerts[0].s = swallVerts[3].s = 0; - swallVerts[2].s = swallVerts[1].s = gpatch->max_s; + swallVerts[2].s = swallVerts[1].s = hwrpatch->max_s; } // flip the texture coords (look familiar?) if (spr->vflip) { - swallVerts[3].t = swallVerts[2].t = gpatch->max_t; + swallVerts[3].t = swallVerts[2].t = hwrpatch->max_t; swallVerts[0].t = swallVerts[1].t = 0; } else { swallVerts[3].t = swallVerts[2].t = 0; - swallVerts[0].t = swallVerts[1].t = gpatch->max_t; + swallVerts[0].t = swallVerts[1].t = hwrpatch->max_t; } sSurf.PolyColor.s.red = 0x01; @@ -3527,6 +3530,7 @@ static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts { basey = FixedToFloat(interp.z); } + lowy = wallVerts[0].y; // Rotate sprites to fully billboard with the camera @@ -3569,7 +3573,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; @@ -3591,13 +3596,15 @@ 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; // cache the patch in the graphics card memory //12/12/99: Hurdler: same comment as above (for md2) //Hurdler: 25/04/2000: now support colormap in hardware mode HWR_GetMappedPatch(gpatch, spr->colormap); + hwrpatch = ((GLPatch_t *)gpatch->hardware); + // Draw shadow BEFORE sprite if (cv_shadow.value // Shadows enabled && (spr->mobj->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. @@ -3607,7 +3614,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) //////////////////// // SHADOW SPRITE! // //////////////////// - HWR_DrawSpriteShadow(spr, gpatch); + HWR_DrawSpriteShadow(spr, gpatch, hwrpatch); } baseWallVerts[0].x = baseWallVerts[3].x = spr->x1; @@ -3625,25 +3632,25 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) if (spr->flip) { - baseWallVerts[0].s = baseWallVerts[3].s = gpatch->max_s; + baseWallVerts[0].s = baseWallVerts[3].s = hwrpatch->max_s; baseWallVerts[2].s = baseWallVerts[1].s = 0; } else { baseWallVerts[0].s = baseWallVerts[3].s = 0; - baseWallVerts[2].s = baseWallVerts[1].s = gpatch->max_s; + baseWallVerts[2].s = baseWallVerts[1].s = hwrpatch->max_s; } // flip the texture coords (look familiar?) if (spr->vflip) { - baseWallVerts[3].t = baseWallVerts[2].t = gpatch->max_t; + baseWallVerts[3].t = baseWallVerts[2].t = hwrpatch->max_t; baseWallVerts[0].t = baseWallVerts[1].t = 0; } else { baseWallVerts[3].t = baseWallVerts[2].t = 0; - baseWallVerts[0].t = baseWallVerts[1].t = gpatch->max_t; + baseWallVerts[0].t = baseWallVerts[1].t = hwrpatch->max_t; } // push it toward the camera to mitigate floor-clipping sprites @@ -3842,7 +3849,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) static void HWR_DrawSprite(gl_vissprite_t *spr) { FOutVector wallVerts[4]; - GLPatch_t *gpatch; // sprite patch converted to hardware + patch_t *gpatch; // sprite patch converted to hardware + GLPatch_t *hwrpatch; FSurfaceInfo Surf; FBITFIELD blend = 0; @@ -3866,7 +3874,14 @@ 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; + + // cache the patch in the graphics card memory + //12/12/99: Hurdler: same comment as above (for md2) + //Hurdler: 25/04/2000: now support colormap in hardware mode + HWR_GetMappedPatch(gpatch, spr->colormap); + + hwrpatch = ((GLPatch_t *)gpatch->hardware); // create the sprite billboard // @@ -3888,32 +3903,27 @@ 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 - //12/12/99: Hurdler: same comment as above (for md2) - //Hurdler: 25/04/2000: now support colormap in hardware mode - HWR_GetMappedPatch(gpatch, spr->colormap); - // Draw shadow BEFORE sprite if (cv_shadow.value // Shadows enabled && (spr->mobj->flags & (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY)) != (MF_SCENERY|MF_SPAWNCEILING|MF_NOGRAVITY) // Ceiling scenery have no shadow. @@ -3923,7 +3933,7 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) //////////////////// // SHADOW SPRITE! // //////////////////// - HWR_DrawSpriteShadow(spr, gpatch); + HWR_DrawSpriteShadow(spr, gpatch, hwrpatch); } // push it toward the camera to mitigate floor-clipping sprites @@ -3992,7 +4002,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; @@ -4001,7 +4012,14 @@ static void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) return; // cache sprite graphics - gpatch = spr->gpatch; //W_CachePatchNum(spr->patchlumpnum, PU_CACHE); + gpatch = spr->gpatch; + + // cache the patch in the graphics card memory + //12/12/99: Hurdler: same comment as above (for md2) + //Hurdler: 25/04/2000: now support colormap in hardware mode + HWR_GetMappedPatch(gpatch, spr->colormap); + + hwrpatch = ((GLPatch_t *)gpatch->hardware); // create the sprite billboard // @@ -4022,15 +4040,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; - - // cache the patch in the graphics card memory - //12/12/99: Hurdler: same comment as above (for md2) - //Hurdler: 25/04/2000: now support colormap in hardware mode - HWR_GetMappedPatch(gpatch, spr->colormap); + wallVerts[0].t = wallVerts[1].t = hwrpatch->max_t; // colormap test sector_t *sector = spr->mobj->subsector->sector; @@ -4786,10 +4799,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 @@ -4889,10 +4902,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; @@ -5060,15 +5073,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 @@ -5538,13 +5551,13 @@ 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) + for (x = vid.width >> 1; x < vid.width; x += pw) { - for (y = vid.height>>1; y < vid.height; y += ph) + for (y = vid.height >> 1; y < vid.height; y += ph) HWR_DrawStretchyFixedPatch(gpatch, (x)<mipmap->data); + png_bytep PNG_image = Z_Malloc(pitch*height, PU_HWRMODELTEXTURE, &glpatch->mipmap->data); png_bytepp row_pointers = png_malloc(png_ptr, height * sizeof (png_bytep)); for (i = 0; i < height; i++) row_pointers[i] = PNG_image + i*pitch; @@ -324,7 +324,7 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h, pw = *w = header.xmax - header.xmin + 1; ph = *h = header.ymax - header.ymin + 1; - image = Z_Malloc(pw*ph*4, PU_HWRCACHE, &glpatch->mipmap->data); + image = Z_Malloc(pw*ph*4, PU_HWRMODELTEXTURE, &glpatch->mipmap->data); if (fread(palette, sizeof (UINT8), PALSIZE, file) != PALSIZE) { @@ -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; @@ -715,11 +729,11 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, glMipmap->data = NULL; } - cur = Z_Malloc(size*4, PU_HWRCACHE, &glMipmap->data); + cur = Z_Malloc(size*4, PU_HWRMODELTEXTURE, &glMipmap->data); memset(cur, 0x00, size*4); - image = 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_HWRMODELTEXTURE_UNLOCKED); + return; + } } } @@ -1080,14 +1113,17 @@ static void HWR_GetBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, INT // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better newMipmap = calloc(1, sizeof (*newMipmap)); if (newMipmap == NULL) - I_Error("%s: Out of memory", "HWR_GetMappedPatch"); + I_Error("%s: Out of memory", "HWR_GetBlendedTexture"); glMipmap->nextcolormap = newMipmap; - newMipmap->colormap = 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); + Z_ChangeTag(newMipmap->data, PU_HWRMODELTEXTURE_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,36 @@ 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) + if ((skincolors_t)spr->mobj->color != SKINCOLOR_NONE) { INT32 tcskinnum = TC_DEFAULT; if ((spr->mobj->flags & MF_BOSS) && (spr->mobj->flags2 & MF2_FRET) && (leveltime & 1)) // Bosses "flash" @@ -1303,19 +1355,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 d2e363079..0533d3676 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -191,7 +191,7 @@ FUNCPRINTF void GL_DBG_Printf(const char *format, ...) if (!gllogstream) gllogstream = fopen("ogllog.txt", "w"); - + va_start(arglist, format); vsnprintf(str, 4096, format, arglist); va_end(arglist); @@ -673,7 +673,7 @@ typedef enum gluniform_light_dir, gluniform_light_contrast, gluniform_light_backlight, - + // palette rendering gluniform_palette_tex, // 1d texture containing a palette gluniform_palette_lookup_tex, // 3d texture containing the rgb->index lookup table @@ -743,7 +743,7 @@ void SetupGLFunc4(void) pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); pglMultiTexCoord2fv = GetGLFunc("glMultiTexCoord2fv"); - + /* 1.5 funcs */ pglGenBuffers = GetGLFunc("glGenBuffers"); pglBindBuffer = GetGLFunc("glBindBuffer"); @@ -753,7 +753,7 @@ void SetupGLFunc4(void) /* 2.0 funcs */ pglBlendEquation = GetGLFunc("glBlendEquation"); - + pglStencilFuncSeparate = GetGLFunc("glStencilFuncSeparate"); pglStencilOpSeparate = GetGLFunc("glStencilOpSeparate"); @@ -809,7 +809,7 @@ boolean GL_InitShaders(void) { if (!pglUseProgram) return false; - + gl_fallback_shader.vertex_shader = Z_StrDup(GLSL_FALLBACK_VERTEX_SHADER); gl_fallback_shader.fragment_shader = Z_StrDup(GLSL_FALLBACK_FRAGMENT_SHADER); @@ -1657,7 +1657,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; @@ -2038,7 +2038,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) { @@ -2327,7 +2327,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) { @@ -2637,7 +2637,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; @@ -2706,7 +2706,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); @@ -2909,7 +2909,7 @@ INT32 GL_GetTextureUsed(void) res += tmp->height*tmp->width*bpp; tmp = tmp->next; } - + return res; } @@ -2927,8 +2927,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 @@ -3025,8 +3025,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 @@ -3054,7 +3054,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); @@ -3093,7 +3093,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 @@ -3177,7 +3177,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 @@ -3274,7 +3274,7 @@ void GL_MakeScreenTexture(int tex) { INT32 texsizew = 512, texsizey = 512; boolean firstTime = (screenTextures[tex] == 0); - + if (!gl_enable_screen_textures) return; @@ -3314,7 +3314,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; @@ -3405,7 +3405,7 @@ void GL_SetPaletteLookup(UINT8 *lut) { internalFormat = GL_R8; } - + if (!paletteLookupTex) pglGenTextures(1, &paletteLookupTex); pglActiveTexture(GL_TEXTURE1); @@ -3454,7 +3454,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 feedf4039..d9cf132b2 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 222890332..951bdec40 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -48,6 +48,10 @@ #include "hardware/hw_main.h" #endif +#ifdef ROTSPRITE +#include "r_patchrotation.h" +#endif + // Hud offset cvars #define IMPL_HUD_OFFSET_X(name)\ consvar_t cv_##name##_xoffset = {"hud_" #name "_xoffset", "0", CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -7749,10 +7753,10 @@ void K_LoadKartHUDGraphics(void) kp_bumperstickerwideclr = W_CachePatchName("K_SCBALW", PU_HUDGFX); kp_karmastickerclr = W_CachePatchName("K_SCKARM", PU_HUDGFX); kp_timeoutstickerclr = W_CachePatchName("K_SCTOUT", PU_HUDGFX); - kp_itembgclr[0] = W_CachePatchName("K_ITBC", PU_HUDGFX); - kp_itembgclr[1] = W_CachePatchName("K_ITBCD", PU_HUDGFX); - kp_itembgclr[2] = W_CachePatchName("K_ISBC", PU_HUDGFX); - kp_itembgclr[3] = W_CachePatchName("K_ISBCD", PU_HUDGFX); + kp_itembgclr[0] = W_CachePatchName("K_ITBC" , PU_HUDGFX); + kp_itembgclr[1] = W_CachePatchName("K_ITBCD" , PU_HUDGFX); + kp_itembgclr[2] = W_CachePatchName("K_ISBC" , PU_HUDGFX); + kp_itembgclr[3] = W_CachePatchName("K_ISBCD" , PU_HUDGFX); kp_itemmulstickerclr[1] = W_CachePatchName("K_ISMULC", PU_HUDGFX); kp_itemmulstickerclr[0] = W_CachePatchName("K_ITMULC", PU_HUDGFX); } @@ -9040,7 +9044,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; @@ -9076,7 +9080,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; @@ -9103,7 +9107,7 @@ static void K_DrawKartPositionNum(INT32 num) const boolean wheeloffs = (cv_showinput.value && cv_posi_xoffset.value == 0 && cv_posi_yoffset.value == 0 && cv_wheel_xoffset.value == 0 && cv_wheel_yoffset.value == 0); boolean win = (stplyr->exiting && num == 1); //INT32 X = POSI_X; - INT32 W = SHORT(kp_positionnum[0][0]->width); + INT32 W = kp_positionnum[0][0]->width; fixed_t scale = FRACUNIT; patch_t *localpatch = kp_positionnum[0][0]; //INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTORIGHT); @@ -9217,7 +9221,7 @@ static void K_DrawKartPositionNum(INT32 num) localpatch = kp_positionnum[num % 10][0]; } - V_DrawFixedPatch((fx<width)*scale/2) : 0), (fy<height)*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL); + V_DrawFixedPatch((fx<width*scale/2) : 0), (fy<height*scale/2) : 0), scale, V_HUDTRANSHALF|fflags, localpatch, NULL); // ^ if we overtake as p1 or p3 in splitscren, we shift it so that it doesn't go off screen. // ^ if we overtake as p1 in 2p splits, shift vertically so that this doesn't happen either. @@ -9551,9 +9555,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; @@ -9604,11 +9608,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 @@ -9697,7 +9701,9 @@ static void K_drawKartSpeedometer(void) // index 0 is the raw value, index 1 is the converted value fixed_t convSpeed[2] = {0,0}; +#ifdef ROTSPRITE fixed_t dial_divisor = DIALSPDDIV; +#endif INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); @@ -9713,12 +9719,16 @@ static void K_drawKartSpeedometer(void) case 2: convSpeed[0] = FixedDiv(FixedMul(stplyr->speed, 88465), mapobjectscale); // 1.349868774 convSpeed[1] = convSpeed[0] / FRACUNIT; +#ifdef ROTSPRITE dial_divisor = MPHDIV; +#endif break; case 3: convSpeed[0] = FixedDiv(stplyr->speed, mapobjectscale); convSpeed[1] = convSpeed[0] / FRACUNIT; +#ifdef ROTSPRITE dial_divisor = MPHDIV; +#endif break; case 4: if (stplyr->mo) @@ -10487,7 +10497,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; } @@ -10605,13 +10615,13 @@ static void K_drawKartMinimapIcon(fixed_t objx, fixed_t objy, INT32 hudx, INT32 if (encoremode) amnumxpos = -amnumxpos; - amxpos = amnumxpos + ((hudx + (SHORT(AutomapPic->width)-SHORT(icon->width))/2)<height)-SHORT(icon->height))/2)<width-icon->width)/2)<height-icon->height)/2)<width) / 4)<height) / 4)<width / 4)<height / 4)<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 @@ -10735,14 +10745,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); @@ -10754,10 +10764,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++) @@ -10875,7 +10885,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) @@ -10891,7 +10901,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; } @@ -10903,14 +10913,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); } @@ -11755,8 +11765,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 { @@ -11831,7 +11841,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 60e4e729c..d1dce0ae0 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -30,6 +30,10 @@ #include "lua_hud.h" #include "lua_hook.h" +#ifdef ROTSPRITE +#include "r_patchrotation.h" +#endif + #define HUDONLY if (!hud_running) return luaL_error(L, "HUD rendering code should not be called outside of rendering hooks!"); boolean hud_running = false; @@ -293,9 +297,13 @@ static int patch_get(lua_State *L) patch_t *patch = *((patch_t **)luaL_checkudata(L, 1, META_PATCH)); enum patch field = Lua_optoption(L, 2, -1, patch_fields_ref); - // patches are CURRENTLY always valid, expected to be cached with PU_STATIC - // this may change in the future, so patch.valid still exists - I_Assert(patch != NULL); + if (!patch) { + if (field == patch_valid) { + lua_pushboolean(L, 0); + return 1; + } + return LUA_ErrInvalid(L, "patch_t"); + } switch (field) { @@ -303,16 +311,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 +404,7 @@ static int libd_patchExists(lua_State *L) static int libd_cachePatch(lua_State *L) { HUDONLY - LUA_PushUserdata(L, W_CachePatchName(luaL_checkstring(L, 1), PU_STATIC), META_PATCH); + LUA_PushUserdata(L, W_CachePatchName(luaL_checkstring(L, 1), PU_PATCH), META_PATCH); return 1; } @@ -406,7 +414,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 +534,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 +702,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) @@ -5093,18 +5093,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++); @@ -5200,10 +5200,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; @@ -5214,12 +5214,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; @@ -5230,8 +5230,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; @@ -5318,13 +5318,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 */ @@ -5396,7 +5396,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: @@ -5429,12 +5429,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); } @@ -5461,7 +5461,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(); } @@ -5583,7 +5583,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 @@ -5613,7 +5613,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 ); } @@ -5643,11 +5643,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 { @@ -5721,7 +5721,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; } @@ -5732,12 +5732,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); } } @@ -6033,7 +6033,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); @@ -6078,7 +6078,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; } } @@ -6099,7 +6099,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 @@ -6215,23 +6215,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); @@ -7240,22 +7240,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; } @@ -7355,7 +7355,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); @@ -7440,7 +7440,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]) @@ -7488,7 +7488,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! @@ -7552,14 +7552,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 @@ -7726,16 +7726,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)); @@ -8370,13 +8370,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]) @@ -8900,7 +8900,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), @@ -8971,10 +8971,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)); } @@ -9141,7 +9141,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) @@ -9158,7 +9158,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) @@ -9225,7 +9225,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 @@ -10267,15 +10267,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; @@ -10307,14 +10307,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; @@ -10796,10 +10796,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; @@ -10977,17 +10977,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 @@ -10995,11 +10995,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)); } } @@ -11129,7 +11129,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); } @@ -11177,7 +11177,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); } } @@ -11186,13 +11186,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)); } @@ -11241,7 +11241,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); } } @@ -11252,13 +11252,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; @@ -11408,7 +11408,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 @@ -11416,7 +11416,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); @@ -12541,7 +12541,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 @@ -12936,7 +12936,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 @@ -12944,7 +12944,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); @@ -12953,8 +12953,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); @@ -13042,7 +13042,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. @@ -13155,7 +13155,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)); } @@ -13316,14 +13316,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; } @@ -13352,18 +13352,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; } @@ -13376,7 +13376,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; @@ -13384,15 +13384,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 { @@ -13417,19 +13417,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)); } } @@ -13591,7 +13591,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); @@ -13661,12 +13661,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; } @@ -13696,12 +13696,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; @@ -13716,7 +13716,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 399276474..8d62130d0 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2973,7 +2973,10 @@ boolean P_SetupLevel(boolean fromnetsave, boolean reloadinggamestate) // Reset the palette now all fades have been done if (rendermode != render_none) + { + //V_ResetPaletteCVars(); // dont carry over changed palettes V_SetPaletteLump(GetPalette()); // Set the level palette + } // Print "SPEEDING OFF TO [ZONE] [ACT 1]..." /*if (rendermode != render_none) @@ -3002,10 +3005,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) @@ -3237,6 +3246,7 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) { name = lumpinfo->name; lumpnum_t lumpnum = i|(wadnum<<16); + if (name[0] == 'D') { if (name[1] == 'S') for (j = 1; j < NUMSFX; j++) @@ -3278,8 +3288,15 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) // // search for sprite replacements // + //Patch_FreeTag(PU_SPRITE); + //Patch_FreeTag(PU_PATCH_ROTATED); R_AddSpriteDefs(wadnum); + // Reload it all anyway, just in case they + // added some textures but didn't insert a + // TEXTURES/etc. list. + //R_LoadTexturesPwad(wadnum); + // everything from MultiSetupWadFile until ST_Start was here originally // @@ -3387,7 +3404,7 @@ boolean P_MultiSetupWadFiles(boolean fullsetup) if (partadd_stage == 0) { // Flush and reload HUD graphics - ST_UnloadGraphics(); + //ST_UnloadGraphics(); HU_LoadGraphics(); ST_LoadGraphics(); ST_ReloadSkinFaceGraphics(); @@ -3404,6 +3421,11 @@ boolean P_MultiSetupWadFiles(boolean fullsetup) if (partadd_stage == 1) { +#ifdef HWRENDER + // Free GPU textures before freeing patches. + if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED)) + HWR_ClearAllTextures(); +#endif // Reload all textures, unconditionally for better or worse. R_LoadTextures(); diff --git a/src/r_bsp.c b/src/r_bsp.c index e2e878078..427a6367c 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -13,12 +13,13 @@ #include "doomdef.h" #include "g_game.h" + +#include "r_fps.h" #include "r_local.h" #include "r_state.h" #include "r_portal.h" // Add seg portals - - #include "r_splats.h" + #include "p_local.h" // camera #include "p_slopes.h" #include "z_zone.h" // Check R_Prep3DFloors diff --git a/src/r_data.c b/src/r_data.c index 6b4bef3d0..53f58de27 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -302,8 +302,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; @@ -322,29 +323,37 @@ 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++) + else { - column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2])); - INT32 topdelta, prevdelta = -1, y = 0; - while (col->topdelta != 0xff) + colofs = (UINT8 *)realpatch->columnofs; + + for (x = 0; x < texture->width; x++) { - topdelta = col->topdelta; - if (topdelta <= prevdelta) - topdelta += prevdelta; - prevdelta = topdelta; - if (topdelta > y) - break; - y = topdelta + col->length + 1; - col = (column_t *)((UINT8 *)col + col->length + 4); + column_t *col = (column_t *)((UINT8 *)realpatch + LONG(*(UINT32 *)&colofs[x<<2])); + + INT32 topdelta, prevdelta = -1, y = 0; + + while (col->topdelta != 0xff) + { + topdelta = col->topdelta; + if (topdelta <= prevdelta) + topdelta += prevdelta; + prevdelta = topdelta; + if (topdelta > y) + break; + y = topdelta + col->length + 1; + col = (column_t *)((UINT8 *)col + col->length + 4); + } + + if (y < texture->height) + holey = true; // this texture is HOLEy! D: } - if (y < texture->height) - holey = true; // this texture is HOLEy! D: } // If the patch uses transparency, we have to save it this way. @@ -352,8 +361,7 @@ static UINT8 *R_GenerateTexture(size_t texnum) { texture->holes = true; blocksize = W_LumpLengthPwad(patch->wad, patch->lump); - block = Z_Calloc(blocksize, PU_STATIC, // will change tag at end of this function - &texturecache[texnum]); + block = Z_Calloc(blocksize, PU_LEVEL, &texturecache[texnum]); M_Memcpy(block, realpatch, blocksize); texturememory += blocksize; @@ -361,8 +369,12 @@ static UINT8 *R_GenerateTexture(size_t texnum) colofs = (block + 8); texturecolumnofs[texnum] = (UINT32 *)colofs; blocktex = block; + for (x = 0; x < texture->width; x++) + { *(UINT32 *)&colofs[x<<2] = LONG(LONG(*(UINT32 *)&colofs[x<<2]) + 3); + } + goto done; } @@ -373,9 +385,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; @@ -387,20 +399,30 @@ 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); - - // Well, it's not valid... - if (realpatch == NULL) - continue; + pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL); + realpatch = (softwarepatch_t *)pdata; 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; @@ -415,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; } @@ -466,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); } // @@ -496,7 +516,7 @@ void R_LoadTextures(void) INT32 i, k, w; UINT16 j; UINT16 texstart, texend, texturesLumpPos; - patch_t *patchlump; + softwarepatch_t *patchlump; texpatch_t *patch; texture_t *texture; @@ -521,7 +541,7 @@ void R_LoadTextures(void) // but the alternative is to spend a ton of time checking and re-checking all previous entries just to skip any potentially patched textures. for (w = 0, numtextures = 0; w < numwadfiles; w++) { - if (wadfiles[w]->type == RET_PK3) + if (W_FileHasFolders(wadfiles[w])) { texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); @@ -585,7 +605,7 @@ void R_LoadTextures(void) for (i = 0, w = 0; w < numwadfiles; w++) { // Get the lump numbers for the markers in the WAD, if they exist. - if (wadfiles[w]->type == RET_PK3) + if (W_FileHasFolders(wadfiles[w])) { texstart = W_CheckNumForFolderStartPK3("textures/", (UINT16)w, 0); texend = W_CheckNumForFolderEndPK3("textures/", (UINT16)w, texstart); @@ -611,18 +631,22 @@ void R_LoadTextures(void) // Work through each lump between the markers in the WAD. for (j = 0; j < (texend - texstart); j++) { + UINT16 wadnum = (UINT16)w; + lumpnum_t lumpnum = texstart + j; + if (W_FileHasFolders(wadfiles[w])) { - if (W_IsLumpFolder(w, texstart + j)) // Check if lump is a folder + if (W_IsLumpFolder(wadnum, lumpnum)) // Check if lump is a folder continue; // If it is then SKIP IT } - patchlump = W_CacheLumpNumPwad((UINT16)w, texstart + j, PU_CACHE); - //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad((UINT16)w,texstart+j),patchlump->width, patchlump->height); + patchlump = (softwarepatch_t *)W_CacheLumpNumPwad(wadnum, lumpnum, PU_STATIC); + + //CONS_Printf("\n\"%s\" is a single patch, dimensions %d x %d",W_CheckNameForNumPwad(wadnum, lumpnum), patchlump->width, patchlump->height); texture = textures[i] = Z_Calloc(sizeof(texture_t) + sizeof(texpatch_t), PU_STATIC, NULL); // Set texture properties. - M_Memcpy(texture->name, W_CheckNameForNumPwad((UINT16)w, texstart + j), sizeof(texture->name)); + M_Memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name)); texture->width = SHORT(patchlump->width); texture->height = SHORT(patchlump->height); texture->patchcount = 1; @@ -632,7 +656,7 @@ void R_LoadTextures(void) patch = &texture->patches[0]; patch->originx = patch->originy = 0; - patch->wad = (UINT16)w; + patch->wad = wadnum; patch->lump = texstart + j; Z_Free(patchlump); @@ -649,7 +673,7 @@ void R_LoadTextures(void) #ifdef HWRENDER if (rendermode == render_opengl) - HWR_LoadTextures(numtextures); + HWR_LoadMapTextures(numtextures); #endif } @@ -1815,7 +1839,7 @@ static void R_PrecacheLevelSprites(void) lump = sf->lumppat[a];\ if (devparm)\ spritememory += W_LumpLength(lump);\ - W_CachePatchNum(lump, PU_CACHE);\ + W_CachePatchNum(lump, PU_SPRITE);\ } // see R_InitSprites for more about lumppat,lumpid switch (sf->rotate) diff --git a/src/r_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..21f59401c 100644 --- a/src/r_patch.c +++ b/src/r_patch.c @@ -13,12 +13,7 @@ /// \brief Patch generation. #include "byteptr.h" -#include "dehacked.h" #include "doomdef.h" -#include "i_video.h" -#include "r_data.h" -#include "r_draw.h" -#include "r_fps.h" #include "r_patch.h" #include "r_things.h" #include "z_zone.h" @@ -329,13 +324,140 @@ 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) * SHORT(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 // // Convert a masked flat to a patch. // Explanation of "masked" flats in R_PatchToMaskedFlat. // -static void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffset, INT16 topoffset, size_t *destsize) +void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffset, INT16 topoffset, size_t *destsize) { INT16 x, y; UINT8 *img; @@ -440,10 +562,17 @@ 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) +UINT16 R_GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip) { fixed_t ofs; column_t *column; @@ -453,14 +582,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) { @@ -485,268 +614,3 @@ 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 -// -// Angles precalculated in R_InitSprites. -// -fixed_t rollcosang[ROTANGLES]; -fixed_t rollsinang[ROTANGLES]; - -INT32 R_GetRollAngle(angle_t rollangle) -{ - INT32 ra = AngleFixed(rollangle)>>FRACBITS; -#if (ROTANGDIFF > 1) - ra += (ROTANGDIFF/2); -#endif - ra /= ROTANGDIFF; - ra %= ROTANGLES; - return ra; -} - -angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp) -{ - return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp->roll) + - FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp->pitch) + - FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp->sloperoll) + - FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp->slopepitch); -} - -patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle) -{ - rotsprite_t *rotsprite; - spriteinfo_t *sprinfo = (spriteinfo_t *)info; - INT32 idx = rotationangle; - - if (rotationangle < 1 || rotationangle >= ROTANGLES) - return NULL; - - rotsprite = sprite->rotated[spriteangle]; - - if (rotsprite == NULL) - { - rotsprite = RotatedPatch_Create(ROTANGLES); - sprite->rotated[spriteangle] = rotsprite; - } - - if (flip) - idx += rotsprite->angles; - - if (rotsprite->patches[idx] == NULL) - { - patch_t *patch; - INT32 xpivot = 0, ypivot = 0; - lumpnum_t lump = sprite->lumppat[spriteangle]; - - if (lump == LUMPERROR) - return NULL; - - patch = (patch_t *)W_CacheLumpNum(lump, PU_CACHE); // PU_LEVEL - - if (sprinfo->available) - { - xpivot = sprinfo->pivot[frame].x; - ypivot = sprinfo->pivot[frame].y; - } - else - { - xpivot = SHORT(patch->leftoffset); - ypivot = SHORT(patch->height) / 2; - } - - RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip); - } - - return rotsprite->patches[idx]; -} - -rotsprite_t *RotatedPatch_Create(INT32 numangles) -{ - rotsprite_t *rotsprite = Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL); - rotsprite->angles = numangles; - rotsprite->patches = Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL); - return rotsprite; -} - - -static void RotatedPatch_CalculateDimensions( - INT32 width, INT32 height, - fixed_t ca, fixed_t sa, - INT32 *newwidth, INT32 *newheight) -{ - fixed_t fixedwidth = (width * FRACUNIT); - fixed_t fixedheight = (height * FRACUNIT); - - fixed_t w1 = abs(FixedMul(fixedwidth, ca) - FixedMul(fixedheight, sa)); - fixed_t w2 = abs(FixedMul(-fixedwidth, ca) - FixedMul(fixedheight, sa)); - fixed_t h1 = abs(FixedMul(fixedwidth, sa) + FixedMul(fixedheight, ca)); - fixed_t h2 = abs(FixedMul(-fixedwidth, sa) + FixedMul(fixedheight, ca)); - - w1 = FixedInt(FixedCeil(w1 + (FRACUNIT/2))); - w2 = FixedInt(FixedCeil(w2 + (FRACUNIT/2))); - h1 = FixedInt(FixedCeil(h1 + (FRACUNIT/2))); - h2 = FixedInt(FixedCeil(h2 + (FRACUNIT/2))); - - *newwidth = max(width, max(w1, w2)); - *newheight = max(height, max(h1, h2)); -} - -void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip) -{ - UINT32 i; - - patch_t *rotated; - - UINT16 *rawdst, *rawconv; - size_t size; - INT32 bflip = (flip != 0x00); - - INT32 width = SHORT(patch->width); - INT32 height = SHORT(patch->height); - INT32 leftoffset = SHORT(patch->leftoffset); - INT32 newwidth, newheight; - - fixed_t ca = rollcosang[angle]; - fixed_t sa = rollsinang[angle]; - fixed_t xcenter, ycenter; - INT32 idx = angle; - INT32 x, y; - INT32 sx, sy; - INT32 dx, dy; - INT32 ox, oy; - INT32 minx, miny, maxx, maxy; - - // Don't cache angle = 0 - if (angle < 1 || angle >= ROTANGLES) - return; - - if (flip) - { - idx += rotsprite->angles; - xpivot = width - xpivot; - leftoffset = width - leftoffset; - } - - if (rotsprite->patches[idx]) - return; - - // Find the dimensions of the rotated patch. - RotatedPatch_CalculateDimensions(width, height, ca, sa, &newwidth, &newheight); - - xcenter = (xpivot * FRACUNIT); - ycenter = (ypivot * FRACUNIT); - - if (xpivot != width / 2 || ypivot != height / 2) - { - newwidth *= 2; - newheight *= 2; - } - - minx = newwidth; - miny = newheight; - maxx = 0; - maxy = 0; - - // Draw the rotated sprite to a temporary buffer. - size = (newwidth * newheight); - if (!size) - size = (width * height); - rawdst = Z_Malloc(size * sizeof(UINT16), PU_STATIC, NULL); - - for (i = 0; i < size; i++) - rawdst[i] = 0xFF00; - - for (dy = 0; dy < newheight; dy++) - { - for (dx = 0; dx < newwidth; dx++) - { - x = (dx - (newwidth / 2)) * FRACUNIT; - y = (dy - (newheight / 2)) * FRACUNIT; - sx = FixedMul(x, ca) + FixedMul(y, sa) + xcenter; - sy = -FixedMul(x, sa) + FixedMul(y, ca) + ycenter; - - sx >>= FRACBITS; - sy >>= FRACBITS; - - if (sx >= 0 && sy >= 0 && sx < width && sy < height) - { - rawdst[(dy * newwidth) + dx] = GetPatchPixel(patch, sx, sy, bflip); - - if (dx < minx) - minx = dx; - if (dy < miny) - miny = dy; - if (dx > maxx) - maxx = dx; - if (dy > maxy) - maxy = dy; - } - } - } - - ox = (newwidth / 2) + (leftoffset - xpivot); - oy = (newheight / 2) + (SHORT(patch->topoffset) - ypivot); - width = (maxx - minx); - height = (maxy - miny); - - if ((unsigned)(width * height) > size) - { - UINT16 *src, *dest; - - size = (width * height); - rawconv = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL); - - src = &rawdst[(miny * newwidth) + minx]; - dest = rawconv; - dy = height; - - while (dy--) - { - M_Memcpy(dest, src, width * sizeof(UINT16)); - dest += width; - src += newwidth; - } - - ox -= minx; - oy -= miny; - - Z_Free(rawdst); - } - else - { - rawconv = rawdst; - width = newwidth; - height = newheight; - } - - // make patch - rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); - - rotated->leftoffset = ox; - rotated->topoffset = oy; - -#ifdef HWRENDER - if (rendermode == render_opengl) - { - rotated = R_CreateHardwarePatch(rotated); - } -#endif // HWRENDER - - //Z_ChangeTag(rotated, PU_LEVEL); - Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); - Z_Free(rawconv); -} -#endif diff --git a/src/r_patch.h b/src/r_patch.h index 75347df3c..2978ff10c 100644 --- a/src/r_patch.h +++ b/src/r_patch.h @@ -15,8 +15,6 @@ #define __R_PATCH__ #include "r_defs.h" -#include "r_fps.h" -#include "doomdef.h" // Structs typedef enum @@ -38,6 +36,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); @@ -46,17 +56,7 @@ extern spriteinfo_t spriteinfo[NUMSPRITES]; void R_LoadSpriteInfoLumps(UINT16 wadnum, UINT16 numlumps); void R_ParseSPRTINFOLump(UINT16 wadNum, UINT16 lumpNum); -// Sprite rotation -#ifdef ROTSPRITE -INT32 R_GetRollAngle(angle_t rollangle); -angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp); - -patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle); -rotsprite_t *RotatedPatch_Create(INT32 numangles); -void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip); - -extern fixed_t rollcosang[ROTANGLES]; -extern fixed_t rollsinang[ROTANGLES]; -#endif +void *R_MaskedFlatToPatch(UINT16 *raw, INT16 width, INT16 height, INT16 leftoffset, INT16 topoffset, size_t *destsize); +UINT16 R_GetPatchPixel(patch_t *patch, INT32 x, INT32 y, boolean flip); #endif // __R_PATCH__ diff --git a/src/r_patchrotation.c b/src/r_patchrotation.c new file mode 100644 index 000000000..3f1836ad1 --- /dev/null +++ b/src/r_patchrotation.c @@ -0,0 +1,262 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020-2023 by Lactozilla. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file r_patchrotation.c +/// \brief Patch rotation. + +#include "doomdef.h" +#include "r_fps.h" +#include "r_patch.h" +#include "r_patchrotation.h" +#include "z_zone.h" +#include "w_wad.h" + +#ifdef ROTSPRITE +// +// R_GetRollAngle +// +// Angles precalculated in R_InitSprites. +// +fixed_t rollcosang[ROTANGLES]; +fixed_t rollsinang[ROTANGLES]; + +INT32 R_GetRollAngle(angle_t rollangle) +{ + INT32 ra = AngleFixed(rollangle)>>FRACBITS; +#if (ROTANGDIFF > 1) + ra += (ROTANGDIFF/2); +#endif + ra /= ROTANGDIFF; + ra %= ROTANGLES; + return ra; +} + +angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp) +{ + return FixedMul(FINECOSINE((ang) >> ANGLETOFINESHIFT), interp->roll) + + FixedMul(FINESINE((ang) >> ANGLETOFINESHIFT), interp->pitch) + + FixedMul(FINECOSINE((camang) >> ANGLETOFINESHIFT), interp->sloperoll) + + FixedMul(FINESINE((camang) >> ANGLETOFINESHIFT), interp->slopepitch); +} + +patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle) +{ + rotsprite_t *rotsprite; + spriteinfo_t *sprinfo = (spriteinfo_t *)info; + INT32 idx = rotationangle; + + if (rotationangle < 1 || rotationangle >= ROTANGLES) + return NULL; + + rotsprite = sprite->rotated[spriteangle]; + + if (rotsprite == NULL) + { + rotsprite = RotatedPatch_Create(ROTANGLES); + sprite->rotated[spriteangle] = rotsprite; + } + + if (flip) + idx += rotsprite->angles; + + if (rotsprite->patches[idx] == NULL) + { + patch_t *patch; + INT32 xpivot = 0, ypivot = 0; + lumpnum_t lump = sprite->lumppat[spriteangle]; + + if (lump == LUMPERROR) + return NULL; + + patch = W_CachePatchNum(lump, PU_SPRITE); + + if (sprinfo->available) + { + xpivot = sprinfo->pivot[frame].x; + ypivot = sprinfo->pivot[frame].y; + } + else + { + xpivot = patch->leftoffset; + ypivot = patch->height / 2; + } + + RotatedPatch_DoRotation(rotsprite, patch, rotationangle, xpivot, ypivot, flip); + } + + return rotsprite->patches[idx]; +} + +rotsprite_t *RotatedPatch_Create(INT32 numangles) +{ + rotsprite_t *rotsprite = Z_Calloc(sizeof(rotsprite_t), PU_STATIC, NULL); + rotsprite->angles = numangles; + rotsprite->patches = Z_Calloc(rotsprite->angles * 2 * sizeof(void *), PU_STATIC, NULL); + return rotsprite; +} + +static void RotatedPatch_CalculateDimensions( + INT32 width, INT32 height, + fixed_t ca, fixed_t sa, + INT32 *newwidth, INT32 *newheight) +{ + fixed_t fixedwidth = (width * FRACUNIT); + fixed_t fixedheight = (height * FRACUNIT); + + fixed_t w1 = abs(FixedMul(fixedwidth, ca) - FixedMul(fixedheight, sa)); + fixed_t w2 = abs(FixedMul(-fixedwidth, ca) - FixedMul(fixedheight, sa)); + fixed_t h1 = abs(FixedMul(fixedwidth, sa) + FixedMul(fixedheight, ca)); + fixed_t h2 = abs(FixedMul(-fixedwidth, sa) + FixedMul(fixedheight, ca)); + + w1 = FixedInt(FixedCeil(w1 + (FRACUNIT/2))); + w2 = FixedInt(FixedCeil(w2 + (FRACUNIT/2))); + h1 = FixedInt(FixedCeil(h1 + (FRACUNIT/2))); + h2 = FixedInt(FixedCeil(h2 + (FRACUNIT/2))); + + *newwidth = max(width, max(w1, w2)); + *newheight = max(height, max(h1, h2)); +} + +void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip) +{ + UINT32 i; + patch_t *rotated; + + UINT16 *rawdst, *rawconv; + size_t size; + INT32 bflip = (flip != 0x00); + + INT32 width = patch->width; + INT32 height = patch->height; + INT32 leftoffset = patch->leftoffset; + INT32 newwidth, newheight; + + fixed_t ca = rollcosang[angle]; + fixed_t sa = rollsinang[angle]; + fixed_t xcenter, ycenter; + INT32 idx = angle; + INT32 x, y; + INT32 sx, sy; + INT32 dx, dy; + INT32 ox, oy; + INT32 minx, miny, maxx, maxy; + + // Don't cache angle = 0 + if (angle < 1 || angle >= ROTANGLES) + return; + + if (flip) + { + idx += rotsprite->angles; + xpivot = width - xpivot; + leftoffset = width - leftoffset; + } + + if (rotsprite->patches[idx]) + return; + + // Find the dimensions of the rotated patch. + RotatedPatch_CalculateDimensions(width, height, ca, sa, &newwidth, &newheight); + + xcenter = (xpivot * FRACUNIT); + ycenter = (ypivot * FRACUNIT); + + if (xpivot != width / 2 || ypivot != height / 2) + { + newwidth *= 2; + newheight *= 2; + } + + minx = newwidth; + miny = newheight; + maxx = 0; + maxy = 0; + + // Draw the rotated sprite to a temporary buffer. + size = (newwidth * newheight); + if (!size) + size = (width * height); + rawdst = Z_Malloc(size * sizeof(UINT16), PU_STATIC, NULL); + + for (i = 0; i < size; i++) + rawdst[i] = 0xFF00; + + for (dy = 0; dy < newheight; dy++) + { + for (dx = 0; dx < newwidth; dx++) + { + x = (dx - (newwidth / 2)) * FRACUNIT; + y = (dy - (newheight / 2)) * FRACUNIT; + sx = FixedMul(x, ca) + FixedMul(y, sa) + xcenter; + sy = -FixedMul(x, sa) + FixedMul(y, ca) + ycenter; + + sx >>= FRACBITS; + sy >>= FRACBITS; + + if (sx >= 0 && sy >= 0 && sx < width && sy < height) + { + rawdst[(dy * newwidth) + dx] = R_GetPatchPixel(patch, sx, sy, bflip); + + if (dx < minx) + minx = dx; + if (dy < miny) + miny = dy; + if (dx > maxx) + maxx = dx; + if (dy > maxy) + maxy = dy; + } + } + } + + ox = (newwidth / 2) + (leftoffset - xpivot); + oy = (newheight / 2) + (patch->topoffset - ypivot); + width = (maxx - minx); + height = (maxy - miny); + + if ((unsigned)(width * height) > size) + { + UINT16 *src, *dest; + + size = (width * height); + rawconv = Z_Calloc(size * sizeof(UINT16), PU_STATIC, NULL); + + src = &rawdst[(miny * newwidth) + minx]; + dest = rawconv; + dy = height; + + while (dy--) + { + M_Memcpy(dest, src, width * sizeof(UINT16)); + dest += width; + src += newwidth; + } + + ox -= minx; + oy -= miny; + + Z_Free(rawdst); + } + else + { + rawconv = rawdst; + width = newwidth; + height = newheight; + } + + // make patch + rotated = (patch_t *)R_MaskedFlatToPatch(rawconv, width, height, 0, 0, &size); + + Z_ChangeTag(rotated, PU_PATCH_ROTATED); + Z_SetUser(rotated, (void **)(&rotsprite->patches[idx])); + Z_Free(rawconv); + + rotated->leftoffset = ox; + rotated->topoffset = oy; +} +#endif diff --git a/src/r_patchrotation.h b/src/r_patchrotation.h new file mode 100644 index 000000000..d387ae20f --- /dev/null +++ b/src/r_patchrotation.h @@ -0,0 +1,30 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020-2023 by Lactozilla. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- +/// \file r_patchrotation.h +/// \brief Patch rotation. + +#ifndef __R_PATCHROTATION__ +#define __R_PATCHROTATION__ + +#include "r_fps.h" + +// Sprite rotation +#ifdef ROTSPRITE +INT32 R_GetRollAngle(angle_t rollangle); +angle_t R_RotationAngle(angle_t ang, angle_t camang, interpmobjstate_t *interp); + +rotsprite_t *RotatedPatch_Create(INT32 numangles); +void RotatedPatch_DoRotation(rotsprite_t *rotsprite, patch_t *patch, INT32 angle, INT32 xpivot, INT32 ypivot, boolean flip); +patch_t *Patch_GetRotatedSprite(spriteframe_t *sprite, size_t frame, size_t spriteangle, boolean flip, void *info, INT32 rotationangle); + +extern fixed_t rollcosang[ROTANGLES]; +extern fixed_t rollsinang[ROTANGLES]; +#endif + +#endif // __R_PATCHROTATION__ diff --git a/src/r_plane.c b/src/r_plane.c index d4e9c92ff..03dea56be 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -128,7 +128,7 @@ static void R_CalculatePlaneRipple(visplane_t *plane, INT32 y, fixed_t plheight, { fixed_t distance = FixedMul(plheight, yslope[y]); const INT32 yay = (planeripple.offset + (distance>>9)) & 8191; - + // ripples da water texture ds_bgofs = FixedDiv(FINESINE(yay), (1<<12) + (distance>>11))>>FRACBITS; @@ -630,7 +630,7 @@ void R_DrawPlanes(void) R_DrawSinglePlane(pl); } } - + #ifndef NOWATER R_UpdatePlaneRipple(); #endif @@ -1050,7 +1050,7 @@ void R_DrawSinglePlane(visplane_t *pl) xoffs = (fixed_t)(xoffs*fudgecanyon); yoffs = (fixed_t)(yoffs/fudgecanyon); - + #ifndef NOWATER if (planeripple.active) { diff --git a/src/r_segs.c b/src/r_segs.c index a1d3b626e..f1954f0e7 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 45afd824d..585274bd3 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -11,34 +11,38 @@ /// \file r_things.c /// \brief Refresh of things, i.e. objects represented by sprites -#include "doomdef.h" -#include "console.h" -#include "g_game.h" -#include "r_local.h" -#include "st_stuff.h" -#include "w_wad.h" -#include "z_zone.h" -#include "m_misc.h" -#include "i_video.h" // rendermode #include "r_main.h" // stplyr #include "r_fps.h" #include "r_things.h" -#include "r_patch.h" #include "r_plane.h" +#include "r_portal.h" +#include "r_local.h" + +#include "dehacked.h" // get_number (for thok) +#include "doomdef.h" +#include "d_netfil.h" // blargh. for nameonly(). +#include "console.h" +#include "g_game.h" +#include "k_kart.h" // SRB2kart #include "p_tick.h" #include "p_local.h" #include "p_setup.h" #include "p_slopes.h" -#include "dehacked.h" // get_number (for thok) -#include "d_netfil.h" // blargh. for nameonly(). +#include "st_stuff.h" #include "m_cheat.h" // objectplace -#include "r_portal.h" -#include "k_kart.h" // SRB2kart -#include "p_local.h" // stplyr +#include "m_misc.h" +#include "i_video.h" // rendermode +#include "w_wad.h" +#include "z_zone.h" + #ifdef HWRENDER #include "hardware/hw_md2.h" #endif +#ifdef ROTSPRITE +#include "r_patchrotation.h" +#endif + #include "qs22j.h" CV_PossibleValue_t Forceskin_cons_t[MAXSKINS+2]; @@ -254,7 +258,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)); @@ -278,7 +282,7 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, for (l = startlump; l < endlump; l++) { - if (memcmp(lumpinfo[l].name,sprname,4)) + if (memcmp(lumpinfo[l].name, sprname, 4)) continue; frame = R_Char2Frame(lumpinfo[l].name[4]); @@ -291,16 +295,16 @@ static boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, } // skip NULL sprites from very old dmadds pwads - if (W_LumpLengthPwad(wadnum,l)<=8) + if (W_LumpLengthPwad(wadnum, l) <= 8) continue; // store sprite info in lookup tables //FIXME : numspritelumps do not duplicate sprite replacements - W_ReadLumpHeaderPwad(wadnum, l, &patch, sizeof (patch_t), 0); - 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 +818,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 +862,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 +886,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 +897,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 +942,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 +965,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); } @@ -1390,10 +1394,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 @@ -1800,7 +1804,7 @@ static void R_ProjectSprite(mobj_t *thing) vis->patch = rotsprite; else #endif - vis->patch = W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE); + vis->patch = W_CachePatchNum(sprframe->lumppat[rot], PU_SPRITE); vis->precip = false; @@ -1985,7 +1989,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/sdl/Srb2SDL.dsp b/src/sdl/Srb2SDL.dsp index 35e5ec32b..67400625a 100644 --- a/src/sdl/Srb2SDL.dsp +++ b/src/sdl/Srb2SDL.dsp @@ -897,6 +897,14 @@ SOURCE=..\r_patch.h # End Source File # Begin Source File +SOURCE=..\r_patchrotation.c +# End Source File +# Begin Source File + +SOURCE=..\r_patchrotation.h +# End Source File +# Begin Source File + SOURCE=..\r_plane.c # End Source File # Begin Source File diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 73f6635e3..d6805cf21 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -134,7 +134,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) if (!first_init) { - if (!gllogstream) + if (!gllogstream) { gllogdir = D_Home(); @@ -147,7 +147,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) gllogstream = fopen("./ogllog.txt", "wt"); #endif } - + gl_version = pglGetString(GL_VERSION); gl_renderer = pglGetString(GL_RENDERER); gl_extensions = pglGetString(GL_EXTENSIONS); @@ -220,7 +220,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) } SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); - + // The screen textures need to be flushed if the width or height change so that they be remade for the correct size if (screen_width != w || screen_height != h) { @@ -310,7 +310,7 @@ void OglSdlFinishUpdate(boolean waitvbl) #if defined (__unix__) #ifdef USE_FBO_OGL - if (loaded_config == true) + if (loaded_config) xwaylandcrap = false; #endif #endif diff --git a/src/st_stuff.c b/src/st_stuff.c index aac9b7fa7..04523f577 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 1d0b7ddfb..34bc9f296 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -48,6 +48,9 @@ consvar_t cv_ticrate = {"showfps", "No", CV_SAVE, fps_cons_t, NULL, 0, NULL, NUL static void CV_palette_OnChange(void); +consvar_t cv_palette = {"palette", "", CV_CALL|CV_NOINIT, NULL, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_palettenum = {"palettenum", "0", CV_CALL|CV_NOINIT, CV_Unsigned, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t gamma_cons_t[] = {{-15, "MIN"}, {4, "MAX"}, {0, NULL}}; consvar_t cv_globalgamma = {"gamma", "0", CV_SAVE|CV_CALL, gamma_cons_t, CV_palette_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -91,6 +94,8 @@ consvar_t cv_menucaps = {"menucaps", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NUL // local copy of the palette for V_GetColor() RGBA_t *pLocalPalette = NULL; +static size_t currentPaletteSize; + /* The following was an extremely helpful resource when developing my Colour Cube LUT. http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html @@ -134,7 +139,7 @@ static boolean InitCube(void) float globalgammamul, globalgammaoffs; boolean doinggamma; - if (loaded_config == false) + if (!loaded_config) return false; #define diffcons(cv) (strcmp(cv.string, cv.defaultvalue)) @@ -411,13 +416,19 @@ const UINT8 gammatable[5][256] = // keep a copy of the palette so that we can get the RGB value for a color index at any time. static void LoadPalette(const char *lumpname) { + UINT8 *pal; + size_t i, palsize; + lumpnum_t lumpnum; + #ifdef BACKWARDSCOMPATCORRECTION const UINT8 *usegamma = gammatable[min(max(cv_globalgamma.value, 0), 4)]; #endif Cubeapply = InitCube(); - lumpnum_t lumpnum = W_GetNumForName(lumpname); - size_t i, palsize = W_LumpLength(lumpnum)/3; - UINT8 *pal; + + lumpnum = W_GetNumForName(lumpname); + + currentPaletteSize = W_LumpLength(lumpnum); + palsize = currentPaletteSize / 3; Z_Free(pLocalPalette); @@ -505,8 +516,23 @@ const char *R_GetPalname(UINT16 num) const char *GetPalette(void) { + const char *user = cv_palette.string; + + if (user && user[0]) + { + if (W_CheckNumForName(user) == LUMPERROR) + { + CONS_Alert(CONS_WARNING, "cv_palette %s lump does not exist\n", user); + } + else + { + return cv_palette.string; + } + } + if (gamestate == GS_LEVEL) return R_GetPalname((encoremode ? mapheaderinfo[gamemap-1]->encorepal : mapheaderinfo[gamemap-1]->palette)); + return "PLAYPAL"; } @@ -524,6 +550,20 @@ void V_SetPalette(INT32 palettenum) if (!pLocalPalette) V_ReloadPalette(); + if (rendermode == render_soft || (rendermode == render_opengl && HWR_ShouldUsePaletteRendering())) // opengl without paletterendering hates subpalettes + { + if (palettenum == 0) + { + palettenum = cv_palettenum.value; + + if (palettenum * 256U > currentPaletteSize - 256) + { + CONS_Alert(CONS_WARNING, "cv_palettenum %d out of range\n", palettenum); + palettenum = 0; + } + } + } + #ifdef HWRENDER if (rendermode == render_opengl) HWR_SetPalette(&pLocalPalette[palettenum*256]); @@ -538,15 +578,7 @@ void V_SetPalette(INT32 palettenum) void V_SetPaletteLump(const char *pal) { LoadPalette(pal); -#ifdef HWRENDER - if (rendermode == render_opengl) - HWR_SetPalette(pLocalPalette); -#if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) - else -#endif -#endif - if (rendermode != render_none) - I_SetPalette(pLocalPalette); + V_SetPalette(0); #ifdef HASINVERT R_MakeInvertmap(); #endif @@ -554,13 +586,27 @@ void V_SetPaletteLump(const char *pal) static void CV_palette_OnChange(void) { - if (loaded_config == false) + if (!loaded_config) return; // reload palette + // recalculate Color Cube V_ReloadPalette(); V_SetPalette(0); } +void V_ResetPaletteCVars(void) +{ + if (!loaded_config) + return; + +#define diffcons(cv) (strcmp(cv.string, cv.defaultvalue)) + if diffcons(cv_palette) + CV_StealthSetValue(&cv_palette, atoi(cv_palette.defaultvalue)); + if diffcons(cv_palettenum) + CV_StealthSetValue(&cv_palettenum, atoi(cv_palettenum.defaultvalue)); +#undef diffcons +} + static void CV_constextsize_OnChange(void) { con_recalc = true; @@ -635,7 +681,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 +756,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 +843,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 +871,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 +918,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 +951,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 +1045,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 +1551,7 @@ void V_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatnum) void V_DrawPatchFill(patch_t *pat) { INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); - INT32 x, y, pw = SHORT(pat->width) * dupz, ph = SHORT(pat->height) * dupz; + INT32 x, y, pw = pat->width * dupz, ph = pat->height * dupz; for (x = 0; x < vid.width; x += pw) { @@ -1706,7 +1752,7 @@ void V_DrawCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed) if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) return; - w = SHORT(hu_font[c]->width); + w = hu_font[c]->width; if (x + w > vid.width) return; @@ -1733,7 +1779,7 @@ void V_DrawChatCharacter(INT32 x, INT32 y, INT32 c, boolean lowercaseallowed, UI if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) return; - w = SHORT(hu_font[c]->width)/2; + w = hu_font[c]->width/2; if (x + w > vid.width) return; @@ -1899,10 +1945,10 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(hu_font[c]->width)*dupx/2; + center = w/2 - hu_font[c]->width*dupx/2; } else - w = SHORT(hu_font[c]->width) * dupx; + w = hu_font[c]->width * dupx; if (cx > scrwidth) break; @@ -2001,10 +2047,10 @@ void V_DrawKartString(INT32 x, INT32 y, INT32 option, const char *string) if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(kart_font[c]->width)*dupx/2; + center = w/2 - kart_font[c]->width*dupx/2; } else - w = SHORT(kart_font[c]->width) * dupx; + w = kart_font[c]->width * dupx; if (cx > scrwidth) break; @@ -2119,10 +2165,10 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(hu_font[c]->width)*dupx/4; + center = w/2 - hu_font[c]->width*dupx/4; } else - w = SHORT(hu_font[c]->width) * dupx / 2; + w = hu_font[c]->width * dupx / 2; if (cx > scrwidth) break; if (cx+left + w < 0) //left boundary check @@ -2236,8 +2282,8 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) if (charwidth) w = charwidth * dupx; else - w = ((option & V_6WIDTHSPACE ? max(1, SHORT(tny_font[c]->width)-1) // Reuse this flag for the alternate bunched-up spacing - : SHORT(tny_font[c]->width)) * dupx); + w = ((option & V_6WIDTHSPACE ? max(1, tny_font[c]->width-1) // Reuse this flag for the alternate bunched-up spacing + : tny_font[c]->width) * dupx); if (cx > scrwidth) break; @@ -2337,10 +2383,10 @@ void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(hu_font[c]->width)*(dupx/2); + center = w/2 - hu_font[c]->width*(dupx/2); } else - w = SHORT(hu_font[c]->width) * dupx; + w = hu_font[c]->width * dupx; if ((cx>>FRACBITS) > scrwidth) break; @@ -2535,10 +2581,10 @@ void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *str if (charwidth) { w = charwidth * dupx; - center = w/2 - SHORT(tny_font[c]->width)*(dupx/2); + center = w/2 - tny_font[c]->width*(dupx/2); } else - w = SHORT(tny_font[c]->width) * dupx; + w = tny_font[c]->width * dupx; if ((cx>>FRACBITS) > scrwidth) break; @@ -2558,7 +2604,7 @@ void V_DrawThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *str // Draws a tallnum. Replaces two functions in y_inter and st_stuff void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num) { - INT32 w = SHORT(tallnum[0]->width); + INT32 w = tallnum[0]->width; boolean neg; if (flags & V_NOSCALESTART) @@ -2584,7 +2630,7 @@ void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num) // Does not handle negative numbers in a special way, don't try to feed it any. void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits) { - INT32 w = SHORT(tallnum[0]->width); + INT32 w = tallnum[0]->width; if (flags & V_NOSCALESTART) w *= vid.dupx; @@ -2605,7 +2651,7 @@ void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits) // Does not handle negative numbers in a special way, don't try to feed it any. void V_DrawPaddedTallColorNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits, const UINT8 *colormap) { - INT32 w = SHORT(tallnum[0]->width); + INT32 w = tallnum[0]->width; if (flags & V_NOSCALESTART) w *= vid.dupx; @@ -2627,7 +2673,7 @@ void V_DrawPaddedTallColorNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 di INT32 V_DrawPingNum(INT32 x, INT32 y, INT32 flags, INT32 num, const UINT8 *colormap) { - INT32 w = SHORT(pingnum[0]->width); // this SHOULD always be 5 but I guess custom graphics exist. + INT32 w = pingnum[0]->width; // this SHOULD always be 5 but I guess custom graphics exist. if (flags & V_NOSCALESTART) w *= vid.dupx; @@ -2650,7 +2696,7 @@ INT32 V_DrawPingNum(INT32 x, INT32 y, INT32 flags, INT32 num, const UINT8 *color // void V_DrawRankNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits, const UINT8 *colormap) { - INT32 w = SHORT(ranknum[0]->width) - 1; + INT32 w = ranknum[0]->width - 1; if (flags & V_NOSCALESTART) w *= vid.dupx; @@ -2709,7 +2755,7 @@ void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string) continue; } - w = SHORT(cred_font[c]->width) * dupx; + w = cred_font[c]->width * dupx; if ((cx>>FRACBITS) > scrwidth) break; @@ -2735,7 +2781,7 @@ INT32 V_CreditStringWidth(const char *string) if (c < 0 || c >= CRED_FONTSIZE) w += 16; else - w += SHORT(cred_font[c]->width); + w += cred_font[c]->width; } return w; @@ -2782,7 +2828,7 @@ void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) continue; } - w = SHORT(lt_font[c]->width) * dupx; + w = lt_font[c]->width * dupx; if (cx > scrwidth) break; if (cx+left + w < 0) //left boundary check @@ -2809,7 +2855,7 @@ INT32 V_LevelNameWidth(const char *string) if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) w += 12; else - w += SHORT(lt_font[c]->width); + w += lt_font[c]->width; } return w; @@ -2828,8 +2874,8 @@ INT32 V_LevelNameHeight(const char *string) if (c < 0 || c >= LT_FONTSIZE || !lt_font[c]) continue; - if (SHORT(lt_font[c]->height) > w) - w = SHORT(lt_font[c]->height); + if (lt_font[c]->height > w) + w = lt_font[c]->height; } return w; @@ -2871,7 +2917,7 @@ INT32 V_SubStringWidth(const char *string, INT32 length, INT32 option) if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) w += spacewidth; else - w += (charwidth ? charwidth : SHORT(hu_font[c]->width)); + w += (charwidth ? charwidth : hu_font[c]->width); } return w; @@ -2913,7 +2959,7 @@ INT32 V_SmallSubStringWidth(const char *string, INT32 length, INT32 option) if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) w += spacewidth; else - w += (charwidth ? charwidth : SHORT(hu_font[c]->width)/2); + w += (charwidth ? charwidth : hu_font[c]->width/2); } return w; @@ -2965,8 +3011,8 @@ INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option) else { w += (charwidth ? charwidth - : ((option & V_6WIDTHSPACE && i < length-1) ? max(1, SHORT(tny_font[c]->width)-1) // Reuse this flag for the alternate bunched-up spacing - : SHORT(tny_font[c]->width))); + : ((option & V_6WIDTHSPACE && i < length-1) ? max(1, tny_font[c]->width-1) // Reuse this flag for the alternate bunched-up spacing + : tny_font[c]->width)); } } @@ -3007,7 +3053,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/v_video.h b/src/v_video.h index 85338751c..c8f614afc 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -28,12 +28,12 @@ extern UINT8 *screens[5]; -extern consvar_t cv_ticrate, cv_accuratefps, cv_allcaps, cv_constextsize, cv_menucaps,\ -cv_globalgamma, cv_globalsaturation,\ -cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue,\ -cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma, \ -cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation; - +extern consvar_t cv_ticrate, cv_accuratefps, cv_allcaps, cv_constextsize, cv_menucaps, +cv_globalgamma, cv_globalsaturation, +cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue, +cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma, +cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation, +cv_palette, cv_palettenum; // Allocates buffer screens, call before R_Init. void V_Init(void); @@ -60,6 +60,8 @@ void V_SetPalette(INT32 palettenum); void V_SetPaletteLump(const char *pal); +void V_ResetPaletteCVars(void); + const char *R_GetPalname(UINT16 num); const char *GetPalette(void); diff --git a/src/w_wad.c b/src/w_wad.c index 3a9ab6c6c..0c7fdbaf0 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -58,6 +58,7 @@ #include "dehacked.h" #include "d_clisrv.h" #include "r_defs.h" +#include "r_patch.h" #include "i_system.h" #include "md5.h" #include "lua_script.h" @@ -72,7 +73,7 @@ #endif #ifdef ROTSPRITE -#include "r_patch.h" // RotatedPatch_Create +#include "r_patchrotation.h" // RotatedPatch_Create #endif #ifndef O_BINARY @@ -821,15 +822,10 @@ 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 - wadfile->rotcache = M_AATreeAlloc(AATREE_ZUSER); + Z_Calloc(numlumps * sizeof (*wadfile->rotcache), PU_STATIC, &wadfile->rotcache); #endif // @@ -1317,15 +1313,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; @@ -1634,7 +1630,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); } @@ -1692,6 +1687,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 // ========================================================================== @@ -1715,41 +1743,56 @@ void *W_CacheLumpName(const char *name, INT32 tag) // Cache a patch into heap memory, convert the patch format as necessary // -// Software-only compile cache the data without conversion -#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_opengl) + Patch_CreateGL(patch); +#endif + + return (void *)patch; } void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag) @@ -1757,24 +1800,28 @@ 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. void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum) { - aatree_t *rotcache = wadfiles[wadnum]->rotcache; - rotsprite_t *rspr; + lumpcache_t *rotcache = wadfiles[wadnum]->rotcache; - if (!(rspr = M_AATreeGet(rotcache, lumpnum))) + if (!rotcache[lumpnum]) { - rspr = RotatedPatch_Create(ROTANGLES); - M_AATreeSet(rotcache, lumpnum, rspr); + rotsprite_t *rspr = RotatedPatch_Create(ROTANGLES); + Z_SetUser(rspr, (void **)(&rotcache[lumpnum])); } - return (void *)rspr; + return (void *)(rotcache[lumpnum]); } - #endif // ROTSPRITE void W_UnlockCachedPatch(void *patch) @@ -1786,19 +1833,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); @@ -1814,9 +1859,7 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag) rotsprite_t *rspr; INT32 idx = rotationangle; - const char *finalname = name; - - num = W_CheckNumForName(finalname); + num = W_CheckNumForName(name); if (num == LUMPERROR) num = W_GetNumForName("MISSING"); @@ -1831,18 +1874,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 d0eb28f2f..12ad8cea7 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -106,8 +106,6 @@ virtlump_t* vres_Find(const virtres_t*, const char*); #define lumpcache_t void * -#include "m_aatree.h" - // Resource type of the WAD. Yeah, I know this sounds dumb, but I'll leave it like this until I clean up the code further. typedef enum restype { @@ -125,11 +123,9 @@ 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. + lumpcache_t *rotcache; // Cache rotsprites for rotating patches. #endif UINT16 numlumps; // this wad's number of resources FILE *handle; @@ -208,18 +204,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..548c1e025 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -656,24 +656,30 @@ 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_TotalUsage()>>10)); + CONS_Printf(M_GetText("Lua : %7s KB\n"), sizeu1(Z_TagUsage(PU_LUA)>>10)); + CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); + CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); + 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) + if (rendermode == render_opengl) { - 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("Model textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRMODELTEXTURE)>>10)); + CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); CONS_Printf(M_GetText("All GPU textures : %7d KB\n"), HWR_GetTextureUsed()>>10); } #endif @@ -684,8 +690,6 @@ static void Command_Memfree_f(void) CONS_Printf(M_GetText("Available physical memory: %s KB\n"), sizeu1(freebytes>>10)); } - - #ifdef ZDEBUG /** The function called by the "memdump" console command. * Prints zone memory debugging information (i.e. tag, size, location in code allocated). diff --git a/src/z_zone.h b/src/z_zone.h index e4ee811f2..41ea1d669 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -44,10 +44,17 @@ 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 + PU_HWRMODELTEXTURE = 23, // Hardware model texture PU_HWRCACHE = 48, // static until unlocked PU_CACHE = 49, // static until unlocked @@ -63,6 +70,7 @@ enum PU_HWRCACHE_UNLOCKED = 102, // 'unlocked' PU_HWRCACHE memory: // 'second-level' cache for graphics // stored in hardware format and downloaded as needed + PU_HWRMODELTEXTURE_UNLOCKED = 103, // 'unlocked' PU_HWRMODELTEXTURE memory }; //