diff options
| author | Nicholas Estelami <NEstelami@users.noreply.github.com> | 2020-12-31 16:23:01 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-31 16:23:01 -0500 |
| commit | 65332778f1994820db7008e23c6e2247e0db02d1 (patch) | |
| tree | 244ed3ae4a14189930256f0b94c732a4d67edae2 /ZAPD/ZSkeleton.cpp | |
| parent | 44b160efc5ef4fb1a911852ceca634fbd2a97bee (diff) | |
CollisionHeader XML support, LOD limbs, various bug fixes and tweaks (#35)
* Update Makefile
* - Removed basefile.txt writes
- CollisionHeader can now be defined in the XML
- Fixed nonmatching issue with ZCutscene
- LOD Limbs should work, but still needs testing
- Fixed bug where default limb DL names would not be generated
- CFG Files no longer generated, since it is no longer necessary.
Diffstat (limited to 'ZAPD/ZSkeleton.cpp')
| -rw-r--r-- | ZAPD/ZSkeleton.cpp | 80 |
1 files changed, 65 insertions, 15 deletions
diff --git a/ZAPD/ZSkeleton.cpp b/ZAPD/ZSkeleton.cpp index e53eb14..631595c 100644 --- a/ZAPD/ZSkeleton.cpp +++ b/ZAPD/ZSkeleton.cpp @@ -2,6 +2,7 @@ #include "BitConverter.h" #include "StringHelper.h" #include "HighLevel/HLModelIntermediette.h" +#include <typeinfo> using namespace std; using namespace tinyxml2; @@ -33,7 +34,9 @@ ZLimbStandard* ZLimbStandard::FromXML(XMLElement* reader, vector<uint8_t> nRawDa limb->name = limbName; limb->address = limbAddress; - limb->parent->AddDeclaration(limb->address, DeclarationAlignment::None, 12, "SkelLimbEntry", StringHelper::Sprintf("%s", limbName.c_str(), limb->address), ""); + string entryType = limbType == ZLimbType::LOD ? "LodLimb" : "StandardLimb"; + + limb->parent->AddDeclaration(limb->address, DeclarationAlignment::None, 12, entryType, StringHelper::Sprintf("%s", limbName.c_str(), limb->address), ""); return limb; } @@ -76,7 +79,10 @@ int ZLimbStandard::GetRawDataSize() ZSkeleton::ZSkeleton() : ZResource() { + type = ZSkeletonType::Normal; limbs = vector<ZLimbStandard*>(); + rootLimb = nullptr; + dListCount = 0; } void ZSkeleton::GenerateHLIntermediette(HLFileIntermediette& hlFile) @@ -98,19 +104,27 @@ ZSkeleton* ZSkeleton::FromXML(XMLElement* reader, vector<uint8_t> nRawData, int skeleton->rawData = nRawData; skeleton->rawDataIndex = rawDataIndex; - if (string(reader->Attribute("Type")) == "Flex") - skeletonType = ZSkeletonType::Flex; - else if (string(reader->Attribute("Type")) == "Skin") - skeletonType = ZSkeletonType::Skin; - else if (string(reader->Attribute("Type")) != "Normal") + if (reader->Attribute("Type") != nullptr) { - // TODO: Print some error here... + if (string(reader->Attribute("Type")) == "Flex") + skeletonType = ZSkeletonType::Flex; + else if (string(reader->Attribute("Type")) == "Skin") + skeletonType = ZSkeletonType::Skin; + else if (string(reader->Attribute("Type")) != "Normal") + { + // TODO: Print some error here... + } } skeleton->type = skeletonType; - if (string(reader->Attribute("LimbType")) == "LOD") - limbType = ZLimbType::LOD; + if (reader->Attribute("LimbType") != nullptr) + { + //printf("C3\n"); + + if (string(reader->Attribute("LimbType")) == "LOD") + limbType = ZLimbType::LOD; + } limbCount = nRawData[rawDataIndex + 4]; skeleton->dListCount = nRawData[rawDataIndex + 8]; @@ -147,18 +161,54 @@ std::string ZSkeleton::GetSourceOutputCode(std::string prefix) for (int i = 0; i < limbs.size(); i++) { ZLimbStandard* limb = limbs[i]; - - string dListStr = limb->dListPtr == 0 ? "NULL" : StringHelper::Sprintf("%s", parent->GetVarName(limb->dListPtr).c_str()); - - string entryStr = StringHelper::Sprintf("\t{ %i, %i, %i }, %i, %i, %s", - limb->transX, limb->transY, limb->transZ, limb->childIndex, limb->siblingIndex, dListStr.c_str()); + + string defaultDLName = StringHelper::Sprintf("%s_dlist_%08X", name.c_str(), limb->dListPtr); + string dListStr = limb->dListPtr == 0 ? "NULL" : StringHelper::Sprintf("%s", parent->GetDeclarationName(limb->dListPtr, defaultDLName).c_str()); + + if (limb->dListPtr != 0 && parent->GetDeclaration(limb->dListPtr) == nullptr) + { + ZDisplayList* dList = new ZDisplayList(rawData, limb->dListPtr, ZDisplayList::GetDListLength(rawData, limb->dListPtr)); + dList->parent = parent; + dList->SetName(StringHelper::Sprintf("%s_dlist_%08X", name.c_str(), limb->dListPtr)); + dList->GetSourceOutputCode(""); + } + + string entryStr = ""; + string entryType = ""; + + if (typeid(*limb) == typeid(ZLimbLOD)) + { + ZLimbLOD* limbLOD = (ZLimbLOD*)limbs[i]; + string defaultFarDLName = StringHelper::Sprintf("%s_farLimbDlist_%08X", name.c_str(), limbLOD->farDListPtr); + string dListStr2 = limbLOD->farDListPtr == 0 ? "NULL" : StringHelper::Sprintf("%s", parent->GetDeclarationName(limbLOD->farDListPtr, defaultFarDLName).c_str()); + + if (limbLOD->farDListPtr != 0 && parent->GetDeclaration(limbLOD->farDListPtr) == nullptr) + { + ZDisplayList* dList = new ZDisplayList(rawData, limbLOD->farDListPtr, ZDisplayList::GetDListLength(rawData, limbLOD->farDListPtr)); + dList->parent = parent; + dList->SetName(StringHelper::Sprintf("%s_farLimbDlist_%08X", name.c_str(), limbLOD->farDListPtr)); + dList->GetSourceOutputCode(""); + } + + entryType = "LodLimb"; + + entryStr = StringHelper::Sprintf("{ %i, %i, %i }, %i, %i, { %s, %s }", + limbLOD->transX, limbLOD->transY, limbLOD->transZ, limbLOD->childIndex, limbLOD->siblingIndex, dListStr.c_str(), dListStr2.c_str()); + } + else + { + entryType = "StandardLimb"; + + entryStr = StringHelper::Sprintf("{ %i, %i, %i }, %i, %i, %s", + limb->transX, limb->transY, limb->transZ, limb->childIndex, limb->siblingIndex, dListStr.c_str()); + } string limbName = StringHelper::Sprintf("%s_limb_%04X", name.c_str(), limb->address); if (parent->HasDeclaration(limb->address)) limbName = parent->GetDeclarationName(limb->address); - parent->AddDeclaration(limb->address, DeclarationAlignment::None, 12, "StandardLimb", limbName, entryStr); + parent->AddDeclaration(limb->address, DeclarationAlignment::None, 12, entryType, limbName, entryStr); } // Table |
