- moved linked textures from file system to texture manager.

This commit is contained in:
Christoph Oelckers 2023-08-18 21:26:22 +02:00
parent 1dc47f91c2
commit 2524ea6b0e
7 changed files with 48 additions and 44 deletions

View file

@ -1135,7 +1135,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FTextureID &value, FTe
const char *name;
auto lump = pic->GetSourceLump();
if (fileSystem.GetLinkedTexture(lump) == pic)
if (TexMan.GetLinkedTexture(lump) == pic)
{
name = fileSystem.GetFileFullName(lump);
}

View file

@ -55,7 +55,6 @@
struct FileSystem::LumpRecord
{
FResourceLump *lump;
FGameTexture* linkedTexture;
LumpShortName shortName;
FString longName;
int rfnum;
@ -67,7 +66,6 @@ struct FileSystem::LumpRecord
{
lump = lmp;
rfnum = filenum;
linkedTexture = nullptr;
flags = 0;
if (lump->Flags & LUMPF_SHORTNAME)
@ -748,35 +746,6 @@ int FileSystem::GetResource (int resid, const char *type, int filenum) const
return i;
}
//==========================================================================
//
// link a texture with a given lump
//
//==========================================================================
void FileSystem::SetLinkedTexture(int lump, FGameTexture *tex)
{
if ((size_t)lump < NumEntries)
{
FileInfo[lump].linkedTexture = tex;
}
}
//==========================================================================
//
// retrieve linked texture
//
//==========================================================================
FGameTexture *FileSystem::GetLinkedTexture(int lump)
{
if ((size_t)lump < NumEntries)
{
return FileInfo[lump].linkedTexture;
}
return NULL;
}
//==========================================================================
//
// FileLength

View file

@ -16,7 +16,6 @@
class FResourceFile;
struct FResourceLump;
class FGameTexture;
union LumpShortName
{
@ -125,10 +124,6 @@ public:
inline int CheckNumForFullName (const FString &name, int wadfile) { return CheckNumForFullName(name.GetChars(), wadfile); }
inline int GetNumForFullName (const FString &name) { return GetNumForFullName(name.GetChars()); }
void SetLinkedTexture(int lump, FGameTexture *tex);
FGameTexture *GetLinkedTexture(int lump);
void ReadFile (int lump, void *dest);
TArray<uint8_t> GetFileData(int lump, int pad = 0); // reads lump into a writable buffer and optionally adds some padding at the end. (FileData isn't writable!)
FileData ReadFile (int lump);

View file

@ -424,7 +424,7 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetName)
{
// Textures for full path names do not have their own name, they merely link to the source lump.
auto lump = tex->GetSourceLump();
if (fileSystem.GetLinkedTexture(lump) == tex)
if (TexMan.GetLinkedTexture(lump) == tex)
retval = fileSystem.GetFileFullName(lump);
}
}

View file

@ -98,8 +98,8 @@ FGameTexture::~FGameTexture()
{
if (Base != nullptr)
{
FGameTexture* link = fileSystem.GetLinkedTexture(GetSourceLump());
if (link == this) fileSystem.SetLinkedTexture(GetSourceLump(), nullptr);
FGameTexture* link = TexMan.GetLinkedTexture(GetSourceLump());
if (link == this) TexMan.SetLinkedTexture(GetSourceLump(), nullptr);
}
if (SoftwareTexture != nullptr)
{

View file

@ -244,11 +244,11 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset
// Any graphic being placed in the zip's root directory can not be found by this.
if (strchr(name, '/') || (flags & TEXMAN_ForceLookup))
{
FGameTexture *const NO_TEXTURE = (FGameTexture*)-1;
FGameTexture *const NO_TEXTURE = (FGameTexture*)-1; // marker for lumps we already checked that do not map to a texture.
int lump = fileSystem.CheckNumForFullName(name);
if (lump >= 0)
{
FGameTexture *tex = fileSystem.GetLinkedTexture(lump);
FGameTexture *tex = GetLinkedTexture(lump);
if (tex == NO_TEXTURE) return FTextureID(-1);
if (tex != NULL) return tex->GetID();
if (flags & TEXMAN_DontCreate) return FTextureID(-1); // we only want to check, there's no need to create a texture if we don't have one yet.
@ -256,13 +256,13 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset
if (tex != NULL)
{
tex->AddAutoMaterials();
fileSystem.SetLinkedTexture(lump, tex);
SetLinkedTexture(lump, tex);
return AddGameTexture(tex);
}
else
{
// mark this lump as having no valid texture so that we don't have to retry creating one later.
fileSystem.SetLinkedTexture(lump, NO_TEXTURE);
SetLinkedTexture(lump, NO_TEXTURE);
}
}
}
@ -1627,6 +1627,37 @@ void FTextureManager::Listaliases()
}
}
//==========================================================================
//
// link a texture with a given lump
//
//==========================================================================
void FTextureManager::SetLinkedTexture(int lump, FGameTexture* tex)
{
if ((size_t)lump < fileSystem.GetNumEntries())
{
linkedMap.Insert(lump, tex);
}
}
//==========================================================================
//
// retrieve linked texture
//
//==========================================================================
FGameTexture* FTextureManager::GetLinkedTexture(int lump)
{
if ((size_t)lump < fileSystem.GetNumEntries())
{
auto check = linkedMap.CheckKey(lump);
if (check) return *check;
}
return nullptr;
}
//==========================================================================
//
// FTextureID::operator+

View file

@ -88,6 +88,15 @@ public:
}
}
//==========================================================================
//
// link a texture with a given lump
//
//==========================================================================
TMap<int, FGameTexture*> linkedMap;
void SetLinkedTexture(int lump, FGameTexture* tex);
FGameTexture* GetLinkedTexture(int lump);
enum
{