mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-12-01 00:21:43 +00:00
- reworked texture lookup for localized textures
This commit is contained in:
parent
a6a091c83a
commit
64dc582fbe
2 changed files with 45 additions and 24 deletions
|
@ -38,6 +38,7 @@
|
|||
#include "doomstat.h"
|
||||
#include "w_wad.h"
|
||||
#include "templates.h"
|
||||
#include "i_system.h"
|
||||
|
||||
#include "r_data/r_translate.h"
|
||||
#include "r_data/sprites.h"
|
||||
|
@ -396,7 +397,7 @@ FTextureID FTextureManager::GetTextureID (const char *name, ETextureType usetype
|
|||
FTexture *FTextureManager::FindTexture(const char *texname, ETextureType usetype, BITFIELD flags)
|
||||
{
|
||||
FTextureID texnum = CheckForTexture (texname, usetype, flags);
|
||||
return !texnum.isValid()? NULL : Textures[texnum.GetIndex()].Texture;
|
||||
return GetTexture(texnum.GetIndex());
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -1060,8 +1061,8 @@ void FTextureManager::AddLocalizedVariants()
|
|||
if (lang.Len() == 2 || lang.Len() == 3)
|
||||
{
|
||||
uint32_t langid = MAKE_ID(lang[0], lang[1], lang[2], 0);
|
||||
uint64_t comboid = (uint64_t(langid) << 32) | tex.GetIndex();
|
||||
LocalizedTextures.Insert(comboid, GetTexture(origTex));
|
||||
uint64_t comboid = (uint64_t(langid) << 32) | origTex.GetIndex();
|
||||
LocalizedTextures.Insert(comboid, tex.GetIndex());
|
||||
Textures[origTex.GetIndex()].HasLocalization = true;
|
||||
}
|
||||
else
|
||||
|
@ -1226,12 +1227,31 @@ void FTextureManager::InitPalettedVersions()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FTextureID FTextureManager::PalCheck(FTextureID tex)
|
||||
int FTextureManager::PalCheck(int tex)
|
||||
{
|
||||
// In any true color mode this shouldn't do anything.
|
||||
if (vid_nopalsubstitutions || V_IsTrueColor()) return tex;
|
||||
auto ftex = GetTexture(tex);
|
||||
if (ftex != nullptr && ftex->PalVersion != nullptr) return ftex->PalVersion->id;
|
||||
auto ftex = Textures[tex].Texture;
|
||||
if (ftex != nullptr && ftex->PalVersion != nullptr) return ftex->PalVersion->id.GetIndex();
|
||||
return tex;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FTextureManager :: PalCheck
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
int FTextureManager::ResolveLocalizedTexture(int tex)
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
uint32_t lang = LanguageIDs[i];
|
||||
uint64_t index = (uint64_t(lang) << 32) + tex;
|
||||
if (auto pTex = LocalizedTextures.CheckKey(index)) return *pTex;
|
||||
index = (uint64_t(lang & MAKE_ID(255, 255, 0, 0)) << 32) + tex;
|
||||
if (auto pTex = LocalizedTextures.CheckKey(index)) return *pTex;
|
||||
}
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
|
|
@ -525,46 +525,47 @@ public:
|
|||
FTextureManager ();
|
||||
~FTextureManager ();
|
||||
|
||||
private:
|
||||
int ResolveLocalizedTexture(int texnum);
|
||||
int PalCheck(int tex);
|
||||
|
||||
FTexture *InternalGetTexture(int texnum, bool animate, bool localize, bool palettesubst)
|
||||
{
|
||||
if ((unsigned)texnum >= Textures.Size()) return nullptr;
|
||||
if (animate) texnum = Translation[texnum];
|
||||
if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(texnum);
|
||||
if (palettesubst) texnum = PalCheck(texnum);
|
||||
return Textures[texnum].Texture;
|
||||
}
|
||||
public:
|
||||
// This only gets used in UI code so we do not need PALVERS handling.
|
||||
FTexture *GetTextureByName(const char *name, bool animate = false)
|
||||
{
|
||||
FTextureID texnum = GetTextureID (name, ETextureType::MiscPatch);
|
||||
if (!texnum.Exists()) return nullptr;
|
||||
if (!animate) return Textures[texnum.GetIndex()].Texture;
|
||||
else return Textures[Translation[texnum.GetIndex()]].Texture;
|
||||
return InternalGetTexture(texnum.GetIndex(), animate, true, false);
|
||||
}
|
||||
|
||||
FTexture *GetTexture(FTextureID texnum, bool animate = false)
|
||||
{
|
||||
if ((size_t)texnum.GetIndex() >= Textures.Size()) return nullptr;
|
||||
if (animate) texnum = Translation[texnum.GetIndex()];
|
||||
return Textures[texnum.GetIndex()].Texture;
|
||||
return InternalGetTexture(texnum.GetIndex(), animate, true, false);
|
||||
}
|
||||
|
||||
// This is the only access function that should be used inside the software renderer.
|
||||
FTexture *GetPalettedTexture(FTextureID texnum, bool animate)
|
||||
{
|
||||
if ((size_t)texnum.texnum >= Textures.Size()) return nullptr;
|
||||
if (animate) texnum = Translation[texnum.GetIndex()];
|
||||
texnum = PalCheck(texnum).GetIndex();
|
||||
return Textures[texnum.GetIndex()].Texture;
|
||||
return InternalGetTexture(texnum.GetIndex(), animate, true, true);
|
||||
}
|
||||
|
||||
FTexture *ByIndex(int i, bool animate = false)
|
||||
{
|
||||
if (unsigned(i) >= Textures.Size()) return NULL;
|
||||
if (animate) i = Translation[i];
|
||||
return Textures[i].Texture;
|
||||
return InternalGetTexture(i, animate, true, false);
|
||||
}
|
||||
|
||||
FTexture *FindTexture(const char *texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny);
|
||||
|
||||
void FlushAll();
|
||||
|
||||
|
||||
//public:
|
||||
|
||||
FTextureID PalCheck(FTextureID tex);
|
||||
|
||||
enum
|
||||
{
|
||||
TEXMAN_TryAny = 1,
|
||||
|
@ -667,7 +668,7 @@ private:
|
|||
};
|
||||
enum { HASH_END = -1, HASH_SIZE = 1027 };
|
||||
TArray<TextureHash> Textures;
|
||||
TMap<uint64_t, FTexture*> LocalizedTextures;
|
||||
TMap<uint64_t, int> LocalizedTextures;
|
||||
TArray<int> Translation;
|
||||
int HashFirst[HASH_SIZE];
|
||||
FTextureID DefaultTexture;
|
||||
|
|
Loading…
Reference in a new issue