- use the lump cache directly for FileData.

This was the final puzzle piece to allow using memory mapped files. :)
This commit is contained in:
Christoph Oelckers 2023-08-20 02:04:19 +02:00
parent 2c2bf0265f
commit 4f8305de5f
2 changed files with 25 additions and 32 deletions

View file

@ -1518,29 +1518,6 @@ bool FileSystem::CreatePathlessCopy(const char *name, int id, int /*flags*/)
return true;
}
// FileData -----------------------------------------------------------------
FileData::FileData (const FileData &copy)
{
Block = copy.Block;
}
FileData &FileData::operator = (const FileData &copy)
{
Block = copy.Block;
return *this;
}
FileData::FileData (FResourceLump* lump)
{
auto size = lump->LumpSize;
Block.resize(1 + size);
memcpy(Block.data(), lump->Lock(), size);
Block[size] = 0;
lump->Unlock();
}
//==========================================================================
//
// PrintLastError

View file

@ -28,18 +28,34 @@ union LumpShortName
class FileData
{
public:
FileData () = default;
FileData (const FileData &copy);
FileData &operator= (const FileData &copy);
const void *GetMem () { return Block.size() <= 1 ? NULL : (void *)Block.data(); }
size_t GetSize () { return Block.size(); }
const char* GetString () const { return (const char*)Block.data(); }
const uint8_t* GetBytes() const { return Block.data(); }
FileData() { lump = nullptr; }
const void *GetMem () { return lump->Cache; }
size_t GetSize () { return lump->LumpSize; }
const char* GetString () const { return (const char*)lump->Cache; }
const uint8_t* GetBytes() const { return (const uint8_t*)lump->Cache; }
FileData& operator = (const FileData& copy) = delete;
FileData(const FileData& copy)
{
lump = copy.lump;
lump->Lock();
}
~FileData()
{
if (lump) lump->Unlock();
}
private:
FileData (FResourceLump* lump);
FileData(FResourceLump* nlump)
{
lump = nlump;
if (lump) lump->Lock();
}
std::vector<uint8_t> Block;
FResourceLump* lump;
friend class FileSystem;
};