mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 23:01:50 +00:00
- allow texture lookup by full path names. Due to technical limitations this may result in double textures if the same graphics lump is also referenced by its short texture name.
This commit is contained in:
parent
ebd6c18bef
commit
ca4179caa3
10 changed files with 84 additions and 60 deletions
|
@ -300,7 +300,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl
|
|||
|
||||
if (flags & DI_ALTERNATEONFAIL)
|
||||
{
|
||||
SetTruth(texture == NULL || !(texture->GetID().isValid()), block, statusBar);
|
||||
SetTruth(texture == NULL || texture->UseType == FTexture::TEX_Null, block, statusBar);
|
||||
}
|
||||
}
|
||||
protected:
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "files.h"
|
||||
|
||||
class FResourceFile;
|
||||
class FTexture;
|
||||
|
||||
struct FResourceLump
|
||||
{
|
||||
|
@ -24,6 +25,7 @@ struct FResourceLump
|
|||
SBYTE RefCount;
|
||||
char * Cache;
|
||||
FResourceFile * Owner;
|
||||
FTexture * LinkedTexture;
|
||||
int Namespace;
|
||||
|
||||
FResourceLump()
|
||||
|
@ -35,6 +37,7 @@ struct FResourceLump
|
|||
RefCount = 0;
|
||||
Namespace = 0; // ns_global
|
||||
*Name = 0;
|
||||
LinkedTexture = NULL;
|
||||
}
|
||||
|
||||
virtual ~FResourceLump();
|
||||
|
|
|
@ -551,7 +551,7 @@ void FTextureManager::ParseTime (FScanner &sc, DWORD &min, DWORD &max)
|
|||
|
||||
void FTextureManager::ParseWarp(FScanner &sc)
|
||||
{
|
||||
const BITFIELD texflags = TEXMAN_Overridable | TEXMAN_TryAny;
|
||||
const BITFIELD texflags = TEXMAN_Overridable | TEXMAN_TryAny | TEXMAN_ShortNameOnly;
|
||||
bool isflat = false;
|
||||
bool type2 = sc.Compare ("warp2"); // [GRB]
|
||||
sc.MustGetString ();
|
||||
|
@ -616,7 +616,7 @@ void FTextureManager::ParseWarp(FScanner &sc)
|
|||
|
||||
void FTextureManager::ParseCameraTexture(FScanner &sc)
|
||||
{
|
||||
const BITFIELD texflags = TEXMAN_Overridable | TEXMAN_TryAny;
|
||||
const BITFIELD texflags = TEXMAN_Overridable | TEXMAN_TryAny | TEXMAN_ShortNameOnly;
|
||||
int width, height;
|
||||
int fitwidth, fitheight;
|
||||
FString picname;
|
||||
|
|
|
@ -1001,21 +1001,7 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part, bool silent, i
|
|||
|
||||
if (!texno.isValid())
|
||||
{
|
||||
int lumpnum = Wads.CheckNumForFullName(sc.String);
|
||||
if (lumpnum >= 0)
|
||||
{
|
||||
texno = TexMan.FindTextureByLumpNum(lumpnum);
|
||||
if (texno.isValid ())
|
||||
{
|
||||
part.Texture = TexMan[texno];
|
||||
}
|
||||
else
|
||||
{
|
||||
part.Texture = FTexture::CreateTexture("", lumpnum, usetype);
|
||||
TexMan.AddTexture(part.Texture);
|
||||
}
|
||||
}
|
||||
else if (strlen(sc.String) <= 8 && !strpbrk(sc.String, "./"))
|
||||
if (strlen(sc.String) <= 8 && !strpbrk(sc.String, "./"))
|
||||
{
|
||||
int lumpnum = Wads.CheckNumForName(sc.String, usetype == TEX_MiscPatch? ns_graphics : ns_patches);
|
||||
if (lumpnum >= 0)
|
||||
|
|
|
@ -167,6 +167,8 @@ FTexture::FTexture (const char *name, int lumpnum)
|
|||
|
||||
FTexture::~FTexture ()
|
||||
{
|
||||
FTexture *link = Wads.GetLinkedTexture(SourceLump);
|
||||
if (link == this) Wads.SetLinkedTexture(SourceLump, NULL);
|
||||
KillNative();
|
||||
}
|
||||
|
||||
|
|
|
@ -224,6 +224,35 @@ FTextureID FTextureManager::CheckForTexture (const char *name, int usetype, BITF
|
|||
return FTextureID(firstfound);
|
||||
}
|
||||
|
||||
|
||||
if (!(flags & TEXMAN_ShortNameOnly))
|
||||
{
|
||||
// We intentionally only look for textures in subdirectories.
|
||||
// Any graphic being placed in the zip's root directory can not be found by this.
|
||||
if (strchr(name, '/'))
|
||||
{
|
||||
FTexture *const NO_TEXTURE = (FTexture*)-1;
|
||||
int lump = Wads.CheckNumForFullName(name);
|
||||
if (lump != NULL)
|
||||
{
|
||||
FTexture *tex = Wads.GetLinkedTexture(lump);
|
||||
if (tex == NO_TEXTURE) return FTextureID(-1);
|
||||
if (tex != NULL) return tex->id;
|
||||
tex = FTexture::CreateTexture("", lump, FTexture::TEX_Override);
|
||||
if (tex != NULL)
|
||||
{
|
||||
Wads.SetLinkedTexture(lump, tex);
|
||||
return AddTexture(tex);
|
||||
}
|
||||
else
|
||||
{
|
||||
// mark this lump as having no valid texture so that we don't have to retry creating one later.
|
||||
Wads.SetLinkedTexture(lump, NO_TEXTURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FTextureID(-1);
|
||||
}
|
||||
|
||||
|
@ -273,30 +302,6 @@ int FTextureManager::ListTextures (const char *name, TArray<FTextureID> &list)
|
|||
return list.Size();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FTextureManager :: FindTextureByLumpNum
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FTextureID FTextureManager::FindTextureByLumpNum (int lumpnum)
|
||||
{
|
||||
if (lumpnum < 0)
|
||||
{
|
||||
return FTextureID(-1);
|
||||
}
|
||||
// This can't use hashing because using ReplaceTexture would break the hash chains. :(
|
||||
for(unsigned i = 0; i <Textures.Size(); i++)
|
||||
{
|
||||
if (Textures[i].Texture->SourceLump == lumpnum)
|
||||
{
|
||||
return FTextureID(i);
|
||||
}
|
||||
}
|
||||
return FTextureID(-1);
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FTextureManager :: GetTextures
|
||||
|
@ -1093,8 +1098,15 @@ void FTextureManager::WriteTexture (FArchive &arc, int picnum)
|
|||
pic = Textures[picnum].Texture;
|
||||
}
|
||||
|
||||
arc.WriteName (pic->Name);
|
||||
arc.WriteCount (pic->UseType);
|
||||
if (Wads.GetLinkedTexture(pic->SourceLump) == pic)
|
||||
{
|
||||
arc.WriteName(Wads.GetLumpFullName(pic->SourceLump));
|
||||
}
|
||||
else
|
||||
{
|
||||
arc.WriteName(pic->Name);
|
||||
}
|
||||
arc.WriteCount(pic->UseType);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -217,7 +217,6 @@ public:
|
|||
virtual int GetSourceLump() { return SourceLump; }
|
||||
virtual FTexture *GetRedirect(bool wantwarped);
|
||||
virtual FTexture *GetRawTexture(); // for FMultiPatchTexture to override
|
||||
FTextureID GetID() const { return id; }
|
||||
|
||||
virtual void Unload () = 0;
|
||||
|
||||
|
@ -363,12 +362,12 @@ public:
|
|||
TEXMAN_TryAny = 1,
|
||||
TEXMAN_Overridable = 2,
|
||||
TEXMAN_ReturnFirst = 4,
|
||||
TEXMAN_AllowSkins = 8
|
||||
TEXMAN_AllowSkins = 8,
|
||||
TEXMAN_ShortNameOnly = 16
|
||||
};
|
||||
|
||||
FTextureID CheckForTexture (const char *name, int usetype, BITFIELD flags=TEXMAN_TryAny);
|
||||
FTextureID GetTexture (const char *name, int usetype, BITFIELD flags=0);
|
||||
FTextureID FindTextureByLumpNum (int lumpnum);
|
||||
int ListTextures (const char *name, TArray<FTextureID> &list);
|
||||
|
||||
void AddTexturesLump (const void *lumpdata, int lumpsize, int deflumpnum, int patcheslump, int firstdup=0, bool texture1=false);
|
||||
|
|
|
@ -2193,19 +2193,6 @@ void V_InitCustomFonts()
|
|||
FTexture **p = &lumplist[*(unsigned char*)sc.String];
|
||||
sc.MustGetString();
|
||||
FTextureID texid = TexMan.CheckForTexture(sc.String, FTexture::TEX_MiscPatch);
|
||||
if (!texid.Exists())
|
||||
{
|
||||
int lumpno = Wads.CheckNumForFullName (sc.String);
|
||||
if (lumpno >= 0)
|
||||
{
|
||||
texid = TexMan.FindTextureByLumpNum(lumpno);
|
||||
if (!texid.Exists())
|
||||
{
|
||||
FTexture *tex = FTexture::CreateTexture("", lumpno, FTexture::TEX_MiscPatch);
|
||||
texid = TexMan.AddTexture(tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (texid.Exists())
|
||||
{
|
||||
*p = TexMan[texid];
|
||||
|
|
|
@ -548,6 +548,37 @@ int FWadCollection::GetNumForFullName (const char *name)
|
|||
return i;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// link a texture with a given lump
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FWadCollection::SetLinkedTexture(int lump, FTexture *tex)
|
||||
{
|
||||
if ((size_t)lump < NumLumps)
|
||||
{
|
||||
FResourceLump *reslump = LumpInfo[lump].lump;
|
||||
reslump->LinkedTexture = tex;
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// retrieve linked texture
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FTexture *FWadCollection::GetLinkedTexture(int lump)
|
||||
{
|
||||
if ((size_t)lump < NumLumps)
|
||||
{
|
||||
FResourceLump *reslump = LumpInfo[lump].lump;
|
||||
return reslump->LinkedTexture;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// W_LumpLength
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
class FResourceFile;
|
||||
struct FResourceLump;
|
||||
class FTexture;
|
||||
|
||||
struct wadinfo_t
|
||||
{
|
||||
|
@ -171,6 +172,9 @@ public:
|
|||
int CheckNumForFullName (const char *name, int wadfile);
|
||||
int GetNumForFullName (const char *name);
|
||||
|
||||
void SetLinkedTexture(int lump, FTexture *tex);
|
||||
FTexture *GetLinkedTexture(int lump);
|
||||
|
||||
|
||||
void ReadLump (int lump, void *dest);
|
||||
FMemLump ReadLump (int lump);
|
||||
|
|
Loading…
Reference in a new issue