rewrote FileSystem::AddFromBuffer so that it gets backed by an actual FResourceFile.

This commit is contained in:
Christoph Oelckers 2023-12-10 15:26:36 +01:00
parent 0a1eccef92
commit c1ecc41f9d
2 changed files with 17 additions and 35 deletions

View file

@ -169,8 +169,7 @@ public:
return (int)Files.size();
}
void AddLump(FResourceLump* lump);
int AddFromBuffer(const char* name, const char* type, char* data, int size, int id, int flags);
int AddFromBuffer(const char* name, char* data, int size, int id, int flags);
FileReader* GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD
void InitHashChains();

View file

@ -287,20 +287,6 @@ bool FileSystem::InitMultipleFiles (std::vector<std::string>& filenames, LumpFil
return true;
}
//==========================================================================
//
// AddLump
//
// Adds a given lump to the directory. Does not perform rehashing
//
//==========================================================================
void FileSystem::AddLump(FResourceLump *lump)
{
FileInfo.resize(FileInfo.size() + 1);
FileInfo.back().SetFromLump(-1, lump, stringpool);
}
//==========================================================================
//
// AddFromBuffer
@ -309,27 +295,24 @@ void FileSystem::AddLump(FResourceLump *lump)
//
//==========================================================================
struct FMemoryLump : public FResourceLump
{
FMemoryLump(const void* data, int length)
{
RefCount = -1;
LumpSize = length;
Cache = new char[length];
memcpy(Cache, data, length);
}
};
FResourceFile* CheckLump(const char* filename, FileReader& file, LumpFilterInfo*, FileSystemMessageFunc Printf, StringPool* sp);
int FileSystem::AddFromBuffer(const char* name, const char* type, char* data, int size, int id, int flags)
int FileSystem::AddFromBuffer(const char* name, char* data, int size, int id, int flags)
{
std::string fullname = name;
fullname += '.';
fullname += type;
auto newlump = new FMemoryLump(data, size);
newlump->LumpNameSetup(fullname.c_str(), stringpool);
AddLump(newlump);
FileInfo.back().resourceId = id;
return (int)FileInfo.size()-1;
FileReader fr;
fr.OpenMemoryArray((uint8_t*)data, size);
// just wrap this into a single lump resource file (should be done a little better later.)
auto rf = CheckLump(name, fr, nullptr, nullptr, stringpool);
if (rf)
{
Files.push_back(rf);
FResourceLump* lump = rf->GetLump(0);
FileInfo.resize(FileInfo.size() + 1);
FileSystem::LumpRecord* lump_p = &FileInfo.back();
lump_p->SetFromLump((int)Files.size(), lump, stringpool);
}
return (int)FileInfo.size() - 1;
}
//==========================================================================