implement the different reader types.

This commit is contained in:
Christoph Oelckers 2023-12-13 22:29:15 +01:00
commit 737e3f22d7
12 changed files with 73 additions and 43 deletions

View file

@ -31,7 +31,8 @@ enum EDecompressFlags
{
DCF_TRANSFEROWNER = 1,
DCF_SEEKABLE = 2,
DCF_EXCEPTIONS = 4
DCF_EXCEPTIONS = 4,
DCF_CACHED = 8,
};
bool OpenDecompressor(FileReader& self, FileReader &parent, FileReader::Size length, int method, int flags = 0); // creates a decompressor stream. 'seekable' uses a buffered version so that the Seek and Tell methods can be used.

View file

@ -93,10 +93,19 @@ public:
FileData ReadFile (const char *name) { return ReadFile (GetNumForName (name)); }
FileData ReadFileFullName(const char* name) { return ReadFile(GetNumForFullName(name)); }
FileReader OpenFileReader(int lump); // opens a reader that redirects to the containing file's one.
FileReader ReopenFileReader(int lump, bool alwayscache = false); // opens an independent reader.
FileReader OpenFileReader(int lump, int readertype, int readerflags); // opens a reader that redirects to the containing file's one.
FileReader OpenFileReader(const char* name);
FileReader ReopenFileReader(const char* name, bool alwayscache = false);
FileReader OpenFileReader(int lump)
{
return OpenFileReader(lump, READER_SHARED, READERFLAG_SEEKABLE);
}
FileReader ReopenFileReader(int lump, bool alwayscache = false)
{
return OpenFileReader(lump, alwayscache ? READER_CACHED : READER_NEW, READERFLAG_SEEKABLE);
}
int FindLump (const char *name, int *lastlump, bool anyns=false); // [RH] Find lumps with duplication
int FindLumpMulti (const char **names, int *lastlump, bool anyns = false, int *nameindex = NULL); // same with multiple possible names

View file

@ -86,6 +86,14 @@ enum ELumpFlags
RESFF_NEEDFILESTART = 32, // The real position is not known yet and needs to be calculated on access
};
enum EReaderType
{
READER_SHARED = 0, // returns a view into the parent's reader.
READER_NEW = 1, // opens a new file handle
READER_CACHED = 2, // returns a MemoryArrayReader
READERFLAG_SEEKABLE = 1 // ensure the reader is seekable.
};
struct FResourceEntry
{
size_t Length;
@ -156,7 +164,8 @@ public:
return (entry < NumLumps) ? Entries[entry].Position : 0;
}
virtual FileReader GetEntryReader(uint32_t entry, bool newreader = true);
// default is the safest reader type.
virtual FileReader GetEntryReader(uint32_t entry, int readertype = READER_NEW, int flags = READERFLAG_SEEKABLE);
int GetEntryFlags(uint32_t entry)
{
@ -180,8 +189,8 @@ public:
virtual FileData Read(int entry)
{
auto fr = GetEntryReader(entry, false);
return fr.Read();
auto fr = GetEntryReader(entry, READER_SHARED, 0);
return fr.Read(entry < NumLumps ? Entries[entry].Length : 0);
}
virtual FCompressedBuffer GetRawData(uint32_t entry);