- renamed the caching functions of FResourceLump.

This commit is contained in:
Christoph Oelckers 2020-04-11 13:19:59 +02:00
parent 510fc2d549
commit d12a9bb77a
4 changed files with 16 additions and 19 deletions

View file

@ -1840,7 +1840,7 @@ void G_DoLoadGame ()
SaveVersion = 0;
void *data = info->CacheLump();
void *data = info->Lock();
FSerializer arc(nullptr);
if (!arc.OpenReader((const char *)data, info->LumpSize))
{
@ -1916,7 +1916,7 @@ void G_DoLoadGame ()
return;
}
data = info->CacheLump();
data = info->Lock();
if (!arc.OpenReader((const char *)data, info->LumpSize))
{
LoadGameError("TXT_SGINFOERR");

View file

@ -58,13 +58,13 @@ public:
FLumpReader(FResourceLump *src)
: MemoryReader(NULL, src->LumpSize), source(src)
{
src->CacheLump();
src->Lock();
bufptr = src->Cache;
}
~FLumpReader()
{
source->ReleaseCache();
source->Unlock();
}
};
@ -163,9 +163,9 @@ void FResourceLump::CheckEmbedded()
FCompressedBuffer FResourceLump::GetRawData()
{
FCompressedBuffer cbuf = { (unsigned)LumpSize, (unsigned)LumpSize, METHOD_STORED, 0, 0, new char[LumpSize] };
memcpy(cbuf.mBuffer, CacheLump(), LumpSize);
memcpy(cbuf.mBuffer, Lock(), LumpSize);
Unlock();
cbuf.mCRC32 = crc32(0, (uint8_t*)cbuf.mBuffer, LumpSize);
ReleaseCache();
return cbuf;
}
@ -198,7 +198,7 @@ FileReader FResourceLump::NewReader()
//
//==========================================================================
void *FResourceLump::CacheLump()
void *FResourceLump::Lock()
{
if (Cache != NULL)
{
@ -217,7 +217,7 @@ void *FResourceLump::CacheLump()
//
//==========================================================================
int FResourceLump::ReleaseCache()
int FResourceLump::Unlock()
{
if (LumpSize > 0 && RefCount > 0)
{

View file

@ -102,9 +102,11 @@ public:
void CheckEmbedded();
virtual FCompressedBuffer GetRawData();
void *CacheLump();
int ReleaseCache();
void *Lock(); // validates the cache and increases the refcount.
int Unlock(); // decreases the refcount and frees the buffer
unsigned Size() const{ return LumpSize; }
int LockCount() const { return RefCount; }
const char* getName() { return FullName.GetChars(); }
protected:

View file

@ -170,7 +170,7 @@ void FSavegameManager::ReadSaveStrings()
// I_FindName only returns the file's name and not its full path
FString filepath = G_BuildSaveName(I_FindName(&c_file), -1);
FResourceFile *savegame = FResourceFile::OpenResourceFile(filepath, true, true);
std::unique_ptr<FResourceFile> savegame(FResourceFile::OpenResourceFile(filepath, true, true));
if (savegame != nullptr)
{
bool oldVer = false;
@ -179,10 +179,9 @@ void FSavegameManager::ReadSaveStrings()
if (info == nullptr)
{
// savegame info not found. This is not a savegame so leave it alone.
delete savegame;
continue;
}
void *data = info->CacheLump();
void *data = info->Lock();
FSerializer arc(nullptr);
if (arc.OpenReader((const char *)data, info->LumpSize))
{
@ -197,7 +196,6 @@ void FSavegameManager::ReadSaveStrings()
{
// different engine or newer version:
// not our business. Leave it alone.
delete savegame;
continue;
}
@ -213,7 +211,6 @@ void FSavegameManager::ReadSaveStrings()
else
{
// different game. Skip this.
delete savegame;
continue;
}
@ -223,7 +220,6 @@ void FSavegameManager::ReadSaveStrings()
node->bMissingWads = missing;
node->SaveTitle = title;
InsertSaveNode(node);
delete savegame;
}
}
@ -472,7 +468,7 @@ unsigned FSavegameManager::ExtractSaveData(int index)
// this should not happen because the file has already been verified.
return index;
}
void *data = info->CacheLump();
void *data = info->Lock();
FSerializer arc(nullptr);
if (arc.OpenReader((const char *)data, info->LumpSize))
{
@ -494,10 +490,9 @@ unsigned FSavegameManager::ExtractSaveData(int index)
picreader.OpenMemoryArray([=](TArray<uint8_t> &array)
{
auto cache = pic->CacheLump();
auto cache = pic->Lock();
array.Resize(pic->LumpSize);
memcpy(&array[0], cache, pic->LumpSize);
pic->ReleaseCache();
return true;
});
PNGHandle *png = M_VerifyPNG(picreader);