diff options
| author | Léo Lam <leo@leolam.fr> | 2021-03-20 10:17:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-20 05:17:39 -0400 |
| commit | 4751db5c9ee0a25a26379ca5b44efad72215d256 (patch) | |
| tree | ce49e6e23e352c93424343f75b2e10601457a9c3 /ZAPD/ZAnimation.cpp | |
| parent | 963a282dc10036f367a2cb09bb5651aefc73d2a4 (diff) | |
Add a clang-format config and reformat all source files (#63)
* build: Add genbuildinfo as a dependency for ZAPD object files
* Add a clang-format config and reformat all source files
The existing code style is mostly preserved; this just makes formatting
more consistent and prevents lines from getting too long.
* Fix missing includes
Diffstat (limited to 'ZAPD/ZAnimation.cpp')
| -rw-r--r-- | ZAPD/ZAnimation.cpp | 262 |
1 files changed, 160 insertions, 102 deletions
diff --git a/ZAPD/ZAnimation.cpp b/ZAPD/ZAnimation.cpp index 614dcd7..4ae07e1 100644 --- a/ZAPD/ZAnimation.cpp +++ b/ZAPD/ZAnimation.cpp @@ -1,11 +1,11 @@ #include "ZAnimation.h" #include <utility> -#include "ZFile.h" #include "BitConverter.h" -#include "StringHelper.h" #include "File.h" -#include "HighLevel/HLAnimationIntermediette.h" #include "Globals.h" +#include "HighLevel/HLAnimationIntermediette.h" +#include "StringHelper.h" +#include "ZFile.h" using namespace std; @@ -61,11 +61,13 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix) if (parent != nullptr) { string defaultPrefix = name.c_str(); - defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables + defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables - string headerStr = StringHelper::Sprintf("{ %i }, %sFrameData, %sJointIndices, %i", - frameCount, defaultPrefix.c_str(), defaultPrefix.c_str(), limit); - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "AnimationHeader", StringHelper::Sprintf("%s", name.c_str()), headerStr); + string headerStr = + StringHelper::Sprintf("{ %i }, %sFrameData, %sJointIndices, %i", frameCount, + defaultPrefix.c_str(), defaultPrefix.c_str(), limit); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "AnimationHeader", + StringHelper::Sprintf("%s", name.c_str()), headerStr); string indicesStr = ""; string valuesStr = " "; @@ -82,17 +84,23 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix) for (size_t i = 0; i < rotationIndices.size(); i++) { - indicesStr += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x, rotationIndices[i].y, rotationIndices[i].z); + indicesStr += + StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x, + rotationIndices[i].y, rotationIndices[i].z); if (i != (rotationIndices.size() - 1)) indicesStr += "\n"; } - parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16, (int)rotationValues.size() * 2, "static s16", - StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()), rotationValues.size(), valuesStr); + parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16, + (int)rotationValues.size() * 2, "static s16", + StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()), + rotationValues.size(), valuesStr); - parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16, (int)rotationIndices.size() * 6, "static JointIndex", - StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()), rotationIndices.size(), indicesStr); + parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16, + (int)rotationIndices.size() * 6, "static JointIndex", + StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()), + rotationIndices.size(), indicesStr); } return ""; @@ -103,7 +111,9 @@ int ZNormalAnimation::GetRawDataSize() return 16; } -ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath) +ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, + std::vector<uint8_t> nRawData, int rawDataIndex, + const std::string& nRelPath) { ZNormalAnimation* anim = new ZNormalAnimation(); anim->rawData = std::move(nRawData); @@ -138,7 +148,9 @@ void ZNormalAnimation::ParseRawData() // Read the Rotation Indices for (uint32_t i = 0; i < ((rawDataIndex - rotationIndicesSeg) / 6); i++) { - rotationIndices.push_back(RotationIndex(BitConverter::ToInt16BE(data, currentPtr), BitConverter::ToInt16BE(data, currentPtr + 2), BitConverter::ToInt16BE(data, currentPtr + 4))); + rotationIndices.push_back(RotationIndex(BitConverter::ToInt16BE(data, currentPtr), + BitConverter::ToInt16BE(data, currentPtr + 2), + BitConverter::ToInt16BE(data, currentPtr + 4))); currentPtr += 6; } } @@ -152,10 +164,14 @@ std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix) { if (parent != nullptr) { - string segSymbol = segmentAddress == 0 ? "NULL" : parent->GetDeclarationName(segmentAddress, StringHelper::Sprintf("%sSeg%06X", name.c_str(), segmentAddress)); - string headerStr = StringHelper::Sprintf("{ %i }, 0x%08X", - frameCount, segmentAddress); - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "LinkAnimationHeader", StringHelper::Sprintf("%s", name.c_str()), headerStr); + string segSymbol = segmentAddress == 0 ? + "NULL" : + parent->GetDeclarationName( + segmentAddress, StringHelper::Sprintf("%sSeg%06X", name.c_str(), + segmentAddress)); + string headerStr = StringHelper::Sprintf("{ %i }, 0x%08X", frameCount, segmentAddress); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "LinkAnimationHeader", + StringHelper::Sprintf("%s", name.c_str()), headerStr); } return ""; @@ -166,7 +182,9 @@ int ZLinkAnimation::GetRawDataSize() return 8; } -ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath) +ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, + std::vector<uint8_t> nRawData, int rawDataIndex, + const std::string& nRelPath) { ZLinkAnimation* anim = new ZLinkAnimation(); anim->rawData = std::move(nRawData); @@ -183,14 +201,14 @@ void ZLinkAnimation::ParseRawData() const uint8_t* data = rawData.data(); - //segmentAddress = GETSEGOFFSET(BitConverter::ToInt32BE(data, rawDataIndex + 4)); + // segmentAddress = GETSEGOFFSET(BitConverter::ToInt32BE(data, rawDataIndex + 4)); segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4)); } - /* ZCurveAnimation */ -TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset) +TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, + uint32_t fileOffset) : parent(parent) { unk_00 = BitConverter::ToUInt16BE(rawData, fileOffset + 0); @@ -200,15 +218,16 @@ TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, unk_08 = BitConverter::ToFloatBE(rawData, fileOffset + 8); } -TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index) +TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, + uint32_t fileOffset, size_t index) : TransformData(parent, rawData, fileOffset + index * GetRawDataSize()) { } std::string TransformData::GetBody(const std::string& prefix) const { - return StringHelper::Sprintf("0x%04X, 0x%04X, %i, %i, %ff", - unk_00, unk_02, unk_04, unk_06, unk_08); + return StringHelper::Sprintf("0x%04X, 0x%04X, %i, %i, %ff", unk_00, unk_02, unk_04, unk_06, + unk_08); } size_t TransformData::GetRawDataSize() @@ -221,8 +240,8 @@ std::string TransformData::GetSourceTypeName() return "TransformData"; } - -ZCurveAnimation::ZCurveAnimation(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex, ZFile* nParent) +ZCurveAnimation::ZCurveAnimation(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, + int nRawDataIndex, ZFile* nParent) { rawData.assign(nRawData.begin(), nRawData.end()); rawDataIndex = nRawDataIndex; @@ -231,36 +250,44 @@ ZCurveAnimation::ZCurveAnimation(tinyxml2::XMLElement* reader, const std::vector ParseXML(reader); ParseRawData(); - skel = new ZSkeleton(ZSkeletonType::Curve, ZLimbType::Curve, "CurveAnim", - nRawData, Seg2Filespace(skelOffset, parent->baseAddress), nParent); + skel = new ZSkeleton(ZSkeletonType::Curve, ZLimbType::Curve, "CurveAnim", nRawData, + Seg2Filespace(skelOffset, parent->baseAddress), nParent); size_t transformDataSize = 0; size_t copyValuesSize = 0; - if (refIndex != 0) { + if (refIndex != 0) + { uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress); - for (size_t i = 0; i < 3 * 3 * skel->GetLimbCount(); i++) { + for (size_t i = 0; i < 3 * 3 * skel->GetLimbCount(); i++) + { uint8_t ref = BitConverter::ToUInt8BE(nRawData, refIndexOffset + i); - if (ref == 0) { + if (ref == 0) + { copyValuesSize++; } - else { + else + { transformDataSize += ref; } refIndexArr.emplace_back(ref); } } - if (transformData != 0) { + if (transformData != 0) + { uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress); - for (size_t i = 0; i < transformDataSize; i++) { + for (size_t i = 0; i < transformDataSize; i++) + { transformDataArr.emplace_back(parent, nRawData, transformDataOffset, i); } } - if (copyValues != 0) { + if (copyValues != 0) + { uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress); - for (size_t i = 0; i < copyValuesSize; i++) { - copyValuesArr.emplace_back(BitConverter::ToInt16BE(nRawData, copyValuesOffset + i*2)); + for (size_t i = 0; i < copyValuesSize; i++) + { + copyValuesArr.emplace_back(BitConverter::ToInt16BE(nRawData, copyValuesOffset + i * 2)); } } } @@ -274,10 +301,13 @@ void ZCurveAnimation::ParseXML(tinyxml2::XMLElement* reader) { ZAnimation::ParseXML(reader); - const char* skelOffsetXml = reader->Attribute("SkelOffset"); - if (skelOffsetXml == nullptr) { - throw std::runtime_error("ZCurveAnimation::ParseXML: Fatal error in '%s'. Missing 'SkelOffset' attribute in xml. You need to provide the offset of the curve skeleton."); - } + const char* skelOffsetXml = reader->Attribute("SkelOffset"); + if (skelOffsetXml == nullptr) + { + throw std::runtime_error( + "ZCurveAnimation::ParseXML: Fatal error in '%s'. Missing 'SkelOffset' attribute in " + "xml. You need to provide the offset of the curve skeleton."); + } skelOffset = std::strtoul(skelOffsetXml, nullptr, 0); } @@ -292,14 +322,17 @@ void ZCurveAnimation::ParseRawData() unk_10 = BitConverter::ToInt16BE(rawData, rawDataIndex + 14); } -ZCurveAnimation* ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex, std::string nRelPath, ZFile* nParent) +ZCurveAnimation* ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector<uint8_t>& nRawData, + int nRawDataIndex, std::string nRelPath, + ZFile* nParent) { ZCurveAnimation* curve = new ZCurveAnimation(reader, nRawData, nRawDataIndex, nParent); curve->relativePath = std::move(nRelPath); - curve->parent->AddDeclaration( - curve->rawDataIndex, DeclarationAlignment::Align16, curve->GetRawDataSize(), - curve->GetSourceTypeName(), curve->name, ""); + curve->parent->AddDeclaration(curve->rawDataIndex, DeclarationAlignment::Align16, + curve->GetRawDataSize(), curve->GetSourceTypeName(), curve->name, + ""); return curve; } @@ -307,84 +340,94 @@ ZCurveAnimation* ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, c void ZCurveAnimation::PreGenValues(const std::string& prefix) { Declaration* decl = parent->GetDeclaration(skelOffset); - if (decl == nullptr) { + if (decl == nullptr) + { skel->GetSourceOutputCode(prefix); } - if (refIndex != 0) { + if (refIndex != 0) + { uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress); - string refIndexStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", refIndexOffset); + string refIndexStr = + StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", refIndexOffset); string entryStr = " "; uint16_t arrayItemCnt = refIndexArr.size(); size_t i = 0; - for (auto& child: refIndexArr) { - entryStr += StringHelper::Sprintf("0x%02X, %s", - child, - (i++ % 8 == 7) ? "\n " : ""); + for (auto& child : refIndexArr) + { + entryStr += StringHelper::Sprintf("0x%02X, %s", child, (i++ % 8 == 7) ? "\n " : ""); } Declaration* decl = parent->GetDeclaration(refIndexOffset); - if (decl == nullptr) { - parent->AddDeclarationArray( - refIndexOffset, DeclarationAlignment::None, - arrayItemCnt * 1, "u8", - refIndexStr, arrayItemCnt, entryStr); + if (decl == nullptr) + { + parent->AddDeclarationArray(refIndexOffset, DeclarationAlignment::None, + arrayItemCnt * 1, "u8", refIndexStr, arrayItemCnt, + entryStr); } - else { + else + { decl->text = entryStr; } } - if (transformData != 0) { + if (transformData != 0) + { uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress); - string transformDataStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), TransformData::GetSourceTypeName().c_str(), transformDataOffset); + string transformDataStr = + StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), + TransformData::GetSourceTypeName().c_str(), transformDataOffset); string entryStr = ""; uint16_t arrayItemCnt = transformDataArr.size(); size_t i = 0; - for (auto& child: transformDataArr) { - entryStr += StringHelper::Sprintf(" { %s },%s", - child.GetBody(prefix).c_str(), - (++i < arrayItemCnt) ? "\n" : ""); + for (auto& child : transformDataArr) + { + entryStr += StringHelper::Sprintf(" { %s },%s", child.GetBody(prefix).c_str(), + (++i < arrayItemCnt) ? "\n" : ""); } Declaration* decl = parent->GetDeclaration(transformDataOffset); - if (decl == nullptr) { - parent->AddDeclarationArray( - transformDataOffset, DeclarationAlignment::None, - arrayItemCnt * TransformData::GetRawDataSize(), TransformData::GetSourceTypeName(), - transformDataStr, arrayItemCnt, entryStr); + if (decl == nullptr) + { + parent->AddDeclarationArray(transformDataOffset, DeclarationAlignment::None, + arrayItemCnt * TransformData::GetRawDataSize(), + TransformData::GetSourceTypeName(), transformDataStr, + arrayItemCnt, entryStr); } - else { + else + { decl->text = entryStr; } } - if (copyValues != 0) { + if (copyValues != 0) + { uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress); - string copyValuesStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", copyValuesOffset); + string copyValuesStr = + StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", copyValuesOffset); string entryStr = " "; uint16_t arrayItemCnt = copyValuesArr.size(); size_t i = 0; - for (auto& child: copyValuesArr) { - entryStr += StringHelper::Sprintf("% 6i, %s", - child, - (i++ % 8 == 7) ? "\n " : ""); + for (auto& child : copyValuesArr) + { + entryStr += StringHelper::Sprintf("% 6i, %s", child, (i++ % 8 == 7) ? "\n " : ""); } Declaration* decl = parent->GetDeclaration(copyValuesOffset); - if (decl == nullptr) { - parent->AddDeclarationArray( - copyValuesOffset, DeclarationAlignment::None, - arrayItemCnt * 2, "s16", - copyValuesStr, arrayItemCnt, entryStr); + if (decl == nullptr) + { + parent->AddDeclarationArray(copyValuesOffset, DeclarationAlignment::None, + arrayItemCnt * 2, "s16", copyValuesStr, arrayItemCnt, + entryStr); } - else { + else + { decl->text = entryStr; } } @@ -403,51 +446,66 @@ std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix) PreGenValues(prefix); string refIndexStr = "NULL"; - if (refIndex != 0) { + if (refIndex != 0) + { uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress); Declaration* decl = parent->GetDeclaration(refIndexOffset); - if (decl == nullptr) { - refIndexStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", refIndexOffset); + if (decl == nullptr) + { + refIndexStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", + refIndexOffset); } - else { + else + { refIndexStr = decl->varName; } } string transformDataStr = "NULL"; - if (transformData != 0) { + if (transformData != 0) + { uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress); Declaration* decl = parent->GetDeclaration(transformDataOffset); - if (decl == nullptr) { - transformDataStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), TransformData::GetSourceTypeName().c_str(), transformDataOffset); + if (decl == nullptr) + { + transformDataStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), + TransformData::GetSourceTypeName().c_str(), + transformDataOffset); } - else { + else + { transformDataStr = decl->varName; } } string copyValuesStr = "NULL"; - if (copyValues != 0) { + if (copyValues != 0) + { uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress); Declaration* decl = parent->GetDeclaration(copyValuesOffset); - if (decl == nullptr) { - copyValuesStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", copyValuesOffset); + if (decl == nullptr) + { + copyValuesStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", + copyValuesOffset); } - else { + else + { copyValuesStr = decl->varName; } } - - bodyStr = StringHelper::Sprintf("\n %s,\n %s,\n %s,\n %i, %i\n", - refIndexStr.c_str(), transformDataStr.c_str(), copyValuesStr.c_str(), unk_0C, unk_10); + bodyStr = + StringHelper::Sprintf("\n %s,\n %s,\n %s,\n %i, %i\n", refIndexStr.c_str(), + transformDataStr.c_str(), copyValuesStr.c_str(), unk_0C, unk_10); Declaration* decl = parent->GetDeclaration(address); - if (decl == nullptr) { - parent->AddDeclaration(address, DeclarationAlignment::None, - GetRawDataSize(), GetSourceTypeName(), name, bodyStr); + if (decl == nullptr) + { + parent->AddDeclaration(address, DeclarationAlignment::None, GetRawDataSize(), + GetSourceTypeName(), name, bodyStr); } - else { + else + { decl->text = bodyStr; } |
