mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 18:24:55 +00:00
Runtime: Make use of std::make_unique where applicable
Makes use of the C++14 make_unique allocation function to allocate class instances where applicable instead of a reset with a new operator within it. This doesn't touch cases where buffers are allocated, given make_unique would zero-initialize them.
This commit is contained in:
@@ -7,17 +7,19 @@ static logvisor::Module Log("CResLoader");
|
||||
CResLoader::CResLoader() { x48_curPak = x18_pakLoadedList.end(); }
|
||||
|
||||
const std::vector<CAssetId>* CResLoader::GetTagListForFile(std::string_view name) const {
|
||||
std::string namePak = std::string(name) + ".upak";
|
||||
for (const std::unique_ptr<CPakFile>& pak : x18_pakLoadedList)
|
||||
if (!CStringExtras::CompareCaseInsensitive(namePak, pak->x18_path))
|
||||
const std::string namePak = std::string(name).append(".upak");
|
||||
for (const std::unique_ptr<CPakFile>& pak : x18_pakLoadedList) {
|
||||
if (!CStringExtras::CompareCaseInsensitive(namePak, pak->x18_path)) {
|
||||
return &pak->GetDepList();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CResLoader::AddPakFileAsync(std::string_view name, bool buildDepList, bool worldPak) {
|
||||
std::string namePak = std::string(name) + ".upak";
|
||||
if (CDvdFile::FileExists(namePak.c_str())) {
|
||||
x30_pakLoadingList.emplace_back(new CPakFile(namePak, buildDepList, worldPak));
|
||||
const std::string namePak = std::string(name).append(".upak");
|
||||
if (CDvdFile::FileExists(namePak)) {
|
||||
x30_pakLoadingList.emplace_back(std::make_unique<CPakFile>(namePak, buildDepList, worldPak));
|
||||
++x44_pakLoadingCount;
|
||||
}
|
||||
}
|
||||
@@ -35,11 +37,13 @@ void CResLoader::WaitForPakFileLoadingComplete() {
|
||||
std::unique_ptr<CInputStream> CResLoader::LoadNewResourcePartSync(const SObjectTag& tag, u32 length, u32 offset,
|
||||
void* extBuf) {
|
||||
void* buf = extBuf;
|
||||
CPakFile* file = FindResourceForLoad(tag);
|
||||
if (!buf)
|
||||
if (buf == nullptr) {
|
||||
buf = new u8[length];
|
||||
}
|
||||
|
||||
CPakFile* const file = FindResourceForLoad(tag);
|
||||
file->SyncSeekRead(buf, length, ESeekOrigin::Begin, x50_cachedResInfo->GetOffset() + offset);
|
||||
return std::unique_ptr<CInputStream>(new athena::io::MemoryReader((atUint8*)buf, length, !extBuf));
|
||||
return std::make_unique<athena::io::MemoryReader>(buf, length, !extBuf);
|
||||
}
|
||||
|
||||
void CResLoader::LoadMemResourceSync(const SObjectTag& tag, std::unique_ptr<u8[]>& bufOut, int* sizeOut) {
|
||||
@@ -52,29 +56,36 @@ void CResLoader::LoadMemResourceSync(const SObjectTag& tag, std::unique_ptr<u8[]
|
||||
|
||||
std::unique_ptr<CInputStream> CResLoader::LoadResourceFromMemorySync(const SObjectTag& tag, const void* buf) {
|
||||
FindResourceForLoad(tag);
|
||||
CInputStream* newStrm = new athena::io::MemoryReader((atUint8*)buf, x50_cachedResInfo->GetSize());
|
||||
std::unique_ptr<CInputStream> newStrm = std::make_unique<athena::io::MemoryReader>(buf, x50_cachedResInfo->GetSize());
|
||||
if (x50_cachedResInfo->IsCompressed()) {
|
||||
newStrm->readUint32Big();
|
||||
newStrm = new CZipInputStream(std::unique_ptr<CInputStream>(newStrm));
|
||||
newStrm = std::make_unique<CZipInputStream>(std::move(newStrm));
|
||||
}
|
||||
return std::unique_ptr<CInputStream>(newStrm);
|
||||
return newStrm;
|
||||
}
|
||||
|
||||
std::unique_ptr<CInputStream> CResLoader::LoadNewResourceSync(const SObjectTag& tag, void* extBuf) {
|
||||
void* buf = extBuf;
|
||||
if (CPakFile* file = FindResourceForLoad(tag)) {
|
||||
size_t resSz = ROUND_UP_32(x50_cachedResInfo->GetSize());
|
||||
if (!buf)
|
||||
if (CPakFile* const file = FindResourceForLoad(tag)) {
|
||||
const size_t resSz = ROUND_UP_32(x50_cachedResInfo->GetSize());
|
||||
|
||||
void* buf = extBuf;
|
||||
if (buf == nullptr) {
|
||||
buf = new u8[resSz];
|
||||
}
|
||||
|
||||
file->SyncSeekRead(buf, resSz, ESeekOrigin::Begin, x50_cachedResInfo->GetOffset());
|
||||
CInputStream* newStrm = new athena::io::MemoryReader((atUint8*)buf, resSz, !extBuf);
|
||||
|
||||
const bool takeOwnership = extBuf == nullptr;
|
||||
std::unique_ptr<CInputStream> newStrm = std::make_unique<athena::io::MemoryReader>(buf, resSz, takeOwnership);
|
||||
if (x50_cachedResInfo->IsCompressed()) {
|
||||
newStrm->readUint32Big();
|
||||
newStrm = new CZipInputStream(std::unique_ptr<CInputStream>(newStrm));
|
||||
newStrm = std::make_unique<CZipInputStream>(std::move(newStrm));
|
||||
}
|
||||
return std::unique_ptr<CInputStream>(newStrm);
|
||||
|
||||
return newStrm;
|
||||
}
|
||||
return {};
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<IDvdRequest> CResLoader::LoadResourcePartAsync(const SObjectTag& tag, u32 off, u32 size, void* buf) {
|
||||
|
||||
Reference in New Issue
Block a user