mirror of https://github.com/AxioDL/metaforce.git
All CResLoader methods in-place
This commit is contained in:
parent
5784759b62
commit
e9de110cee
|
@ -6,15 +6,9 @@
|
|||
|
||||
#include "RetroTypes.hpp"
|
||||
|
||||
#include <Athena/IStreamReader.hpp>
|
||||
#include <Athena/IStreamWriter.hpp>
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
using CInputStream = Athena::io::IStreamReader;
|
||||
using COutputStream = Athena::io::IStreamWriter;
|
||||
|
||||
class CBasics
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -20,12 +20,14 @@ class CDvdRequest;
|
|||
|
||||
class CDvdFile
|
||||
{
|
||||
friend class CResLoader;
|
||||
std::string x18_name;
|
||||
public:
|
||||
CDvdFile(const char*);
|
||||
void UpdateFilePos(int);
|
||||
void CalcFileOffset(int, ESeekOrigin);
|
||||
static void internalCallback(s32, DVDFileInfo*);
|
||||
bool FileExists(const char*);
|
||||
static bool FileExists(const char*);
|
||||
void CloseFile();
|
||||
CDvdRequest* AsyncSeekRead(void*, u32, ESeekOrigin, int);
|
||||
void SyncSeekRead(void*, u32, ESeekOrigin, int);
|
||||
|
|
|
@ -3,13 +3,81 @@
|
|||
namespace Retro
|
||||
{
|
||||
|
||||
bool CGameAllocator::Initialize(COsContext&)
|
||||
CGameAllocator::SGameMemInfo* CGameAllocator::FindFreeBlock(u32)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
CGameAllocator::SGameMemInfo* CGameAllocator::FindFreeBlockFromTopOfHeap(u32)
|
||||
{
|
||||
}
|
||||
u32 CGameAllocator::FixupAllocPtrs(SGameMemInfo*, u32, u32, EHint, const CCallStack&)
|
||||
{
|
||||
}
|
||||
void CGameAllocator::UpdateAllocDebugStats(u32, u32, u32)
|
||||
{
|
||||
}
|
||||
bool CGameAllocator::FreeNormalAllocation(void*)
|
||||
{
|
||||
}
|
||||
u32 CGameAllocator::GetFreeBinEntryForSize(u32)
|
||||
{
|
||||
}
|
||||
void CGameAllocator::AddFreeEntryToFreeList(SGameMemInfo*)
|
||||
{
|
||||
}
|
||||
void CGameAllocator::RemoveFreeEntryFromFreeList(SGameMemInfo*)
|
||||
{
|
||||
}
|
||||
void CGameAllocator::DumpAllocations() const
|
||||
{
|
||||
}
|
||||
u32 CGameAllocator::GetLargestFreeChunk() const
|
||||
{
|
||||
}
|
||||
CGameAllocator::SGameMemInfo* CGameAllocator::GetMemInfoFromBlockPtr(void* ptr)
|
||||
{
|
||||
return reinterpret_cast<SGameMemInfo*>(reinterpret_cast<u8*>(ptr) - 32);
|
||||
}
|
||||
|
||||
bool CGameAllocator::Initialize(COsContext&)
|
||||
{
|
||||
}
|
||||
void CGameAllocator::Shutdown()
|
||||
{
|
||||
}
|
||||
void* CGameAllocator::Alloc(size_t, EHint, EScope, EType, const CCallStack&)
|
||||
{
|
||||
}
|
||||
void CGameAllocator::Free(void*)
|
||||
{
|
||||
}
|
||||
void CGameAllocator::ReleaseAll()
|
||||
{
|
||||
}
|
||||
void* CGameAllocator::AllocSecondary(size_t, EHint, EScope, EType, const CCallStack&)
|
||||
{
|
||||
}
|
||||
void CGameAllocator::FreeSecondary(void*)
|
||||
{
|
||||
}
|
||||
void CGameAllocator::ReleaseAllSecondary()
|
||||
{
|
||||
}
|
||||
void CGameAllocator::SetOutOfMemoryCallback(const TOutOfMemoryCallback cb, void* ctx)
|
||||
{
|
||||
x58_oomCb = cb;
|
||||
x5c_oomCtx = ctx;
|
||||
}
|
||||
int CGameAllocator::EnumAllocations(const TAllocationVisitCallback, void*, bool) const
|
||||
{
|
||||
}
|
||||
CGameAllocator::SAllocInfo CGameAllocator::GetAllocInfo(void*) const
|
||||
{
|
||||
}
|
||||
void CGameAllocator::OffsetFakeStatics(int)
|
||||
{
|
||||
}
|
||||
CGameAllocator::SMetrics CGameAllocator::GetMetrics() const
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ public:
|
|||
{
|
||||
};
|
||||
private:
|
||||
SGameMemInfo* x10_rootInfo;
|
||||
SGameMemInfo* x10_rootInfo = nullptr;
|
||||
TOutOfMemoryCallback x58_oomCb = nullptr;
|
||||
void* x5c_oomCtx = nullptr;
|
||||
u32 xbc_fakeStaticOff = 0;
|
||||
public:
|
||||
SGameMemInfo* FindFreeBlock(u32);
|
||||
|
@ -27,15 +29,14 @@ public:
|
|||
void RemoveFreeEntryFromFreeList(SGameMemInfo*);
|
||||
void DumpAllocations() const;
|
||||
u32 GetLargestFreeChunk() const;
|
||||
SGameMemInfo* GetMemInfoFromBlockPtr(void* ptr)
|
||||
{return reinterpret_cast<SGameMemInfo*>(reinterpret_cast<u8*>(ptr) - 32);}
|
||||
SGameMemInfo* GetMemInfoFromBlockPtr(void* ptr);
|
||||
|
||||
bool Initialize(COsContext&);
|
||||
void Shutdown();
|
||||
void* Alloc(u32, EHint, EScope, EType, const CCallStack&);
|
||||
void* Alloc(size_t, EHint, EScope, EType, const CCallStack&);
|
||||
void Free(void*);
|
||||
void ReleaseAll();
|
||||
void* AllocSecondary(u32, EHint, EScope, EType, const CCallStack&);
|
||||
void* AllocSecondary(size_t, EHint, EScope, EType, const CCallStack&);
|
||||
void FreeSecondary(void*);
|
||||
void ReleaseAllSecondary();
|
||||
void SetOutOfMemoryCallback(const TOutOfMemoryCallback, void*);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "CGameState.hpp"
|
||||
#include "IOStreams.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -60,6 +60,7 @@ add_library(RuntimeCommon
|
|||
CPakFile.hpp CPakFile.cpp
|
||||
CStringExtras.hpp
|
||||
CCallStack.hpp
|
||||
IOStreams.hpp IOStreams.cpp
|
||||
rstl.hpp rstl.cpp
|
||||
GameGlobalObjects.hpp
|
||||
RetroTypes.hpp
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "CMemory.hpp"
|
||||
#include "CGameAllocator.hpp"
|
||||
#include "CCallStack.hpp"
|
||||
#include <LogVisor/LogVisor.hpp>
|
||||
|
||||
namespace Retro
|
||||
|
@ -46,7 +47,7 @@ void CMemory::Free(void* ptr)
|
|||
g_memoryAllocator->Free(ptr);
|
||||
}
|
||||
|
||||
void* CMemory::Alloc(u32 sz, IAllocator::EHint hint, IAllocator::EScope scope,
|
||||
void* CMemory::Alloc(size_t sz, IAllocator::EHint hint, IAllocator::EScope scope,
|
||||
IAllocator::EType type, const CCallStack& cs)
|
||||
{
|
||||
void* newPtr = g_memoryAllocator->Alloc(sz, hint, scope, type, cs);
|
||||
|
@ -69,3 +70,47 @@ CMemorySys::~CMemorySys()
|
|||
IAllocator& CMemorySys::GetGameAllocator() {return g_gameAllocator;}
|
||||
|
||||
}
|
||||
|
||||
void* operator new(std::size_t)
|
||||
{
|
||||
extern void *bare_new_erroneously_called();
|
||||
return bare_new_erroneously_called();
|
||||
}
|
||||
|
||||
void* operator new(std::size_t sz,
|
||||
const char* funcName, const char* typeName)
|
||||
{
|
||||
Retro::CCallStack cs(funcName, typeName);
|
||||
return Retro::CMemory::Alloc(sz,
|
||||
Retro::IAllocator::HintNone,
|
||||
Retro::IAllocator::ScopeDefault,
|
||||
Retro::IAllocator::TypePrimitive,
|
||||
cs);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr) noexcept
|
||||
{
|
||||
Retro::CMemory::Free(ptr);
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t)
|
||||
{
|
||||
extern void *bare_new_array_erroneously_called();
|
||||
return bare_new_array_erroneously_called();
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t sz,
|
||||
const char* funcName, const char* typeName)
|
||||
{
|
||||
Retro::CCallStack cs(funcName, typeName);
|
||||
return Retro::CMemory::Alloc(sz,
|
||||
Retro::IAllocator::HintNone,
|
||||
Retro::IAllocator::ScopeDefault,
|
||||
Retro::IAllocator::TypeArray,
|
||||
cs);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr) noexcept
|
||||
{
|
||||
Retro::CMemory::Free(ptr);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public:
|
|||
static void OffsetFakeStatics(int);
|
||||
static void SetOutOfMemoryCallback(const IAllocator::TOutOfMemoryCallback, void*);
|
||||
static void Free(void*);
|
||||
static void* Alloc(u32, IAllocator::EHint, IAllocator::EScope, IAllocator::EType, const CCallStack&);
|
||||
static void* Alloc(size_t, IAllocator::EHint, IAllocator::EScope, IAllocator::EType, const CCallStack&);
|
||||
};
|
||||
|
||||
class CMemorySys
|
||||
|
@ -29,4 +29,12 @@ public:
|
|||
|
||||
}
|
||||
|
||||
/* Custom new funcs */
|
||||
void* operator new(std::size_t sz, const char* funcName, const char* typeName);
|
||||
void* operator new[](std::size_t sz, const char* funcName, const char* typeName);
|
||||
|
||||
/* Macro to perform custom with debug strings */
|
||||
#define NEW(T) new (AT_PRETTY_FUNCTION, typeid(T).name()) T
|
||||
#define NEWA(T, N) new (AT_PRETTY_FUNCTION, typeid(T).name()) T[N]
|
||||
|
||||
#endif // __RETRO_CMEMORY_HPP__
|
||||
|
|
|
@ -16,12 +16,13 @@ class CPakFile : public CDvdFile
|
|||
public:
|
||||
struct SResInfo
|
||||
{
|
||||
u32 compressed;
|
||||
SObjectTag tag;
|
||||
u32 size;
|
||||
u32 offset;
|
||||
FourCC x0_type;
|
||||
u32 x4_offset;
|
||||
u32 x8_size;
|
||||
bool xb_compressed;
|
||||
};
|
||||
private:
|
||||
bool x28_b24_ctFlag;
|
||||
enum EAsyncPhase
|
||||
{
|
||||
PakAsyncWarmup = 0,
|
||||
|
@ -34,7 +35,7 @@ private:
|
|||
std::vector<u32> x5c_depList;
|
||||
std::vector<std::pair<u32, SResInfo>> x6c_resList;
|
||||
public:
|
||||
CPakFile(const std::string& filename);
|
||||
CPakFile(const std::string& filename, bool flag);
|
||||
const std::vector<u32>& GetDepList() const {return x5c_depList;}
|
||||
u32 GetResIdByName(const char* name) const
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "RetroTypes.hpp"
|
||||
#include "CBasics.hpp"
|
||||
#include "CStaticInterference.hpp"
|
||||
#include "IOStreams.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
|
|
@ -0,0 +1,223 @@
|
|||
#include "CResLoader.hpp"
|
||||
#include "CPakFile.hpp"
|
||||
#include "CMemory.hpp"
|
||||
#include "CCallStack.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
const std::vector<u32>* CResLoader::GetTagListForFile(const std::string& name) const
|
||||
{
|
||||
std::string namePak = name + ".pak";
|
||||
for (const std::unique_ptr<CPakFile>& pak : x1c_pakLoadedList)
|
||||
if (!CStringExtras::CompareCaseInsensitive(namePak, pak->x18_name))
|
||||
return &pak->GetDepList();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CResLoader::AddPakFileAsync(const std::string& name, bool flag)
|
||||
{
|
||||
std::string namePak = name + ".pak";
|
||||
if (CDvdFile::FileExists(namePak.c_str()))
|
||||
{
|
||||
x34_pakLoadingList.emplace_back(NEW(CPakFile)(namePak, flag));
|
||||
++x44_pakLoadingCount;
|
||||
}
|
||||
}
|
||||
|
||||
void CResLoader::AddPakFile(const std::string& name, bool flag)
|
||||
{
|
||||
AddPakFileAsync(name, flag);
|
||||
while (x44_pakLoadingCount)
|
||||
AsyncIdlePakLoading();
|
||||
}
|
||||
|
||||
CInputStream* CResLoader::LoadNewResourcePartSync(const SObjectTag& tag, int offset, int length, void* extBuf)
|
||||
{
|
||||
void* buf = extBuf;
|
||||
CPakFile* file = FindResourceForLoad(tag);
|
||||
if (!buf)
|
||||
{
|
||||
CCallStack cs(AT_PRETTY_FUNCTION, "UnknownType");
|
||||
buf = CMemory::Alloc(length,
|
||||
IAllocator::HintLarge,
|
||||
IAllocator::ScopeDefault,
|
||||
IAllocator::TypePrimitive,
|
||||
cs);
|
||||
}
|
||||
file->SyncSeekRead(buf, length, OriginBegin, x50_cachedResInfo->x4_offset + offset);
|
||||
return NEW(CMemoryInStream)((atUint8*)buf, length, !extBuf);
|
||||
}
|
||||
|
||||
void CResLoader::LoadMemResourceSync(const SObjectTag& tag, void** bufOut, int* sizeOut)
|
||||
{
|
||||
CPakFile* file = FindResourceForLoad(tag);
|
||||
CCallStack cs(AT_PRETTY_FUNCTION, "UnknownType");
|
||||
void* buf = CMemory::Alloc(x50_cachedResInfo->x8_size,
|
||||
IAllocator::HintLarge,
|
||||
IAllocator::ScopeDefault,
|
||||
IAllocator::TypePrimitive,
|
||||
cs);
|
||||
file->SyncSeekRead(buf, x50_cachedResInfo->x8_size, OriginBegin,
|
||||
x50_cachedResInfo->x4_offset);
|
||||
*bufOut = buf;
|
||||
*sizeOut = x50_cachedResInfo->x8_size;
|
||||
}
|
||||
|
||||
CInputStream* CResLoader::LoadResourceFromMemorySync(const SObjectTag& tag, const void* buf)
|
||||
{
|
||||
FindResourceForLoad(tag);
|
||||
CInputStream* newStrm = NEW(CMemoryInStream)((atUint8*)buf, x50_cachedResInfo->x8_size);
|
||||
if (x50_cachedResInfo->xb_compressed)
|
||||
{
|
||||
newStrm->readUint32Big();
|
||||
newStrm = NEW(CZipInputStream)(std::move(std::unique_ptr<CInputStream>(newStrm)));
|
||||
}
|
||||
return newStrm;
|
||||
}
|
||||
|
||||
CInputStream* CResLoader::LoadNewResourceSync(const SObjectTag& tag, void* extBuf)
|
||||
{
|
||||
void* buf = extBuf;
|
||||
CPakFile* file = FindResourceForLoad(tag);
|
||||
size_t resSz = ROUND_UP_32(x50_cachedResInfo->x8_size);
|
||||
if (!buf)
|
||||
{
|
||||
CCallStack cs(AT_PRETTY_FUNCTION, "UnknownType");
|
||||
buf = CMemory::Alloc(resSz,
|
||||
IAllocator::HintLarge,
|
||||
IAllocator::ScopeDefault,
|
||||
IAllocator::TypePrimitive,
|
||||
cs);
|
||||
}
|
||||
file->SyncSeekRead(buf, resSz, OriginBegin, x50_cachedResInfo->x4_offset);
|
||||
CInputStream* newStrm = NEW(CMemoryInStream)((atUint8*)buf, resSz, !extBuf);
|
||||
if (x50_cachedResInfo->xb_compressed)
|
||||
{
|
||||
newStrm->readUint32Big();
|
||||
newStrm = NEW(CZipInputStream)(std::move(std::unique_ptr<CInputStream>(newStrm)));
|
||||
}
|
||||
return newStrm;
|
||||
}
|
||||
|
||||
CDvdRequest* CResLoader::LoadResourcePartAsync(const SObjectTag& tag, int offset, int length, void* buf)
|
||||
{
|
||||
return FindResourceForLoad(tag.id)->AsyncSeekRead(buf, length,
|
||||
OriginBegin, x50_cachedResInfo->x4_offset + offset);
|
||||
}
|
||||
|
||||
CDvdRequest* CResLoader::LoadResourceAsync(const SObjectTag& tag, void* buf)
|
||||
{
|
||||
return FindResourceForLoad(tag.id)->AsyncSeekRead(buf, ROUND_UP_32(x50_cachedResInfo->x8_size),
|
||||
OriginBegin, x50_cachedResInfo->x4_offset);
|
||||
}
|
||||
|
||||
bool CResLoader::GetResourceCompression(const SObjectTag& tag)
|
||||
{
|
||||
if (FindResource(tag.id))
|
||||
return x50_cachedResInfo->xb_compressed;
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 CResLoader::ResourceSize(const SObjectTag& tag)
|
||||
{
|
||||
if (FindResource(tag.id))
|
||||
return x50_cachedResInfo->x8_size;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CResLoader::ResourceExists(const SObjectTag& tag)
|
||||
{
|
||||
return FindResource(tag.id);
|
||||
}
|
||||
|
||||
FourCC CResLoader::GetResourceTypeById(u32 id)
|
||||
{
|
||||
if (FindResource(id))
|
||||
return x50_cachedResInfo->x0_type;
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 CResLoader::GetResourceIdByName(const char* name) const
|
||||
{
|
||||
for (const std::unique_ptr<CPakFile>& file : x1c_pakLoadedList)
|
||||
{
|
||||
u32 id = file->GetResIdByName(name);
|
||||
if (id)
|
||||
return id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CResLoader::AreAllPaksLoaded() const
|
||||
{
|
||||
return x44_pakLoadingCount == 0;
|
||||
}
|
||||
|
||||
void CResLoader::AsyncIdlePakLoading()
|
||||
{
|
||||
for (auto it=x34_pakLoadingList.begin();
|
||||
it != x34_pakLoadingList.end();
|
||||
++it)
|
||||
{
|
||||
(*it)->AsyncIdle();
|
||||
if ((*it)->x2c_asyncLoadPhase == CPakFile::PakAsyncLoaded)
|
||||
{
|
||||
MoveToCorrectLoadedList(std::move(*it));
|
||||
it = x34_pakLoadingList.erase(it);
|
||||
--x44_pakLoadingCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CResLoader::FindResource(u32 id)
|
||||
{
|
||||
for (const std::unique_ptr<CPakFile>& file : x1c_pakLoadedList)
|
||||
if (CacheFromPak(*file, id))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
CPakFile* CResLoader::FindResourceForLoad(u32 id)
|
||||
{
|
||||
for (std::unique_ptr<CPakFile>& file : x1c_pakLoadedList)
|
||||
if (CacheFromPakForLoad(*file, id))
|
||||
return file.get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CPakFile* CResLoader::FindResourceForLoad(const SObjectTag& tag)
|
||||
{
|
||||
return FindResourceForLoad(tag.id);
|
||||
}
|
||||
|
||||
bool CResLoader::CacheFromPakForLoad(CPakFile& file, u32 id)
|
||||
{
|
||||
const CPakFile::SResInfo* info = file.GetResInfoForLoad(id);
|
||||
if (info)
|
||||
{
|
||||
x4c_cachedResId = id;
|
||||
x50_cachedResInfo = info;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CResLoader::CacheFromPak(const CPakFile& file, u32 id)
|
||||
{
|
||||
const CPakFile::SResInfo* info = file.GetResInfo(id);
|
||||
if (info)
|
||||
{
|
||||
x4c_cachedResId = id;
|
||||
x50_cachedResInfo = info;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CResLoader::MoveToCorrectLoadedList(std::unique_ptr<CPakFile>&& file)
|
||||
{
|
||||
x1c_pakLoadedList.push_back(std::move(file));
|
||||
}
|
||||
|
||||
}
|
|
@ -5,8 +5,7 @@
|
|||
#include <string>
|
||||
#include "RetroTypes.hpp"
|
||||
#include "CPakFile.hpp"
|
||||
#include "CBasics.hpp"
|
||||
#include "CMemory.hpp"
|
||||
#include "IOStreams.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
@ -22,140 +21,28 @@ class CResLoader
|
|||
u32 x4c_cachedResId = -1;
|
||||
const CPakFile::SResInfo* x50_cachedResInfo = nullptr;
|
||||
public:
|
||||
const std::vector<u32>& GetTagListForFile(const std::string&) const;
|
||||
void AddPakFileAsync(const std::string&, bool);
|
||||
void AddPakFile(const std::string&, bool);
|
||||
CInputStream* LoadNewResourcePartSync(const SObjectTag&, int, int, char*);
|
||||
void LoadMemResourceSync(const SObjectTag&, char*, int*);
|
||||
CInputStream* LoadResourceFromMemorySync(const SObjectTag&, const void*);
|
||||
CInputStream* LoadNewResourceSync(const SObjectTag& tag, void* buf)
|
||||
{
|
||||
FindResourceForLoad(tag);
|
||||
if (!buf)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
CDvdRequest* LoadResourcePartAsync(const SObjectTag& tag, int offset, int length, void* buf)
|
||||
{
|
||||
return FindResourceForLoad(tag.id)->AsyncSeekRead(buf, length,
|
||||
OriginBegin, x50_cachedResInfo->offset + offset);
|
||||
}
|
||||
|
||||
CDvdRequest* LoadResourceAsync(const SObjectTag& tag, void* buf)
|
||||
{
|
||||
return FindResourceForLoad(tag.id)->AsyncSeekRead(buf, ROUND_UP_32(x50_cachedResInfo->size),
|
||||
OriginBegin, x50_cachedResInfo->offset);
|
||||
}
|
||||
|
||||
bool GetResourceCompression(const SObjectTag& tag)
|
||||
{
|
||||
if (FindResource(tag.id))
|
||||
return x50_cachedResInfo->compressed;
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 ResourceSize(const SObjectTag& tag)
|
||||
{
|
||||
if (FindResource(tag.id))
|
||||
return x50_cachedResInfo->size;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ResourceExists(const SObjectTag& tag)
|
||||
{
|
||||
return FindResource(tag.id);
|
||||
}
|
||||
|
||||
FourCC GetResourceTypeById(u32 id)
|
||||
{
|
||||
if (FindResource(id))
|
||||
return x50_cachedResInfo->tag.type;
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 GetResourceIdByName(const char* name) const
|
||||
{
|
||||
for (const std::unique_ptr<CPakFile>& file : x1c_pakLoadedList)
|
||||
{
|
||||
u32 id = file->GetResIdByName(name);
|
||||
if (id)
|
||||
return id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AreAllPaksLoaded() const
|
||||
{
|
||||
return x44_pakLoadingCount == 0;
|
||||
}
|
||||
|
||||
void AsyncIdlePakLoading()
|
||||
{
|
||||
for (auto it=x34_pakLoadingList.begin();
|
||||
it != x34_pakLoadingList.end();
|
||||
++it)
|
||||
{
|
||||
(*it)->AsyncIdle();
|
||||
if ((*it)->x2c_asyncLoadPhase == CPakFile::PakAsyncLoaded)
|
||||
{
|
||||
MoveToCorrectLoadedList(std::move(*it));
|
||||
it = x34_pakLoadingList.erase(it);
|
||||
--x44_pakLoadingCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FindResource(u32 id)
|
||||
{
|
||||
for (const std::unique_ptr<CPakFile>& file : x1c_pakLoadedList)
|
||||
if (CacheFromPak(*file, id))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
CPakFile* FindResourceForLoad(u32 id)
|
||||
{
|
||||
for (std::unique_ptr<CPakFile>& file : x1c_pakLoadedList)
|
||||
if (CacheFromPakForLoad(*file, id))
|
||||
return file.get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CPakFile* FindResourceForLoad(const SObjectTag& tag)
|
||||
{
|
||||
return FindResourceForLoad(tag.id);
|
||||
}
|
||||
|
||||
bool CacheFromPakForLoad(CPakFile& file, u32 id)
|
||||
{
|
||||
const CPakFile::SResInfo* info = file.GetResInfoForLoad(id);
|
||||
if (info)
|
||||
{
|
||||
x4c_cachedResId = id;
|
||||
x50_cachedResInfo = info;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CacheFromPak(const CPakFile& file, u32 id)
|
||||
{
|
||||
const CPakFile::SResInfo* info = file.GetResInfo(id);
|
||||
if (info)
|
||||
{
|
||||
x4c_cachedResId = id;
|
||||
x50_cachedResInfo = info;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MoveToCorrectLoadedList(std::unique_ptr<CPakFile>&& file)
|
||||
{
|
||||
x1c_pakLoadedList.push_back(std::move(file));
|
||||
}
|
||||
const std::vector<u32>* GetTagListForFile(const std::string& name) const;
|
||||
void AddPakFileAsync(const std::string& name, bool flag);
|
||||
void AddPakFile(const std::string& name, bool flag);
|
||||
CInputStream* LoadNewResourcePartSync(const SObjectTag& tag, int offset, int length, void* extBuf);
|
||||
void LoadMemResourceSync(const SObjectTag& tag, void** bufOut, int* sizeOut);
|
||||
CInputStream* LoadResourceFromMemorySync(const SObjectTag& tag, const void* buf);
|
||||
CInputStream* LoadNewResourceSync(const SObjectTag& tag, void* extBuf=nullptr);
|
||||
CDvdRequest* LoadResourcePartAsync(const SObjectTag& tag, int offset, int length, void* buf);
|
||||
CDvdRequest* LoadResourceAsync(const SObjectTag& tag, void* buf);
|
||||
bool GetResourceCompression(const SObjectTag& tag);
|
||||
u32 ResourceSize(const SObjectTag& tag);
|
||||
bool ResourceExists(const SObjectTag& tag);
|
||||
FourCC GetResourceTypeById(u32 id);
|
||||
u32 GetResourceIdByName(const char* name) const;
|
||||
bool AreAllPaksLoaded() const;
|
||||
void AsyncIdlePakLoading();
|
||||
bool FindResource(u32 id);
|
||||
CPakFile* FindResourceForLoad(u32 id);
|
||||
CPakFile* FindResourceForLoad(const SObjectTag& tag);
|
||||
bool CacheFromPakForLoad(CPakFile& file, u32 id);
|
||||
bool CacheFromPak(const CPakFile& file, u32 id);
|
||||
void MoveToCorrectLoadedList(std::unique_ptr<CPakFile>&& file);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -14,12 +14,19 @@ public:
|
|||
virtual ~IAllocator() {}
|
||||
enum EHint
|
||||
{
|
||||
HintNone = 0x0,
|
||||
HintTopOfHeap = 0x1,
|
||||
HintLarge = 0x2
|
||||
};
|
||||
enum EScope
|
||||
{
|
||||
ScopeNone = 0,
|
||||
ScopeDefault = 1
|
||||
};
|
||||
enum EType
|
||||
{
|
||||
TypePrimitive = 0,
|
||||
TypeArray = 1
|
||||
};
|
||||
struct SAllocInfo
|
||||
{
|
||||
|
@ -54,10 +61,10 @@ public:
|
|||
|
||||
virtual bool Initialize(COsContext&)=0;
|
||||
virtual void Shutdown()=0;
|
||||
virtual void* Alloc(u32, EHint, EScope, EType, const CCallStack&)=0;
|
||||
virtual void* Alloc(size_t, EHint, EScope, EType, const CCallStack&)=0;
|
||||
virtual void Free(void*)=0;
|
||||
virtual void ReleaseAll()=0;
|
||||
virtual void* AllocSecondary(u32, EHint, EScope, EType, const CCallStack&)=0;
|
||||
virtual void* AllocSecondary(size_t, EHint, EScope, EType, const CCallStack&)=0;
|
||||
virtual void FreeSecondary(void*)=0;
|
||||
virtual void ReleaseAllSecondary()=0;
|
||||
virtual void SetOutOfMemoryCallback(const TOutOfMemoryCallback, void*)=0;
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
#include "IOStreams.hpp"
|
||||
#include "CMemory.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
class CZipSupport
|
||||
{
|
||||
public:
|
||||
static void* Alloc(void*, u32 c, u32 n)
|
||||
{
|
||||
return NEWA(u8, c*n);
|
||||
}
|
||||
static void Free(void*, void* buf)
|
||||
{
|
||||
delete[] static_cast<u8*>(buf);
|
||||
}
|
||||
};
|
||||
|
||||
CZipInputStream::CZipInputStream(std::unique_ptr<CInputStream>&& strm)
|
||||
: x24_compBuf(NEWA(u8, 4096)), x28_strm(std::move(strm))
|
||||
{
|
||||
x30_zstrm.next_in = x24_compBuf.get();
|
||||
x30_zstrm.avail_in = 0;
|
||||
x30_zstrm.zalloc = CZipSupport::Alloc;
|
||||
x30_zstrm.zfree = CZipSupport::Free;
|
||||
inflateInit(&x30_zstrm);
|
||||
}
|
||||
|
||||
CZipInputStream::~CZipInputStream()
|
||||
{
|
||||
inflateEnd(&x30_zstrm);
|
||||
}
|
||||
|
||||
atUint64 CZipInputStream::readUBytesToBuf(void *buf, atUint64 len)
|
||||
{
|
||||
x30_zstrm.next_out = (Bytef*)buf;
|
||||
x30_zstrm.avail_out = len;
|
||||
if (!x30_zstrm.avail_in)
|
||||
{
|
||||
atUint64 readSz = x28_strm->readUBytesToBuf(x24_compBuf.get(), 4096);
|
||||
x30_zstrm.avail_in = readSz;
|
||||
x30_zstrm.next_in = x24_compBuf.get();
|
||||
}
|
||||
inflate(&x30_zstrm, Z_NO_FLUSH);
|
||||
return x30_zstrm.total_out;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef __RETRO_IOSTREAMS_HPP__
|
||||
#define __RETRO_IOSTREAMS_HPP__
|
||||
|
||||
#include "RetroTypes.hpp"
|
||||
#include <Athena/IStreamReader.hpp>
|
||||
#include <Athena/IStreamWriter.hpp>
|
||||
#include <Athena/MemoryReader.hpp>
|
||||
#include <zlib.h>
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
||||
using CInputStream = Athena::io::IStreamReader;
|
||||
using COutputStream = Athena::io::IStreamWriter;
|
||||
|
||||
using CMemoryInStream = Athena::io::MemoryReader;
|
||||
|
||||
class CZipInputStream : public CInputStream
|
||||
{
|
||||
std::unique_ptr<u8[]> x24_compBuf;
|
||||
std::unique_ptr<CInputStream> x28_strm;
|
||||
z_stream x30_zstrm = {};
|
||||
public:
|
||||
CZipInputStream(std::unique_ptr<CInputStream>&& strm);
|
||||
~CZipInputStream();
|
||||
atUint64 readUBytesToBuf(void *buf, atUint64 len);
|
||||
void seek(atInt64, Athena::SeekOrigin) {}
|
||||
atUint64 position() const {return 0;}
|
||||
atUint64 length() const {return 0;}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __RETRO_IOSTREAMS_HPP__
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __RETRO_CTWEAKPARTICLE_HPP__
|
||||
#define __RETRO_CTWEAKPARTICLE_HPP__
|
||||
|
||||
#include "CBasics.hpp"
|
||||
#include "IOStreams.hpp"
|
||||
#include "DataSpec/DNAMP1/Tweaks/CTweakParticle.hpp"
|
||||
|
||||
namespace Retro
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __RETRO_CTWEAKS_HPP__
|
||||
#define __RETRO_CTWEAKS_HPP__
|
||||
|
||||
#include "RetroTypes.hpp"
|
||||
#include "CTweakParticle.hpp"
|
||||
|
||||
namespace Retro
|
||||
|
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
|||
Subproject commit 2a9a822dc7643c43731876ae506fcef43b7550ae
|
||||
Subproject commit cba8336d73c7ea0dd8f673881a6a6d8d4ec5af34
|
Loading…
Reference in New Issue