- moved the handling for paletted replacements into the texture manager.

This is something the texture should not concern itself with.
This commit is contained in:
Christoph Oelckers 2020-04-16 00:27:12 +02:00
parent 18760d6622
commit da873ca8d1
4 changed files with 31 additions and 27 deletions

View file

@ -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();
}
}
}

View file

@ -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<FGameTexture*>(tex);
}
}

View file

@ -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();

View file

@ -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)
{