mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 12:11:25 +00:00
- use the lump cache directly for FileData.
This was the final puzzle piece to allow using memory mapped files. :)
This commit is contained in:
parent
2c2bf0265f
commit
4f8305de5f
2 changed files with 25 additions and 32 deletions
|
@ -1518,29 +1518,6 @@ bool FileSystem::CreatePathlessCopy(const char *name, int id, int /*flags*/)
|
|||
return true;
|
||||
}
|
||||
|
||||
// FileData -----------------------------------------------------------------
|
||||
|
||||
FileData::FileData (const FileData ©)
|
||||
{
|
||||
Block = copy.Block;
|
||||
}
|
||||
|
||||
FileData &FileData::operator = (const FileData ©)
|
||||
{
|
||||
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
|
||||
|
|
|
@ -28,18 +28,34 @@ union LumpShortName
|
|||
class FileData
|
||||
{
|
||||
public:
|
||||
FileData () = default;
|
||||
FileData (const FileData ©);
|
||||
FileData &operator= (const FileData ©);
|
||||
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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue