From da873ca8d111c5fd298a5901798ce7114d7f1e5f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 00:27:12 +0200 Subject: [PATCH] - moved the handling for paletted replacements into the texture manager. This is something the texture should not concern itself with. --- src/common/textures/texturemanager.cpp | 9 ++---- src/common/textures/texturemanager.h | 30 ++++++++++++++++--- src/common/textures/textures.h | 7 ----- .../swrenderer/textures/r_swtexture.cpp | 12 ++------ 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 32d66d1b0d..410a2c9a48 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -396,7 +396,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) hash = -1; } - TextureHash hasher = { texture, hash }; + TextureHash hasher = { texture, -1, hash }; int trans = Textures.Push (hasher); Translation.Push (trans); if (bucket >= 0) HashFirst[bucket] = trans; @@ -1166,14 +1166,11 @@ void FTextureManager::InitPalettedVersions() FTextureID pic2 = CheckForTexture(sc.String, ETextureType::Any); if (!pic2.isValid()) { - sc.ScriptMessage("Unknown texture %s to use as replacement", sc.String); + sc.ScriptMessage("Unknown texture %s to use as paletted replacement", sc.String); } if (pic1.isValid() && pic2.isValid()) { - auto owner = GetGameTexture(pic1); - auto owned = GetGameTexture(pic2); - - if (owner && owned) owner->GetTexture()->PalVersion = owned; + Textures[pic1.GetIndex()].Paletted = pic2.GetIndex(); } } } diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 641b97c476..9fdb22a8da 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -24,14 +24,27 @@ public: private: int ResolveLocalizedTexture(int texnum); - FGameTexture *InternalGetTexture(int texnum, bool animate, bool localize) + int ResolveTextureIndex(int texnum, bool animate, bool localize) { - if ((unsigned)texnum >= Textures.Size()) return nullptr; + if ((unsigned)texnum >= Textures.Size()) return -1; if (animate) texnum = Translation[texnum]; if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(texnum); + return texnum; + } + + FGameTexture *InternalGetTexture(int texnum, bool animate, bool localize) + { + texnum = ResolveTextureIndex(texnum, animate, localize); + if (texnum == -1) return nullptr; return Textures[texnum].Texture; } + public: + FTextureID ResolveTextureIndex(FTextureID texid, bool animate, bool localize) + { + return FSetTextureID(ResolveTextureIndex(texid.GetIndex(), animate, localize)); + } + // This only gets used in UI code so we do not need PALVERS handling. FGameTexture* GetGameTextureByName(const char *name, bool animate = false) { @@ -44,6 +57,14 @@ public: return InternalGetTexture(texnum.GetIndex(), animate, true); } + FGameTexture* GetPalettedTexture(FTextureID texnum, bool animate = false, bool allowsubstitute = true) + { + auto texid = ResolveTextureIndex(texnum.GetIndex(), animate, true); + if (texid == -1) return nullptr; + if (allowsubstitute && Textures[texid].Paletted > 0) texid = Textures[texid].Paletted; + return Textures[texid].Texture; + } + FGameTexture* GameByIndex(int i, bool animate = false) { return InternalGetTexture(i, animate, true); @@ -148,7 +169,8 @@ private: struct TextureHash { - FGameTexture *Texture; + FGameTexture* Texture; + int Paletted; // redirection to paletted variant int HashNext; bool HasLocalization; }; @@ -182,4 +204,4 @@ extern FTextureManager TexMan; inline FGameTexture* MakeGameTexture(FTexture* tex) { return reinterpret_cast(tex); -} \ No newline at end of file +} diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 6753d8ed15..abfabd3863 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -382,8 +382,6 @@ protected: // Front sky layer variant where color 0 is transparent FGameTexture* FrontSkyLayer = nullptr; public: - // Paletted variant - FGameTexture *PalVersion = nullptr; // Material layers FTexture *Brightmap = nullptr; FTexture* Detailmap = nullptr; @@ -483,10 +481,6 @@ public: { return Material[num]; } - FGameTexture* GetPalVersion() - { - return PalVersion; - } private: int CheckDDPK3(); @@ -724,7 +718,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* GetPalVersion() { return wrapped.GetPalVersion(); } FGameTexture* GetRawTexture(); FGameTexture* GetFrontSkyLayer(); diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index c501f4df00..ef7d3decb3 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -612,18 +612,10 @@ CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL) R_InitSkyMap(); } -static FGameTexture* PalCheck(FGameTexture* tex) -{ - // In any true color mode this shouldn't do anything. - if (vid_nopalsubstitutions || V_IsTrueColor() || tex == nullptr) return tex; - auto palvers = tex->GetPalVersion(); - if (palvers) return palvers; - return tex; -} - FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat, bool allownull, bool frontsky) { - auto tex = PalCheck(TexMan.GetGameTexture(texid, true)); + bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor(); + auto tex = TexMan.GetPalettedTexture(texid, true, needpal); if (tex == nullptr || (!allownull && !tex->isValid())) return nullptr; if (frontsky) {