mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 22:11:43 +00:00
- 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:
parent
18760d6622
commit
da873ca8d1
4 changed files with 31 additions and 27 deletions
|
@ -396,7 +396,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture)
|
||||||
hash = -1;
|
hash = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureHash hasher = { texture, hash };
|
TextureHash hasher = { texture, -1, hash };
|
||||||
int trans = Textures.Push (hasher);
|
int trans = Textures.Push (hasher);
|
||||||
Translation.Push (trans);
|
Translation.Push (trans);
|
||||||
if (bucket >= 0) HashFirst[bucket] = trans;
|
if (bucket >= 0) HashFirst[bucket] = trans;
|
||||||
|
@ -1166,14 +1166,11 @@ void FTextureManager::InitPalettedVersions()
|
||||||
FTextureID pic2 = CheckForTexture(sc.String, ETextureType::Any);
|
FTextureID pic2 = CheckForTexture(sc.String, ETextureType::Any);
|
||||||
if (!pic2.isValid())
|
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())
|
if (pic1.isValid() && pic2.isValid())
|
||||||
{
|
{
|
||||||
auto owner = GetGameTexture(pic1);
|
Textures[pic1.GetIndex()].Paletted = pic2.GetIndex();
|
||||||
auto owned = GetGameTexture(pic2);
|
|
||||||
|
|
||||||
if (owner && owned) owner->GetTexture()->PalVersion = owned;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,27 @@ public:
|
||||||
private:
|
private:
|
||||||
int ResolveLocalizedTexture(int texnum);
|
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 (animate) texnum = Translation[texnum];
|
||||||
if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(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;
|
return Textures[texnum].Texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
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.
|
// This only gets used in UI code so we do not need PALVERS handling.
|
||||||
FGameTexture* GetGameTextureByName(const char *name, bool animate = false)
|
FGameTexture* GetGameTextureByName(const char *name, bool animate = false)
|
||||||
{
|
{
|
||||||
|
@ -44,6 +57,14 @@ public:
|
||||||
return InternalGetTexture(texnum.GetIndex(), animate, true);
|
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)
|
FGameTexture* GameByIndex(int i, bool animate = false)
|
||||||
{
|
{
|
||||||
return InternalGetTexture(i, animate, true);
|
return InternalGetTexture(i, animate, true);
|
||||||
|
@ -148,7 +169,8 @@ private:
|
||||||
|
|
||||||
struct TextureHash
|
struct TextureHash
|
||||||
{
|
{
|
||||||
FGameTexture *Texture;
|
FGameTexture* Texture;
|
||||||
|
int Paletted; // redirection to paletted variant
|
||||||
int HashNext;
|
int HashNext;
|
||||||
bool HasLocalization;
|
bool HasLocalization;
|
||||||
};
|
};
|
||||||
|
@ -182,4 +204,4 @@ extern FTextureManager TexMan;
|
||||||
inline FGameTexture* MakeGameTexture(FTexture* tex)
|
inline FGameTexture* MakeGameTexture(FTexture* tex)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<FGameTexture*>(tex);
|
return reinterpret_cast<FGameTexture*>(tex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,8 +382,6 @@ protected:
|
||||||
// Front sky layer variant where color 0 is transparent
|
// Front sky layer variant where color 0 is transparent
|
||||||
FGameTexture* FrontSkyLayer = nullptr;
|
FGameTexture* FrontSkyLayer = nullptr;
|
||||||
public:
|
public:
|
||||||
// Paletted variant
|
|
||||||
FGameTexture *PalVersion = nullptr;
|
|
||||||
// Material layers
|
// Material layers
|
||||||
FTexture *Brightmap = nullptr;
|
FTexture *Brightmap = nullptr;
|
||||||
FTexture* Detailmap = nullptr;
|
FTexture* Detailmap = nullptr;
|
||||||
|
@ -483,10 +481,6 @@ public:
|
||||||
{
|
{
|
||||||
return Material[num];
|
return Material[num];
|
||||||
}
|
}
|
||||||
FGameTexture* GetPalVersion()
|
|
||||||
{
|
|
||||||
return PalVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int CheckDDPK3();
|
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.
|
// 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* GetRawTexture();
|
||||||
FGameTexture* GetFrontSkyLayer();
|
FGameTexture* GetFrontSkyLayer();
|
||||||
|
|
||||||
|
|
|
@ -612,18 +612,10 @@ CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL)
|
||||||
R_InitSkyMap();
|
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)
|
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 (tex == nullptr || (!allownull && !tex->isValid())) return nullptr;
|
||||||
if (frontsky)
|
if (frontsky)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue