From 5352682697cffd237cc43a163c417777d9e60b5d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 00:33:12 +0200 Subject: [PATCH] - moved the front layer hack for Hexen's skies to the texture manager. --- src/common/textures/texture.cpp | 26 ------------- src/common/textures/texturemanager.cpp | 38 +++++++++++++++++-- src/common/textures/texturemanager.h | 4 +- src/common/textures/textures.h | 1 - src/rendering/hwrenderer/scene/hw_sky.cpp | 1 - src/rendering/r_sky.cpp | 9 +++-- .../swrenderer/line/r_renderdrawsegment.cpp | 2 +- src/rendering/swrenderer/plane/r_skyplane.cpp | 2 +- .../swrenderer/textures/r_swtexture.cpp | 11 +----- .../swrenderer/textures/r_swtexture.h | 2 +- 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index a5e6e138e..6d19723f5 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -217,32 +217,6 @@ FGameTexture *FGameTexture::GetRawTexture() return tex->OffsetLess; } -//========================================================================== -// -// Same shit for a different hack, this time Hexen's front sky layers. -// -//========================================================================== - -FGameTexture* FGameTexture::GetFrontSkyLayer() -{ - auto tex = GetTexture(); - if (tex->FrontSkyLayer) return tex->FrontSkyLayer; - // Reject anything that cannot have been a front layer for the sky in Hexen. - auto image = tex->GetImage(); - if (image == nullptr || !image->SupportRemap0() || GetUseType() != ETextureType::Wall || tex->Scale.X != 1 || tex->Scale.Y != 1 || useWorldPanning() || tex->_TopOffset[0] != 0 || - image->GetWidth() != GetTexelWidth() || image->GetHeight() != GetTexelHeight()) - { - tex->FrontSkyLayer = this; - return this; - } - - tex->FrontSkyLayer = MakeGameTexture(new FImageTexture(image, "")); - TexMan.AddGameTexture(tex->FrontSkyLayer); - tex->FrontSkyLayer->GetTexture()->bNoRemap0 = true; - return tex->FrontSkyLayer; -} - - void FTexture::SetDisplaySize(int fitwidth, int fitheight) { Scale.X = double(Width) / fitwidth; diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 410a2c9a4..3a25f0a0b 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -375,7 +375,7 @@ bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitut // //========================================================================== -FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) +FTextureID FTextureManager::AddGameTexture (FGameTexture *texture, bool addtohash) { int bucket; int hash; @@ -385,7 +385,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) // Later textures take precedence over earlier ones // Textures without name can't be looked for - if (texture->GetName().IsNotEmpty()) + if (addtohash && texture->GetName().IsNotEmpty()) { bucket = int(MakeKey (texture->GetName()) % HASH_SIZE); hash = HashFirst[bucket]; @@ -396,7 +396,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) hash = -1; } - TextureHash hasher = { texture, -1, hash }; + TextureHash hasher = { texture, -1, -1, hash }; int trans = Textures.Push (hasher); Translation.Push (trans); if (bucket >= 0) HashFirst[bucket] = trans; @@ -1176,6 +1176,38 @@ void FTextureManager::InitPalettedVersions() } } +//========================================================================== +// +// Same shit for a different hack, this time Hexen's front sky layers. +// +//========================================================================== + +FTextureID FTextureManager::GetFrontSkyLayer(FTextureID texid) +{ + int texidx = texid.GetIndex(); + if (texidx >= Textures.Size()) return texid; + if (Textures[texidx].FrontSkyLayer != -1) return FSetTextureID(Textures[texidx].FrontSkyLayer); + + // Reject anything that cannot have been a front layer for the sky in original Hexen, i.e. it needs to be an unscaled wall texture only using Doom patches. + auto tex = Textures[texidx].Texture; + auto image = tex->GetTexture()->GetImage(); + if (image == nullptr || !image->SupportRemap0() || tex->GetUseType() != ETextureType::Wall || tex->useWorldPanning() || tex->GetTexelTopOffset() != 0 || + tex->GetTexelWidth() != tex->GetDisplayWidth() || tex->GetTexelHeight() != tex->GetDisplayHeight()) + { + Textures[texidx].FrontSkyLayer = texidx; + return texid; + } + + // Set this up so that it serializes to the same info as the base texture - this is needed to restore it on load. + auto FrontSkyLayer = MakeGameTexture(new FImageTexture(image, tex->GetName())); + FrontSkyLayer->SetUseType(tex->GetUseType()); + FrontSkyLayer->GetTexture()->bNoRemap0 = true; + texid = TexMan.AddGameTexture(FrontSkyLayer); + Textures[texidx].FrontSkyLayer = texid.GetIndex(); + Textures[texid.GetIndex()].FrontSkyLayer = texid.GetIndex(); // also let it refer to itself as its front sky layer, in case for repeated InitSkyMap calls. + return texid; +} + //========================================================================== // // diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 9fdb22a8d..2b3bb0829 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -75,6 +75,7 @@ public: bool OkForLocalization(FTextureID texnum, const char *substitute, int locnum); void FlushAll(); + FTextureID GetFrontSkyLayer(FTextureID); enum @@ -113,7 +114,7 @@ public: void AddLocalizedVariants(); FTextureID CreateTexture (int lumpnum, ETextureType usetype=ETextureType::Any); // Also calls AddTexture - FTextureID AddGameTexture(FGameTexture* texture); + FTextureID AddGameTexture(FGameTexture* texture, bool addtohash = true); FTextureID GetDefaultTexture() const { return DefaultTexture; } void LoadTextureX(int wadnum, FMultipatchTextureBuilder &build); @@ -171,6 +172,7 @@ private: { FGameTexture* Texture; int Paletted; // redirection to paletted variant + int FrontSkyLayer; int HashNext; bool HasLocalization; }; diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index abfabd386..ed438e36a 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -719,7 +719,6 @@ public: // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. FGameTexture* GetRawTexture(); - FGameTexture* GetFrontSkyLayer(); // Glowing is a pure material property that should not filter down to the actual texture objects. void GetGlowColor(float* data) { wrapped.GetGlowColor(data); } diff --git a/src/rendering/hwrenderer/scene/hw_sky.cpp b/src/rendering/hwrenderer/scene/hw_sky.cpp index af2328bbc..5a0c4f139 100644 --- a/src/rendering/hwrenderer/scene/hw_sky.cpp +++ b/src/rendering/hwrenderer/scene/hw_sky.cpp @@ -75,7 +75,6 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) if (di->Level->flags&LEVEL_DOUBLESKY) { auto tex1 = TexMan.GetGameTexture(di->Level->skytexture1, true); - if (tex1) tex1 = tex1->GetFrontSkyLayer(); texture[1] = tex1; x_offset[1] = di->Level->hw_sky1pos; doublesky = true; diff --git a/src/rendering/r_sky.cpp b/src/rendering/r_sky.cpp index b51a44783..051068162 100644 --- a/src/rendering/r_sky.cpp +++ b/src/rendering/r_sky.cpp @@ -75,6 +75,11 @@ void InitSkyMap(FLevelLocals *Level) { Level->skytexture2 = TexMan.CheckForTexture("-noflat-", ETextureType::Any); } + if (Level->flags & LEVEL_DOUBLESKY) + { + Level->skytexture1 = TexMan.GetFrontSkyLayer(Level->skytexture1); + } + skytex1 = TexMan.GetGameTexture(Level->skytexture1, false); skytex2 = TexMan.GetGameTexture(Level->skytexture2, false); @@ -82,10 +87,6 @@ void InitSkyMap(FLevelLocals *Level) if (skytex1 == nullptr) return; - if (Level->flags & LEVEL_DOUBLESKY) - { - skytex1 = skytex1->GetFrontSkyLayer(); - } if ((Level->flags & LEVEL_DOUBLESKY) && skytex1->GetDisplayHeight() != skytex2->GetDisplayHeight()) { diff --git a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp index 4d203ec4a..041e96b18 100644 --- a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp @@ -91,7 +91,7 @@ namespace swrenderer auto viewport = Thread->Viewport.get(); Clip3DFloors *clip3d = Thread->Clip3D.get(); - auto tex = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::mid), true, curline->GetLevel()); + auto tex = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::mid), true, !!(curline->GetLevel()->i_compatflags & COMPATF_MASKEDMIDTEX)); const short *mfloorclip = ds->drawsegclip.sprbottomclip; const short *mceilingclip = ds->drawsegclip.sprtopclip; diff --git a/src/rendering/swrenderer/plane/r_skyplane.cpp b/src/rendering/swrenderer/plane/r_skyplane.cpp index 7276aa604..5b9b60c4c 100644 --- a/src/rendering/swrenderer/plane/r_skyplane.cpp +++ b/src/rendering/swrenderer/plane/r_skyplane.cpp @@ -71,7 +71,7 @@ namespace swrenderer Thread = thread; auto Level = Thread->Viewport->Level(); - auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true, !!(Level->flags & LEVEL_DOUBLESKY)); + auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true); auto sskytex2 = GetPalettedSWTexture(Level->skytexture2, true, nullptr, true); if (sskytex1 == nullptr) diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index ef7d3decb..5094aa355 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -612,19 +612,12 @@ CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL) R_InitSkyMap(); } -FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat, bool allownull, bool frontsky) +FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool checkcompat, bool allownull) { bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor(); auto tex = TexMan.GetPalettedTexture(texid, true, needpal); if (tex == nullptr || (!allownull && !tex->isValid())) return nullptr; - if (frontsky) - { - tex = tex->GetFrontSkyLayer(); - } - else if (checkcompat && checkcompat->i_compatflags & COMPATF_MASKEDMIDTEX) - { - tex = tex->GetRawTexture(); - } + if (checkcompat) tex = tex->GetRawTexture(); return GetSoftwareTexture(tex); } diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index 595acbd77..bf9a83c5a 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -193,4 +193,4 @@ public: }; FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex); -FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat = nullptr, bool allownull = false, bool frontsky = false); +FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool checkcompat = false, bool allownull = false);