mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-12-01 08:31:45 +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 "doomstat.h"
|
||||||
#include "w_wad.h"
|
#include "w_wad.h"
|
||||||
#include "templates.h"
|
#include "templates.h"
|
||||||
|
#include "i_system.h"
|
||||||
|
|
||||||
#include "r_data/r_translate.h"
|
#include "r_data/r_translate.h"
|
||||||
#include "r_data/sprites.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)
|
FTexture *FTextureManager::FindTexture(const char *texname, ETextureType usetype, BITFIELD flags)
|
||||||
{
|
{
|
||||||
FTextureID texnum = CheckForTexture (texname, usetype, 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)
|
if (lang.Len() == 2 || lang.Len() == 3)
|
||||||
{
|
{
|
||||||
uint32_t langid = MAKE_ID(lang[0], lang[1], lang[2], 0);
|
uint32_t langid = MAKE_ID(lang[0], lang[1], lang[2], 0);
|
||||||
uint64_t comboid = (uint64_t(langid) << 32) | tex.GetIndex();
|
uint64_t comboid = (uint64_t(langid) << 32) | origTex.GetIndex();
|
||||||
LocalizedTextures.Insert(comboid, GetTexture(origTex));
|
LocalizedTextures.Insert(comboid, tex.GetIndex());
|
||||||
Textures[origTex.GetIndex()].HasLocalization = true;
|
Textures[origTex.GetIndex()].HasLocalization = true;
|
||||||
}
|
}
|
||||||
else
|
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.
|
// In any true color mode this shouldn't do anything.
|
||||||
if (vid_nopalsubstitutions || V_IsTrueColor()) return tex;
|
if (vid_nopalsubstitutions || V_IsTrueColor()) return tex;
|
||||||
auto ftex = GetTexture(tex);
|
auto ftex = Textures[tex].Texture;
|
||||||
if (ftex != nullptr && ftex->PalVersion != nullptr) return ftex->PalVersion->id;
|
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;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -525,46 +525,47 @@ public:
|
||||||
FTextureManager ();
|
FTextureManager ();
|
||||||
~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.
|
// This only gets used in UI code so we do not need PALVERS handling.
|
||||||
FTexture *GetTextureByName(const char *name, bool animate = false)
|
FTexture *GetTextureByName(const char *name, bool animate = false)
|
||||||
{
|
{
|
||||||
FTextureID texnum = GetTextureID (name, ETextureType::MiscPatch);
|
FTextureID texnum = GetTextureID (name, ETextureType::MiscPatch);
|
||||||
if (!texnum.Exists()) return nullptr;
|
return InternalGetTexture(texnum.GetIndex(), animate, true, false);
|
||||||
if (!animate) return Textures[texnum.GetIndex()].Texture;
|
|
||||||
else return Textures[Translation[texnum.GetIndex()]].Texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FTexture *GetTexture(FTextureID texnum, bool animate = false)
|
FTexture *GetTexture(FTextureID texnum, bool animate = false)
|
||||||
{
|
{
|
||||||
if ((size_t)texnum.GetIndex() >= Textures.Size()) return nullptr;
|
return InternalGetTexture(texnum.GetIndex(), animate, true, false);
|
||||||
if (animate) texnum = Translation[texnum.GetIndex()];
|
|
||||||
return Textures[texnum.GetIndex()].Texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the only access function that should be used inside the software renderer.
|
// This is the only access function that should be used inside the software renderer.
|
||||||
FTexture *GetPalettedTexture(FTextureID texnum, bool animate)
|
FTexture *GetPalettedTexture(FTextureID texnum, bool animate)
|
||||||
{
|
{
|
||||||
if ((size_t)texnum.texnum >= Textures.Size()) return nullptr;
|
return InternalGetTexture(texnum.GetIndex(), animate, true, true);
|
||||||
if (animate) texnum = Translation[texnum.GetIndex()];
|
|
||||||
texnum = PalCheck(texnum).GetIndex();
|
|
||||||
return Textures[texnum.GetIndex()].Texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FTexture *ByIndex(int i, bool animate = false)
|
FTexture *ByIndex(int i, bool animate = false)
|
||||||
{
|
{
|
||||||
if (unsigned(i) >= Textures.Size()) return NULL;
|
return InternalGetTexture(i, animate, true, false);
|
||||||
if (animate) i = Translation[i];
|
|
||||||
return Textures[i].Texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FTexture *FindTexture(const char *texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny);
|
FTexture *FindTexture(const char *texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny);
|
||||||
|
|
||||||
void FlushAll();
|
void FlushAll();
|
||||||
|
|
||||||
|
|
||||||
//public:
|
|
||||||
|
|
||||||
FTextureID PalCheck(FTextureID tex);
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
TEXMAN_TryAny = 1,
|
TEXMAN_TryAny = 1,
|
||||||
|
@ -667,7 +668,7 @@ private:
|
||||||
};
|
};
|
||||||
enum { HASH_END = -1, HASH_SIZE = 1027 };
|
enum { HASH_END = -1, HASH_SIZE = 1027 };
|
||||||
TArray<TextureHash> Textures;
|
TArray<TextureHash> Textures;
|
||||||
TMap<uint64_t, FTexture*> LocalizedTextures;
|
TMap<uint64_t, int> LocalizedTextures;
|
||||||
TArray<int> Translation;
|
TArray<int> Translation;
|
||||||
int HashFirst[HASH_SIZE];
|
int HashFirst[HASH_SIZE];
|
||||||
FTextureID DefaultTexture;
|
FTextureID DefaultTexture;
|
||||||
|
|
Loading…
Reference in a new issue