mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-11 07:11:54 +00:00
- moved most parts of the Doom specific lump setup out of the file format implementations into the main class.
This is to keep as much higher level logic out of these as possible. The presentation of the data should be a concern of the file system, not the data containers.
This commit is contained in:
parent
ef300a9ea8
commit
1574799683
9 changed files with 179 additions and 285 deletions
|
@ -114,7 +114,6 @@ bool FGrpFile::Open(bool quiet)
|
|||
Lumps[i].Position = Position;
|
||||
Lumps[i].LumpSize = LittleLong(fileinfo[i].Size);
|
||||
Position += fileinfo[i].Size;
|
||||
Lumps[i].Namespace = ns_global;
|
||||
Lumps[i].Flags = 0;
|
||||
fileinfo[i].NameWithZero[12] = '\0'; // Be sure filename is null-terminated
|
||||
Lumps[i].LumpNameSetup(fileinfo[i].NameWithZero);
|
||||
|
|
|
@ -77,7 +77,6 @@ bool FLumpFile::Open(bool quiet)
|
|||
Lumps[0].Owner = this;
|
||||
Lumps[0].Position = 0;
|
||||
Lumps[0].LumpSize = (int)Reader.GetLength();
|
||||
Lumps[0].Namespace = ns_global;
|
||||
Lumps[0].Flags = 0;
|
||||
NumLumps = 1;
|
||||
if (!quiet)
|
||||
|
|
|
@ -174,14 +174,6 @@ bool FRFFFile::Open(bool quiet)
|
|||
name[len+3] = lumps[i].Extension[2];
|
||||
name[len+4] = 0;
|
||||
Lumps[i].LumpNameSetup(name);
|
||||
if (name[len+1] == 'S' && name[len+2] == 'F' && name[len+3] == 'X')
|
||||
{
|
||||
Lumps[i].Namespace = ns_bloodsfx;
|
||||
}
|
||||
else if (name[len+1] == 'R' && name[len+2] == 'A' && name[len+3] == 'W')
|
||||
{
|
||||
Lumps[i].Namespace = ns_bloodraw;
|
||||
}
|
||||
}
|
||||
delete[] lumps;
|
||||
GenerateHash();
|
||||
|
|
|
@ -51,6 +51,9 @@ class FWadFileLump : public FResourceLump
|
|||
public:
|
||||
bool Compressed;
|
||||
int Position;
|
||||
int Namespace;
|
||||
|
||||
int GetNamespace() const override { return Namespace; }
|
||||
|
||||
int GetFileOffset() { return Position; }
|
||||
FileReader *GetReader()
|
||||
|
@ -104,7 +107,7 @@ public:
|
|||
|
||||
class FWadFile : public FResourceFile
|
||||
{
|
||||
FWadFileLump *Lumps;
|
||||
TArray<FWadFileLump> Lumps;
|
||||
|
||||
bool IsMarker(int lump, const char *marker);
|
||||
void SetNamespace(const char *startmarker, const char *endmarker, namespace_t space, bool flathack=false);
|
||||
|
@ -112,8 +115,6 @@ class FWadFile : public FResourceFile
|
|||
|
||||
public:
|
||||
FWadFile(const char * filename, FileReader &file);
|
||||
~FWadFile();
|
||||
void FindStrifeTeaserVoices ();
|
||||
FResourceLump *GetLump(int lump) { return &Lumps[lump]; }
|
||||
bool Open(bool quiet);
|
||||
};
|
||||
|
@ -130,12 +131,6 @@ public:
|
|||
FWadFile::FWadFile(const char *filename, FileReader &file)
|
||||
: FResourceFile(filename, file)
|
||||
{
|
||||
Lumps = NULL;
|
||||
}
|
||||
|
||||
FWadFile::~FWadFile()
|
||||
{
|
||||
delete[] Lumps;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -170,46 +165,45 @@ bool FWadFile::Open(bool quiet)
|
|||
}
|
||||
}
|
||||
|
||||
wadlump_t *fileinfo = new wadlump_t[NumLumps];
|
||||
TArray<wadlump_t> fileinfo(NumLumps, true);
|
||||
Reader.Seek (InfoTableOfs, FileReader::SeekSet);
|
||||
Reader.Read (fileinfo, NumLumps * sizeof(wadlump_t));
|
||||
Reader.Read (fileinfo.Data(), NumLumps * sizeof(wadlump_t));
|
||||
|
||||
Lumps = new FWadFileLump[NumLumps];
|
||||
Lumps.Resize(NumLumps);
|
||||
|
||||
for(uint32_t i = 0; i < NumLumps; i++)
|
||||
{
|
||||
uppercopy (Lumps[i].Name, fileinfo[i].Name);
|
||||
Lumps[i].Name[8] = 0;
|
||||
Lumps[i].Compressed = !(gameinfo.flags & GI_SHAREWARE) && (Lumps[i].Name[0] & 0x80) == 0x80;
|
||||
Lumps[i].Name[0] &= ~0x80;
|
||||
char n[9];
|
||||
uppercopy(n, fileinfo[i].Name);
|
||||
n[8] = 0;
|
||||
Lumps[i].Compressed = !(gameinfo.flags & GI_SHAREWARE) && (n[0] & 0x80) == 0x80;
|
||||
n[0] &= ~0x80;
|
||||
Lumps[i].LumpNameSetup(n);
|
||||
|
||||
Lumps[i].Owner = this;
|
||||
Lumps[i].Position = isBigEndian ? BigLong(fileinfo[i].FilePos) : LittleLong(fileinfo[i].FilePos);
|
||||
Lumps[i].LumpSize = isBigEndian ? BigLong(fileinfo[i].Size) : LittleLong(fileinfo[i].Size);
|
||||
Lumps[i].Namespace = ns_global;
|
||||
Lumps[i].Flags = Lumps[i].Compressed ? LUMPF_COMPRESSED | LUMPF_SHORTNAME : LUMPF_SHORTNAME;
|
||||
Lumps[i].FullName = "";
|
||||
|
||||
// Check if the lump is within the WAD file and print a warning if not.
|
||||
if (Lumps[i].Position + Lumps[i].LumpSize > wadSize || Lumps[i].Position < 0 || Lumps[i].LumpSize < 0)
|
||||
{
|
||||
if (Lumps[i].LumpSize != 0)
|
||||
{
|
||||
Printf(PRINT_HIGH, "%s: Lump %s contains invalid positioning info and will be ignored\n", FileName.GetChars(), Lumps[i].Name);
|
||||
Lumps[i].Name[0] = 0;
|
||||
Printf(PRINT_HIGH, "%s: Lump %s contains invalid positioning info and will be ignored\n", FileName.GetChars(), Lumps[i].getName());
|
||||
Lumps[i].LumpNameSetup("");
|
||||
}
|
||||
Lumps[i].LumpSize = Lumps[i].Position = 0;
|
||||
}
|
||||
}
|
||||
|
||||
delete[] fileinfo;
|
||||
GenerateHash(); // Do this before the lump processing below.
|
||||
|
||||
if (!quiet)
|
||||
if (!quiet) // don't bother with namespaces in quiet mode. We won't need them.
|
||||
{
|
||||
if (!batchrun) Printf(", %d lumps\n", NumLumps);
|
||||
|
||||
// don't bother with namespaces here. We won't need them.
|
||||
SetNamespace("S_START", "S_END", ns_sprites);
|
||||
SetNamespace("F_START", "F_END", ns_flats, true);
|
||||
SetNamespace("C_START", "C_END", ns_colormaps);
|
||||
|
@ -233,10 +227,10 @@ bool FWadFile::Open(bool quiet)
|
|||
|
||||
inline bool FWadFile::IsMarker(int lump, const char *marker)
|
||||
{
|
||||
if (Lumps[lump].Name[0] == marker[0])
|
||||
if (Lumps[lump].getName()[0] == marker[0])
|
||||
{
|
||||
return (!strcmp(Lumps[lump].Name, marker) ||
|
||||
(marker[1] == '_' && !strcmp(Lumps[lump].Name+1, marker)));
|
||||
return (!strcmp(Lumps[lump].getName(), marker) ||
|
||||
(marker[1] == '_' && !strcmp(Lumps[lump].getName() +1, marker)));
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
@ -301,7 +295,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name
|
|||
{
|
||||
// We can't add this to the flats namespace but
|
||||
// it needs to be flagged for the texture manager.
|
||||
DPrintf(DMSG_NOTIFY, "Marking %s as potential flat\n", Lumps[i].Name);
|
||||
DPrintf(DMSG_NOTIFY, "Marking %s as potential flat\n", Lumps[i].getName());
|
||||
Lumps[i].Flags |= LUMPF_MAYBEFLAT;
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +358,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name
|
|||
// ignore sprite lumps smaller than 8 bytes (the smallest possible)
|
||||
// in size -- this was used by some dmadds wads
|
||||
// as an 'empty' graphics resource
|
||||
DPrintf(DMSG_WARNING, " Skipped empty sprite %s (lump %d)\n", Lumps[j].Name, j);
|
||||
DPrintf(DMSG_WARNING, " Skipped empty sprite %s (lump %d)\n", Lumps[j].getName(), j);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -390,6 +384,7 @@ void FWadFile::SetNamespace(const char *startmarker, const char *endmarker, name
|
|||
|
||||
void FWadFile::SkinHack ()
|
||||
{
|
||||
// this being static is not a problem. The only relevant thing is that each skin gets a different number.
|
||||
static int namespc = ns_firstskin;
|
||||
bool skinned = false;
|
||||
bool hasmap = false;
|
||||
|
@ -399,14 +394,9 @@ void FWadFile::SkinHack ()
|
|||
{
|
||||
FResourceLump *lump = &Lumps[i];
|
||||
|
||||
if (lump->Name[0] == 'S' &&
|
||||
lump->Name[1] == '_' &&
|
||||
lump->Name[2] == 'S' &&
|
||||
lump->Name[3] == 'K' &&
|
||||
lump->Name[4] == 'I' &&
|
||||
lump->Name[5] == 'N')
|
||||
if (!strnicmp(lump->getName(), "S_SKIN", 6))
|
||||
{ // Wad has at least one skin.
|
||||
lump->Name[6] = lump->Name[7] = 0;
|
||||
lump->LumpNameSetup("S_SKIN");
|
||||
if (!skinned)
|
||||
{
|
||||
skinned = true;
|
||||
|
@ -419,18 +409,18 @@ void FWadFile::SkinHack ()
|
|||
namespc++;
|
||||
}
|
||||
}
|
||||
if ((lump->Name[0] == 'M' &&
|
||||
lump->Name[1] == 'A' &&
|
||||
lump->Name[2] == 'P' &&
|
||||
lump->Name[3] >= '0' && lump->Name[3] <= '9' &&
|
||||
lump->Name[4] >= '0' && lump->Name[4] <= '9' &&
|
||||
lump->Name[5] >= '\0')
|
||||
if ((lump->getName()[0] == 'M' &&
|
||||
lump->getName()[1] == 'A' &&
|
||||
lump->getName()[2] == 'P' &&
|
||||
lump->getName()[3] >= '0' && lump->getName()[3] <= '9' &&
|
||||
lump->getName()[4] >= '0' && lump->getName()[4] <= '9' &&
|
||||
lump->getName()[5] >= '\0')
|
||||
||
|
||||
(lump->Name[0] == 'E' &&
|
||||
lump->Name[1] >= '0' && lump->Name[1] <= '9' &&
|
||||
lump->Name[2] == 'M' &&
|
||||
lump->Name[3] >= '0' && lump->Name[3] <= '9' &&
|
||||
lump->Name[4] >= '\0'))
|
||||
(lump->getName()[0] == 'E' &&
|
||||
lump->getName()[1] >= '0' && lump->getName()[1] <= '9' &&
|
||||
lump->getName()[2] == 'M' &&
|
||||
lump->getName()[3] >= '0' && lump->getName()[3] <= '9' &&
|
||||
lump->getName()[4] >= '\0'))
|
||||
{
|
||||
hasmap = true;
|
||||
}
|
||||
|
@ -446,39 +436,6 @@ void FWadFile::SkinHack ()
|
|||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FindStrifeTeaserVoices
|
||||
//
|
||||
// Strife0.wad does not have the voices between V_START/V_END markers, so
|
||||
// figure out which lumps are voices based on their names.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FWadFile::FindStrifeTeaserVoices ()
|
||||
{
|
||||
for (uint32_t i = 0; i <= NumLumps; ++i)
|
||||
{
|
||||
if (Lumps[i].Name[0] == 'V' &&
|
||||
Lumps[i].Name[1] == 'O' &&
|
||||
Lumps[i].Name[2] == 'C')
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 3; j < 8; ++j)
|
||||
{
|
||||
if (Lumps[i].Name[j] != 0 && !isdigit(Lumps[i].Name[j]))
|
||||
break;
|
||||
}
|
||||
if (j == 8)
|
||||
{
|
||||
Lumps[i].Namespace = ns_strifevoices;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// File open
|
||||
|
|
|
@ -100,52 +100,7 @@ void FResourceLump::LumpNameSetup(FString iname)
|
|||
iname = "";
|
||||
}
|
||||
|
||||
long slash = iname.LastIndexOf('/');
|
||||
FString base = (slash >= 0) ? iname.Mid(slash + 1) : iname;
|
||||
auto dot = base.LastIndexOf('.');
|
||||
if (dot >= 0) base.Truncate(dot);
|
||||
uppercopy(Name, base);
|
||||
Name[8] = 0;
|
||||
FullName = iname;
|
||||
|
||||
// Map some directories to WAD namespaces.
|
||||
// Note that some of these namespaces don't exist in WADS.
|
||||
// CheckNumForName will handle any request for these namespaces accordingly.
|
||||
Namespace = !strncmp(iname, "flats/", 6) ? ns_flats :
|
||||
!strncmp(iname, "textures/", 9) ? ns_newtextures :
|
||||
!strncmp(iname, "hires/", 6) ? ns_hires :
|
||||
!strncmp(iname, "sprites/", 8) ? ns_sprites :
|
||||
!strncmp(iname, "voxels/", 7) ? ns_voxels :
|
||||
!strncmp(iname, "colormaps/", 10) ? ns_colormaps :
|
||||
!strncmp(iname, "acs/", 4) ? ns_acslibrary :
|
||||
!strncmp(iname, "voices/", 7) ? ns_strifevoices :
|
||||
!strncmp(iname, "patches/", 8) ? ns_patches :
|
||||
!strncmp(iname, "graphics/", 9) ? ns_graphics :
|
||||
!strncmp(iname, "sounds/", 7) ? ns_sounds :
|
||||
!strncmp(iname, "music/", 6) ? ns_music :
|
||||
!strchr(iname, '/') ? ns_global :
|
||||
ns_hidden;
|
||||
|
||||
// Anything that is not in one of these subdirectories or the main directory
|
||||
// should not be accessible through the standard WAD functions but only through
|
||||
// the ones which look for the full name.
|
||||
if (Namespace == ns_hidden)
|
||||
{
|
||||
memset(Name, 0, 8);
|
||||
}
|
||||
|
||||
// Since '\' can't be used as a file name's part inside a ZIP
|
||||
// we have to work around this for sprites because it is a valid
|
||||
// frame character.
|
||||
else if (Namespace == ns_sprites || Namespace == ns_voxels || Namespace == ns_hires)
|
||||
{
|
||||
char *c;
|
||||
|
||||
while ((c = (char*)memchr(Name, '^', 8)))
|
||||
{
|
||||
*c = '\\';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -177,9 +132,7 @@ void FResourceLump::CheckEmbedded()
|
|||
const char *c = strstr(FullName, ".wad");
|
||||
if (c && strlen(c) == 4 && (!strchr(FullName, '/') || IsWadInFolder(Owner, FullName)))
|
||||
{
|
||||
// Mark all embedded WADs
|
||||
Flags |= LUMPF_EMBEDDED;
|
||||
memset(Name, 0, 8);
|
||||
}
|
||||
/* later
|
||||
else
|
||||
|
@ -381,7 +334,6 @@ void FResourceFile::GenerateHash()
|
|||
for(uint32_t i = 0; i < NumLumps; i++)
|
||||
{
|
||||
auto lump = GetLump(i);
|
||||
md5.Update((const uint8_t*)lump->Name, (unsigned)strlen(lump->Name) + 1); // +1 to hash the terminating 0 as well.
|
||||
md5.Update((const uint8_t*)lump->FullName.GetChars(), (unsigned)lump->FullName.Len() + 1);
|
||||
md5.Update((const uint8_t*)&lump->LumpSize, 4);
|
||||
}
|
||||
|
@ -552,8 +504,6 @@ void FResourceFile::JunkLeftoverFilters(void *lumps, size_t lumpsize, uint32_t m
|
|||
{
|
||||
FResourceLump *lump = (FResourceLump *)p;
|
||||
lump->FullName = "";
|
||||
lump->Name[0] = '\0';
|
||||
lump->Namespace = ns_hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -632,16 +582,6 @@ bool FResourceFile::FindPrefixRange(FString filter, void *lumps, size_t lumpsize
|
|||
return true;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Needs to be virtual in the base class. Implemented only for WADs
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void FResourceFile::FindStrifeTeaserVoices ()
|
||||
{
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Finds a lump by a given name. Used for savegames
|
||||
|
@ -777,7 +717,6 @@ bool FMemoryFile::Open(bool quiet)
|
|||
Lumps[0].Owner = this;
|
||||
Lumps[0].Position = 0;
|
||||
Lumps[0].LumpSize = (int)Reader.GetLength();
|
||||
Lumps[0].Namespace = ns_global;
|
||||
Lumps[0].Flags = 0;
|
||||
NumLumps = 1;
|
||||
return true;
|
||||
|
|
|
@ -8,6 +8,37 @@
|
|||
class FResourceFile;
|
||||
class FTexture;
|
||||
|
||||
// [RH] Namespaces from BOOM.
|
||||
// These are needed here in the low level part so that WAD files can be properly set up.
|
||||
typedef enum {
|
||||
ns_hidden = -1,
|
||||
|
||||
ns_global = 0,
|
||||
ns_sprites,
|
||||
ns_flats,
|
||||
ns_colormaps,
|
||||
ns_acslibrary,
|
||||
ns_newtextures,
|
||||
ns_bloodraw, // no longer used - kept for ZScript.
|
||||
ns_bloodsfx, // no longer used - kept for ZScript.
|
||||
ns_bloodmisc, // no longer used - kept for ZScript.
|
||||
ns_strifevoices,
|
||||
ns_hires,
|
||||
ns_voxels,
|
||||
|
||||
// These namespaces are only used to mark lumps in special subdirectories
|
||||
// so that their contents doesn't interfere with the global namespace.
|
||||
// searching for data in these namespaces works differently for lumps coming
|
||||
// from Zips or other files.
|
||||
ns_specialzipdirectory,
|
||||
ns_sounds,
|
||||
ns_patches,
|
||||
ns_graphics,
|
||||
ns_music,
|
||||
|
||||
ns_firstskin,
|
||||
} namespace_t;
|
||||
|
||||
enum ELumpFlags
|
||||
{
|
||||
LUMPF_MAYBEFLAT = 1, // might be a flat outside F_START/END
|
||||
|
@ -47,19 +78,11 @@ struct FResourceLump
|
|||
int LumpSize;
|
||||
protected:
|
||||
FString FullName; // only valid for files loaded from a non-wad archive
|
||||
union
|
||||
{
|
||||
char Name[9];
|
||||
|
||||
uint32_t dwName; // These are for accessing the first 4 or 8 chars of
|
||||
uint64_t qwName; // Name as a unit without breaking strict aliasing rules
|
||||
};
|
||||
public:
|
||||
uint8_t Flags;
|
||||
int8_t RefCount;
|
||||
char * Cache;
|
||||
FResourceFile * Owner;
|
||||
int Namespace;
|
||||
|
||||
FResourceLump()
|
||||
{
|
||||
|
@ -67,8 +90,6 @@ public:
|
|||
Owner = NULL;
|
||||
Flags = 0;
|
||||
RefCount = 0;
|
||||
Namespace = 0; // ns_global
|
||||
*Name = 0;
|
||||
}
|
||||
|
||||
virtual ~FResourceLump();
|
||||
|
@ -76,6 +97,7 @@ public:
|
|||
virtual FileReader NewReader();
|
||||
virtual int GetFileOffset() { return -1; }
|
||||
virtual int GetIndexNum() const { return 0; }
|
||||
virtual int GetNamespace() const { return 0; }
|
||||
void LumpNameSetup(FString iname);
|
||||
void CheckEmbedded();
|
||||
virtual FCompressedBuffer GetRawData();
|
||||
|
@ -83,9 +105,7 @@ public:
|
|||
void *CacheLump();
|
||||
int ReleaseCache();
|
||||
|
||||
const char* shortName() { return Name; }
|
||||
const FString &longName() { return FullName; }
|
||||
const char* getName() { return FullName.IsNotEmpty() ? FullName.GetChars() : Name; }
|
||||
const char* getName() { return FullName.GetChars(); }
|
||||
|
||||
protected:
|
||||
virtual int FillCache() { return -1; }
|
||||
|
@ -131,7 +151,6 @@ public:
|
|||
const FString &GetHash() const { return Hash; }
|
||||
|
||||
|
||||
virtual void FindStrifeTeaserVoices ();
|
||||
virtual bool Open(bool quiet) = 0;
|
||||
virtual FResourceLump *GetLump(int no) = 0;
|
||||
FResourceLump *FindLump(const char *name);
|
||||
|
|
|
@ -72,11 +72,104 @@ union LumpShortName
|
|||
|
||||
struct FWadCollection::LumpRecord
|
||||
{
|
||||
int wadnum;
|
||||
FResourceLump *lump;
|
||||
FTexture* linkedTexture;
|
||||
LumpShortName shortName;
|
||||
FString longName;
|
||||
FString longName;
|
||||
int wadnum;
|
||||
int Namespace;
|
||||
int resourceId;
|
||||
|
||||
void SetFromLump(int filenum, FResourceLump* lmp)
|
||||
{
|
||||
lump = lmp;
|
||||
wadnum = filenum;
|
||||
linkedTexture = nullptr;
|
||||
|
||||
if (lump->Flags & LUMPF_SHORTNAME)
|
||||
{
|
||||
uppercopy(shortName.String, lump->getName());
|
||||
shortName.String[8] = 0;
|
||||
longName = "";
|
||||
Namespace = lump->GetNamespace();
|
||||
resourceId = 0;
|
||||
|
||||
if (gameinfo.gametype == GAME_Strife && gameinfo.flags & GI_SHAREWARE && filenum == Wads.GetIwadNum())
|
||||
{
|
||||
if (shortName.String[0] == 'V' &&
|
||||
shortName.String[1] == 'O' &&
|
||||
shortName.String[2] == 'C')
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 3; j < 8; ++j)
|
||||
{
|
||||
if (shortName.String[j] != 0 && !isdigit(shortName.String[j]))
|
||||
break;
|
||||
}
|
||||
if (j == 8)
|
||||
{
|
||||
Namespace = ns_strifevoices;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if ((lump->Flags & LUMPF_EMBEDDED) || !lump->getName() || !*lump->getName())
|
||||
{
|
||||
shortName.qword = 0;
|
||||
longName = "";
|
||||
Namespace = ns_hidden;
|
||||
resourceId = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
longName = lump->getName();
|
||||
resourceId = lump->GetIndexNum();
|
||||
|
||||
// Map some directories to WAD namespaces.
|
||||
// Note that some of these namespaces don't exist in WADS.
|
||||
// CheckNumForName will handle any request for these namespaces accordingly.
|
||||
Namespace = !strncmp(longName.GetChars(), "flats/", 6) ? ns_flats :
|
||||
!strncmp(longName.GetChars(), "textures/", 9) ? ns_newtextures :
|
||||
!strncmp(longName.GetChars(), "hires/", 6) ? ns_hires :
|
||||
!strncmp(longName.GetChars(), "sprites/", 8) ? ns_sprites :
|
||||
!strncmp(longName.GetChars(), "voxels/", 7) ? ns_voxels :
|
||||
!strncmp(longName.GetChars(), "colormaps/", 10) ? ns_colormaps :
|
||||
!strncmp(longName.GetChars(), "acs/", 4) ? ns_acslibrary :
|
||||
!strncmp(longName.GetChars(), "voices/", 7) ? ns_strifevoices :
|
||||
!strncmp(longName.GetChars(), "patches/", 8) ? ns_patches :
|
||||
!strncmp(longName.GetChars(), "graphics/", 9) ? ns_graphics :
|
||||
!strncmp(longName.GetChars(), "sounds/", 7) ? ns_sounds :
|
||||
!strncmp(longName.GetChars(), "music/", 6) ? ns_music :
|
||||
!strchr(longName.GetChars(), '/') ? ns_global :
|
||||
ns_hidden;
|
||||
|
||||
if (Namespace == ns_hidden) shortName.qword = 0;
|
||||
else
|
||||
{
|
||||
long slash = longName.LastIndexOf('/');
|
||||
FString base = (slash >= 0) ? longName.Mid(slash + 1) : longName;
|
||||
auto dot = base.LastIndexOf('.');
|
||||
if (dot >= 0) base.Truncate(dot);
|
||||
uppercopy(shortName.String, base);
|
||||
shortName.String[8] = 0;
|
||||
|
||||
// Since '\' can't be used as a file name's part inside a ZIP
|
||||
// we have to work around this for sprites because it is a valid
|
||||
// frame character.
|
||||
if (Namespace == ns_sprites || Namespace == ns_voxels || Namespace == ns_hires)
|
||||
{
|
||||
char* c;
|
||||
|
||||
while ((c = (char*)memchr(shortName.String, '^', 8)))
|
||||
{
|
||||
*c = '\\';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
||||
|
@ -224,11 +317,7 @@ int FWadCollection::AddExternalFile(const char *filename)
|
|||
FResourceLump *lump = new FExternalLump(filename);
|
||||
|
||||
FWadCollection::LumpRecord *lumprec = &LumpInfo[LumpInfo.Reserve(1)];
|
||||
lumprec->lump = lump;
|
||||
lumprec->wadnum = -1;
|
||||
lumprec->linkedTexture = nullptr;
|
||||
memcpy(lumprec->shortName.String, lump->shortName(), 9);
|
||||
lumprec->longName = lump->longName();
|
||||
lumprec->SetFromLump(-1, lump);
|
||||
return LumpInfo.Size()-1; // later
|
||||
}
|
||||
|
||||
|
@ -295,18 +384,9 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadr, bool quiet
|
|||
{
|
||||
FResourceLump *lump = resfile->GetLump(i);
|
||||
FWadCollection::LumpRecord *lump_p = &LumpInfo[LumpInfo.Reserve(1)];
|
||||
|
||||
lump_p->lump = lump;
|
||||
lump_p->wadnum = Files.Size();
|
||||
lump_p->linkedTexture = nullptr;
|
||||
memcpy(lump_p->shortName.String, lump->shortName(), 9);
|
||||
lump_p->longName = lump->longName();
|
||||
lump_p->SetFromLump(Files.Size(), lump);
|
||||
}
|
||||
|
||||
if (static_cast<int>(Files.Size()) == GetIwadNum() && gameinfo.gametype == GAME_Strife && gameinfo.flags & GI_SHAREWARE)
|
||||
{
|
||||
resfile->FindStrifeTeaserVoices();
|
||||
}
|
||||
Files.Push(resfile);
|
||||
|
||||
for (uint32_t i=0; i < resfile->LumpCount(); i++)
|
||||
|
@ -459,15 +539,15 @@ int FWadCollection::CheckNumForName (const char *name, int space)
|
|||
|
||||
if (LumpInfo[i].shortName.qword == qname)
|
||||
{
|
||||
FResourceLump* lump = LumpInfo[i].lump;
|
||||
if (lump->Namespace == space) break;
|
||||
auto &lump = LumpInfo[i];
|
||||
if (lump.Namespace == space) break;
|
||||
// If the lump is from one of the special namespaces exclusive to Zips
|
||||
// the check has to be done differently:
|
||||
// If we find a lump with this name in the global namespace that does not come
|
||||
// from a Zip return that. WADs don't know these namespaces and single lumps must
|
||||
// work as well.
|
||||
if (space > ns_specialzipdirectory && lump->Namespace == ns_global &&
|
||||
!(lump->Flags & LUMPF_FULLPATH)) break;
|
||||
if (space > ns_specialzipdirectory && lump.Namespace == ns_global &&
|
||||
!(lump.lump->Flags & LUMPF_FULLPATH)) break;
|
||||
}
|
||||
i = NextLumpIndex[i];
|
||||
}
|
||||
|
@ -477,7 +557,6 @@ int FWadCollection::CheckNumForName (const char *name, int space)
|
|||
|
||||
int FWadCollection::CheckNumForName (const char *name, int space, int wadnum, bool exact)
|
||||
{
|
||||
FResourceLump *lump;
|
||||
union
|
||||
{
|
||||
char uname[8];
|
||||
|
@ -497,8 +576,7 @@ int FWadCollection::CheckNumForName (const char *name, int space, int wadnum, bo
|
|||
// also those in earlier WADs.
|
||||
|
||||
while (i != NULL_INDEX &&
|
||||
(lump = LumpInfo[i].lump, LumpInfo[i].shortName.qword != qname ||
|
||||
lump->Namespace != space ||
|
||||
(LumpInfo[i].shortName.qword != qname || LumpInfo[i].Namespace != space ||
|
||||
(exact? (LumpInfo[i].wadnum != wadnum) : (LumpInfo[i].wadnum > wadnum)) ))
|
||||
{
|
||||
i = NextLumpIndex[i];
|
||||
|
@ -872,7 +950,7 @@ void FWadCollection::RenameSprites (const TArray<FString> &deletelumps)
|
|||
{
|
||||
// check for full Minotaur animations. If this is not found
|
||||
// some frames need to be renamed.
|
||||
if (LumpInfo[i].lump->Namespace == ns_sprites)
|
||||
if (LumpInfo[i].Namespace == ns_sprites)
|
||||
{
|
||||
if (LumpInfo[i].shortName.dword == MAKE_ID('M', 'N', 'T', 'R') && LumpInfo[i].shortName.String[4] == 'Z' )
|
||||
{
|
||||
|
@ -886,7 +964,7 @@ void FWadCollection::RenameSprites (const TArray<FString> &deletelumps)
|
|||
|
||||
for (uint32_t i = 0; i < LumpInfo.Size(); i++)
|
||||
{
|
||||
if (LumpInfo[i].lump->Namespace == ns_sprites)
|
||||
if (LumpInfo[i].Namespace == ns_sprites)
|
||||
{
|
||||
// Only sprites in the IWAD normally get renamed
|
||||
if (renameAll || LumpInfo[i].wadnum == GetIwadNum())
|
||||
|
@ -932,7 +1010,7 @@ void FWadCollection::RenameSprites (const TArray<FString> &deletelumps)
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (LumpInfo[i].lump->Namespace == ns_global)
|
||||
else if (LumpInfo[i].Namespace == ns_global)
|
||||
{
|
||||
if (LumpInfo[i].wadnum >= GetIwadNum() && LumpInfo[i].wadnum <= GetMaxIwadNum() && deletelumps.Find(LumpInfo[i].shortName.String) < deletelumps.Size())
|
||||
{
|
||||
|
@ -1134,11 +1212,8 @@ void FWadCollection::MoveLumpsInFolder(const char *path)
|
|||
LumpInfo.Push(li);
|
||||
li.lump = &placeholderLump; // Make the old entry point to something empty. We cannot delete the lump record here because it'd require adjustment of all indices in the list.
|
||||
auto &ln = LumpInfo.Last();
|
||||
ln.wadnum = wadnum; // pretend this is from the WAD this is injected into.
|
||||
ln.lump->LumpNameSetup(ln.longName.Mid(len));
|
||||
ln.linkedTexture = nullptr;
|
||||
strcpy(ln.shortName.String, ln.lump->shortName());
|
||||
ln.longName = ln.lump->longName();
|
||||
ln.SetFromLump(wadnum, ln.lump);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1167,9 +1242,7 @@ int FWadCollection::FindLump (const char *name, int *lastlump, bool anyns)
|
|||
lump_p = &LumpInfo[*lastlump];
|
||||
while (lump_p < &LumpInfo[NumLumps])
|
||||
{
|
||||
FResourceLump *lump = lump_p->lump;
|
||||
|
||||
if ((anyns || lump->Namespace == ns_global) && lump_p->shortName.qword == qname)
|
||||
if ((anyns || lump_p->Namespace == ns_global) && lump_p->shortName.qword == qname)
|
||||
{
|
||||
int lump = int(lump_p - &LumpInfo[0]);
|
||||
*lastlump = lump + 1;
|
||||
|
@ -1209,9 +1282,7 @@ int FWadCollection::FindLumpMulti (const char **names, int *lastlump, bool anyns
|
|||
lump_p = &LumpInfo[*lastlump];
|
||||
while (lump_p < &LumpInfo[NumLumps])
|
||||
{
|
||||
FResourceLump *lump = lump_p->lump;
|
||||
|
||||
if (anyns || lump->Namespace == ns_global)
|
||||
if (anyns || lump_p->Namespace == ns_global)
|
||||
{
|
||||
|
||||
for(const char **name = names; *name != NULL; name++)
|
||||
|
@ -1343,7 +1414,7 @@ int FWadCollection::GetLumpNamespace (int lump) const
|
|||
if ((size_t)lump >= NumLumps)
|
||||
return ns_global;
|
||||
else
|
||||
return LumpInfo[lump].lump->Namespace;
|
||||
return LumpInfo[lump].Namespace;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(_Wads, GetLumpNamespace)
|
||||
|
@ -1368,7 +1439,7 @@ int FWadCollection::GetLumpIndexNum(int lump) const
|
|||
if ((size_t)lump >= NumLumps)
|
||||
return 0;
|
||||
else
|
||||
return LumpInfo[lump].lump->GetIndexNum();
|
||||
return LumpInfo[lump].resourceId;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "doomdef.h"
|
||||
#include "tarray.h"
|
||||
#include "zstring.h"
|
||||
#include "resourcefiles/resourcefile.h"
|
||||
|
||||
class FResourceFile;
|
||||
struct FResourceLump;
|
||||
|
@ -37,37 +38,6 @@ struct wadlump_t
|
|||
#define PWAD_ID MAKE_ID('P','W','A','D')
|
||||
|
||||
|
||||
// [RH] Namespaces from BOOM.
|
||||
typedef enum {
|
||||
ns_hidden = -1,
|
||||
|
||||
ns_global = 0,
|
||||
ns_sprites,
|
||||
ns_flats,
|
||||
ns_colormaps,
|
||||
ns_acslibrary,
|
||||
ns_newtextures,
|
||||
ns_bloodraw,
|
||||
ns_bloodsfx,
|
||||
ns_bloodmisc,
|
||||
ns_strifevoices,
|
||||
ns_hires,
|
||||
ns_voxels,
|
||||
|
||||
// These namespaces are only used to mark lumps in special subdirectories
|
||||
// so that their contents doesn't interfere with the global namespace.
|
||||
// searching for data in these namespaces works differently for lumps coming
|
||||
// from Zips or other files.
|
||||
ns_specialzipdirectory,
|
||||
ns_sounds,
|
||||
ns_patches,
|
||||
ns_graphics,
|
||||
ns_music,
|
||||
|
||||
ns_firstskin,
|
||||
} namespace_t;
|
||||
|
||||
|
||||
// [RH] Copy an 8-char string and uppercase it.
|
||||
void uppercopy (char *to, const char *from);
|
||||
|
||||
|
|
|
@ -791,10 +791,6 @@ void S_ParseSndInfo (bool redefine)
|
|||
}
|
||||
break;
|
||||
|
||||
case ns_bloodsfx:
|
||||
S_AddBloodSFX (lump);
|
||||
break;
|
||||
|
||||
case ns_strifevoices:
|
||||
S_AddStrifeVoice (lump);
|
||||
break;
|
||||
|
@ -1274,54 +1270,6 @@ static void S_AddSNDINFO (int lump)
|
|||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// S_AddBloodSFX
|
||||
//
|
||||
// Registers a new sound with the name "<lumpname>.sfx"
|
||||
// Actual sound data is searched for in the ns_bloodraw namespace.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void S_AddBloodSFX (int lumpnum)
|
||||
{
|
||||
FMemLump sfxlump = Wads.ReadLump(lumpnum);
|
||||
const FBloodSFX *sfx = (FBloodSFX *)sfxlump.GetMem();
|
||||
int rawlump = Wads.CheckNumForName(sfx->RawName, ns_bloodraw);
|
||||
int sfxnum;
|
||||
|
||||
if (rawlump != -1)
|
||||
{
|
||||
auto &S_sfx = soundEngine->GetSounds();
|
||||
const char *name = Wads.GetLumpFullName(lumpnum);
|
||||
sfxnum = S_AddSound(name, rawlump);
|
||||
if (sfx->Format < 5 || sfx->Format > 12)
|
||||
{ // [0..4] + invalid formats
|
||||
S_sfx[sfxnum].RawRate = 11025;
|
||||
}
|
||||
else if (sfx->Format < 9)
|
||||
{ // [5..8]
|
||||
S_sfx[sfxnum].RawRate = 22050;
|
||||
}
|
||||
else
|
||||
{ // [9..12]
|
||||
S_sfx[sfxnum].RawRate = 44100;
|
||||
}
|
||||
S_sfx[sfxnum].bLoadRAW = true;
|
||||
S_sfx[sfxnum].LoopStart = LittleLong(sfx->LoopStart);
|
||||
// Make an ambient sound out of it, whether it has a loop point
|
||||
// defined or not. (Because none of the standard Blood ambient
|
||||
// sounds are explicitly defined as looping.)
|
||||
FAmbientSound *ambient = &Ambients[Wads.GetLumpIndexNum(lumpnum)];
|
||||
ambient->type = CONTINUOUS;
|
||||
ambient->periodmin = 0;
|
||||
ambient->periodmax = 0;
|
||||
ambient->volume = 1;
|
||||
ambient->attenuation = 1;
|
||||
ambient->sound = FSoundID(sfxnum);
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// S_AddStrifeVoice
|
||||
|
|
Loading…
Reference in a new issue