2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 03:47:43 +00:00

Explicit Asset ID refactor

This commit is contained in:
Jack Andersen
2019-09-30 21:38:03 -10:00
parent c7ffe725ae
commit 16ca0d24c2
113 changed files with 1782 additions and 2057 deletions

View File

@@ -9,9 +9,6 @@ ThreadLocalPtr<SpecBase> g_curSpec;
ThreadLocalPtr<PAKRouterBase> g_PakRouter;
ThreadLocalPtr<hecl::blender::Token> g_ThreadBlenderToken;
ThreadLocalPtr<hecl::Database::Project> UniqueIDBridge::s_Project;
ThreadLocalPtr<IDRestorer<UniqueID32>> UniqueIDBridge::s_restorer32;
ThreadLocalPtr<IDRestorer<UniqueID64>> UniqueIDBridge::s_restorer64;
ThreadLocalPtr<IDRestorer<UniqueID128>> UniqueIDBridge::s_restorer128;
UniqueID32 UniqueID32::kInvalidId;
template <class IDType>
@@ -40,12 +37,6 @@ hecl::ProjectPath UniqueIDBridge::TranslatePakIdToPath(const IDType& id, bool si
const hecl::ProjectPath* search = project->lookupBridgePath(id.toUint64());
if (!search) {
if (IDRestorer<IDType>* restorer = GetIDRestorer<IDType>()) {
IDType newId = restorer->originalToNew(id);
if (newId.isValid())
if (const hecl::ProjectPath* newSearch = project->lookupBridgePath(newId.toUint64()))
return *newSearch;
}
if (hecl::VerbosityLevel >= 1 && !silenceWarnings && id.isValid())
LogDNACommon.report(logvisor::Warning, fmt("unable to translate {} to path"), id);
return {};
@@ -70,26 +61,9 @@ hecl::ProjectPath UniqueIDBridge::MakePathFromString(std::string_view str) {
template hecl::ProjectPath UniqueIDBridge::MakePathFromString<UniqueID32>(std::string_view str);
template hecl::ProjectPath UniqueIDBridge::MakePathFromString<UniqueID64>(std::string_view str);
template <class IDType>
void UniqueIDBridge::TransformOldHashToNewHash(IDType& id) {
id = TranslatePakIdToPath(id);
}
template void UniqueIDBridge::TransformOldHashToNewHash(UniqueID32& id);
template void UniqueIDBridge::TransformOldHashToNewHash(UniqueID64& id);
void UniqueIDBridge::SetThreadProject(hecl::Database::Project& project) { s_Project.reset(&project); }
/** PAK 32-bit Unique ID */
void UniqueID32::assign(uint32_t id, bool noOriginal) {
m_id = id ? id : 0xffffffff;
if (!noOriginal)
if (IDRestorer<UniqueID32>* restorer = UniqueIDBridge::GetIDRestorer<UniqueID32>()) {
UniqueID32 origId = restorer->newToOriginal(*this);
if (origId.isValid())
*this = origId;
}
}
template <>
void UniqueID32::Enumerate<BigDNA::Read>(typename Read::StreamT& reader) {
assign(reader.readUint32Big());
@@ -100,7 +74,7 @@ void UniqueID32::Enumerate<BigDNA::Write>(typename Write::StreamT& writer) {
}
template <>
void UniqueID32::Enumerate<BigDNA::ReadYaml>(typename ReadYaml::StreamT& reader) {
*this = UniqueIDBridge::MakePathFromString<UniqueID32>(reader.readString(nullptr));
*this = UniqueIDBridge::MakePathFromString<UniqueID32>(reader.readString());
}
template <>
void UniqueID32::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& writer) {
@@ -109,9 +83,7 @@ void UniqueID32::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& write
hecl::ProjectPath path = UniqueIDBridge::TranslatePakIdToPath(*this);
if (!path)
return;
writer.writeString(nullptr, path.getAuxInfo().size()
? (std::string(path.getRelativePathUTF8()) + '|' + path.getAuxInfoUTF8().data())
: path.getRelativePathUTF8());
writer.writeString(path.getEncodableStringUTF8());
}
template <>
void UniqueID32::Enumerate<BigDNA::BinarySize>(typename BinarySize::StreamT& s) {
@@ -143,62 +115,7 @@ void UniqueID32Zero::Enumerate<BigDNA::BinarySize>(typename BinarySize::StreamT&
UniqueID32::Enumerate<BigDNA::BinarySize>(s);
}
AuxiliaryID32& AuxiliaryID32::operator=(const hecl::ProjectPath& path) {
assign(path.ensureAuxInfo(m_auxStr).hash().val32());
return *this;
}
AuxiliaryID32& AuxiliaryID32::operator=(const UniqueID32& id) {
m_baseId = id;
hecl::ProjectPath path = UniqueIDBridge::TranslatePakIdToPath(id);
if (path) {
if (m_addExtension)
path = path.getWithExtension(m_addExtension);
*this = path;
}
return *this;
}
template <>
void AuxiliaryID32::Enumerate<BigDNA::Read>(typename Read::StreamT& reader) {
assign(reader.readUint32Big());
m_baseId = *this;
}
template <>
void AuxiliaryID32::Enumerate<BigDNA::Write>(typename Write::StreamT& writer) {
writer.writeUint32Big(m_id);
}
template <>
void AuxiliaryID32::Enumerate<BigDNA::ReadYaml>(typename ReadYaml::StreamT& reader) {
hecl::ProjectPath readPath = UniqueIDBridge::MakePathFromString<UniqueID32>(reader.readString(nullptr));
*this = readPath.ensureAuxInfo(m_auxStr);
}
template <>
void AuxiliaryID32::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& writer) {
if (!isValid())
return;
hecl::ProjectPath path = UniqueIDBridge::TranslatePakIdToPath<UniqueID32>(*this, true);
if (!path)
path = UniqueIDBridge::TranslatePakIdToPath(m_baseId);
if (!path)
return;
if (m_addExtension)
path = path.getWithExtension(m_addExtension);
hecl::SystemUTF8Conv ufx8AuxStr(m_auxStr);
writer.writeString(nullptr, std::string(path.getRelativePathUTF8()) + '|' + ufx8AuxStr);
}
/** PAK 64-bit Unique ID */
void UniqueID64::assign(uint64_t id, bool noOriginal) {
m_id = id ? id : 0xffffffffffffffff;
if (!noOriginal)
if (IDRestorer<UniqueID64>* restorer = UniqueIDBridge::GetIDRestorer<UniqueID64>()) {
UniqueID64 origId = restorer->newToOriginal(*this);
if (origId.isValid())
*this = origId;
}
}
template <>
void UniqueID64::Enumerate<BigDNA::Read>(typename Read::StreamT& reader) {
assign(reader.readUint64Big());
@@ -209,7 +126,7 @@ void UniqueID64::Enumerate<BigDNA::Write>(typename Write::StreamT& writer) {
}
template <>
void UniqueID64::Enumerate<BigDNA::ReadYaml>(typename ReadYaml::StreamT& reader) {
*this = UniqueIDBridge::MakePathFromString<UniqueID64>(reader.readString(nullptr));
*this = UniqueIDBridge::MakePathFromString<UniqueID64>(reader.readString());
}
template <>
void UniqueID64::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& writer) {
@@ -218,9 +135,7 @@ void UniqueID64::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& write
hecl::ProjectPath path = UniqueIDBridge::TranslatePakIdToPath(*this);
if (!path)
return;
writer.writeString(nullptr, path.getAuxInfo().size()
? (std::string(path.getRelativePathUTF8()) + '|' + path.getAuxInfoUTF8().data())
: path.getRelativePathUTF8());
writer.writeString(path.getEncodableStringUTF8());
}
template <>
void UniqueID64::Enumerate<BigDNA::BinarySize>(typename BinarySize::StreamT& s) {
@@ -244,7 +159,7 @@ void UniqueID128::Enumerate<BigDNA::Write>(typename Write::StreamT& writer) {
}
template <>
void UniqueID128::Enumerate<BigDNA::ReadYaml>(typename ReadYaml::StreamT& reader) {
*this = UniqueIDBridge::MakePathFromString<UniqueID128>(reader.readString(nullptr));
*this = UniqueIDBridge::MakePathFromString<UniqueID128>(reader.readString());
}
template <>
void UniqueID128::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& writer) {
@@ -253,9 +168,7 @@ void UniqueID128::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& writ
hecl::ProjectPath path = UniqueIDBridge::TranslatePakIdToPath(*this);
if (!path)
return;
writer.writeString(nullptr, path.getAuxInfo().size()
? (std::string(path.getRelativePathUTF8()) + '|' + path.getAuxInfoUTF8().data())
: path.getRelativePathUTF8());
writer.writeString(path.getEncodableStringUTF8());
}
template <>
void UniqueID128::Enumerate<BigDNA::BinarySize>(typename BinarySize::StreamT& s) {
@@ -281,4 +194,12 @@ void WordBitmap::write(athena::io::IStreamWriter& writer) const {
}
void WordBitmap::binarySize(size_t& __isz) const { __isz += m_words.size() * 4; }
hecl::ProjectPath GetPathBeginsWith(const hecl::DirectoryEnumerator& dEnum, const hecl::ProjectPath& parentPath,
hecl::SystemStringView test) {
for (const auto& ent : dEnum)
if (hecl::StringUtils::BeginsWith(ent.m_name, test))
return hecl::ProjectPath(parentPath, ent.m_name);
return {};
}
} // namespace DataSpec