From d90bdcaf912d51e14a660c56af8727da1a0819bf Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Sun, 10 Mar 2024 19:47:10 -0600 Subject: [PATCH] Cleaned up --- src/factories/ResourceType.h | 3 ++ src/factories/sf64/AnimFactory.cpp | 56 +++++++++--------------------- src/factories/sf64/AnimFactory.h | 2 -- 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/src/factories/ResourceType.h b/src/factories/ResourceType.h index e8abd39b..efd32791 100644 --- a/src/factories/ResourceType.h +++ b/src/factories/ResourceType.h @@ -31,5 +31,8 @@ enum class ResourceType { Waypoints = 0x57505453, // WPTS Metadata = 0x4D444154, // MDAT SpawnData = 0x53444154, // SDAT + + // SF64 + AnimData = 0x414E494D, // ANIM }; } // namespace LUS diff --git a/src/factories/sf64/AnimFactory.cpp b/src/factories/sf64/AnimFactory.cpp index 98448f51..a57f1f2f 100644 --- a/src/factories/sf64/AnimFactory.cpp +++ b/src/factories/sf64/AnimFactory.cpp @@ -6,14 +6,13 @@ #define NUM(x) std::dec << std::setfill(' ') << std::setw(6) << x #define HEX(x) std::hex << std::setfill(' ') << std::setw(6) << x -// #define COL(c) std::dec << std::setfill(' ') << std::setw(3) << c SF64::AnimData::AnimData(int16_t frameCount, int16_t limbCount, uint32_t dataOffset, std::vector frameData, uint32_t keyOffset, std::vector jointKeys): mFrameCount(frameCount), mLimbCount(limbCount), mDataOffset(dataOffset), mFrameData(std::move(frameData)), mKeyOffset(keyOffset), mJointKeys(std::move(jointKeys)) { if((mDataOffset + sizeof(mFrameData) > mKeyOffset) && (mKeyOffset + sizeof(mJointKeys) > mDataOffset)) { - // error 1 + throw std::runtime_error("Data and Key offsets overlap"); } if(mJointKeys.size() != limbCount) { - // error 2 + throw std::runtime_error("Joint Key count does not match Limb count"); } } @@ -29,18 +28,15 @@ void SF64::AnimHeaderExporter::Export(std::ostream &write, std::shared_ptr raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { - // auto limbCount = std::static_pointer_cast(raw)->mLimbCount; - // auto frameCount = std::static_pointer_cast(raw)->mFrameCount; - // auto jointKeys = std::static_pointer_cast(raw)->mJointKeys; - // auto frameData = std::static_pointer_cast(raw)->mFrameData; auto anim = std::static_pointer_cast(raw); const auto symbol = GetSafeNode(node, "symbol", entryName); - // auto dataName = GetSafeNode(node, "data_symbol", entryName); - // auto keyName = GetSafeNode(node, "key_symbol", entryName); + const auto offset = GetSafeNode(node, "offset"); + auto dataOffset = anim->mDataOffset; auto keyOffset = anim->mKeyOffset; auto dataSegment = 0; auto keySegment = 0; + std::ostringstream dataDefaultName; std::ostringstream keyDefaultName; @@ -48,6 +44,7 @@ void SF64::AnimCodeExporter::Export(std::ostream &write, std::shared_ptrIsDebug()) { - // write << "// 0x" << std::hex << std::uppercase << offset << "\n"; - // } + if (Companion::Instance->IsDebug()) { + write << "// 0x" << std::hex << std::uppercase << offset << "\n"; + } write << "u16 " << dataName << "[] = {"; for(int i = 0; i < anim->mFrameData.size(); i++) { - if((i % 12) == 0) { write << "\n" << fourSpaceTab; } - // if(i < 3) { - write << NUM(anim->mFrameData[i]) << ", "; - // } else { - // write << HEX(anim->mFrameData[i]) << ", "; - // } + write << NUM(anim->mFrameData[i]) << ", "; } - write << "\n};\n"; - - write << "\n"; + write << "\n};\n\n"; write << "JointKey " << keyName << "[] = {\n"; for(auto joint : anim->mJointKeys) { @@ -87,32 +76,23 @@ void SF64::AnimCodeExporter::Export(std::ostream &write, std::shared_ptrmFrameCount) << ", " << NUM(anim->mLimbCount) << ", " << dataName << ", " << keyName << ",\n"; - write << "};\n"; - - write << "\n"; - + write << "};\n\n"; } void SF64::AnimBinaryExporter::Export(std::ostream &write, std::shared_ptr raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto anim = std::static_pointer_cast(raw); auto writer = LUS::BinaryWriter(); - WriteHeader(writer, LUS::ResourceType::Vertex, 0); + WriteHeader(writer, LUS::ResourceType::AnimData, 0); writer.Write(anim->mFrameCount); writer.Write(anim->mLimbCount); - writer.Write(anim->mFrameData.size()); - writer.Write(anim->mJointKeys.size()); - + writer.Write((uint32_t) anim->mFrameData.size()); + writer.Write((uint32_t) anim->mJointKeys.size()); + for(auto joint : anim->mJointKeys) { for (int i = 0; i < 6; i++) { writer.Write(joint.keys[i]); @@ -125,7 +105,6 @@ void SF64::AnimBinaryExporter::Export(std::ostream &write, std::shared_ptr> SF64::AnimFactory::parse(std::vector& buffer, YAML::Node& node) { - // uint32_t offset = GetSafeNode(node, "offset"); YAML::Node dataNode; YAML::Node keyNode; std::vector jointKeys; @@ -135,7 +114,6 @@ std::optional> SF64::AnimFactory::parse(std::vector LUS::BinaryReader reader(segment.data, segment.size); reader.SetEndianness(LUS::Endianness::Big); - // reader.Seek(offset, Start); int16_t frameCount = reader.ReadInt16(); int16_t limbCount = reader.ReadInt16(); uint32_t dataOffset = reader.ReadUInt32(); diff --git a/src/factories/sf64/AnimFactory.h b/src/factories/sf64/AnimFactory.h index fc574a92..0fd4d370 100644 --- a/src/factories/sf64/AnimFactory.h +++ b/src/factories/sf64/AnimFactory.h @@ -16,7 +16,6 @@ class AnimData : public IParsedData { uint32_t mKeyOffset; std::vector mFrameData; std::vector mJointKeys; - AnimData(int16_t frameCount, int16_t limbCount, uint32_t dataOffset, std::vector frameData, uint32_t keyOffset, std::vector jointKeys); }; @@ -48,5 +47,4 @@ class AnimFactory : public BaseFactory { } bool SupportModdedAssets() override { return false; } }; - }