From f3b5b9f49acdefb9134a689777628a6c7e63f5f9 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 22 Aug 2015 20:42:29 -1000 Subject: [PATCH] various implementation --- DataSpec/DNACommon/DNACommon.hpp | 16 +- DataSpec/DNAMP1/ANCS.hpp | 2 +- DataSpec/DNAMP1/DNAMP1.cpp | 4 +- DataSpec/DNAMP1/EVNT.hpp | 2 +- DataSpec/DNAMP1/MLVL.hpp | 2 +- DataSpec/DNAMP1/PAK.hpp | 4 +- DataSpec/DNAMP1/STRG.cpp | 4 +- DataSpec/DNAMP2/ANCS.hpp | 4 +- DataSpec/DNAMP2/DNAMP2.cpp | 4 +- DataSpec/DNAMP2/MLVL.hpp | 2 +- DataSpec/DNAMP2/STRG.cpp | 6 +- DataSpec/DNAMP3/CMDLMaterials.hpp | 8 +- DataSpec/DNAMP3/DNAMP3.cpp | 2 +- DataSpec/DNAMP3/PAK.cpp | 6 +- DataSpec/DNAMP3/PAK.hpp | 4 +- DataSpec/DNAMP3/STRG.cpp | 10 +- DataSpec/DNAMP3/STRG.hpp | 4 +- Runtime/CDvdFile.hpp | 48 ++++++ Runtime/CDvdRequest.hpp | 34 ++++ Runtime/CFactoryMgr.cpp | 0 Runtime/CFactoryMgr.hpp | 28 ++++ Runtime/CMakeLists.txt | 19 ++- ...oryCardSysPC.cpp => CMemoryCardSysNix.cpp} | 0 Runtime/CMemoryCardSysOSX.cpp | 0 Runtime/CMemoryCardSysWin.cpp | 0 Runtime/CNODDvdFile.cpp | 0 Runtime/CNODDvdRequest.cpp | 16 ++ Runtime/CPakFile.cpp | 0 Runtime/CPakFile.hpp | 76 +++++++++ Runtime/CResFactory.cpp | 8 +- Runtime/CResFactory.hpp | 28 +++- Runtime/CResLoader.cpp | 0 Runtime/CResLoader.hpp | 155 ++++++++++++++++++ Runtime/CStringExtras.hpp | 29 ++++ Runtime/CToken.hpp | 63 ++++++- Runtime/Character/CAssetFactory.hpp | 9 +- Runtime/Character/CCharLayoutInfo.cpp | 0 Runtime/Character/CCharLayoutInfo.hpp | 0 Runtime/Character/CHierarchyPoseBuilder.cpp | 0 Runtime/Character/CHierarchyPoseBuilder.hpp | 13 ++ Runtime/Character/CMakeLists.txt | 3 +- Runtime/IFactory.hpp | 5 +- Runtime/IObj.hpp | 6 +- Runtime/IObjectStore.hpp | 24 +-- Runtime/RetroTypes.hpp | 16 +- 45 files changed, 580 insertions(+), 84 deletions(-) create mode 100644 Runtime/CDvdFile.hpp create mode 100644 Runtime/CDvdRequest.hpp create mode 100644 Runtime/CFactoryMgr.cpp create mode 100644 Runtime/CFactoryMgr.hpp rename Runtime/{CMemoryCardSysPC.cpp => CMemoryCardSysNix.cpp} (100%) create mode 100644 Runtime/CMemoryCardSysOSX.cpp create mode 100644 Runtime/CMemoryCardSysWin.cpp create mode 100644 Runtime/CNODDvdFile.cpp create mode 100644 Runtime/CNODDvdRequest.cpp create mode 100644 Runtime/CPakFile.cpp create mode 100644 Runtime/CPakFile.hpp create mode 100644 Runtime/CResLoader.cpp create mode 100644 Runtime/CResLoader.hpp create mode 100644 Runtime/CStringExtras.hpp create mode 100644 Runtime/Character/CCharLayoutInfo.cpp create mode 100644 Runtime/Character/CCharLayoutInfo.hpp create mode 100644 Runtime/Character/CHierarchyPoseBuilder.cpp create mode 100644 Runtime/Character/CHierarchyPoseBuilder.hpp diff --git a/DataSpec/DNACommon/DNACommon.hpp b/DataSpec/DNACommon/DNACommon.hpp index d4a491141..667709070 100644 --- a/DataSpec/DNACommon/DNACommon.hpp +++ b/DataSpec/DNACommon/DNACommon.hpp @@ -18,15 +18,15 @@ typedef Athena::io::DNA BigDNA; typedef Athena::io::DNAYaml BigYAML; /* FourCC with DNA read/write */ -class FourCC final : public BigYAML, public HECL::FourCC +class DNAFourCC final : public BigYAML, public HECL::FourCC { public: - FourCC() : HECL::FourCC() {} - FourCC(const HECL::FourCC& other) + DNAFourCC() : HECL::FourCC() {} + DNAFourCC(const HECL::FourCC& other) : HECL::FourCC() {num = other.toUint32();} - FourCC(const char* name) + DNAFourCC(const char* name) : HECL::FourCC(name) {} - FourCC(uint32_t n) + DNAFourCC(uint32_t n) : HECL::FourCC(n) {} Delete expl; @@ -40,6 +40,8 @@ public: {writer.writeString(nullptr, std::string(fcc, 4));} }; +using FourCC = HECL::FourCC; + /* PAK 32-bit Unique ID */ class UniqueID32 : public BigYAML { @@ -243,9 +245,9 @@ typedef std::function namespace std { template<> -struct hash +struct hash { - inline size_t operator()(const Retro::FourCC& fcc) const + inline size_t operator()(const Retro::DNAFourCC& fcc) const {return fcc.toUint32();} }; diff --git a/DataSpec/DNAMP1/ANCS.hpp b/DataSpec/DNAMP1/ANCS.hpp index 7a63b9fb8..ae7ebc774 100644 --- a/DataSpec/DNAMP1/ANCS.hpp +++ b/DataSpec/DNAMP1/ANCS.hpp @@ -130,7 +130,7 @@ struct ANCS : BigYAML { DECL_YAML String<-1> name; - FourCC type; + DNAFourCC type; UniqueID32 id; String<-1> name2; Value unk1; diff --git a/DataSpec/DNAMP1/DNAMP1.cpp b/DataSpec/DNAMP1/DNAMP1.cpp index 1bb93922b..dd8de08fe 100644 --- a/DataSpec/DNAMP1/DNAMP1.cpp +++ b/DataSpec/DNAMP1/DNAMP1.cpp @@ -23,7 +23,7 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar /* Append Level String */ for (const PAK::Entry& entry : m_pak.m_entries) { - if (entry.type == SBIG('MLVL')) + if (entry.type == FOURCC('MLVL')) { PAKEntryReadStream rs = entry.beginReadStream(m_node); MLVL mlvl; @@ -119,7 +119,7 @@ void PAKBridge::build() /* First pass: build per-area/per-layer dependency map */ for (const PAK::Entry& entry : m_pak.m_entries) { - if (entry.type == SBIG('MLVL')) + if (entry.type == FOURCC('MLVL')) { PAKEntryReadStream rs = entry.beginReadStream(m_node); MLVL mlvl; diff --git a/DataSpec/DNAMP1/EVNT.hpp b/DataSpec/DNAMP1/EVNT.hpp index 23ac88c32..8823e3670 100644 --- a/DataSpec/DNAMP1/EVNT.hpp +++ b/DataSpec/DNAMP1/EVNT.hpp @@ -48,7 +48,7 @@ struct EVNT : BigYAML { DECL_YAML Value frameCount; - FourCC effectType; + DNAFourCC effectType; UniqueID32 effectId; String<-1> boneName; Value scale; diff --git a/DataSpec/DNAMP1/MLVL.hpp b/DataSpec/DNAMP1/MLVL.hpp index c74bc2e90..27fd18cc5 100644 --- a/DataSpec/DNAMP1/MLVL.hpp +++ b/DataSpec/DNAMP1/MLVL.hpp @@ -48,7 +48,7 @@ struct MLVL : BigYAML { DECL_YAML UniqueID32 id; - FourCC type; + DNAFourCC type; }; Vector deps; diff --git a/DataSpec/DNAMP1/PAK.hpp b/DataSpec/DNAMP1/PAK.hpp index 4c5dc7060..10c5f61b2 100644 --- a/DataSpec/DNAMP1/PAK.hpp +++ b/DataSpec/DNAMP1/PAK.hpp @@ -20,7 +20,7 @@ struct PAK : BigDNA struct NameEntry : BigDNA { DECL_DNA - FourCC type; + DNAFourCC type; UniqueID32 id; Value nameLen; String name; @@ -30,7 +30,7 @@ struct PAK : BigDNA { DECL_DNA Value compressed; - FourCC type; + DNAFourCC type; UniqueID32 id; Value size; Value offset; diff --git a/DataSpec/DNAMP1/STRG.cpp b/DataSpec/DNAMP1/STRG.cpp index d1fcec21a..c9d5b957d 100644 --- a/DataSpec/DNAMP1/STRG.cpp +++ b/DataSpec/DNAMP1/STRG.cpp @@ -15,7 +15,7 @@ void STRG::_read(Athena::io::IStreamReader& reader) readLangs.reserve(langCount); for (atUint32 l=0 ; l>& lang : langs) { - lang.first.write(writer); + DNAFourCC(lang.first).write(writer); writer.writeUint32Big(offset); offset += strCount * 4 + 4; atUint32 langStrCount = lang.second.size(); diff --git a/DataSpec/DNAMP2/ANCS.hpp b/DataSpec/DNAMP2/ANCS.hpp index 10ad88729..f72cc9884 100644 --- a/DataSpec/DNAMP2/ANCS.hpp +++ b/DataSpec/DNAMP2/ANCS.hpp @@ -74,7 +74,7 @@ struct ANCS : BigYAML { DECL_YAML String<-1> name; - FourCC type; + DNAFourCC type; UniqueID32 id; Value unkMP2; Value unk1; @@ -162,7 +162,7 @@ struct ANCS : BigYAML { DECL_YAML Value frameCount; - FourCC effectType; + DNAFourCC effectType; UniqueID32 effectId; Value boneId; Value scale; diff --git a/DataSpec/DNAMP2/DNAMP2.cpp b/DataSpec/DNAMP2/DNAMP2.cpp index 54d3593e4..fe56bdfc1 100644 --- a/DataSpec/DNAMP2/DNAMP2.cpp +++ b/DataSpec/DNAMP2/DNAMP2.cpp @@ -22,7 +22,7 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar /* Append Level String */ for (const DNAMP1::PAK::Entry& entry : m_pak.m_entries) { - if (entry.type == SBIG('MLVL')) + if (entry.type == FOURCC('MLVL')) { PAKEntryReadStream rs = entry.beginReadStream(m_node); MLVL mlvl; @@ -118,7 +118,7 @@ void PAKBridge::build() /* First pass: build per-area/per-layer dependency map */ for (const DNAMP1::PAK::Entry& entry : m_pak.m_entries) { - if (entry.type == SBIG('MLVL')) + if (entry.type == FOURCC('MLVL')) { PAKEntryReadStream rs = entry.beginReadStream(m_node); MLVL mlvl; diff --git a/DataSpec/DNAMP2/MLVL.hpp b/DataSpec/DNAMP2/MLVL.hpp index 51029c00c..991c26e5a 100644 --- a/DataSpec/DNAMP2/MLVL.hpp +++ b/DataSpec/DNAMP2/MLVL.hpp @@ -38,7 +38,7 @@ struct MLVL : BigDNA { DECL_DNA UniqueID32 id; - FourCC type; + DNAFourCC type; }; Vector deps; diff --git a/DataSpec/DNAMP2/STRG.cpp b/DataSpec/DNAMP2/STRG.cpp index a7ae582ad..75bf6f62b 100644 --- a/DataSpec/DNAMP2/STRG.cpp +++ b/DataSpec/DNAMP2/STRG.cpp @@ -15,7 +15,7 @@ void STRG::_read(Athena::io::IStreamReader& reader) readLangs.reserve(langCount); for (atUint32 l=0 ; l>& lang : langs) + for (const std::pair>& lang : langs) { lang.first.write(writer); writer.writeUint32Big(offset); @@ -114,7 +114,7 @@ void STRG::write(Athena::io::IStreamWriter& writer) const for (const std::pair& name : names) writer.writeString(name.first); - for (const std::pair>& lang : langs) + for (const std::pair>& lang : langs) { offset = strCount * 4; atUint32 langStrCount = lang.second.size(); diff --git a/DataSpec/DNAMP3/CMDLMaterials.hpp b/DataSpec/DNAMP3/CMDLMaterials.hpp index 4a9d16f2b..d05335557 100644 --- a/DataSpec/DNAMP3/CMDLMaterials.hpp +++ b/DataSpec/DNAMP3/CMDLMaterials.hpp @@ -79,7 +79,7 @@ struct MaterialSet : BigDNA XRAY = SBIG('XRAY'), TOON = SBIG('TOON') }; - FourCC subtype; + DNAFourCC subtype; struct Flags : BigDNA { DECL_DNA @@ -106,7 +106,7 @@ struct MaterialSet : BigDNA CLR = SBIG('CLR '), DIFB = SBIG('DIFB') }; - FourCC subtype; + DNAFourCC subtype; GX::Color color; }; struct SectionINT : ISection @@ -121,7 +121,7 @@ struct MaterialSet : BigDNA BNIF = SBIG('BNIF'), XRBR = SBIG('XRBR') }; - FourCC subtype; + DNAFourCC subtype; Value value; }; struct SectionFactory : BigDNA @@ -130,7 +130,7 @@ struct MaterialSet : BigDNA std::unique_ptr section; void read(Athena::io::IStreamReader& reader) { - FourCC type; + DNAFourCC type; type.read(reader); switch (type) { diff --git a/DataSpec/DNAMP3/DNAMP3.cpp b/DataSpec/DNAMP3/DNAMP3.cpp index 2951a43c2..82df96de3 100644 --- a/DataSpec/DNAMP3/DNAMP3.cpp +++ b/DataSpec/DNAMP3/DNAMP3.cpp @@ -24,7 +24,7 @@ PAKBridge::PAKBridge(HECL::Database::Project& project, const NOD::DiscBase::IPar std::set uniq; for (const PAK::Entry& entry : m_pak.m_entries) { - if (entry.type == SBIG('MLVL')) + if (entry.type == FOURCC('MLVL')) { PAKEntryReadStream rs = entry.beginReadStream(m_node); MLVL mlvl; diff --git a/DataSpec/DNAMP3/PAK.cpp b/DataSpec/DNAMP3/PAK.cpp index 5d5eb24fb..a0d003c70 100644 --- a/DataSpec/DNAMP3/PAK.cpp +++ b/DataSpec/DNAMP3/PAK.cpp @@ -62,7 +62,7 @@ void PAK::write(Athena::io::IStreamWriter& writer) const { m_header.write(writer); - FourCC("STRG").write(writer); + DNAFourCC("STRG").write(writer); atUint32 strgSz = 4; for (const NameEntry& entry : m_nameEntries) strgSz += (atUint32)entry.name.size() + 13; @@ -70,14 +70,14 @@ void PAK::write(Athena::io::IStreamWriter& writer) const strgSz += strgPad; writer.writeUint32Big(strgSz); - FourCC("RSHD").write(writer); + DNAFourCC("RSHD").write(writer); atUint32 rshdSz = 4 + 24 * m_entries.size(); atUint32 rshdPad = ((rshdSz + 63) & ~63) - rshdSz; rshdSz += rshdPad; writer.writeUint32Big(rshdSz); atUint32 dataOffset = 128 + strgSz + rshdSz; - FourCC("DATA").write(writer); + DNAFourCC("DATA").write(writer); atUint32 dataSz = 0; for (const Entry& entry : m_entries) dataSz += (entry.size + 63) & ~63; diff --git a/DataSpec/DNAMP3/PAK.hpp b/DataSpec/DNAMP3/PAK.hpp index 35a9da055..4c538a5e8 100644 --- a/DataSpec/DNAMP3/PAK.hpp +++ b/DataSpec/DNAMP3/PAK.hpp @@ -29,7 +29,7 @@ struct PAK : BigDNA { DECL_DNA String<-1> name; - FourCC type; + DNAFourCC type; UniqueID64 id; }; @@ -37,7 +37,7 @@ struct PAK : BigDNA { DECL_DNA Value compressed; - FourCC type; + DNAFourCC type; UniqueID64 id; Value size; Value offset; diff --git a/DataSpec/DNAMP3/STRG.cpp b/DataSpec/DNAMP3/STRG.cpp index 7d8846aac..e0c6b91c9 100644 --- a/DataSpec/DNAMP3/STRG.cpp +++ b/DataSpec/DNAMP3/STRG.cpp @@ -29,11 +29,11 @@ void STRG::_read(Athena::io::IStreamReader& reader) } } - std::vector readLangs; + std::vector readLangs; readLangs.reserve(langCount); for (atUint32 l=0 ; l>& item : langs) + for (std::pair>& item : langs) langMap.emplace(item.first, &item.second); } @@ -142,12 +142,12 @@ void STRG::fromYAML(Athena::io::YAMLDocReader& reader) for (const auto& node : item.second->m_seqChildren) if (node->m_type == YAML_SCALAR_NODE) strs.emplace_back(node->m_scalarString); - langs.emplace_back(std::make_pair(FourCC(item.first.c_str()), std::move(strs))); + langs.emplace_back(std::make_pair(DNAFourCC(item.first.c_str()), std::move(strs))); } langMap.clear(); langMap.reserve(langs.size()); - for (std::pair>& item : langs) + for (std::pair>& item : langs) langMap.emplace(item.first, &item.second); } diff --git a/DataSpec/DNAMP3/STRG.hpp b/DataSpec/DNAMP3/STRG.hpp index e8c90b08b..a6bf1ebc1 100644 --- a/DataSpec/DNAMP3/STRG.hpp +++ b/DataSpec/DNAMP3/STRG.hpp @@ -15,8 +15,8 @@ struct STRG : ISTRG DECL_YAML Delete expl; void _read(Athena::io::IStreamReader& reader); - std::vector>> langs; - std::unordered_map*> langMap; + std::vector>> langs; + std::unordered_map*> langMap; std::map names; inline int32_t lookupIdx(const std::string& name) const diff --git a/Runtime/CDvdFile.hpp b/Runtime/CDvdFile.hpp new file mode 100644 index 000000000..c05398453 --- /dev/null +++ b/Runtime/CDvdFile.hpp @@ -0,0 +1,48 @@ +#ifndef __RETRO_CDVDFILE_HPP__ +#define __RETRO_CDVDFILE_HPP__ + +#include "RetroTypes.hpp" + +namespace Retro +{ + +const char* DecodeARAMFile(const char* name); + +enum ESeekOrigin +{ + OriginBegin = 0, + OriginCur = 1, + OriginEnd = 2 +}; + +struct DVDFileInfo; +class CDvdRequest; + +class CDvdFile +{ +public: + CDvdFile(const char*); + void UpdateFilePos(int); + void CalcFileOffset(int, ESeekOrigin); + static void internalCallback(s32, DVDFileInfo*); + bool FileExists(const char*); + void CloseFile(); + CDvdRequest* AsyncSeekRead(void*, u32, ESeekOrigin, int); + void SyncSeekRead(void*, u32, ESeekOrigin, int); + CDvdRequest* AsyncRead(void*, u32); + void SyncRead(void*, u32); + void StallForARAMFile(); + void StartARAMFileLoad(); + void PopARAMFileLoad(); + void PushARAMFileLoad(); + void TryARAMFile(); + void PingARAMTransfer(); + void HandleDVDInterrupt(); + void HandleARAMInterrupt(); + static void ARAMARAMXferCallback(u32); + static void DVDARAMXferCallback(s32, DVDFileInfo*); +}; + +} + +#endif // __RETRO_CDVDFILE_HPP__ diff --git a/Runtime/CDvdRequest.hpp b/Runtime/CDvdRequest.hpp new file mode 100644 index 000000000..06a22b7c1 --- /dev/null +++ b/Runtime/CDvdRequest.hpp @@ -0,0 +1,34 @@ +#ifndef __RETRO_CDVDREQUEST_HPP__ +#define __RETRO_CDVDREQUEST_HPP__ + +namespace Retro +{ + +class CDvdRequest +{ +public: + virtual void WaitUntilComplete()=0; + virtual bool IsComplete()=0; + virtual void PostCancelRequest()=0; + + enum EMediaType + { + MediaARAM = 0, + MediaReal = 1, + MediaNOD = 2 + }; + virtual EMediaType GetMediaType() const=0; +}; + +class CNODDvdRequest : public CDvdRequest +{ +public: + void WaitUntilComplete(); + bool IsComplete(); + void PostCancelRequest(); + EMediaType GetMediaType() const {return MediaNOD;} +}; + +} + +#endif // __RETRO_CDVDREQUEST_HPP__ diff --git a/Runtime/CFactoryMgr.cpp b/Runtime/CFactoryMgr.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/CFactoryMgr.hpp b/Runtime/CFactoryMgr.hpp new file mode 100644 index 000000000..eace220bc --- /dev/null +++ b/Runtime/CFactoryMgr.hpp @@ -0,0 +1,28 @@ +#ifndef __RETRO_CFACTORYMGR_HPP__ +#define __RETRO_CFACTORYMGR_HPP__ + +#include +#include "RetroTypes.hpp" + +namespace Retro +{ +class SObjectTag; +class CVParamTransfer; +class CInputStream; + +typedef void(*CFactoryFnReturn)(const SObjectTag&, CInputStream&, const CVParamTransfer&); + +class CFactoryMgr +{ + std::unordered_map m_factories; +public: + MakeObjectFromMemory(const SObjectTag&, void*, int, bool, const CVParamTransfer&); + void AddFactory(FourCC key, CFactoryFnReturn func) + { + m_factories[key] = func; + } +}; + +} + +#endif // __RETRO_CFACTORYMGR_HPP__ diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 03c6a0025..f1096ab2c 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -7,11 +7,19 @@ add_subdirectory(GuiSys) add_subdirectory(Input) add_subdirectory(Particle) +if(WIN32) + list(APPEND PLAT_SRCS CMemoryCardSysWin.cpp) +elseif(APPLE) + list(APPEND PLAT_SRCS CMemoryCardSysMac.cpp) +else() + list(APPEND PLAT_SRCS CMemoryCardSysNix.cpp) +endif() + add_library(RuntimeCommon COsContext.hpp COsContextBoo.cpp CMainFlow.hpp CMainFlow.cpp CMemory.hpp CMemory.cpp - CMemoryCardSys.hpp CMemoryCardSysPC.cpp + CMemoryCardSys.hpp IAllocator.hpp IAllocator.cpp CGameAllocator.hpp CGameAllocator.cpp CBasics.hpp CBasicsPC.cpp @@ -25,6 +33,9 @@ add_library(RuntimeCommon CWorldTransManager.hpp CWorldTransManager.cpp CRandom16.hpp CRandom16.cpp CResFactory.hpp CResFactory.cpp + CResLoader.hpp CResLoader.cpp + CDvdRequest.hpp CNODDvdRequest.cpp + CDvdFile.hpp CNODDvdFile.cpp IObjectStore.hpp CSimplePool.hpp CSimplePool.cpp CAi.hpp CAi.cpp @@ -45,10 +56,14 @@ add_library(RuntimeCommon CAreaOctTree.hpp CAreaOctTree.cpp CActor.hpp CActor.cpp CPhysicsActor.hpp CPhysicsActor.cpp + CFactoryMgr.hpp CFactoryMgr.cpp + CPakFile.hpp CPakFile.cpp + CStringExtras.hpp rstl.hpp rstl.cpp GameGlobalObjects.hpp RetroTypes.hpp - GCNTypes.hpp) + GCNTypes.hpp + ${PLAT_SRCS}) add_subdirectory(MP1) add_subdirectory(MP2) diff --git a/Runtime/CMemoryCardSysPC.cpp b/Runtime/CMemoryCardSysNix.cpp similarity index 100% rename from Runtime/CMemoryCardSysPC.cpp rename to Runtime/CMemoryCardSysNix.cpp diff --git a/Runtime/CMemoryCardSysOSX.cpp b/Runtime/CMemoryCardSysOSX.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/CMemoryCardSysWin.cpp b/Runtime/CMemoryCardSysWin.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/CNODDvdFile.cpp b/Runtime/CNODDvdFile.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/CNODDvdRequest.cpp b/Runtime/CNODDvdRequest.cpp new file mode 100644 index 000000000..4221fe89f --- /dev/null +++ b/Runtime/CNODDvdRequest.cpp @@ -0,0 +1,16 @@ +#include "CDvdRequest.hpp" + +namespace Retro +{ + +void CNODDvdRequest::WaitUntilComplete() +{ +} +bool CNODDvdRequest::IsComplete() +{ +} +void CNODDvdRequest::PostCancelRequest() +{ +} + +} diff --git a/Runtime/CPakFile.cpp b/Runtime/CPakFile.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/CPakFile.hpp b/Runtime/CPakFile.hpp new file mode 100644 index 000000000..fb4c47d3b --- /dev/null +++ b/Runtime/CPakFile.hpp @@ -0,0 +1,76 @@ +#ifndef __RETRO_CPAKFILE_HPP__ +#define __RETRO_CPAKFILE_HPP__ + +#include +#include "RetroTypes.hpp" +#include "CStringExtras.hpp" +#include "CDvdFile.hpp" +#include "CDvdRequest.hpp" + +namespace Retro +{ + +class CPakFile : public CDvdFile +{ + friend class CResLoader; +public: + struct SResInfo + { + u32 compressed; + SObjectTag tag; + u32 size; + u32 offset; + }; +private: + enum EAsyncPhase + { + PakAsyncWarmup = 0, + PakAsyncInitialHeader = 1, + PakAsyncDataLoad = 2, + PakAsyncLoaded = 3 + } x2c_asyncLoadPhase; + CDvdRequest* x34_dvdReq; + std::vector> x4c_nameList; + std::vector x5c_depList; + std::vector> x6c_resList; +public: + CPakFile(const std::string& filename); + const std::vector& GetDepList() const {return x5c_depList;} + u32 GetResIdByName(const char* name) const + { + for (const std::pair& p : x4c_nameList) + if (!CStringExtras::CompareCaseInsensitive(p.first.c_str(), name)) + return p.second.id; + return 0; + } + const SResInfo* GetResInfoForLoad(u32 id); + const SResInfo* GetResInfo(u32 id) const; + u32 GetFakeStaticSize() const; + void DataLoad(); + void InitialHeaderLoad(); + void Warmup(); + void AsyncIdle() + { + if (x2c_asyncLoadPhase == PakAsyncLoaded) + return; + if (x34_dvdReq && x34_dvdReq->IsComplete()) + return; + switch (x2c_asyncLoadPhase) + { + case PakAsyncWarmup: + Warmup(); + break; + case PakAsyncInitialHeader: + InitialHeaderLoad(); + break; + case PakAsyncDataLoad: + DataLoad(); + break; + default: break; + } + } +}; + +} + +#endif // __RETRO_CPAKFILE_HPP__ diff --git a/Runtime/CResFactory.cpp b/Runtime/CResFactory.cpp index c1a2c9fda..580481492 100644 --- a/Runtime/CResFactory.cpp +++ b/Runtime/CResFactory.cpp @@ -3,7 +3,7 @@ namespace Retro { -void CResFactory::Build(const SObjectTag&, const CVParamTransfer&) +std::unique_ptr CResFactory::Build(const SObjectTag&, const CVParamTransfer&) { } void CResFactory::BuildAsync(const SObjectTag&, const CVParamTransfer&, IObj**) @@ -12,11 +12,5 @@ void CResFactory::BuildAsync(const SObjectTag&, const CVParamTransfer&, IObj**) void CResFactory::CancelBuild(const SObjectTag&) { } -bool CResFactory::CanBuild(const SObjectTag&) -{ -} -const SObjectTag& CResFactory::GetResourceIdByName(const char*) const -{ -} } diff --git a/Runtime/CResFactory.hpp b/Runtime/CResFactory.hpp index 4fd03fd9a..e381f6cda 100644 --- a/Runtime/CResFactory.hpp +++ b/Runtime/CResFactory.hpp @@ -1,19 +1,41 @@ #ifndef __RETRO_CRESFACTORY_HPP__ #define __RETRO_CRESFACTORY_HPP__ +#include #include "IFactory.hpp" +#include "CResLoader.hpp" namespace Retro { +class CDvdRequest; class CResFactory : public IFactory { + CResLoader x4_loader; public: - void Build(const SObjectTag&, const CVParamTransfer&); + struct SLoadingData + { + SObjectTag tag; + CDvdRequest* dvdReq; + IObj** targetPtr; + void* loadBuffer; + u32 resSize; + }; +private: + std::unordered_map m_loadList; + void AddToLoadList(const SLoadingData& data) {m_loadList[data.tag] = data;} +public: + std::unique_ptr Build(const SObjectTag&, const CVParamTransfer&); void BuildAsync(const SObjectTag&, const CVParamTransfer&, IObj**); void CancelBuild(const SObjectTag&); - bool CanBuild(const SObjectTag&); - const SObjectTag& GetResourceIdByName(const char*) const; + bool CanBuild(const SObjectTag& tag) {return x4_loader.ResourceExists(tag);} + u32 GetResourceIdByName(const char* name) const {return x4_loader.GetResourceIdByName(name);} + + std::vector> GetResourceIdToNameList() const + { + std::vector> retval; + return retval; + } }; } diff --git a/Runtime/CResLoader.cpp b/Runtime/CResLoader.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/CResLoader.hpp b/Runtime/CResLoader.hpp new file mode 100644 index 000000000..de43c2d98 --- /dev/null +++ b/Runtime/CResLoader.hpp @@ -0,0 +1,155 @@ +#ifndef __RETRO_CRESLOADER_HPP__ +#define __RETRO_CRESLOADER_HPP__ + +#include +#include +#include "RetroTypes.hpp" +#include "CPakFile.hpp" +#include "CBasics.hpp" + +namespace Retro +{ +class SObjectTag; +class CDvdRequest; + +class CResLoader +{ + //std::list> x4_unusedList; + std::list> x1c_pakLoadedList; + std::list> x34_pakLoadingList; + u32 x44_pakLoadingCount = 0; + u32 x4c_cachedResId = -1; + const CPakFile::SResInfo* x50_cachedResInfo = nullptr; +public: + const std::vector& 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&, char*); + + 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& 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& file : x1c_pakLoadedList) + if (CacheFromPak(*file, id)) + return true; + return false; + } + + CPakFile* FindResourceForLoad(u32 id) + { + for (std::unique_ptr& 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&& file) + { + x1c_pakLoadedList.push_back(std::move(file)); + } +}; + +} + +#endif // __RETRO_CRESLOADER_HPP__ diff --git a/Runtime/CStringExtras.hpp b/Runtime/CStringExtras.hpp new file mode 100644 index 000000000..cf14a9e0b --- /dev/null +++ b/Runtime/CStringExtras.hpp @@ -0,0 +1,29 @@ +#ifndef __RETRO_CSTRINGEXTRAS_HPP__ +#define __RETRO_CSTRINGEXTRAS_HPP__ + +#include +#include + +namespace Retro +{ + +class CStringExtras +{ +public: + static int CompareCaseInsensitive(const char* a, const char* b) + { +#if _WIN32 + return _stricmp(a, b); +#else + return strcasecmp(a, b); +#endif + } + static int CompareCaseInsensitive(const std::string& a, const std::string& b) + { + return CompareCaseInsensitive(a.c_str(), b.c_str()); + } +}; + +} + +#endif // __RETRO_CSTRINGEXTRAS_HPP__ diff --git a/Runtime/CToken.hpp b/Runtime/CToken.hpp index 876530cb5..61bd3f53d 100644 --- a/Runtime/CToken.hpp +++ b/Runtime/CToken.hpp @@ -2,9 +2,11 @@ #define __RETRO_CTOKEN_HPP__ #include +#include "IObj.hpp" #include "RetroTypes.hpp" -#include "CVParamTransfer.hpp" +#include "IVParamObj.hpp" #include "IObjectStore.hpp" +#include "IFactory.hpp" namespace Retro { @@ -28,23 +30,72 @@ public: bool IsLoading() const {return x3_loading;} void Unlock() {} - void RemoveReference() {} + void Lock() {} + u32 RemoveReference() + { + --x0_refCount; + if (x0_refCount == 0) + { + if (x10_object) + Unload(); + if (IsLoading()) + CancelLoad(); + xC_objectStore->ObjectUnreferenced(x4_objTag); + } + } void CancelLoad() {} - void Unload() {} - void GetObject() {} + void Unload() + { + x10_object.reset(nullptr); + x3_loading = false; + } + IObj& GetObject() + { + IFactory& factory = xC_objectStore->GetFactory(); + factory.Build(x4_objTag, x14_params); + } }; class CToken { - CObjectReference* x0_objRef; + CObjectReference& x0_objRef; bool x4_lockHeld = false; public: - ~CToken() + void Unlock() { if (x4_lockHeld) + { + x0_objRef.Unlock(); + x4_lockHeld = false; + } + } + void Lock() + { + if (!x4_lockHeld) + { + x0_objRef.Lock(); + x4_lockHeld = true; + } + } + void RemoveRef() + { } + IObj& GetObj() + { + Lock(); + return x0_objRef.GetObject(); + } + CToken& operator=(CToken&& other) + { + + } + ~CToken() + { + if (x0_objRef && x4_lockHeld) + x0_objRef->Unlock(); + } }; template diff --git a/Runtime/Character/CAssetFactory.hpp b/Runtime/Character/CAssetFactory.hpp index 8cf1ade7c..962ee388a 100644 --- a/Runtime/Character/CAssetFactory.hpp +++ b/Runtime/Character/CAssetFactory.hpp @@ -5,16 +5,9 @@ namespace Retro { - -class CCharacterFactoryBuilder +class CCharacterFactoryBuilder : public IFactory { -public: - CCharacterFactoryBuilder(); - class CDummyFactory : public IFactory - { - }; }; - } #endif // __RETRO_CASSETFACTORY_HPP__ diff --git a/Runtime/Character/CCharLayoutInfo.cpp b/Runtime/Character/CCharLayoutInfo.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Character/CCharLayoutInfo.hpp b/Runtime/Character/CCharLayoutInfo.hpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Character/CHierarchyPoseBuilder.cpp b/Runtime/Character/CHierarchyPoseBuilder.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Character/CHierarchyPoseBuilder.hpp b/Runtime/Character/CHierarchyPoseBuilder.hpp new file mode 100644 index 000000000..b16bd0bba --- /dev/null +++ b/Runtime/Character/CHierarchyPoseBuilder.hpp @@ -0,0 +1,13 @@ +#ifndef __RETRO_CHIERARCHYPOSEBUILDER_HPP__ +#define __RETRO_CHIERARCHYPOSEBUILDER_HPP__ + +namespace Retro +{ + +class CHierarchyPoseBuilder +{ +}; + +} + +#endif // __RETRO_CHIERARCHYPOSEBUILDER_HPP__ diff --git a/Runtime/Character/CMakeLists.txt b/Runtime/Character/CMakeLists.txt index d066ef80e..0e3256c5d 100644 --- a/Runtime/Character/CMakeLists.txt +++ b/Runtime/Character/CMakeLists.txt @@ -8,4 +8,5 @@ add_library(RuntimeCommonCharacter CAnimationDatabase.hpp CAnimationDatabaseGame.hpp CTransitionDatabase.hpp - CTransitionDatabaseGame.hpp) + CTransitionDatabaseGame.hpp + CHierarchyPoseBuilder.hpp CHierarchyPoseBuilder.cpp) diff --git a/Runtime/IFactory.hpp b/Runtime/IFactory.hpp index df3864942..1ae2b249d 100644 --- a/Runtime/IFactory.hpp +++ b/Runtime/IFactory.hpp @@ -1,6 +1,7 @@ #ifndef __RETRO_IFACTORY_HPP__ #define __RETRO_IFACTORY_HPP__ +#include #include "RetroTypes.hpp" namespace Retro @@ -12,11 +13,11 @@ class IFactory { public: virtual ~IFactory() {} - virtual void Build(const SObjectTag&, const CVParamTransfer&)=0; + virtual std::unique_ptr Build(const SObjectTag&, const CVParamTransfer&)=0; virtual void BuildAsync(const SObjectTag&, const CVParamTransfer&, IObj**)=0; virtual void CancelBuild(const SObjectTag&)=0; virtual bool CanBuild(const SObjectTag&)=0; - virtual const SObjectTag& GetResourceIdByName(const char*) const=0; + virtual u32 GetResourceIdByName(const char*) const=0; }; } diff --git a/Runtime/IObj.hpp b/Runtime/IObj.hpp index 51b4e478b..649eda475 100644 --- a/Runtime/IObj.hpp +++ b/Runtime/IObj.hpp @@ -8,13 +8,15 @@ namespace Retro class IObj { +public: + virtual ~IObj() {} }; class TObjOwnerDerivedFromIObjUntyped : public IObj { protected: - void* m_objPtr; - TObjOwnerDerivedFromIObjUntyped(void* objPtr) : m_objPtr(objPtr) {} + IObj* m_objPtr; + TObjOwnerDerivedFromIObjUntyped(IObj* objPtr) : m_objPtr(objPtr) {} }; template diff --git a/Runtime/IObjectStore.hpp b/Runtime/IObjectStore.hpp index 3add8116b..b5fc6d651 100644 --- a/Runtime/IObjectStore.hpp +++ b/Runtime/IObjectStore.hpp @@ -3,21 +3,23 @@ namespace Retro { +class SObjectTag; +class CVParamTransfer; +class IFactory; +class IObj; class IObjectStore { public: - /* - GetObj((SObjectTag const &,CVParamTransfer const &)) - GetObj((SObjectTag const &)) - GetObj((char const *)) - GetObj((char const *,CVParamTransfer const &)) - HasObject(const(SObjectTag const &)) - .data6:80352C6C .long CSimplePool::ObjectIsLive(const(SObjectTag const &)) - .data6:80352C70 .long CSimplePool::GetFactory(const(void)) - .data6:80352C74 .long CSimplePool::Flush((void)) - .data6:80352C78 .long CSimplePool::ObjectUnreferenced((SObjectTag const &)) - */ + virtual IObj& GetObj(const SObjectTag&, const CVParamTransfer&)=0; + virtual IObj& GetObj(const SObjectTag&)=0; + virtual IObj& GetObj(char const*)=0; + virtual IObj& GetObj(char const*, const CVParamTransfer&)=0; + virtual void HasObject(const SObjectTag&) const=0; + virtual void ObjectIsLive(const SObjectTag&) const=0; + virtual IFactory& GetFactory() const=0; + virtual void Flush()=0; + virtual void ObjectUnreferenced(const SObjectTag&)=0; }; } diff --git a/Runtime/RetroTypes.hpp b/Runtime/RetroTypes.hpp index a750baf89..6c657d37c 100644 --- a/Runtime/RetroTypes.hpp +++ b/Runtime/RetroTypes.hpp @@ -11,10 +11,14 @@ namespace Retro { +using FourCC = HECL::FourCC; + struct SObjectTag { FourCC type; - UniqueID32 id; + u32 id; + bool operator!=(const SObjectTag& other) const {return id != other.id;} + bool operator==(const SObjectTag& other) const {return id == other.id;} }; /** @@ -62,4 +66,14 @@ using TAreaId = u32; } +namespace std +{ +template<> +struct hash +{ + inline size_t operator()(const Retro::SObjectTag& tag) const + {return tag.id;} +}; +} + #endif // __RETRO_TYPES_HPP__