From b51911ed3dbe050dfa47dec310e14571d4bca887 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 21 Aug 2015 15:58:41 -1000 Subject: [PATCH] more classes added --- DataSpec/DNACommon/CMDL.hpp | 2 +- DataSpec/DNACommon/CMakeLists.txt | 1 + DataSpec/DNACommon/DNACommon.hpp | 403 ----------------- DataSpec/DNACommon/PAK.hpp | 414 ++++++++++++++++++ DataSpec/DNACommon/TXTR.cpp | 1 + DataSpec/DNACommon/TXTR.hpp | 1 + DataSpec/DNAMP1/MLVL.hpp | 2 +- DataSpec/DNAMP1/PAK.hpp | 2 +- DataSpec/DNAMP2/STRG.hpp | 2 +- DataSpec/DNAMP3/PAK.hpp | 2 +- DataSpec/DNAMP3/STRG.hpp | 2 +- Runtime/{CFactoryStore.cpp => CActor.cpp} | 0 Runtime/CActor.hpp | 23 + Runtime/CAi.hpp | 6 + Runtime/CArchitectureMessage.hpp | 1 - Runtime/CBasics.hpp | 1 - Runtime/CEntity.cpp | 1 + Runtime/CEntity.hpp | 2 +- Runtime/CFactoryStore.hpp | 13 - Runtime/CIOWin.hpp | 4 +- Runtime/CIOWinManager.cpp | 1 + Runtime/CMFGame.cpp | 28 ++ Runtime/CMainFlow.cpp | 34 +- Runtime/CMainFlow.hpp | 36 +- Runtime/CMakeLists.txt | 6 +- Runtime/CMemory.hpp | 5 +- Runtime/CPhysicsActor.cpp | 0 Runtime/CPhysicsActor.hpp | 15 + Runtime/CResFactory.cpp | 16 + Runtime/CResFactory.hpp | 6 + Runtime/CSimplePool.cpp | 1 + Runtime/CSimplePool.hpp | 4 +- Runtime/CStateManager.hpp | 8 +- Runtime/CToken.hpp | 39 ++ Runtime/Character/CAnimationDatabase.hpp | 26 ++ Runtime/Character/CAnimationDatabaseGame.hpp | 21 + Runtime/Character/CAssetFactory.hpp | 3 +- Runtime/Character/CMakeLists.txt | 8 +- Runtime/Character/CTransitionDatabase.hpp | 18 + Runtime/Character/CTransitionDatabaseGame.hpp | 17 + Runtime/Character/IMetaAnim.hpp | 15 + Runtime/Character/IMetaTrans.hpp | 15 + Runtime/Graphics/CBooRenderer.hpp | 9 +- Runtime/Graphics/IRenderer.hpp | 16 +- Runtime/IAllocator.hpp | 3 +- Runtime/IFactory.hpp | 11 + Runtime/IObj.hpp | 7 - Runtime/IObjectStore.hpp | 25 ++ Runtime/IVParamObj.hpp | 47 ++ Runtime/MP1/main.cpp | 1 + Runtime/RetroTypes.hpp | 27 +- Runtime/rstl.cpp | 8 + Runtime/rstl.hpp | 40 ++ 53 files changed, 882 insertions(+), 517 deletions(-) create mode 100644 DataSpec/DNACommon/PAK.hpp rename Runtime/{CFactoryStore.cpp => CActor.cpp} (100%) create mode 100644 Runtime/CActor.hpp delete mode 100644 Runtime/CFactoryStore.hpp create mode 100644 Runtime/CPhysicsActor.cpp create mode 100644 Runtime/CPhysicsActor.hpp create mode 100644 Runtime/Character/CAnimationDatabase.hpp create mode 100644 Runtime/Character/CAnimationDatabaseGame.hpp create mode 100644 Runtime/Character/CTransitionDatabase.hpp create mode 100644 Runtime/Character/CTransitionDatabaseGame.hpp create mode 100644 Runtime/Character/IMetaAnim.hpp create mode 100644 Runtime/Character/IMetaTrans.hpp create mode 100644 Runtime/IObjectStore.hpp create mode 100644 Runtime/IVParamObj.hpp create mode 100644 Runtime/rstl.cpp create mode 100644 Runtime/rstl.hpp diff --git a/DataSpec/DNACommon/CMDL.hpp b/DataSpec/DNACommon/CMDL.hpp index 056716419..e32a25915 100644 --- a/DataSpec/DNACommon/CMDL.hpp +++ b/DataSpec/DNACommon/CMDL.hpp @@ -1,7 +1,7 @@ #ifndef _DNACOMMON_CMDL_HPP_ #define _DNACOMMON_CMDL_HPP_ -#include "DNACommon.hpp" +#include "PAK.hpp" #include "BlenderConnection.hpp" #include "GX.hpp" #include "TXTR.hpp" diff --git a/DataSpec/DNACommon/CMakeLists.txt b/DataSpec/DNACommon/CMakeLists.txt index 838a8be64..3515c0458 100644 --- a/DataSpec/DNACommon/CMakeLists.txt +++ b/DataSpec/DNACommon/CMakeLists.txt @@ -3,6 +3,7 @@ make_dnalist(liblist add_library(DNACommon DNACommon.hpp DNACommon.cpp ${liblist} + PAK.hpp GX.hpp STRG.hpp STRG.cpp TXTR.hpp TXTR.cpp diff --git a/DataSpec/DNACommon/DNACommon.hpp b/DataSpec/DNACommon/DNACommon.hpp index bc07ed7d8..d4a491141 100644 --- a/DataSpec/DNACommon/DNACommon.hpp +++ b/DataSpec/DNACommon/DNACommon.hpp @@ -234,409 +234,6 @@ struct WordBitmap Iterator end() const {return Iterator(*this, m_bitCount);} }; -/* PAK entry stream reader */ -class PAKEntryReadStream : public Athena::io::IStreamReader -{ - std::unique_ptr m_buf; - atUint64 m_sz; - atUint64 m_pos; -public: - PAKEntryReadStream() {} - operator bool() const {return m_buf.operator bool();} - PAKEntryReadStream(const PAKEntryReadStream& other) = delete; - PAKEntryReadStream(PAKEntryReadStream&& other) = default; - PAKEntryReadStream& operator=(const PAKEntryReadStream& other) = delete; - PAKEntryReadStream& operator=(PAKEntryReadStream&& other) = default; - PAKEntryReadStream(std::unique_ptr&& buf, atUint64 sz, atUint64 pos) - : m_buf(std::move(buf)), m_sz(sz), m_pos(pos) - { - if (m_pos >= m_sz) - LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun"); - } - inline void seek(atInt64 pos, Athena::SeekOrigin origin) - { - if (origin == Athena::Begin) - m_pos = pos; - else if (origin == Athena::Current) - m_pos += pos; - else if (origin == Athena::End) - m_pos = m_sz + pos; - if (m_pos >= m_sz) - LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun"); - } - inline atUint64 position() const {return m_pos;} - inline atUint64 length() const {return m_sz;} - inline const atUint8* data() const {return m_buf.get();} - inline atUint64 readUBytesToBuf(void* buf, atUint64 len) - { - atUint64 bufEnd = m_pos + len; - if (bufEnd > m_sz) - len -= bufEnd - m_sz; - memcpy(buf, m_buf.get() + m_pos, len); - m_pos += len; - return len; - } -}; - -struct UniqueResult -{ - enum Type - { - UNIQUE_NOTFOUND, - UNIQUE_LEVEL, - UNIQUE_AREA, - UNIQUE_LAYER - } type = UNIQUE_NOTFOUND; - const HECL::SystemString* areaName = nullptr; - const HECL::SystemString* layerName = nullptr; - UniqueResult() = default; - UniqueResult(Type tp) : type(tp) {} - inline HECL::ProjectPath uniquePath(const HECL::ProjectPath& pakPath) const - { - if (type == UNIQUE_AREA) - { - HECL::ProjectPath areaDir(pakPath, *areaName); - areaDir.makeDir(); - return areaDir; - } - else if (type == UNIQUE_LAYER) - { - HECL::ProjectPath areaDir(pakPath, *areaName); - areaDir.makeDir(); - HECL::ProjectPath layerDir(areaDir, *layerName); - layerDir.makeDir(); - return layerDir; - } - return pakPath; - } -}; - -template -class PAKRouter; - -/* Resource extractor type */ -template -struct ResExtractor -{ - std::function func_a; - std::function&, - const typename PAKBRIDGE::PAKType::Entry&, bool)> func_b; - const char* fileExts[4]; - unsigned weight; -}; - -/* PAKRouter (for detecting shared entry locations) */ -template -class PAKRouter -{ -public: - using PAKType = typename BRIDGETYPE::PAKType; - using IDType = typename PAKType::IDType; - using EntryType = typename PAKType::Entry; -private: - const SpecBase& m_dataSpec; - const std::vector* m_bridges = nullptr; - std::vector> m_bridgePaths; - size_t m_curBridgeIdx = 0; - const HECL::ProjectPath& m_gameWorking; - const HECL::ProjectPath& m_gameCooked; - HECL::ProjectPath m_sharedWorking; - HECL::ProjectPath m_sharedCooked; - const PAKType* m_pak = nullptr; - const NOD::DiscBase::IPartition::Node* m_node = nullptr; - std::unordered_map> m_uniqueEntries; - std::unordered_map> m_sharedEntries; -public: - PAKRouter(const SpecBase& dataSpec, const HECL::ProjectPath& working, const HECL::ProjectPath& cooked) - : m_dataSpec(dataSpec), - m_gameWorking(working), m_gameCooked(cooked), - m_sharedWorking(working, "Shared"), m_sharedCooked(cooked, "Shared") {} - void build(std::vector& bridges, std::function progress) - { - m_bridges = &bridges; - m_bridgePaths.clear(); - - m_uniqueEntries.clear(); - m_sharedEntries.clear(); - size_t count = 0; - float bridgesSz = bridges.size(); - - /* Route entries unique/shared per-pak */ - size_t bridgeIdx = 0; - for (BRIDGETYPE& bridge : bridges) - { - const std::string& name = bridge.getName(); - HECL::SystemStringView sysName(name); - - HECL::SystemString::const_iterator extit = sysName.sys_str().end() - 4; - HECL::SystemString baseName(sysName.sys_str().begin(), extit); - - m_bridgePaths.emplace_back(std::make_pair(HECL::ProjectPath(m_gameWorking, baseName), - HECL::ProjectPath(m_gameCooked, baseName))); - - bridge.build(); - const typename BRIDGETYPE::PAKType& pak = bridge.getPAK(); - for (const auto& entry : pak.m_idMap) - { - auto sSearch = m_sharedEntries.find(entry.first); - if (sSearch != m_sharedEntries.end()) - continue; - auto uSearch = m_uniqueEntries.find(entry.first); - if (uSearch != m_uniqueEntries.end()) - { - m_uniqueEntries.erase(uSearch); - m_sharedEntries[entry.first] = std::make_pair(bridgeIdx, entry.second); - } - else - m_uniqueEntries[entry.first] = std::make_pair(bridgeIdx, entry.second); - } - progress(++count / bridgesSz); - ++bridgeIdx; - } - } - - void enterPAKBridge(const BRIDGETYPE& pakBridge) - { - auto pit = m_bridgePaths.begin(); - size_t bridgeIdx = 0; - for (const BRIDGETYPE& bridge : *m_bridges) - { - if (&bridge == &pakBridge) - { - pit->first.makeDir(); - pit->second.makeDir(); - m_pak = &pakBridge.getPAK(); - m_node = &pakBridge.getNode(); - m_curBridgeIdx = bridgeIdx; - return; - } - ++pit; - ++bridgeIdx; - } - LogDNACommon.report(LogVisor::FatalError, "PAKBridge provided to PAKRouter::enterPAKBridge() was not part of build()"); - } - - HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::Entry* entry, - const ResExtractor& extractor) const - { - if (!m_pak) - LogDNACommon.report(LogVisor::FatalError, - "PAKRouter::enterPAKBridge() must be called before PAKRouter::getWorkingPath()"); - auto uniqueSearch = m_uniqueEntries.find(entry->id); - if (uniqueSearch != m_uniqueEntries.end()) - { - const HECL::ProjectPath& pakPath = m_bridgePaths[uniqueSearch->second.first].first; - pakPath.makeDir(); - HECL::ProjectPath uniquePath = entry->unique.uniquePath(pakPath); - HECL::SystemString entName = m_pak->bestEntryName(*entry); - if (extractor.fileExts[0] && !extractor.fileExts[1]) - entName += extractor.fileExts[0]; - return HECL::ProjectPath(uniquePath, entName); - } - auto sharedSearch = m_sharedEntries.find(entry->id); - if (sharedSearch != m_sharedEntries.end()) - { - const HECL::ProjectPath& pakPath = m_bridgePaths[m_curBridgeIdx].first; - HECL::ProjectPath uniquePathPre = entry->unique.uniquePath(pakPath); - HECL::SystemString entBase = m_pak->bestEntryName(*entry); - HECL::SystemString entName = entBase; - if (extractor.fileExts[0] && !extractor.fileExts[1]) - entName += extractor.fileExts[0]; - HECL::ProjectPath sharedPath(m_sharedWorking, entName); - HECL::ProjectPath uniquePath(uniquePathPre, entName); - if (extractor.func_a || extractor.func_b) - { - if (extractor.fileExts[0] && !extractor.fileExts[1]) - uniquePath.makeLinkTo(sharedPath); - else - { - for (int e=0 ; e<4 ; ++e) - { - if (!extractor.fileExts[e]) - break; - HECL::SystemString entName = entBase + extractor.fileExts[e]; - HECL::ProjectPath sharedPath(m_sharedWorking, entName); - HECL::ProjectPath uniquePath(uniquePathPre, entName); - uniquePath.makeLinkTo(sharedPath); - } - } - } - m_sharedWorking.makeDir(); - return sharedPath; - } - LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str()); - return HECL::ProjectPath(); - } - - HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::Entry* entry) const - { - return getWorking(entry, BRIDGETYPE::LookupExtractor(*entry)); - } - - HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::IDType& id) const - { - return getWorking(lookupEntry(id)); - } - - HECL::ProjectPath getCooked(const typename BRIDGETYPE::PAKType::Entry* entry) const - { - if (!m_pak) - LogDNACommon.report(LogVisor::FatalError, - "PAKRouter::enterPAKBridge() must be called before PAKRouter::getCookedPath()"); - auto uniqueSearch = m_uniqueEntries.find(entry->id); - if (uniqueSearch != m_uniqueEntries.end()) - { - const HECL::ProjectPath& pakPath = m_bridgePaths[uniqueSearch->second.first].second; - pakPath.makeDir(); - HECL::ProjectPath uniquePath = entry->unique.uniquePath(pakPath); - return HECL::ProjectPath(uniquePath, m_pak->bestEntryName(*entry)); - } - auto sharedSearch = m_sharedEntries.find(entry->id); - if (sharedSearch != m_sharedEntries.end()) - { - m_sharedCooked.makeDir(); - return HECL::ProjectPath(m_sharedCooked, m_pak->bestEntryName(*entry)); - } - LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str()); - return HECL::ProjectPath(); - } - - HECL::ProjectPath getCooked(const typename BRIDGETYPE::PAKType::IDType& id) const - { - return getCooked(lookupEntry(id)); - } - - HECL::SystemString getResourceRelativePath(const typename BRIDGETYPE::PAKType::Entry& a, - const typename BRIDGETYPE::PAKType::IDType& b) const - { - if (!m_pak) - LogDNACommon.report(LogVisor::FatalError, - "PAKRouter::enterPAKBridge() must be called before PAKRouter::getResourceRelativePath()"); - const typename BRIDGETYPE::PAKType::Entry* be = lookupEntry(b); - if (!be) - return HECL::SystemString(); - HECL::ProjectPath aPath = getWorking(&a, BRIDGETYPE::LookupExtractor(a)); - HECL::SystemString ret; - for (int i=0 ; ibestEntryName(entry); - } - - std::string getBestEntryName(const typename BRIDGETYPE::PAKType::IDType& entry) const - { - if (!m_pak) - LogDNACommon.report(LogVisor::FatalError, - "PAKRouter::enterPAKBridge() must be called before PAKRouter::getBestEntryName()"); - const typename BRIDGETYPE::PAKType::Entry* e = m_pak->lookupEntry(entry); - if (!e) - return entry.toString(); - return m_pak->bestEntryName(*e); - } - - bool extractResources(const BRIDGETYPE& pakBridge, bool force, std::function progress) - { - enterPAKBridge(pakBridge); - size_t count = 0; - size_t sz = m_pak->m_idMap.size(); - float fsz = sz; - for (unsigned w=0 ; countm_idMap) - { - ResExtractor extractor = BRIDGETYPE::LookupExtractor(*item.second); - if (extractor.weight != w) - continue; - - HECL::ProjectPath cooked = getCooked(item.second); - if (force || cooked.getPathType() == HECL::ProjectPath::PT_NONE) - { - PAKEntryReadStream s = item.second->beginReadStream(*m_node); - FILE* fout = HECL::Fopen(cooked.getAbsolutePath().c_str(), _S("wb")); - fwrite(s.data(), 1, s.length(), fout); - fclose(fout); - } - - HECL::ProjectPath working = getWorking(item.second, extractor); - if (extractor.func_a) /* Doesn't need PAKRouter access */ - { - if (force || working.getPathType() == HECL::ProjectPath::PT_NONE) - { - PAKEntryReadStream s = item.second->beginReadStream(*m_node); - extractor.func_a(m_dataSpec, s, working); - } - } - else if (extractor.func_b) /* Needs PAKRouter access */ - { - if (force || working.getPathType() == HECL::ProjectPath::PT_NONE) - { - PAKEntryReadStream s = item.second->beginReadStream(*m_node); - extractor.func_b(m_dataSpec, s, working, *this, *item.second, force); - } - } - - progress(++count / fsz); - } - } - - return true; - } - - const typename BRIDGETYPE::PAKType::Entry* lookupEntry(const typename BRIDGETYPE::PAKType::IDType& entry, - const NOD::DiscBase::IPartition::Node** nodeOut=nullptr) const - { - if (!m_bridges) - LogDNACommon.report(LogVisor::FatalError, - "PAKRouter::build() must be called before PAKRouter::lookupEntry()"); - if (m_pak) - { - const typename BRIDGETYPE::PAKType::Entry* ent = m_pak->lookupEntry(entry); - if (ent) - { - if (nodeOut) - *nodeOut = m_node; - return ent; - } - } - for (const BRIDGETYPE& bridge : *m_bridges) - { - const typename BRIDGETYPE::PAKType& pak = bridge.getPAK(); - const typename BRIDGETYPE::PAKType::Entry* ent = pak.lookupEntry(entry); - if (ent) - { - if (nodeOut) - *nodeOut = &bridge.getNode(); - return ent; - } - } - LogDNACommon.report(LogVisor::Warning, "unable to find PAK entry %s", entry.toString().c_str()); - if (nodeOut) - *nodeOut = nullptr; - return nullptr; - } - - template - bool lookupAndReadDNA(const typename BRIDGETYPE::PAKType::IDType& id, DNA& out) - { - const NOD::DiscBase::IPartition::Node* node; - const typename BRIDGETYPE::PAKType::Entry* entry = lookupEntry(id, &node); - if (!entry) - return false; - PAKEntryReadStream rs = entry->beginReadStream(*node); - out.read(rs); - return true; - } -}; - /* Resource cooker function */ typedef std::function ResCooker; diff --git a/DataSpec/DNACommon/PAK.hpp b/DataSpec/DNACommon/PAK.hpp new file mode 100644 index 000000000..6214bab66 --- /dev/null +++ b/DataSpec/DNACommon/PAK.hpp @@ -0,0 +1,414 @@ +#ifndef __DNACOMMON_PAK_HPP__ +#define __DNACOMMON_PAK_HPP__ + +#include "DNACommon.hpp" + +namespace Retro +{ + +/* PAK entry stream reader */ +class PAKEntryReadStream : public Athena::io::IStreamReader +{ + std::unique_ptr m_buf; + atUint64 m_sz; + atUint64 m_pos; +public: + PAKEntryReadStream() {} + operator bool() const {return m_buf.operator bool();} + PAKEntryReadStream(const PAKEntryReadStream& other) = delete; + PAKEntryReadStream(PAKEntryReadStream&& other) = default; + PAKEntryReadStream& operator=(const PAKEntryReadStream& other) = delete; + PAKEntryReadStream& operator=(PAKEntryReadStream&& other) = default; + PAKEntryReadStream(std::unique_ptr&& buf, atUint64 sz, atUint64 pos) + : m_buf(std::move(buf)), m_sz(sz), m_pos(pos) + { + if (m_pos >= m_sz) + LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun"); + } + inline void seek(atInt64 pos, Athena::SeekOrigin origin) + { + if (origin == Athena::Begin) + m_pos = pos; + else if (origin == Athena::Current) + m_pos += pos; + else if (origin == Athena::End) + m_pos = m_sz + pos; + if (m_pos >= m_sz) + LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun"); + } + inline atUint64 position() const {return m_pos;} + inline atUint64 length() const {return m_sz;} + inline const atUint8* data() const {return m_buf.get();} + inline atUint64 readUBytesToBuf(void* buf, atUint64 len) + { + atUint64 bufEnd = m_pos + len; + if (bufEnd > m_sz) + len -= bufEnd - m_sz; + memcpy(buf, m_buf.get() + m_pos, len); + m_pos += len; + return len; + } +}; + +struct UniqueResult +{ + enum Type + { + UNIQUE_NOTFOUND, + UNIQUE_LEVEL, + UNIQUE_AREA, + UNIQUE_LAYER + } type = UNIQUE_NOTFOUND; + const HECL::SystemString* areaName = nullptr; + const HECL::SystemString* layerName = nullptr; + UniqueResult() = default; + UniqueResult(Type tp) : type(tp) {} + inline HECL::ProjectPath uniquePath(const HECL::ProjectPath& pakPath) const + { + if (type == UNIQUE_AREA) + { + HECL::ProjectPath areaDir(pakPath, *areaName); + areaDir.makeDir(); + return areaDir; + } + else if (type == UNIQUE_LAYER) + { + HECL::ProjectPath areaDir(pakPath, *areaName); + areaDir.makeDir(); + HECL::ProjectPath layerDir(areaDir, *layerName); + layerDir.makeDir(); + return layerDir; + } + return pakPath; + } +}; + +template +class PAKRouter; + +/* Resource extractor type */ +template +struct ResExtractor +{ + std::function func_a; + std::function&, + const typename PAKBRIDGE::PAKType::Entry&, bool)> func_b; + const char* fileExts[4]; + unsigned weight; +}; + +/* PAKRouter (for detecting shared entry locations) */ +template +class PAKRouter +{ +public: + using PAKType = typename BRIDGETYPE::PAKType; + using IDType = typename PAKType::IDType; + using EntryType = typename PAKType::Entry; +private: + const SpecBase& m_dataSpec; + const std::vector* m_bridges = nullptr; + std::vector> m_bridgePaths; + size_t m_curBridgeIdx = 0; + const HECL::ProjectPath& m_gameWorking; + const HECL::ProjectPath& m_gameCooked; + HECL::ProjectPath m_sharedWorking; + HECL::ProjectPath m_sharedCooked; + const PAKType* m_pak = nullptr; + const NOD::DiscBase::IPartition::Node* m_node = nullptr; + std::unordered_map> m_uniqueEntries; + std::unordered_map> m_sharedEntries; +public: + PAKRouter(const SpecBase& dataSpec, const HECL::ProjectPath& working, const HECL::ProjectPath& cooked) + : m_dataSpec(dataSpec), + m_gameWorking(working), m_gameCooked(cooked), + m_sharedWorking(working, "Shared"), m_sharedCooked(cooked, "Shared") {} + void build(std::vector& bridges, std::function progress) + { + m_bridges = &bridges; + m_bridgePaths.clear(); + + m_uniqueEntries.clear(); + m_sharedEntries.clear(); + size_t count = 0; + float bridgesSz = bridges.size(); + + /* Route entries unique/shared per-pak */ + size_t bridgeIdx = 0; + for (BRIDGETYPE& bridge : bridges) + { + const std::string& name = bridge.getName(); + HECL::SystemStringView sysName(name); + + HECL::SystemString::const_iterator extit = sysName.sys_str().end() - 4; + HECL::SystemString baseName(sysName.sys_str().begin(), extit); + + m_bridgePaths.emplace_back(std::make_pair(HECL::ProjectPath(m_gameWorking, baseName), + HECL::ProjectPath(m_gameCooked, baseName))); + + bridge.build(); + const typename BRIDGETYPE::PAKType& pak = bridge.getPAK(); + for (const auto& entry : pak.m_idMap) + { + auto sSearch = m_sharedEntries.find(entry.first); + if (sSearch != m_sharedEntries.end()) + continue; + auto uSearch = m_uniqueEntries.find(entry.first); + if (uSearch != m_uniqueEntries.end()) + { + m_uniqueEntries.erase(uSearch); + m_sharedEntries[entry.first] = std::make_pair(bridgeIdx, entry.second); + } + else + m_uniqueEntries[entry.first] = std::make_pair(bridgeIdx, entry.second); + } + progress(++count / bridgesSz); + ++bridgeIdx; + } + } + + void enterPAKBridge(const BRIDGETYPE& pakBridge) + { + auto pit = m_bridgePaths.begin(); + size_t bridgeIdx = 0; + for (const BRIDGETYPE& bridge : *m_bridges) + { + if (&bridge == &pakBridge) + { + pit->first.makeDir(); + pit->second.makeDir(); + m_pak = &pakBridge.getPAK(); + m_node = &pakBridge.getNode(); + m_curBridgeIdx = bridgeIdx; + return; + } + ++pit; + ++bridgeIdx; + } + LogDNACommon.report(LogVisor::FatalError, "PAKBridge provided to PAKRouter::enterPAKBridge() was not part of build()"); + } + + HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::Entry* entry, + const ResExtractor& extractor) const + { + if (!m_pak) + LogDNACommon.report(LogVisor::FatalError, + "PAKRouter::enterPAKBridge() must be called before PAKRouter::getWorkingPath()"); + auto uniqueSearch = m_uniqueEntries.find(entry->id); + if (uniqueSearch != m_uniqueEntries.end()) + { + const HECL::ProjectPath& pakPath = m_bridgePaths[uniqueSearch->second.first].first; + pakPath.makeDir(); + HECL::ProjectPath uniquePath = entry->unique.uniquePath(pakPath); + HECL::SystemString entName = m_pak->bestEntryName(*entry); + if (extractor.fileExts[0] && !extractor.fileExts[1]) + entName += extractor.fileExts[0]; + return HECL::ProjectPath(uniquePath, entName); + } + auto sharedSearch = m_sharedEntries.find(entry->id); + if (sharedSearch != m_sharedEntries.end()) + { + const HECL::ProjectPath& pakPath = m_bridgePaths[m_curBridgeIdx].first; + HECL::ProjectPath uniquePathPre = entry->unique.uniquePath(pakPath); + HECL::SystemString entBase = m_pak->bestEntryName(*entry); + HECL::SystemString entName = entBase; + if (extractor.fileExts[0] && !extractor.fileExts[1]) + entName += extractor.fileExts[0]; + HECL::ProjectPath sharedPath(m_sharedWorking, entName); + HECL::ProjectPath uniquePath(uniquePathPre, entName); + if (extractor.func_a || extractor.func_b) + { + if (extractor.fileExts[0] && !extractor.fileExts[1]) + uniquePath.makeLinkTo(sharedPath); + else + { + for (int e=0 ; e<4 ; ++e) + { + if (!extractor.fileExts[e]) + break; + HECL::SystemString entName = entBase + extractor.fileExts[e]; + HECL::ProjectPath sharedPath(m_sharedWorking, entName); + HECL::ProjectPath uniquePath(uniquePathPre, entName); + uniquePath.makeLinkTo(sharedPath); + } + } + } + m_sharedWorking.makeDir(); + return sharedPath; + } + LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str()); + return HECL::ProjectPath(); + } + + HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::Entry* entry) const + { + return getWorking(entry, BRIDGETYPE::LookupExtractor(*entry)); + } + + HECL::ProjectPath getWorking(const typename BRIDGETYPE::PAKType::IDType& id) const + { + return getWorking(lookupEntry(id)); + } + + HECL::ProjectPath getCooked(const typename BRIDGETYPE::PAKType::Entry* entry) const + { + if (!m_pak) + LogDNACommon.report(LogVisor::FatalError, + "PAKRouter::enterPAKBridge() must be called before PAKRouter::getCookedPath()"); + auto uniqueSearch = m_uniqueEntries.find(entry->id); + if (uniqueSearch != m_uniqueEntries.end()) + { + const HECL::ProjectPath& pakPath = m_bridgePaths[uniqueSearch->second.first].second; + pakPath.makeDir(); + HECL::ProjectPath uniquePath = entry->unique.uniquePath(pakPath); + return HECL::ProjectPath(uniquePath, m_pak->bestEntryName(*entry)); + } + auto sharedSearch = m_sharedEntries.find(entry->id); + if (sharedSearch != m_sharedEntries.end()) + { + m_sharedCooked.makeDir(); + return HECL::ProjectPath(m_sharedCooked, m_pak->bestEntryName(*entry)); + } + LogDNACommon.report(LogVisor::FatalError, "Unable to find entry %s", entry->id.toString().c_str()); + return HECL::ProjectPath(); + } + + HECL::ProjectPath getCooked(const typename BRIDGETYPE::PAKType::IDType& id) const + { + return getCooked(lookupEntry(id)); + } + + HECL::SystemString getResourceRelativePath(const typename BRIDGETYPE::PAKType::Entry& a, + const typename BRIDGETYPE::PAKType::IDType& b) const + { + if (!m_pak) + LogDNACommon.report(LogVisor::FatalError, + "PAKRouter::enterPAKBridge() must be called before PAKRouter::getResourceRelativePath()"); + const typename BRIDGETYPE::PAKType::Entry* be = lookupEntry(b); + if (!be) + return HECL::SystemString(); + HECL::ProjectPath aPath = getWorking(&a, BRIDGETYPE::LookupExtractor(a)); + HECL::SystemString ret; + for (int i=0 ; ibestEntryName(entry); + } + + std::string getBestEntryName(const typename BRIDGETYPE::PAKType::IDType& entry) const + { + if (!m_pak) + LogDNACommon.report(LogVisor::FatalError, + "PAKRouter::enterPAKBridge() must be called before PAKRouter::getBestEntryName()"); + const typename BRIDGETYPE::PAKType::Entry* e = m_pak->lookupEntry(entry); + if (!e) + return entry.toString(); + return m_pak->bestEntryName(*e); + } + + bool extractResources(const BRIDGETYPE& pakBridge, bool force, std::function progress) + { + enterPAKBridge(pakBridge); + size_t count = 0; + size_t sz = m_pak->m_idMap.size(); + float fsz = sz; + for (unsigned w=0 ; countm_idMap) + { + ResExtractor extractor = BRIDGETYPE::LookupExtractor(*item.second); + if (extractor.weight != w) + continue; + + HECL::ProjectPath cooked = getCooked(item.second); + if (force || cooked.getPathType() == HECL::ProjectPath::PT_NONE) + { + PAKEntryReadStream s = item.second->beginReadStream(*m_node); + FILE* fout = HECL::Fopen(cooked.getAbsolutePath().c_str(), _S("wb")); + fwrite(s.data(), 1, s.length(), fout); + fclose(fout); + } + + HECL::ProjectPath working = getWorking(item.second, extractor); + if (extractor.func_a) /* Doesn't need PAKRouter access */ + { + if (force || working.getPathType() == HECL::ProjectPath::PT_NONE) + { + PAKEntryReadStream s = item.second->beginReadStream(*m_node); + extractor.func_a(m_dataSpec, s, working); + } + } + else if (extractor.func_b) /* Needs PAKRouter access */ + { + if (force || working.getPathType() == HECL::ProjectPath::PT_NONE) + { + PAKEntryReadStream s = item.second->beginReadStream(*m_node); + extractor.func_b(m_dataSpec, s, working, *this, *item.second, force); + } + } + + progress(++count / fsz); + } + } + + return true; + } + + const typename BRIDGETYPE::PAKType::Entry* lookupEntry(const typename BRIDGETYPE::PAKType::IDType& entry, + const NOD::DiscBase::IPartition::Node** nodeOut=nullptr) const + { + if (!m_bridges) + LogDNACommon.report(LogVisor::FatalError, + "PAKRouter::build() must be called before PAKRouter::lookupEntry()"); + if (m_pak) + { + const typename BRIDGETYPE::PAKType::Entry* ent = m_pak->lookupEntry(entry); + if (ent) + { + if (nodeOut) + *nodeOut = m_node; + return ent; + } + } + for (const BRIDGETYPE& bridge : *m_bridges) + { + const typename BRIDGETYPE::PAKType& pak = bridge.getPAK(); + const typename BRIDGETYPE::PAKType::Entry* ent = pak.lookupEntry(entry); + if (ent) + { + if (nodeOut) + *nodeOut = &bridge.getNode(); + return ent; + } + } + LogDNACommon.report(LogVisor::Warning, "unable to find PAK entry %s", entry.toString().c_str()); + if (nodeOut) + *nodeOut = nullptr; + return nullptr; + } + + template + bool lookupAndReadDNA(const typename BRIDGETYPE::PAKType::IDType& id, DNA& out) + { + const NOD::DiscBase::IPartition::Node* node; + const typename BRIDGETYPE::PAKType::Entry* entry = lookupEntry(id, &node); + if (!entry) + return false; + PAKEntryReadStream rs = entry->beginReadStream(*node); + out.read(rs); + return true; + } +}; + +} + +#endif // __DNACOMMON_PAK_HPP__ diff --git a/DataSpec/DNACommon/TXTR.cpp b/DataSpec/DNACommon/TXTR.cpp index 2ddf9fc47..a2fca231d 100644 --- a/DataSpec/DNACommon/TXTR.cpp +++ b/DataSpec/DNACommon/TXTR.cpp @@ -1,6 +1,7 @@ #include #include #include "TXTR.hpp" +#include "PAK.hpp" namespace Retro { diff --git a/DataSpec/DNACommon/TXTR.hpp b/DataSpec/DNACommon/TXTR.hpp index bbdbe7eaf..39a7aebcb 100644 --- a/DataSpec/DNACommon/TXTR.hpp +++ b/DataSpec/DNACommon/TXTR.hpp @@ -5,6 +5,7 @@ namespace Retro { +class PAKEntryReadStream; struct TXTR { diff --git a/DataSpec/DNAMP1/MLVL.hpp b/DataSpec/DNAMP1/MLVL.hpp index 638abcfa4..c74bc2e90 100644 --- a/DataSpec/DNAMP1/MLVL.hpp +++ b/DataSpec/DNAMP1/MLVL.hpp @@ -1,7 +1,7 @@ #ifndef __DNAMP1_MLVL_HPP__ #define __DNAMP1_MLVL_HPP__ -#include "../DNACommon/DNACommon.hpp" +#include "../DNACommon/PAK.hpp" namespace Retro { diff --git a/DataSpec/DNAMP1/PAK.hpp b/DataSpec/DNAMP1/PAK.hpp index d8b148a99..4c5dc7060 100644 --- a/DataSpec/DNAMP1/PAK.hpp +++ b/DataSpec/DNAMP1/PAK.hpp @@ -4,7 +4,7 @@ #include #include -#include "../DNACommon/DNACommon.hpp" +#include "../DNACommon/PAK.hpp" namespace Retro { diff --git a/DataSpec/DNAMP2/STRG.hpp b/DataSpec/DNAMP2/STRG.hpp index 3e9b972cb..ac33d15be 100644 --- a/DataSpec/DNAMP2/STRG.hpp +++ b/DataSpec/DNAMP2/STRG.hpp @@ -2,7 +2,7 @@ #define __DNAMP2_STRG_HPP__ #include -#include "../DNACommon/DNACommon.hpp" +#include "../DNACommon/PAK.hpp" #include "../DNACommon/STRG.hpp" namespace Retro diff --git a/DataSpec/DNAMP3/PAK.hpp b/DataSpec/DNAMP3/PAK.hpp index 8d66727ac..35a9da055 100644 --- a/DataSpec/DNAMP3/PAK.hpp +++ b/DataSpec/DNAMP3/PAK.hpp @@ -5,7 +5,7 @@ #include #include -#include "../DNACommon/DNACommon.hpp" +#include "../DNACommon/PAK.hpp" namespace Retro { diff --git a/DataSpec/DNAMP3/STRG.hpp b/DataSpec/DNAMP3/STRG.hpp index 9340658e9..e8c90b08b 100644 --- a/DataSpec/DNAMP3/STRG.hpp +++ b/DataSpec/DNAMP3/STRG.hpp @@ -2,7 +2,7 @@ #define __DNAMP3_STRG_HPP__ #include -#include "../DNACommon/DNACommon.hpp" +#include "../DNACommon/PAK.hpp" #include "../DNACommon/STRG.hpp" namespace Retro diff --git a/Runtime/CFactoryStore.cpp b/Runtime/CActor.cpp similarity index 100% rename from Runtime/CFactoryStore.cpp rename to Runtime/CActor.cpp diff --git a/Runtime/CActor.hpp b/Runtime/CActor.hpp new file mode 100644 index 000000000..17619b159 --- /dev/null +++ b/Runtime/CActor.hpp @@ -0,0 +1,23 @@ +#ifndef __RETRO_CACTOR_HPP__ +#define __RETRO_CACTOR_HPP__ + +#include "CEntity.hpp" + +namespace Retro +{ +class CTransform; +class CModelData; +class CMaterialList; +class CActorParameters; + +class CActor : public CEntity +{ +public: + CActor(TUniqueId, bool, const std::string&, const CEntityInfo&, + const CTransform&, const CModelData&, const CMaterialList&, + const CActorParameters&, TUniqueId); +}; + +} + +#endif // __RETRO_CACTOR_HPP__ diff --git a/Runtime/CAi.hpp b/Runtime/CAi.hpp index 16f86c325..3c8469fc8 100644 --- a/Runtime/CAi.hpp +++ b/Runtime/CAi.hpp @@ -8,6 +8,12 @@ class CAiFuncMap { }; +class CAi +{ +public: + +}; + } #endif // __RETRO_CAI_HPP__ diff --git a/Runtime/CArchitectureMessage.hpp b/Runtime/CArchitectureMessage.hpp index 5d4ba7e5b..2df0b17dc 100644 --- a/Runtime/CArchitectureMessage.hpp +++ b/Runtime/CArchitectureMessage.hpp @@ -7,7 +7,6 @@ namespace Retro { - class CIOWin; enum EArchMsgTarget diff --git a/Runtime/CBasics.hpp b/Runtime/CBasics.hpp index a2868e501..4ab3be986 100644 --- a/Runtime/CBasics.hpp +++ b/Runtime/CBasics.hpp @@ -9,7 +9,6 @@ #include #include - namespace Retro { diff --git a/Runtime/CEntity.cpp b/Runtime/CEntity.cpp index 45409de99..642c9f394 100644 --- a/Runtime/CEntity.cpp +++ b/Runtime/CEntity.cpp @@ -1,4 +1,5 @@ #include "CEntity.hpp" +#include "CStateManager.hpp" namespace Retro { diff --git a/Runtime/CEntity.hpp b/Runtime/CEntity.hpp index 174ae4761..cd4de1846 100644 --- a/Runtime/CEntity.hpp +++ b/Runtime/CEntity.hpp @@ -3,10 +3,10 @@ #include "RetroTypes.hpp" #include "ScriptObjectSupport.hpp" -#include "CStateManager.hpp" namespace Retro { +class CStateManager; struct SConnection { diff --git a/Runtime/CFactoryStore.hpp b/Runtime/CFactoryStore.hpp deleted file mode 100644 index 22811c7ae..000000000 --- a/Runtime/CFactoryStore.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __RETRO_CFACTORYSTORE_HPP__ -#define __RETRO_CFACTORYSTORE_HPP__ - -namespace Retro -{ - -class IObjectStore -{ -}; - -} - -#endif // __RETRO_CFACTORYSTORE_HPP__ diff --git a/Runtime/CIOWin.hpp b/Runtime/CIOWin.hpp index 2819e57b8..93ee17700 100644 --- a/Runtime/CIOWin.hpp +++ b/Runtime/CIOWin.hpp @@ -2,11 +2,11 @@ #define __RETRO_CIOWIN_HPP__ #include -#include "CArchitectureMessage.hpp" -#include "CArchitectureQueue.hpp" namespace Retro { +class CArchitectureMessage; +class CArchitectureQueue; class CIOWin { diff --git a/Runtime/CIOWinManager.cpp b/Runtime/CIOWinManager.cpp index f7cf976d7..c768b067b 100644 --- a/Runtime/CIOWinManager.cpp +++ b/Runtime/CIOWinManager.cpp @@ -1,4 +1,5 @@ #include "CIOWinManager.hpp" +#include "CArchitectureMessage.hpp" namespace Retro { diff --git a/Runtime/CMFGame.cpp b/Runtime/CMFGame.cpp index e69de29bb..f8ccfcb6f 100644 --- a/Runtime/CMFGame.cpp +++ b/Runtime/CMFGame.cpp @@ -0,0 +1,28 @@ +#include "CMFGame.hpp" +#include "CArchitectureQueue.hpp" +#include "GameGlobalObjects.hpp" +#include "CGameState.hpp" + +namespace Retro +{ + +bool CMFGameLoader::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) +{ + switch (msg.GetType()) + { + case MsgTimerTick: + { + const CArchMsgParmReal32& tick = MakeMsg::GetParmTimerTick(msg); + g_GameState->WorldTransitionManager(); + } + default: break; + } + return true; +} + +void CMFGameLoader::Draw() const +{ + g_GameState->WorldTransitionManager().Draw(); +} + +} diff --git a/Runtime/CMainFlow.cpp b/Runtime/CMainFlow.cpp index 4c21994bd..271f05fb7 100644 --- a/Runtime/CMainFlow.cpp +++ b/Runtime/CMainFlow.cpp @@ -1,27 +1,39 @@ #include "CMainFlow.hpp" -#include "GameGlobalObjects.hpp" -#include "CGameState.hpp" +#include "CArchitectureQueue.hpp" +#include "CMFGame.hpp" namespace Retro { -bool CMFGameLoader::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) +void CMainFlow::AdvanceGameState(CArchitectureQueue& queue) +{ +} +void CMainFlow::SetGameState(EClientFlowStates state, CArchitectureQueue& queue) +{ + switch (state) + { + case StateGameLoad: + queue.PushMessage(std::move(MakeMsg::CreateCreateIOWin(TargetMainFlow, 10, 1000, new CMFGameLoader()))); + break; + default: break; + } +} +bool CMainFlow::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) { switch (msg.GetType()) { case MsgTimerTick: + AdvanceGameState(queue); + break; + case MsgSetGameState: { - const CArchMsgParmReal32& tick = MakeMsg::GetParmTimerTick(msg); - g_GameState->WorldTransitionManager(); + CArchMsgParmInt32 state = MakeMsg::GetParmNewGameflowState(msg); + SetGameState(EClientFlowStates(state.m_parm), queue); + return true; } default: break; } - return true; -} - -void CMFGameLoader::Draw() const -{ - g_GameState->WorldTransitionManager().Draw(); + return false; } } diff --git a/Runtime/CMainFlow.hpp b/Runtime/CMainFlow.hpp index 4e2276908..c0e3db95e 100644 --- a/Runtime/CMainFlow.hpp +++ b/Runtime/CMainFlow.hpp @@ -2,10 +2,11 @@ #define __RETRO_CMAINFLOW_HPP__ #include "CIOWin.hpp" -#include "CMFGame.hpp" namespace Retro { +class CArchitectureMessage; +class CArchitectureQueue; enum EClientFlowStates { @@ -16,36 +17,9 @@ class CMainFlow : public CIOWin { public: CMainFlow() : CIOWin("CMainFlow") {} - void AdvanceGameState(CArchitectureQueue& queue) - { - } - void SetGameState(EClientFlowStates state, CArchitectureQueue& queue) - { - switch (state) - { - case StateGameLoad: - queue.PushMessage(std::move(MakeMsg::CreateCreateIOWin(TargetMainFlow, 10, 1000, new CMFGameLoader()))); - break; - default: break; - } - } - bool OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) - { - switch (msg.GetType()) - { - case MsgTimerTick: - AdvanceGameState(queue); - break; - case MsgSetGameState: - { - CArchMsgParmInt32 state = MakeMsg::GetParmNewGameflowState(msg); - SetGameState(EClientFlowStates(state.m_parm), queue); - return true; - } - default: break; - } - return false; - } + void AdvanceGameState(CArchitectureQueue& queue); + void SetGameState(EClientFlowStates state, CArchitectureQueue& queue); + bool OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue); bool GetIsContinueDraw() const {return false;} void Draw() const {} }; diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 77871d01f..03c6a0025 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -25,7 +25,7 @@ add_library(RuntimeCommon CWorldTransManager.hpp CWorldTransManager.cpp CRandom16.hpp CRandom16.cpp CResFactory.hpp CResFactory.cpp - CFactoryStore.hpp CFactoryStore.cpp + IObjectStore.hpp CSimplePool.hpp CSimplePool.cpp CAi.hpp CAi.cpp CGameOptions.hpp CGameOptions.cpp @@ -40,8 +40,12 @@ add_library(RuntimeCommon CArchitectureMessage.hpp CArchitectureQueue.hpp CArchitectureQueue.cpp IObj.hpp + IVParamObj.hpp CToken.hpp CAreaOctTree.hpp CAreaOctTree.cpp + CActor.hpp CActor.cpp + CPhysicsActor.hpp CPhysicsActor.cpp + rstl.hpp rstl.cpp GameGlobalObjects.hpp RetroTypes.hpp GCNTypes.hpp) diff --git a/Runtime/CMemory.hpp b/Runtime/CMemory.hpp index ec1641c35..6b4838006 100644 --- a/Runtime/CMemory.hpp +++ b/Runtime/CMemory.hpp @@ -1,11 +1,10 @@ #ifndef __RETRO_CMEMORY_HPP__ #define __RETRO_CMEMORY_HPP__ -#include "IAllocator.hpp" -#include "COsContext.hpp" - namespace Retro { +class IAllocator; +class COsContext; class CMemory { diff --git a/Runtime/CPhysicsActor.cpp b/Runtime/CPhysicsActor.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/CPhysicsActor.hpp b/Runtime/CPhysicsActor.hpp new file mode 100644 index 000000000..883c372af --- /dev/null +++ b/Runtime/CPhysicsActor.hpp @@ -0,0 +1,15 @@ +#ifndef __RETRO_CPHYSICSACTOR_HPP__ +#define __RETRO_CPHYSICSACTOR_HPP__ + +#include "CActor.hpp" + +namespace Retro +{ + +class CPhysicsActor : public CActor +{ +}; + +} + +#endif // __RETRO_CPHYSICSACTOR_HPP__ diff --git a/Runtime/CResFactory.cpp b/Runtime/CResFactory.cpp index cfbfa2405..c1a2c9fda 100644 --- a/Runtime/CResFactory.cpp +++ b/Runtime/CResFactory.cpp @@ -3,4 +3,20 @@ namespace Retro { +void CResFactory::Build(const SObjectTag&, const CVParamTransfer&) +{ +} +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 c820c7d08..4fd03fd9a 100644 --- a/Runtime/CResFactory.hpp +++ b/Runtime/CResFactory.hpp @@ -8,6 +8,12 @@ namespace Retro class CResFactory : public IFactory { +public: + void 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; }; } diff --git a/Runtime/CSimplePool.cpp b/Runtime/CSimplePool.cpp index a4d9637fe..aa04b87d2 100644 --- a/Runtime/CSimplePool.cpp +++ b/Runtime/CSimplePool.cpp @@ -1,4 +1,5 @@ #include "CSimplePool.hpp" +#include "IVParamObj.hpp" namespace Retro { diff --git a/Runtime/CSimplePool.hpp b/Runtime/CSimplePool.hpp index f19fb006d..db6d507ad 100644 --- a/Runtime/CSimplePool.hpp +++ b/Runtime/CSimplePool.hpp @@ -1,11 +1,11 @@ #ifndef __RETRO_CSIMPLEPOOL_HPP__ #define __RETRO_CSIMPLEPOOL_HPP__ -#include "IFactory.hpp" -#include "CFactoryStore.hpp" +#include "IObjectStore.hpp" namespace Retro { +class IFactory; class CSimplePool : public IObjectStore { diff --git a/Runtime/CStateManager.hpp b/Runtime/CStateManager.hpp index 30976c216..a268c57bf 100644 --- a/Runtime/CStateManager.hpp +++ b/Runtime/CStateManager.hpp @@ -3,14 +3,14 @@ #include #include "CBasics.hpp" -#include "CScriptMailbox.hpp" -#include "CMapWorldInfo.hpp" -#include "CPlayerState.hpp" -#include "CWorldTransManager.hpp" #include "ScriptObjectSupport.hpp" namespace Retro { +class CScriptMailbox; +class CMapWorldInfo; +class CPlayerState; +class CWorldTransManager; class CStateManager { diff --git a/Runtime/CToken.hpp b/Runtime/CToken.hpp index 4a16e2b05..876530cb5 100644 --- a/Runtime/CToken.hpp +++ b/Runtime/CToken.hpp @@ -1,11 +1,50 @@ #ifndef __RETRO_CTOKEN_HPP__ #define __RETRO_CTOKEN_HPP__ +#include +#include "RetroTypes.hpp" +#include "CVParamTransfer.hpp" +#include "IObjectStore.hpp" + namespace Retro { +class IObjectStore; +class IObj; + +class CObjectReference +{ + u16 x0_refCount = 0; + bool x3_loading = false; + SObjectTag x4_objTag; + IObjectStore* xC_objectStore = nullptr; + std::unique_ptr x10_object; + CVParamTransfer x14_params; +public: + CObjectReference(IObjectStore& objStore, std::unique_ptr&& obj, + const SObjectTag& objTag, CVParamTransfer buildParams) + : x4_objTag(objTag), xC_objectStore(&objStore), + x10_object(std::move(obj)), x14_params(buildParams) {} + CObjectReference(std::unique_ptr&& obj); + + bool IsLoading() const {return x3_loading;} + void Unlock() {} + void RemoveReference() {} + void CancelLoad() {} + void Unload() {} + void GetObject() {} + +}; class CToken { + CObjectReference* x0_objRef; + bool x4_lockHeld = false; +public: + ~CToken() + { + if (x4_lockHeld) + + } }; template diff --git a/Runtime/Character/CAnimationDatabase.hpp b/Runtime/Character/CAnimationDatabase.hpp new file mode 100644 index 000000000..c2206d203 --- /dev/null +++ b/Runtime/Character/CAnimationDatabase.hpp @@ -0,0 +1,26 @@ +#ifndef __RETRO_CANIMATIONDATABASE_HPP__ +#define __RETRO_CANIMATIONDATABASE_HPP__ + +#include "../RetroTypes.hpp" +#include +#include +#include + +namespace Retro +{ +class IMetaAnim; +class CPrimitive; + +class CAnimationDatabase +{ +public: + virtual const IMetaAnim* GetMetaAnim(u32) const=0; + virtual u32 GetNumMetaAnims() const=0; + virtual const char* GetMetaAnimName(u32) const=0; + virtual void GetAllUniquePrimitives(std::vector&) const=0; + virtual void GetUniquePrimitivesFromMetaAnim(std::set&, const std::string&) const=0; +}; + +} + +#endif // __RETRO_CANIMATIONDATABASE_HPP__ diff --git a/Runtime/Character/CAnimationDatabaseGame.hpp b/Runtime/Character/CAnimationDatabaseGame.hpp new file mode 100644 index 000000000..daa4c7283 --- /dev/null +++ b/Runtime/Character/CAnimationDatabaseGame.hpp @@ -0,0 +1,21 @@ +#ifndef __RETRO_CANIMATIONDATABASEGAME_HPP__ +#define __RETRO_CANIMATIONDATABASEGAME_HPP__ + +#include "CAnimationDatabase.hpp" + +namespace Retro +{ + +class CAnimationDatabaseGame : public CAnimationDatabase +{ +public: + const IMetaAnim* GetMetaAnim(u32) const; + u32 GetNumMetaAnims() const; + const char* GetMetaAnimName(u32) const; + void GetAllUniquePrimitives(std::vector&) const; + void GetUniquePrimitivesFromMetaAnim(std::set&, const std::string&) const; +}; + +} + +#endif // __RETRO_CANIMATIONDATABASEGAME_HPP__ diff --git a/Runtime/Character/CAssetFactory.hpp b/Runtime/Character/CAssetFactory.hpp index 23f4f473d..8cf1ade7c 100644 --- a/Runtime/Character/CAssetFactory.hpp +++ b/Runtime/Character/CAssetFactory.hpp @@ -6,9 +6,10 @@ namespace Retro { -class CCharacterFactoryBuilder : public IFactory +class CCharacterFactoryBuilder { public: + CCharacterFactoryBuilder(); class CDummyFactory : public IFactory { }; diff --git a/Runtime/Character/CMakeLists.txt b/Runtime/Character/CMakeLists.txt index a9a1cd5e2..d066ef80e 100644 --- a/Runtime/Character/CMakeLists.txt +++ b/Runtime/Character/CMakeLists.txt @@ -2,4 +2,10 @@ add_library(RuntimeCommonCharacter CAssetFactory.hpp CAssetFactory.cpp CCharacterFactory.hpp CCharacterFactory.cpp CAnimData.hpp CAnimData.cpp - CCharAnimTime.hpp CCharAnimTime.cpp) + CCharAnimTime.hpp CCharAnimTime.cpp + IMetaAnim.hpp + IMetaTrans.hpp + CAnimationDatabase.hpp + CAnimationDatabaseGame.hpp + CTransitionDatabase.hpp + CTransitionDatabaseGame.hpp) diff --git a/Runtime/Character/CTransitionDatabase.hpp b/Runtime/Character/CTransitionDatabase.hpp new file mode 100644 index 000000000..bcea98430 --- /dev/null +++ b/Runtime/Character/CTransitionDatabase.hpp @@ -0,0 +1,18 @@ +#ifndef __RETRO_CTRANSITIONDATABASE_HPP__ +#define __RETRO_CTRANSITIONDATABASE_HPP__ + +#include "../RetroTypes.hpp" + +namespace Retro +{ +class IMetaTrans; + +class CTransitionDatabase +{ +public: + virtual const IMetaTrans* GetMetaTrans(u32, u32) const=0; +}; + +} + +#endif // __RETRO_CTRANSITIONDATABASE_HPP__ diff --git a/Runtime/Character/CTransitionDatabaseGame.hpp b/Runtime/Character/CTransitionDatabaseGame.hpp new file mode 100644 index 000000000..dddae3218 --- /dev/null +++ b/Runtime/Character/CTransitionDatabaseGame.hpp @@ -0,0 +1,17 @@ +#ifndef __RETRO_CTRANSITIONDATABASEGAME_HPP__ +#define __RETRO_CTRANSITIONDATABASEGAME_HPP__ + +#include "CTransitionDatabase.hpp" + +namespace Retro +{ + +class CTransitionDatabaseGame : public CTransitionDatabase +{ +public: + const IMetaTrans* GetMetaTrans(u32, u32); +}; + +} + +#endif // __RETRO_CTRANSITIONDATABASEGAME_HPP__ diff --git a/Runtime/Character/IMetaAnim.hpp b/Runtime/Character/IMetaAnim.hpp new file mode 100644 index 000000000..66778d723 --- /dev/null +++ b/Runtime/Character/IMetaAnim.hpp @@ -0,0 +1,15 @@ +#ifndef __RETRO_IMETAANIM_HPP__ +#define __RETRO_IMETAANIM_HPP__ + +#include "../RetroTypes.hpp" + +namespace Retro +{ + +class IMetaAnim +{ +}; + +} + +#endif // __RETRO_IMETAANIM_HPP__ diff --git a/Runtime/Character/IMetaTrans.hpp b/Runtime/Character/IMetaTrans.hpp new file mode 100644 index 000000000..810d4b147 --- /dev/null +++ b/Runtime/Character/IMetaTrans.hpp @@ -0,0 +1,15 @@ +#ifndef __RETRO_IMETATRANS_HPP__ +#define __RETRO_IMETATRANS_HPP__ + +#include "../RetroTypes.hpp" + +namespace Retro +{ + +class IMetaTrans +{ +}; + +} + +#endif // __RETRO_IMETATRANS_HPP__ diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index afa973fd0..50f3f06db 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -1,13 +1,12 @@ #ifndef __RETRO_CBOORENDERER_HPP__ #define __RETRO_CBOORENDERER_HPP__ -#include "../CFactoryStore.hpp" -#include "../COsContext.hpp" -#include "../CMemory.hpp" -#include "../CResFactory.hpp" - namespace Retro { +class IObjectStore; +class COsContext; +class CMemorySys; +class CResFactory; class CBooRenderer { diff --git a/Runtime/Graphics/IRenderer.hpp b/Runtime/Graphics/IRenderer.hpp index 4ce1d8784..722031c52 100644 --- a/Runtime/Graphics/IRenderer.hpp +++ b/Runtime/Graphics/IRenderer.hpp @@ -48,12 +48,12 @@ public: virtual void SetDrawableCallback(TDrawableCallback, const void*); virtual void SetWorldViewpoint(const CTransform&); virtual void SetPerspectiveFovScalar(float); - virtual void SetPerspective(float,float,float,float,float); - virtual void SetPerspective(float,float,float,float); - virtual void SetViewportOrtho(bool,float,float); + virtual void SetPerspective(float, float, float, float, float); + virtual void SetPerspective(float, float, float, float); + virtual void SetViewportOrtho(bool, float, float); virtual void SetClippingPlanes(const CFrustum&); - virtual void SetViewport(int,int,int,int); - virtual void SetDepthReadWrite(bool,bool); + virtual void SetViewport(int, int, int, int); + virtual void SetDepthReadWrite(bool, bool); virtual void SetBlendMode_AdditiveAlpha(); virtual void SetBlendMode_AlphaBlended(); virtual void SetBlendMode_NoColorWrite(); @@ -62,10 +62,10 @@ public: virtual void SetBlendMode_InvertSrc(); virtual void SetBlendMode_Replace(); virtual void SetBlendMode_AdditiveDestColor(); - virtual void SetDebugOption(EDebugOption,int); + virtual void SetDebugOption(EDebugOption, int); virtual void BeginScene(); virtual void EndScene(); - virtual void BeginPrimitive(EPrimitiveType,int); + virtual void BeginPrimitive(EPrimitiveType, int); virtual void BeginLines(int); virtual void BeginLineStrip(int); virtual void BeginTriangles(int); @@ -73,7 +73,7 @@ public: virtual void BeginTriangleFan(int); virtual void PrimVertex(const CVector3f&); virtual void PrimNormal(const CVector3f&); - virtual void PrimColor(float,float,float,float); + virtual void PrimColor(float, float, float, float); virtual void PrimColor(const CColor&); virtual void EndPrimitive(); virtual void SetAmbientColor(const CColor&); diff --git a/Runtime/IAllocator.hpp b/Runtime/IAllocator.hpp index 70e8727d6..8d3ef1c31 100644 --- a/Runtime/IAllocator.hpp +++ b/Runtime/IAllocator.hpp @@ -1,10 +1,9 @@ #ifndef __RETRO_IALLOCATOR_HPP__ #define __RETRO_IALLOCATOR_HPP__ -#include "COsContext.hpp" - namespace Retro { +class COsContext; class IAllocator { diff --git a/Runtime/IFactory.hpp b/Runtime/IFactory.hpp index 20b51382f..df3864942 100644 --- a/Runtime/IFactory.hpp +++ b/Runtime/IFactory.hpp @@ -1,11 +1,22 @@ #ifndef __RETRO_IFACTORY_HPP__ #define __RETRO_IFACTORY_HPP__ +#include "RetroTypes.hpp" + namespace Retro { +class CVParamTransfer; +class IObj; class IFactory { +public: + virtual ~IFactory() {} + virtual void 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; }; } diff --git a/Runtime/IObj.hpp b/Runtime/IObj.hpp index faf94b8a9..537897439 100644 --- a/Runtime/IObj.hpp +++ b/Runtime/IObj.hpp @@ -1,18 +1,11 @@ #ifndef __RETRO_IOBJ_HPP__ #define __RETRO_IOBJ_HPP__ -#include #include "RetroTypes.hpp" namespace Retro { -struct SObjectTag -{ - HECL::FourCC fcc; - u32 id; -}; - class IObj { }; diff --git a/Runtime/IObjectStore.hpp b/Runtime/IObjectStore.hpp new file mode 100644 index 000000000..3add8116b --- /dev/null +++ b/Runtime/IObjectStore.hpp @@ -0,0 +1,25 @@ +#ifndef __RETRO_IOBJECTSTORE_HPP__ +#define __RETRO_IOBJECTSTORE_HPP__ + +namespace Retro +{ + +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 &)) + */ +}; + +} + +#endif // __RETRO_IOBJECTSTORE_HPP__ diff --git a/Runtime/IVParamObj.hpp b/Runtime/IVParamObj.hpp new file mode 100644 index 000000000..7bcf0ce45 --- /dev/null +++ b/Runtime/IVParamObj.hpp @@ -0,0 +1,47 @@ +#ifndef __RETRO_IVPARAMOBJ_HPP__ +#define __RETRO_IVPARAMOBJ_HPP__ + +#include "IObj.hpp" + +namespace Retro +{ + +class IVParamObj : public IObj +{ +public: + virtual ~IVParamObj() {} +}; + +class CVParamTransfer +{ + rstl::CRefData* m_refData; +public: + CVParamTransfer(rstl::CRefData* rd) : m_refData(rd) {m_refData->AddRef();} + ~CVParamTransfer() + { + if (m_refData->DelRef() <= 0) + { + delete static_cast(m_refData->GetPtr()); + delete m_refData; + } + } + IVParamObj* GetObj() const {return static_cast(m_refData->GetPtr());} + CVParamTransfer ShareTransferRef() {return CVParamTransfer(m_refData);} + + static CVParamTransfer Null() {return CVParamTransfer(&rstl::CRefData::sNull);} +}; + +template +class TObjOwnerParam : public IVParamObj +{ + T m_param; +protected: + ~TObjOwnerParam() {} +public: + TObjOwnerParam(T&& obj) : m_param(std::move(obj)) {} + CVParamTransfer NewTransferRef() {return CVParamTransfer(new rstl::CRefData(this));} +}; + +} + +#endif // __RETRO_IVPARAMOBJ_HPP__ diff --git a/Runtime/MP1/main.cpp b/Runtime/MP1/main.cpp index c42e70893..0c282e43e 100644 --- a/Runtime/MP1/main.cpp +++ b/Runtime/MP1/main.cpp @@ -24,6 +24,7 @@ #include "GuiSys/CConsoleOutputWindow.hpp" #include "Audio/CAudioStateWin.hpp" #include "GameGlobalObjects.hpp" +#include "CArchitectureQueue.hpp" namespace Retro { diff --git a/Runtime/RetroTypes.hpp b/Runtime/RetroTypes.hpp index a06c93828..a750baf89 100644 --- a/Runtime/RetroTypes.hpp +++ b/Runtime/RetroTypes.hpp @@ -3,11 +3,20 @@ #include #include +#include #include "GCNTypes.hpp" +#include "rstl.hpp" +#include "DataSpec/DNACommon/DNACommon.hpp" namespace Retro { +struct SObjectTag +{ + FourCC type; + UniqueID32 id; +}; + /** * @brief singleton static-allocator */ @@ -27,15 +36,15 @@ public: template TOneStatic(typename std::enable_if::value>::type* = 0) - {++ReferenceCount();} + {++m_refCount;} template TOneStatic(typename std::enable_if::value>::type* = 0) - {++ReferenceCount(); new (m_allocspace) T();} + {++m_refCount; new (m_allocspace) T();} template TOneStatic(Args&&... args) - {++ReferenceCount(); new (m_allocspace) T(std::forward(args)...);} + {++m_refCount; new (m_allocspace) T(std::forward(args)...);} - ~TOneStatic() {--ReferenceCount();} + ~TOneStatic() {--m_refCount;} template void reset(Args&&... args) {new (m_allocspace) T(std::forward(args)...);} @@ -53,14 +62,4 @@ using TAreaId = u32; } -namespace rstl -{ -template -class reserved_vector : public std::vector -{ -public: - reserved_vector() {this->reserve(N);} -}; -} - #endif // __RETRO_TYPES_HPP__ diff --git a/Runtime/rstl.cpp b/Runtime/rstl.cpp new file mode 100644 index 000000000..600622b9d --- /dev/null +++ b/Runtime/rstl.cpp @@ -0,0 +1,8 @@ +#include "rstl.hpp" + +namespace rstl +{ + +CRefData rstl::CRefData::sNull; + +} diff --git a/Runtime/rstl.hpp b/Runtime/rstl.hpp new file mode 100644 index 000000000..0c5e5fc9b --- /dev/null +++ b/Runtime/rstl.hpp @@ -0,0 +1,40 @@ +#ifndef __RSTL_HPP__ +#define __RSTL_HPP__ + +#include +#include + +namespace rstl +{ + +/** + * @brief Vector reserved on construction + */ +template +class reserved_vector : public std::vector +{ +public: + reserved_vector() {this->reserve(N);} +}; + +/** + * @brief Simple data/refcount pair + */ +class CRefData +{ + void* m_ptr; + int m_refCount; +public: + CRefData() : m_ptr(nullptr), m_refCount(0xffffff) {} + CRefData(void* ptr) : m_ptr(ptr), m_refCount(0) {} + + void* GetPtr() const {return m_ptr;} + int AddRef() {return ++m_refCount;} + int DelRef() {return --m_refCount;} + + static CRefData sNull; +}; + +} + +#endif // __RSTL_HPP__