mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-21 19:51:27 +00:00
simplification of MemoryArrayReader interface.
This commit is contained in:
parent
9bcbdfa09c
commit
235d36fe69
3 changed files with 3 additions and 33 deletions
|
@ -236,7 +236,6 @@ public:
|
|||
bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer.
|
||||
bool OpenMemoryArray(std::vector<uint8_t>& data); // take the given array
|
||||
bool OpenMemoryArray(FileData& data); // take the given array
|
||||
bool OpenMemoryArray(std::function<bool(std::vector<uint8_t>&)> getter); // read contents to a buffer and return a reader to it
|
||||
|
||||
Size Tell() const
|
||||
{
|
||||
|
|
|
@ -399,13 +399,6 @@ bool FileReader::OpenMemoryArray(const void *mem, FileReader::Size length)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FileReader::OpenMemoryArray(std::vector<uint8_t>& data)
|
||||
{
|
||||
Close();
|
||||
if (data.size() > 0) mReader = new MemoryArrayReader<std::vector<uint8_t>>(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileReader::OpenMemoryArray(FileData& data)
|
||||
{
|
||||
Close();
|
||||
|
@ -413,23 +406,6 @@ bool FileReader::OpenMemoryArray(FileData& data)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FileReader::OpenMemoryArray(std::function<bool(std::vector<uint8_t>&)> getter)
|
||||
{
|
||||
auto reader = new MemoryArrayReader<std::vector<uint8_t>>(nullptr, 0);
|
||||
if (getter(reader->GetArray()))
|
||||
{
|
||||
Close();
|
||||
reader->UpdateBuffer();
|
||||
mReader = reader;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This will keep the old buffer, if one existed
|
||||
delete reader;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -317,14 +317,9 @@ unsigned FSavegameManagerBase::ExtractSaveData(int index)
|
|||
if (pic >= 0)
|
||||
{
|
||||
FileReader picreader;
|
||||
|
||||
picreader.OpenMemoryArray([=](std::vector<uint8_t>& array)
|
||||
{
|
||||
auto rd = resf->GetEntryReader(pic, false);
|
||||
array.resize(resf->Length(pic));
|
||||
rd.Read(array.data(), array.size());
|
||||
return true;
|
||||
});
|
||||
// we must create a memory reader copy of the PNG if we want to close the savegame file here.
|
||||
auto rd = resf->Read(pic);
|
||||
picreader.OpenMemoryArray(rd);
|
||||
PNGHandle *png = M_VerifyPNG(picreader);
|
||||
if (png != nullptr)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue