From 1426ebec20ca6695b64cb77fa63168e8c744f2e6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 17 Oct 2019 12:45:25 +0200 Subject: [PATCH] Moved hightile replacement data into the textures Not tested yet! --- source/build/include/build.h | 5 - source/build/include/hightile.h | 54 +---- source/build/include/mdsprite.h | 2 +- source/build/include/polymost.h | 4 +- source/build/src/defs.cpp | 78 ++------ source/build/src/engine.cpp | 1 - source/build/src/hightile.cpp | 271 -------------------------- source/build/src/polymost.cpp | 57 ++---- source/build/src/texcache.cpp | 7 - source/common/textures/buildtiles.cpp | 103 +++++++++- source/common/textures/texture.cpp | 47 +++++ source/common/textures/textures.h | 20 ++ 12 files changed, 196 insertions(+), 453 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 3c3838839..56fc2e41d 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -1330,11 +1330,6 @@ extern int32_t r_rorphase; void hicinit(void); void hicsetpalettetint(int32_t palnum, char r, char g, char b, char sr, char sg, char sb, polytintflags_t effect); // flags bitset: 1 = don't compress -int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float alphacut, - float xscale, float yscale, float specpower, float specfactor, char flags); -int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6], int32_t flags); -int32_t hicclearsubst(int32_t picnum, int32_t palnum); - int32_t Ptile2tile(int32_t tile, int32_t palette) ATTRIBUTE((pure)); int32_t md_loadmodel(const char *fn); int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, float yoffset, int32_t flags); diff --git a/source/build/include/hightile.h b/source/build/include/hightile.h index c85513828..37d1f5a84 100644 --- a/source/build/include/hightile.h +++ b/source/build/include/hightile.h @@ -1,19 +1,6 @@ #ifndef HIGHTILE_PRIV_H #define HIGHTILE_PRIV_H -struct hicskybox_t { - char *face[6]; -}; - -typedef struct hicreplc_t { - struct hicreplc_t *next; - char *filename; - struct hicskybox_t *skybox; - vec2f_t scale; - float alphacut, specpower, specfactor; - char palnum, flags; -} hicreplctyp; - typedef struct { polytintflags_t f; uint8_t r, g, b; @@ -21,27 +8,6 @@ typedef struct { } polytint_t; extern polytint_t hictinting[MAXPALOOKUPS]; -extern hicreplctyp *hicreplc[MAXTILES]; -extern int32_t hicinitcounter; - -typedef struct texcachehead_t -{ - char magic[4]; // 'PMST', was 'Polymost' - int xdim, ydim; // of image, unpadded - int flags; // 1 = !2^x, 2 = has alpha, 4 = lzw compressed - int quality; // r_downsize at the time the cache was written -} texcacheheader; - -typedef struct texcachepic_t -{ - int size; - int format; - int xdim, ydim; // of mipmap (possibly padded) - int border, depth; -} texcachepicture; - -hicreplctyp * hicfindsubst(int picnum, int palnum, int nozero = 0); -hicreplctyp * hicfindskybox(int picnum, int palnum, int nozero = 0); static inline int have_basepal_tint(void) { @@ -81,25 +47,11 @@ static inline void globaltinting_apply_ub(uint8_t *color) color[2] = (uint8_t)(color[2] * (float)globalb * (1.f/255.f)); } -// texcacheheader cachead.flags bits -enum -{ - CACHEAD_NONPOW2 = 1, - CACHEAD_HASALPHA = 2, - CACHEAD_COMPRESSED = 4, - CACHEAD_NODOWNSIZE = 8, - CACHEAD_HASFULLBRIGHT = 16, - CACHEAD_NPOTWALL = 32, -}; -// hicreplctyp hicr->flags bits +// replacement flags enum { - HICR_NOTEXCOMPRESS = 1, HICR_FORCEFILTER = 2, - - HICR_NODOWNSIZE = 16, - HICR_ARTIMMUNITY = 32, }; // hictinting[].f / gloadtile_hi() and mdloadskin() arg bits @@ -128,8 +80,4 @@ enum HICTINT_MEMORY_COMBINATIONS = 1<<5, }; -#define GRAYSCALE_COEFF_RED 0.3 -#define GRAYSCALE_COEFF_GREEN 0.59 -#define GRAYSCALE_COEFF_BLUE 0.11 - #endif diff --git a/source/build/include/mdsprite.h b/source/build/include/mdsprite.h index 00d86560b..3a3a67537 100644 --- a/source/build/include/mdsprite.h +++ b/source/build/include/mdsprite.h @@ -39,7 +39,7 @@ typedef struct _mdanim_t typedef struct _mdskinmap_t { - uint8_t palette, flags, filler[2]; // Build palette number, flags the same as hicreplctyp + uint8_t palette, flags, filler[2]; // Build palette number, flags the same as hightiles int32_t skinnum, surfnum; // Skin identifier, surface number char *fn; // Skin filename FHardwareTexture *texid[HICTINT_MEMORY_COMBINATIONS]; // OpenGL texture numbers for effect variations diff --git a/source/build/include/polymost.h b/source/build/include/polymost.h index c775c142b..8e1c619ec 100644 --- a/source/build/include/polymost.h +++ b/source/build/include/polymost.h @@ -149,7 +149,7 @@ typedef struct pthtyp_t { struct pthtyp_t *next; struct pthtyp_t *ofb; // fullbright pixels - hicreplctyp *hicr; + // *hicr; FHardwareTexture * glpic; vec2f_t scale; @@ -164,7 +164,7 @@ typedef struct pthtyp_t } pthtyp; void gloadtile_art(int32_t dapic, int32_t dameth, pthtyp* pth, int32_t doalloc); -extern int32_t gloadtile_hi(int32_t,int32_t,int32_t,hicreplctyp *,int32_t,pthtyp *,int32_t, polytintflags_t); +extern int32_t gloadtile_hi(int32_t,int32_t,int32_t, int32_t,pthtyp *,int32_t, polytintflags_t); extern int32_t globalnoeffect; extern int32_t drawingskybox; diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index afda0ba03..cf637dd10 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -361,9 +361,7 @@ static int32_t defsparser(scriptfile *script) if (check_file_exist(fn)) break; -#ifdef USE_OPENGL - hicsetsubsttex(tile,pal,fn,-1.0,1.0,1.0,1.0,1.0,0); -#endif + tileSetHightileReplacement(tile,pal,fn,-1.0,1.0,1.0,1.0,1.0,0); } break; case T_DEFINESKYBOX: @@ -382,9 +380,7 @@ static int32_t defsparser(scriptfile *script) happy = 0; } if (i < 6 || !happy) break; -#ifdef USE_OPENGL - hicsetskybox(tile,pal,fn, 0); -#endif + tileSetSkybox(tile, pal, (const char **)fn, 0); } break; case T_DEFINETINT: @@ -1445,14 +1441,8 @@ static int32_t defsparser(scriptfile *script) case T_SURF: scriptfile_getnumber(script,&surfnum); break; #ifdef USE_OPENGL - case T_NOCOMPRESS: - flags |= HICR_NOTEXCOMPRESS; break; - case T_NODOWNSIZE: - flags |= HICR_NODOWNSIZE; break; case T_FORCEFILTER: flags |= HICR_FORCEFILTER; break; - case T_ARTQUALITY: - flags |= HICR_ARTIMMUNITY; break; #endif } } @@ -1749,9 +1739,7 @@ static int32_t defsparser(scriptfile *script) char *fn[6] = {0,0,0,0,0,0}; char *modelend; int32_t i, tile = -1, pal = 0, happy = 1; -#ifdef USE_OPENGL - int32_t flags = 0; -#endif + int flags = 0; static const tokenlist skyboxtokens[] = { @@ -1792,15 +1780,10 @@ static int32_t defsparser(scriptfile *script) case T_BOTTOM: scriptfile_getstring(script,&fn[5]); break; #ifdef USE_OPENGL - case T_NOCOMPRESS: - flags |= HICR_NOTEXCOMPRESS; break; - case T_NODOWNSIZE: - flags |= HICR_NODOWNSIZE; break; - case T_FORCEFILTER: - flags |= HICR_FORCEFILTER; break; - case T_ARTQUALITY: - flags |= HICR_ARTIMMUNITY; break; + case T_FORCEFILTER: + flags |= HICR_FORCEFILTER; break; #endif + } } @@ -1814,9 +1797,7 @@ static int32_t defsparser(scriptfile *script) } if (!happy) break; -#ifdef USE_OPENGL - hicsetskybox(tile,pal,fn, flags); -#endif + tileSetSkybox(tile, pal, (const char **)fn, flags); } break; case T_HIGHPALOOKUP: @@ -2065,9 +2046,7 @@ static int32_t defsparser(scriptfile *script) int32_t pal=-1, xsiz = 0, ysiz = 0; char *fn = NULL; double alphacut = -1.0, xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0; -#ifdef USE_OPENGL - char flags = 0; -#endif + uint8_t flags = 0; static const tokenlist texturetokens_pal[] = { @@ -2102,16 +2081,6 @@ static int32_t defsparser(scriptfile *script) scriptfile_getdouble(script,&specpower); break; case T_SPECFACTOR: scriptfile_getdouble(script,&specfactor); break; -#ifdef USE_OPENGL - case T_NOCOMPRESS: - flags |= HICR_NOTEXCOMPRESS; break; - case T_NODOWNSIZE: - flags |= HICR_NODOWNSIZE; break; - case T_FORCEFILTER: - flags |= HICR_FORCEFILTER; break; - case T_ARTQUALITY: - flags |= HICR_ARTIMMUNITY; break; -#endif case T_ORIGSIZEX: scriptfile_getnumber(script, &xsiz); break; @@ -2144,21 +2113,17 @@ static int32_t defsparser(scriptfile *script) { tileSetDummy(tile, xsiz, ysiz); } -#ifdef USE_OPENGL xscale = 1.0f / xscale; yscale = 1.0f / yscale; - hicsetsubsttex(tile,pal,fn,alphacut,xscale,yscale, specpower, specfactor,flags); -#endif + tileSetHightileReplacement(tile,pal,fn,alphacut,xscale,yscale, specpower, specfactor,flags); } break; case T_DETAIL: case T_GLOW: case T_SPECULAR: case T_NORMAL: { char *detailtokptr = script->ltextptr, *detailend; -#ifdef USE_OPENGL int32_t pal = 0; char flags = 0; -#endif char *fn = NULL; double xscale = 1.0, yscale = 1.0, specpower = 1.0, specfactor = 1.0; @@ -2191,16 +2156,6 @@ static int32_t defsparser(scriptfile *script) scriptfile_getdouble(script,&specpower); break; case T_SPECFACTOR: scriptfile_getdouble(script,&specfactor); break; -#ifdef USE_OPENGL - case T_NOCOMPRESS: - flags |= HICR_NOTEXCOMPRESS; break; - case T_NODOWNSIZE: - flags |= HICR_NODOWNSIZE; break; - case T_FORCEFILTER: - flags |= HICR_FORCEFILTER; break; - case T_ARTQUALITY: - flags |= HICR_ARTIMMUNITY; break; -#endif default: break; } @@ -2217,7 +2172,6 @@ static int32_t defsparser(scriptfile *script) if (EDUKE32_PREDICT_FALSE(check_file_exist(fn))) break; -#ifdef USE_OPENGL switch (token) { case T_DETAIL: @@ -2235,8 +2189,7 @@ static int32_t defsparser(scriptfile *script) pal = NORMALPAL; break; } - hicsetsubsttex(tile,pal,fn,-1.0f,xscale,yscale, specpower, specfactor,flags); -#endif + tileSetHightileReplacement(tile,pal,fn,-1.0f,xscale,yscale, specpower, specfactor,flags); } break; default: @@ -2308,10 +2261,6 @@ static int32_t defsparser(scriptfile *script) case T_UNDEFTEXTURERANGE: { int32_t r0,r1; -#ifdef USE_OPENGL - int32_t i; -#endif - if (EDUKE32_PREDICT_FALSE(scriptfile_getsymbol(script,&r0))) break; if (tokn == T_UNDEFTEXTURERANGE) { @@ -2327,12 +2276,7 @@ static int32_t defsparser(scriptfile *script) if (EDUKE32_PREDICT_FALSE(check_tile("undeftexture", r0, script, cmdtokptr))) break; } - -#ifdef USE_OPENGL - for (; r0 <= r1; r0++) - for (i=MAXPALOOKUPS-1; i>=0; i--) - hicclearsubst(r0,i); -#endif + for (; r0 <= r1; r0++) tileRemoveReplacement(r0); } break; diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 1fcbfcec0..33de62b29 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -8197,7 +8197,6 @@ int32_t engineInit(void) paletteLoadFromDisk(); #ifdef USE_OPENGL - if (!hicinitcounter) hicinit(); if (!mdinited) mdinit(); #endif diff --git a/source/build/src/hightile.cpp b/source/build/src/hightile.cpp index 381723909..d4027f226 100644 --- a/source/build/src/hightile.cpp +++ b/source/build/src/hightile.cpp @@ -5,9 +5,6 @@ */ #include "build.h" - -#ifdef USE_OPENGL - #include "compat.h" #include "kplib.h" #include "hightile.h" @@ -16,56 +13,6 @@ polytint_t hictinting[MAXPALOOKUPS]; -hicreplctyp *hicreplc[MAXTILES]; -int32_t hicinitcounter = 0; - -// -// find the index into hicreplc[] which contains the replacement tile particulars -// -hicreplctyp *hicfindsubst(int picnum, int palnum, int nozero) -{ - if (!hicreplc[picnum] || !hicinitcounter) return NULL; - - do - { - hicreplctyp *hr = hicreplc[picnum]; - for (; hr; hr = hr->next) - if (hr->palnum == palnum) - return hr; - - if (!palnum || nozero) - return NULL; - - palnum = 0; - } while (1); - - return NULL; // no replacement found -} - -// -// this is separate because it's not worth passing an extra parameter which is "0" in 99.9999% of cases -// to the regular hicfindsubst() function -// -hicreplctyp *hicfindskybox(int picnum, int palnum, int nozero) -{ - if (!hicreplc[picnum] || !hicinitcounter) return NULL; - - do - { - hicreplctyp *hr = hicreplc[picnum]; - for (; hr; hr = hr->next) - if (hr->skybox && hr->palnum == palnum) - return hr; - - if (!palnum || nozero) - return NULL; - - palnum = 0; - } while (1); - - return NULL; // no replacement found -} - // // hicinit() @@ -81,36 +28,6 @@ void hicinit(void) tint.r = tint.g = tint.b = 0xff; tint.f = 0; } - - if (hicinitcounter) - { - hicreplctyp *hr, *next; - int32_t j; - - for (i=MAXTILES-1; i>=0; i--) - { - for (hr=hicreplc[i]; hr;) - { - next = hr->next; - - if (hr->skybox) - { - for (j=5; j>=0; j--) - Xfree(hr->skybox->face[j]); - Xfree(hr->skybox); - } - - Xfree(hr->filename); - Xfree(hr); - - hr = next; - } - } - } - - Bmemset(hicreplc,0,sizeof(hicreplc)); - - hicinitcounter++; } @@ -123,7 +40,6 @@ void hicinit(void) void hicsetpalettetint(int32_t palnum, char r, char g, char b, char sr, char sg, char sb, polytintflags_t effect) { if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return; - if (!hicinitcounter) hicinit(); polytint_t & tint = hictinting[palnum]; tint.r = r; @@ -136,191 +52,4 @@ void hicsetpalettetint(int32_t palnum, char r, char g, char b, char sr, char sg, } -// -// hicsetsubsttex(picnum,pal,filen,alphacut) -// Specifies a replacement graphic file for an ART tile. -// -int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float alphacut, float xscale, float yscale, float specpower, float specfactor, char flags) -{ - hicreplctyp *hr, *hrn; - - if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1; - if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1; - if (!hicinitcounter) hicinit(); - - for (hr = hicreplc[picnum]; hr; hr = hr->next) - { - if (hr->palnum == palnum) - break; - } - - if (!hr) - { - // no replacement yet defined - hrn = (hicreplctyp *)Xcalloc(1,sizeof(hicreplctyp)); - hrn->palnum = palnum; - } - else hrn = hr; - - // store into hicreplc the details for this replacement - Xfree(hrn->filename); - - hrn->filename = Xstrdup(filen); - hrn->alphacut = min(alphacut,1.f); - hrn->scale.x = xscale; - hrn->scale.y = yscale; - hrn->specpower = specpower; - hrn->specfactor = specfactor; - hrn->flags = flags; - if (hr == NULL) - { - hrn->next = hicreplc[picnum]; - hicreplc[picnum] = hrn; - } - - if (tilesiz[picnum].x<=0 || tilesiz[picnum].y<=0) - { - static int32_t first=1; - if (first) - { - initprintf("Warning: defined hightile replacement for empty tile %d.", picnum); - initprintf(" Maybe some tilesXXX.art are not loaded?"); - initprintf("\n"); - first = 0; - } - } - - //printf("Replacement [%d,%d]: %s\n", picnum, palnum, hicreplc[i]->filename); - - return 0; -} - - -// -// hicsetskybox(picnum,pal,faces[6]) -// Specifies a graphic files making up a skybox. -// -int32_t hicsetskybox( int32_t picnum, int32_t palnum, char *faces[6], int32_t flags ) -{ - hicreplctyp *hr, *hrn; - int32_t j; - - if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1; - if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1; - for (j=5; j>=0; j--) if (!faces[j]) return -1; - if (!hicinitcounter) hicinit(); - - for (hr = hicreplc[picnum]; hr; hr = hr->next) - { - if (hr->palnum == palnum) - break; - } - - if (!hr) - { - // no replacement yet defined - hrn = (hicreplctyp *)Xcalloc(1,sizeof(hicreplctyp)); - hrn->palnum = palnum; - } - else hrn = hr; - - if (!hrn->skybox) - hrn->skybox = (struct hicskybox_t *)Xcalloc(1,sizeof(struct hicskybox_t)); - else - { - for (j=0; j<6; j++) - DO_FREE_AND_NULL(hrn->skybox->face[j]); - } - - // store each face's filename - for (j=0; j<6; j++) - hrn->skybox->face[j] = Xstrdup(faces[j]); - - hrn->flags = flags; - - if (hr == NULL) - { - hrn->next = hicreplc[picnum]; - hicreplc[picnum] = hrn; - } - - return 0; -} - - -// -// hicclearsubst(picnum,pal) -// Clears a replacement for an ART tile, including skybox faces. -// -int32_t hicclearsubst(int32_t picnum, int32_t palnum) -{ - hicreplctyp *hr, *hrn = NULL; - - if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1; - if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1; - if (!hicinitcounter) return 0; - - for (hr = hicreplc[picnum]; hr; hrn = hr, hr = hr->next) - { - if (hr->palnum == palnum) - break; - } - - if (!hr) return 0; - - Xfree(hr->filename); - if (hr->skybox) - { - int32_t i; - for (i=5; i>=0; i--) - Xfree(hr->skybox->face[i]); - Xfree(hr->skybox); - } - - if (hrn) hrn->next = hr->next; - else hicreplc[picnum] = hr->next; - Xfree(hr); - - return 0; -} - -#else /* USE_OPENGL */ - -#include "compat.h" - -void hicsetpalettetint(int32_t palnum, char r, char g, char b, char sr, char sg, char sb, polytintflags_t effect) -{ - UNREFERENCED_PARAMETER(palnum); - UNREFERENCED_PARAMETER(r); - UNREFERENCED_PARAMETER(g); - UNREFERENCED_PARAMETER(b); - UNREFERENCED_PARAMETER(sr); - UNREFERENCED_PARAMETER(sg); - UNREFERENCED_PARAMETER(sb); - UNREFERENCED_PARAMETER(effect); -} -int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float alphacut) -{ - UNREFERENCED_PARAMETER(picnum); - UNREFERENCED_PARAMETER(palnum); - UNREFERENCED_PARAMETER(filen); - UNREFERENCED_PARAMETER(alphacut); - return 0; -} -int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6], int32_t flags) -{ - UNREFERENCED_PARAMETER(picnum); - UNREFERENCED_PARAMETER(palnum); - UNREFERENCED_PARAMETER(faces); - UNREFERENCED_PARAMETER(flags); - return 0; -} -int32_t hicclearsubst(int32_t picnum, int32_t palnum) -{ - UNREFERENCED_PARAMETER(picnum); - UNREFERENCED_PARAMETER(palnum); - return 0; -} - -#endif diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 6796718bc..0c1076c65 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -513,18 +513,9 @@ int32_t polymost_maskWallHasTranslucency(uwalltype const * const wall) if (wall->cstat & CSTAT_WALL_TRANSLUCENT) return true; - //POGO: only hightiles may have translucency in their texture - if (!usehightile) - return false; - - hicreplctyp* si = hicfindsubst(wall->picnum, wall->pal, hictinting[wall->pal].f & HICTINT_ALWAYSUSEART); - if (!si) return false; // regular tiles have no translucency - - uint8_t pal = wall->pal; - if (palookup[pal] == NULL) - pal = 0; - - auto tex = TileFiles.GetTexture(si->filename); + auto tex = TileFiles.tiles[wall->picnum]; + auto si = tex->FindReplacement(wall->pal); + if (si && usehightile) tex = si->faces[0]; return tex && tex->GetTranslucency(); } @@ -534,18 +525,9 @@ int32_t polymost_spriteHasTranslucency(uspritetype const * const tspr) ((unsigned)tspr->owner < MAXSPRITES && spriteext[tspr->owner].alpha)) return true; - //POGO: only hightiles may have translucency in their texture - if (!usehightile) - return false; - - hicreplctyp* si = hicfindsubst(tspr->picnum, tspr->shade, hictinting[tspr->shade].f & HICTINT_ALWAYSUSEART); - if (!si) return false; // regular tiles have no translucency - - uint8_t pal = tspr->shade; - if (palookup[pal] == NULL) - pal = 0; - - auto tex = TileFiles.GetTexture(si->filename); + auto tex = TileFiles.tiles[tspr->picnum]; + auto si = tex->FindReplacement(tspr->shade, hictinting[tspr->shade].f & HICTINT_ALWAYSUSEART); + if (si && usehightile) tex = si->faces[0]; return tex && tex->GetTranslucency(); } @@ -2076,8 +2058,7 @@ static void polymost_internal_nonparallaxed(vec2f_t n0, vec2f_t n1, float ryp0, drawpoly_alpha = 0.f; drawpoly_blend = 0; - //if ((usehightile && hicfindsubst(globalpicnum, globalpal, hictinting[globalpal].f & HICTINT_ALWAYSUSEART))) - calc_and_apply_fog(fogshade(global_cf_shade, global_cf_pal), sec->visibility, POLYMOST_CHOOSE_FOG_PAL(global_cf_fogpal, global_cf_pal)); + calc_and_apply_fog(fogshade(global_cf_shade, global_cf_pal), sec->visibility, POLYMOST_CHOOSE_FOG_PAL(global_cf_fogpal, global_cf_pal)); if (have_floor) { @@ -2544,9 +2525,7 @@ static void polymost_drawalls(int32_t const bunch) } else if ((nextsectnum < 0) || (!(sector[nextsectnum].floorstat&1))) { - //Parallaxing sky... hacked for Ken's mountain texture - //if ((usehightile && hicfindsubst(globalpicnum, globalpal, hictinting[globalpal].f & HICTINT_ALWAYSUSEART))) - calc_and_apply_fog_factor(sec->floorshade, sec->visibility, sec->floorpal, 0.005f); + calc_and_apply_fog_factor(sec->floorshade, sec->visibility, sec->floorpal, 0.005f); globvis2 = globalpisibility; if (sec->visibility != 0) @@ -2806,9 +2785,7 @@ static void polymost_drawalls(int32_t const bunch) } else if ((nextsectnum < 0) || (!(sector[nextsectnum].ceilingstat&1))) { - //Parallaxing sky... hacked for Ken's mountain texture - //if ((usehightile && hicfindsubst(globalpicnum, globalpal, hictinting[globalpal].f & HICTINT_ALWAYSUSEART))) - calc_and_apply_fog_factor(sec->ceilingshade, sec->visibility, sec->ceilingpal, 0.005f); + calc_and_apply_fog_factor(sec->ceilingshade, sec->visibility, sec->ceilingpal, 0.005f); globvis2 = globalpisibility; if (sec->visibility != 0) @@ -3122,8 +3099,7 @@ static void polymost_drawalls(int32_t const bunch) } if (wal->cstat&256) { xtex.v = -xtex.v; ytex.v = -ytex.v; otex.v = -otex.v; } //yflip - //if ((usehightile && hicfindsubst(globalpicnum, globalpal, hictinting[globalpal].f & HICTINT_ALWAYSUSEART))) - calc_and_apply_fog(fogshade(wal->shade, wal->pal), sec->visibility, get_floor_fogpal(sec)); + calc_and_apply_fog(fogshade(wal->shade, wal->pal), sec->visibility, get_floor_fogpal(sec)); pow2xsplit = 1; #ifdef YAX_ENABLE @@ -3167,8 +3143,7 @@ static void polymost_drawalls(int32_t const bunch) } if (nwal->cstat&256) { xtex.v = -xtex.v; ytex.v = -ytex.v; otex.v = -otex.v; } //yflip - //if ((usehightile && hicfindsubst(globalpicnum, globalpal, hictinting[globalpal].f & HICTINT_ALWAYSUSEART))) - calc_and_apply_fog(fogshade(nwal->shade, nwal->pal), sec->visibility, get_floor_fogpal(sec)); + calc_and_apply_fog(fogshade(nwal->shade, nwal->pal), sec->visibility, get_floor_fogpal(sec)); pow2xsplit = 1; #ifdef YAX_ENABLE @@ -3224,8 +3199,7 @@ static void polymost_drawalls(int32_t const bunch) } if (wal->cstat&256) { xtex.v = -xtex.v; ytex.v = -ytex.v; otex.v = -otex.v; } //yflip - //if ((usehightile && hicfindsubst(globalpicnum, globalpal, hictinting[globalpal].f & HICTINT_ALWAYSUSEART))) - calc_and_apply_fog(fogshade(wal->shade, wal->pal), sec->visibility, get_floor_fogpal(sec)); + calc_and_apply_fog(fogshade(wal->shade, wal->pal), sec->visibility, get_floor_fogpal(sec)); pow2xsplit = 1; @@ -3904,8 +3878,7 @@ static void polymost_drawmaskwallinternal(int32_t wallIndex) drawpoly_alpha = 0.f; drawpoly_blend = blend; - //if ((usehightile && hicfindsubst(globalpicnum, globalpal, hictinting[globalpal].f & HICTINT_ALWAYSUSEART))) - calc_and_apply_fog(fogshade(wal->shade, wal->pal), sec->visibility, get_floor_fogpal(sec)); + calc_and_apply_fog(fogshade(wal->shade, wal->pal), sec->visibility, get_floor_fogpal(sec)); float const csy[4] = { ((float)(cz[0] - globalposz)) * ryp0 + ghoriz, ((float)(cz[1] - globalposz)) * ryp0 + ghoriz, @@ -4215,9 +4188,7 @@ void polymost_drawsprite(int32_t snum) sec = (usectorptr_t)§or[tspr->sectnum]; - //if ((usehightile && hicfindsubst(globalpicnum, globalpal, hictinting[globalpal].f & HICTINT_ALWAYSUSEART)) - //|| (usemodels && md_tilehasmodel(globalpicnum, globalpal) >= 0)) - calc_and_apply_fog(fogshade(globalshade, globalpal), sec->visibility, get_floor_fogpal(sec)); + calc_and_apply_fog(fogshade(globalshade, globalpal), sec->visibility, get_floor_fogpal(sec)); while (!(spriteext[spritenum].flags & SPREXT_NOTMD)) { diff --git a/source/build/src/texcache.cpp b/source/build/src/texcache.cpp index e16bbe9b2..bfa0a420c 100644 --- a/source/build/src/texcache.cpp +++ b/source/build/src/texcache.cpp @@ -341,9 +341,6 @@ pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int3 if (!tilestat) continue; - if (tilestat == -2) // bad filename - hicclearsubst(dapicnum, dapalnum); - return (drawingskybox || hicprecaching) ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); } @@ -366,10 +363,6 @@ pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int3 texcache.list[j] = pth; return pth; } - - if (tilestat == -2) // bad filename - hicclearsubst(dapicnum, dapalnum); - Xfree(pth); return (drawingskybox || hicprecaching) ? NULL : texcache_tryart(dapicnum, dapalnum, dashade, dameth); diff --git a/source/common/textures/buildtiles.cpp b/source/common/textures/buildtiles.cpp index eee7e8f04..5a09c22a4 100644 --- a/source/common/textures/buildtiles.cpp +++ b/source/common/textures/buildtiles.cpp @@ -439,7 +439,7 @@ int tileImportFromTexture(const char* fn, int tilenum, int alphacut, int istextu //#if 0 // Does this make any difference when the texture gets *properly* inserted into the tile array? //if (istexture) - hicsetsubsttex(tilenum, 0, fn, (float)(255 - alphacut) * (1.f / 255.f), 1.0f, 1.0f, 1.0, 1.0, 0); // At the moment this is the only way to load the texture. The texture creation code is not ready yet for downconverting an image. + tileSetHightileReplacement(tilenum, 0, fn, (float)(255 - alphacut) * (1.f / 255.f), 1.0f, 1.0f, 1.0, 1.0, 0); // At the moment this is the only way to load the texture. The texture creation code is not ready yet for downconverting an image. //#endif return 0; @@ -538,9 +538,20 @@ void tileDelete(int tile) TileFiles.tiles[tile] = TileFiles.tilesbak[tile] = TileFiles.Placeholder; vox_undefine(tile); md_undefinetile(tile); - for (ssize_t i = MAXPALOOKUPS - 1; i >= 0; --i) - hicclearsubst(tile, i); + tileRemoveReplacement(tile); +} +//========================================================================== +// +// +// +//========================================================================== + +void tileRemoveReplacement(int tile) +{ + if ((unsigned)tileNum >= MAXTILES) return false; + FTexture *tex = TileFiles.tiles[tile]; + tex->DeleteReplacements(); } //========================================================================== @@ -674,6 +685,92 @@ void BuildFiles::CloseAll() Placeholder = nullptr; } +//========================================================================== +// +// Specifies a replacement texture for an ART tile. +// +//========================================================================== + +int tileSetHightileReplacement(int picnum, int palnum, const char *filename, float alphacut, float xscale, float yscale, float specpower, float specfactor, uint8_t flags) +{ + if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1; + if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1; + + auto tex = TileFiles.tiles[picnum]; + if (tex->GetWidth() <= 0 || tex->GetHeight() <= 0) + { + initprintf("Warning: defined hightile replacement for empty tile %d.", picnum); + return -1; // cannot add replacements to empty tiles, must create one beforehand + } + HightileReplacement replace = {}; + + replace.faces[0] = TileFiles.GetTexture(filename); + if (replace.faces[0] == nullptr) + { + initprintf("%s: Replacement for tile %d does not exist or is invalid\n", filename, picnum); + return -1; + } + replace.alphacut = min(alphacut,1.f); + replace.scale = { xscale, yscale }; + replace.specpower = specpower; // currently unused + replace.specfactor = specfactor; // currently unused + replace.flags = flags; + replace.palnum = (uint8_t)palnum; + tex->AddReplacement(replace); + return 0; +} + + +//========================================================================== +// +// Define the faces of a skybox +// +//========================================================================== + +int tileSetSkybox(int picnum, int palnum, const char **facenames, int flags ) +{ + if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1; + if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1; + + if (tex->GetWidth() <= 0 || tex->GetHeight() <= 0) + { + initprintf("Warning: defined skybox replacement for empty tile %d.", picnum); + return -1; // cannot add replacements to empty tiles, must create one beforehand + } + HightileReplacement replace = {}; + + for (auto &face : replace.faces) + { + face = TileFiles.GetTexture(*facenames); + if (face == nullptr) + { + initprintf("%s: Skybox image for tile %d does not exist or is invalid\n", *facenames, picnum); + return -1; + } + } + replace.flags = flags; + replace.palnum = (uint8_t)palnum; + tex->AddReplacement(replace); + return 0; +} + +//========================================================================== +// +// Remove a replacement +// +//========================================================================== + +int tileDeleteReplacement(int picnum, int palnum) +{ + if ((uint32_t)picnum >= (uint32_t)MAXTILES) return -1; + if ((uint32_t)palnum >= (uint32_t)MAXPALOOKUPS) return -1; + auto tex = TileFiles.tiles[picnum]; + tex->DeleteReplacement(palnum); + return 0; +} + + + TileSiz tilesiz; PicAnm picanm; diff --git a/source/common/textures/texture.cpp b/source/common/textures/texture.cpp index db9f9c827..94ce33bba 100644 --- a/source/common/textures/texture.cpp +++ b/source/common/textures/texture.cpp @@ -400,6 +400,53 @@ void FTexture::Create8BitPixels(uint8_t *buffer) // The base class does not fill the texture. } +//=========================================================================== +// +// Replacement textures +// +//=========================================================================== + +void FTexture::AddReplacement(const HightileReplacement & replace) +{ + for (auto &ht : Hightiles) + { + if (replace.palnum == ht.palnum && (replace.faces[1] == nullptr) == (ht.faces[1] == nullptr)) + { + ht = replace; + return; + } + } + Hightiles.Push(replace); +} + +void FTexture::DeleteReplacement(int palnum) +{ + for (int i = Hightiles.Size() -1; i >= 0; i--) + { + if (Hightiles[i].palnum == palnum) Hightiles.Delete(i); + } +} + +//=========================================================================== +// +// +// +//=========================================================================== + +HightileReplacement *FTexture::FindReplacement(int palnum, int nozero, bool skybox) +{ + for(;;) + { + for (auto &rep : Hightiles) + { + if (rep.palnum == palnum && (rep.faces[1] != nullptr) == skybox) return &rep; + } + if (!palnum || nozero) break; + palnum = 0; + } + return nullptr; // no replacement found +} + #if 0 //========================================================================== // diff --git a/source/common/textures/textures.h b/source/common/textures/textures.h index ef12b0370..8fedb3746 100644 --- a/source/common/textures/textures.h +++ b/source/common/textures/textures.h @@ -100,6 +100,13 @@ struct rottile_t int16_t owner; }; +struct HightileReplacement +{ + FTexture *faces[6]; // only one gets used by a texture, the other 5 are for skyboxes only + vec2f_t scale; + float alphacut, specpower, specfactor; + uint8_t palnum, flags; +}; class FBitmap; struct FRemapTable; @@ -234,7 +241,15 @@ public: bool ProcessData(unsigned char * buffer, int w, int h, bool ispatch); virtual void Reload() {} UseType GetUseType() const { return useType; } + void AddReplacement(const HightileReplacement &); + void DeleteReplacement(int palnum); + void DeleteReplacements() + { + Hightiles.Clear(); + } + HightileReplacement * FindReplacement(int palnum, int nozero = 0, bool skybox = false); + int alphaThreshold = 128; picanm_t PicAnim = {}; @@ -282,6 +297,7 @@ protected: PalEntry CeilingSkyColor; intptr_t CacheHandle = 0; // For tiles that do not have a static image but get accessed by the software renderer. uint8_t CacheLock = 0; + TArray Hightiles; FTexture (const char *name = NULL); }; @@ -525,10 +541,14 @@ int tileImportFromTexture(const char* fn, int tilenum, int alphacut, int istextu void tileCopy(int tile, int tempsource, int temppal, int xoffset, int yoffset, int flags); void tileSetDummy(int tile, int width, int height); void tileDelete(int tile); +void tileRemoveReplacement(int tile); bool tileLoad(int tileNum); void artClearMapArt(void); void artSetupMapArt(const char* filename); void tileSetAnim(int tile, const picanm_t& anm); +int tileSetHightileReplacement(int picnum, int palnum, const char *filen, float alphacut, float xscale, float yscale, float specpower, float specfactor, uint8_t flags); +int tileSetSkybox(int picnum, int palnum, const char **facenames, int flags ); +int tileDeleteReplacement(int picnum, int palnum); extern BuildFiles TileFiles; inline bool tileCheck(int num)