From abcb9c2424f11cef5f319ae7040d5fb7bb7d786d Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 13 Aug 2016 09:37:03 -1000 Subject: [PATCH] MREA generation fixes --- DataSpec/DNACommon/AROTBuilder.cpp | 29 ++++++++++++++++++++++++----- DataSpec/DNACommon/DeafBabe.cpp | 4 ++-- DataSpec/DNAMP1/MREA.cpp | 8 ++++---- hecl | 2 +- specter | 2 +- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/DataSpec/DNACommon/AROTBuilder.cpp b/DataSpec/DNACommon/AROTBuilder.cpp index e56f4e3ac..3295d1e10 100644 --- a/DataSpec/DNACommon/AROTBuilder.cpp +++ b/DataSpec/DNACommon/AROTBuilder.cpp @@ -2,8 +2,9 @@ namespace DataSpec { +logvisor::Module Log("AROTBuilder"); -#define AROT_MAX_LEVEL 11 /* These go to 11 */ +#define AROT_MAX_LEVEL 7 static const uint32_t AROTChildCounts[] = { 0, 2, 2, 4, 2, 4, 4, 8 }; @@ -51,6 +52,9 @@ bool AROTBuilder::Node::addChild(int level, const zeus::CAABox& curAabb, const z } if (inX[0] ^ inX[1]) flags |= 0x1; + + if (!flags) + childNodes.clear(); } return true; } @@ -63,6 +67,9 @@ void AROTBuilder::Node::nodeCount(size_t& sz, size_t& idxRefs, BitmapPool& bmpPo { sz += 1; poolIdx = bmpPool.addIndices(childIndices); + if (poolIdx > 65535) + Log.report(logvisor::Fatal, "AROT bitmap exceeds 16-bit node addressing; area too complex"); + if (childNodes.size()) { for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i) @@ -77,7 +84,7 @@ void AROTBuilder::Node::nodeCount(size_t& sz, size_t& idxRefs, BitmapPool& bmpPo } uint32_t childCount = AROTChildCounts[flags]; nodeOff = curOff; - nodeSz += childCount * 2; + nodeSz = childCount * 2 + 4; curOff += nodeSz; idxRefs += childCount; } @@ -114,6 +121,9 @@ void AROTBuilder::Node::writeNodes(athena::io::MemoryWriter& w, int nodeIdx) if (childNodes.size()) { int curIdx = nodeIdx + 1; + if (curIdx > 65535) + Log.report(logvisor::Fatal, "AROT node exceeds 16-bit node addressing; area too complex"); + int childIndices[8]; for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i) @@ -177,6 +187,7 @@ void AROTBuilder::Node::colSize(size_t& totalSz) } else { + totalSz += 36; for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i) { for (int j=0 ; j < 1 + ((flags & 0x2) != 0) ; ++j) @@ -197,8 +208,15 @@ void AROTBuilder::Node::writeColNodes(uint8_t*& ptr, const zeus::CAABox& curAABB { if (childNodes.empty()) { - *reinterpret_cast(ptr) = curAABB.min; - *reinterpret_cast(ptr + 12) = curAABB.max; + zeus::CAABox swapAABB = curAABB; + swapAABB.min[0] = hecl::SBig(swapAABB.min[0]); + swapAABB.min[1] = hecl::SBig(swapAABB.min[1]); + swapAABB.min[2] = hecl::SBig(swapAABB.min[2]); + swapAABB.max[0] = hecl::SBig(swapAABB.max[0]); + swapAABB.max[1] = hecl::SBig(swapAABB.max[1]); + swapAABB.max[2] = hecl::SBig(swapAABB.max[2]); + *reinterpret_cast(ptr) = swapAABB.min; + *reinterpret_cast(ptr + 12) = swapAABB.max; athena::io::MemoryWriter w(ptr + 24, INT32_MAX); w.writeUint16Big(childIndices.size()); for (int idx : childIndices) @@ -222,11 +240,12 @@ void AROTBuilder::Node::writeColNodes(uint8_t*& ptr, const zeus::CAABox& curAABB if (thisFlags) { *pflags |= thisFlags << (idx * 2); - offsets[idx] = thisOffset - nodeOff; + offsets[idx] = hecl::SBig(uint32_t(thisOffset - nodeOff - 36)); } } } } + *pflags = hecl::SBig(*pflags); ptr += 36; zeus::CAABox X[2]; diff --git a/DataSpec/DNACommon/DeafBabe.cpp b/DataSpec/DNACommon/DeafBabe.cpp index 674900122..126af5f94 100644 --- a/DataSpec/DNACommon/DeafBabe.cpp +++ b/DataSpec/DNACommon/DeafBabe.cpp @@ -126,10 +126,10 @@ void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataS db.triMatsCount = colMesh.trianges.size(); db.triangleEdgesCount = colMesh.trianges.size() * 3; - db.unk1 = 0; + db.unk1 = 0x1000000; db.length = db.binarySize(0) - 8; db.magic = 0xDEAFBABE; - db.version = 0; + db.version = 3; db.aabb[0] = colMesh.aabbMin; db.aabb[1] = colMesh.aabbMax; } diff --git a/DataSpec/DNAMP1/MREA.cpp b/DataSpec/DNAMP1/MREA.cpp index 448958320..70825c98b 100644 --- a/DataSpec/DNAMP1/MREA.cpp +++ b/DataSpec/DNAMP1/MREA.cpp @@ -336,7 +336,7 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath, /* SCLY */ { - DNAMP1::SCLY sclyData; + DNAMP1::SCLY sclyData = {}; sclyData.fourCC = 'SCLY'; sclyData.version = 1; for (const hecl::ProjectPath& layer : layerScriptPaths) @@ -372,8 +372,8 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath, /* Collision */ - { - DeafBabe collision; + { + DeafBabe collision = {}; DeafBabeBuildFromBlender(collision, cMesh); secs.emplace_back(collision.binarySize(0), 0); @@ -414,7 +414,7 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath, { if (l.layer == lay) { - BabeDeadLight light; + BabeDeadLight light = {}; WriteBabeDeadLightFromBlender(light, l); light.write(w); } diff --git a/hecl b/hecl index 7535cb1a2..d50aeab9f 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 7535cb1a2ff157cc759473ad272daa861e340e32 +Subproject commit d50aeab9f16b3b6c06125316022fa7398024c68d diff --git a/specter b/specter index eea8bd42f..4efe7e484 160000 --- a/specter +++ b/specter @@ -1 +1 @@ -Subproject commit eea8bd42fc4c6854636ea6d1d08ae3ba76596f40 +Subproject commit 4efe7e48480f99f74da4fc8f546a09c7cb529485