summaryrefslogtreecommitdiff
path: root/ZAPD/ZRoom/Commands/SetMesh.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-10-16 18:55:56 -0300
committerGitHub <noreply@github.com>2021-10-16 17:55:56 -0400
commite7a8a48cf361a7591b88592eb3e333ddf8d3ab34 (patch)
tree4f63eac4c2136dd74e05593ea200b2c24c284a3f /ZAPD/ZRoom/Commands/SetMesh.cpp
parent3e9ed72e202b1165152d42f7d160695f9f2f233a (diff)
`ExternalFile`: Expose other XML's declarations during extraction (#151)
* proof of concept * fix header include paths * GetDeclarationAlignment and others * this should fix this * minor * DeclareVar in ExtractFromXML * fix vtx intersections * Fix segmented vtxs * --version * zcollision changes * Use GetSegmentedPtrName a lot more * memory related stuff * minor style fixes and use the actual symbol for zlinkanimation instead of the hex address * Simplify lots of GetSourceOutputCode * ZSkeleton cleanup and other changes * Elevate unknown types in skeleton to errors * ZAnimation cleanup * Add ExternalFile to config * delete some code * Remove unused code * fix conflicts * format * remove redundant constructors * minor fixes * fix vtx warnings * extract every vtx as standalone files * format * uups * Bugfix: don't create extra blank files * Fix some Vtx warnings and remove "defaulting to normal" in skeleton error * Refactor ZLimb * Make each limb to look up in every file for dlists * Use GetSegmentedArrayIndexedName in VTX references in dlists * simplify simple condition * search by type * run format * Revert "search by type" This reverts commit a049bdfc94c4ab04613b354f466dee836a20508a. * Add range checks * uups * Always set rangeEnd * special case zsymbol * Revert "Revert "search by type"" This reverts commit 3f6e77c780bd30dc7000614304021a0940168316. * symbol fix and IsOffsetInFileRange * Bugfix and minor checks * run format * Don't extract data from external files * Fix extraction of overly big tluts * Minor changes * More minor fixes * Fix clang warnings * Remove unused parameter * Fix merge issues * Fix ZLimbTable::DeclareVar * Fix limbs not naming properly their DLists * Remove segment number check * Fix merge problems * Run formatter * Maybe fix? * path * empty commit * Fix a typo * Fix merge issues * Fix null ptr dereferencing * Fix merge issues and some clang warnings * Format * Fix not-matching * Format * Fix merge issues * Fix exporter * Last fixes I hope * Fix merge issues * format * fix * fix * I'm dumb * format * static fix * Whoops * fix asan * Fix? * fix * reduce artificial changes * reduce artificial changes 2 * reorder more stuff * format * fix borken thing * Remove redundant stuff in zfile * fix * Format * Fix conflict issues * format * cleanup header includes * format * Add error checks in for ExternalXMLFolder * format
Diffstat (limited to 'ZAPD/ZRoom/Commands/SetMesh.cpp')
-rw-r--r--ZAPD/ZRoom/Commands/SetMesh.cpp304
1 files changed, 121 insertions, 183 deletions
diff --git a/ZAPD/ZRoom/Commands/SetMesh.cpp b/ZAPD/ZRoom/Commands/SetMesh.cpp
index 676fedd..4fa1f05 100644
--- a/ZAPD/ZRoom/Commands/SetMesh.cpp
+++ b/ZAPD/ZRoom/Commands/SetMesh.cpp
@@ -22,15 +22,15 @@ void SetMesh::ParseRawData()
switch (meshHeaderType)
{
case 0:
- polyType = std::make_shared<PolygonType2>(parent, parentRawData, segmentOffset, zRoom);
+ polyType = std::make_shared<PolygonType2>(parent, segmentOffset, zRoom);
break;
case 1:
- polyType = std::make_shared<PolygonType1>(parent, parentRawData, segmentOffset, zRoom);
+ polyType = std::make_shared<PolygonType1>(parent, segmentOffset, zRoom);
break;
case 2:
- polyType = std::make_shared<PolygonType2>(parent, parentRawData, segmentOffset, zRoom);
+ polyType = std::make_shared<PolygonType2>(parent, segmentOffset, zRoom);
break;
default:
@@ -49,29 +49,18 @@ void SetMesh::DeclareReferences(const std::string& prefix)
polyType->DeclareAndGenerateOutputCode(prefix);
}
+// TODO: is this really needed?
void GenDListDeclarations(ZRoom* zRoom, ZFile* parent, ZDisplayList* dList)
{
if (dList == nullptr)
{
return;
}
- std::string srcVarName =
- StringHelper::Sprintf("%s%s", zRoom->GetName().c_str(), dList->GetName().c_str());
- dList->SetName(srcVarName);
std::string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName());
for (ZDisplayList* otherDList : dList->otherDLists)
GenDListDeclarations(zRoom, parent, otherDList);
-
- for (const auto& vtxEntry : dList->vtxDeclarations)
- {
- parent->AddDeclarationArray(
- vtxEntry.first, DeclarationAlignment::Align16,
- dList->vertices[vtxEntry.first].size() * 16, "Vtx",
- StringHelper::Sprintf("%sVtx_%06X", zRoom->GetName().c_str(), vtxEntry.first),
- dList->vertices[vtxEntry.first].size(), vtxEntry.second);
- }
}
std::string SetMesh::GenDListExterns(ZDisplayList* dList)
@@ -84,14 +73,13 @@ std::string SetMesh::GenDListExterns(ZDisplayList* dList)
for (ZDisplayList* otherDList : dList->otherDLists)
sourceOutput += GenDListExterns(otherDList);
- sourceOutput += dList->defines;
-
return sourceOutput;
}
std::string SetMesh::GetBodySourceCode() const
{
- std::string list = parent->GetDeclarationPtrName(cmdArg2);
+ std::string list;
+ Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "", list);
return StringHelper::Sprintf("SCENE_CMD_MESH(%s)", list.c_str());
}
@@ -105,15 +93,8 @@ RoomCommand SetMesh::GetRoomCommand() const
return RoomCommand::SetMesh;
}
-PolygonDlist::PolygonDlist(const std::string& prefix,
- [[maybe_unused]] const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom)
+PolygonDlist::PolygonDlist(ZFile* nParent) : ZResource(nParent)
{
- rawDataIndex = nRawDataIndex;
- parent = nParent;
- zRoom = nRoom;
-
- name = GetDefaultName(prefix.c_str(), rawDataIndex);
}
void PolygonDlist::ParseRawData()
@@ -144,109 +125,42 @@ void PolygonDlist::DeclareReferences(const std::string& prefix)
xluDList = MakeDlist(xlu, prefix);
}
-ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, [[maybe_unused]] const std::string& prefix)
-{
- if (ptr == 0)
- {
- return nullptr;
- }
-
- uint32_t dlistAddress = Seg2Filespace(ptr, parent->baseAddress);
-
- int32_t dlistLength = ZDisplayList::GetDListLength(
- parent->GetRawData(), dlistAddress,
- Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
- ZDisplayList* dlist = new ZDisplayList(parent);
- dlist->ExtractFromBinary(dlistAddress, dlistLength);
- dlist->SetName(dlist->GetDefaultName(prefix));
- GenDListDeclarations(zRoom, parent, dlist);
-
- return dlist;
-}
-
-size_t PolygonDlist::GetRawDataSize() const
-{
- switch (polyType)
- {
- case 2:
- return 0x10;
-
- default:
- return 0x08;
- }
-}
-
-void PolygonDlist::SetPolyType(uint8_t nPolyType)
-{
- polyType = nPolyType;
-}
-
-void PolygonDlist::DeclareVar(const std::string& prefix, const std::string& bodyStr)
-{
- std::string auxName = name;
- if (name == "")
- {
- auxName = GetDefaultName(prefix, rawDataIndex);
- }
- parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
- GetSourceTypeName(), auxName, bodyStr);
-}
-
-std::string PolygonDlist::GetBodySourceCode(bool arrayElement)
+std::string PolygonDlist::GetBodySourceCode() const
{
std::string bodyStr;
- std::string opaStr = parent->GetDeclarationPtrName(opa);
- std::string xluStr = parent->GetDeclarationPtrName(xlu);
- if (arrayElement)
- {
- bodyStr += " { ";
- }
- else
- {
- bodyStr += "\n ";
- }
+ std::string opaStr;
+ std::string xluStr;
+ Globals::Instance->GetSegmentedPtrName(opa, parent, "Gfx", opaStr);
+ Globals::Instance->GetSegmentedPtrName(xlu, parent, "Gfx", xluStr);
if (polyType == 2)
{
bodyStr += StringHelper::Sprintf("{ %6i, %6i, %6i }, %6i, ", x, y, z, unk_06);
}
- bodyStr += StringHelper::Sprintf("%s, ", opaStr.c_str());
- bodyStr += StringHelper::Sprintf("%s", xluStr.c_str());
-
- if (arrayElement)
- {
- bodyStr += " },";
- }
- else
- {
- bodyStr += "\n";
- }
+ bodyStr += StringHelper::Sprintf("%s, %s", opaStr.c_str(), xluStr.c_str());
return bodyStr;
}
-void PolygonDlist::DeclareAndGenerateOutputCode()
+std::string PolygonDlist::GetSourceOutputCode(const std::string& prefix)
{
- std::string bodyStr = GetBodySourceCode(false);
+ std::string bodyStr = StringHelper::Sprintf("\n\t%s\n", GetBodySourceCode().c_str());
Declaration* decl = parent->GetDeclaration(rawDataIndex);
if (decl == nullptr)
{
- DeclareVar("", bodyStr);
+ DeclareVar(prefix, bodyStr);
}
else
{
decl->text = bodyStr;
}
-}
-std::string PolygonDlist::GetDefaultName(const std::string& prefix, uint32_t address)
-{
- return StringHelper::Sprintf("%sPolyDlist_%06X", prefix.c_str(), address);
+ return "";
}
-std::string PolygonDlist::GetSourceTypeName()
+std::string PolygonDlist::GetSourceTypeName() const
{
switch (polyType)
{
@@ -258,20 +172,64 @@ std::string PolygonDlist::GetSourceTypeName()
}
}
-std::string PolygonDlist::GetName()
+ZResourceType PolygonDlist::GetResourceType() const
{
- return name;
+ // TODO
+ return ZResourceType::Error;
}
-BgImage::BgImage(bool nIsSubStruct, const std::string& prefix,
- [[maybe_unused]] const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
+size_t PolygonDlist::GetRawDataSize() const
+{
+ switch (polyType)
+ {
+ case 2:
+ return 0x10;
+
+ default:
+ return 0x08;
+ }
+}
+
+void PolygonDlist::SetPolyType(uint8_t nPolyType)
+{
+ polyType = nPolyType;
+}
+
+ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, [[maybe_unused]] const std::string& prefix)
+{
+ if (ptr == 0)
+ {
+ return nullptr;
+ }
+
+ uint32_t dlistAddress = Seg2Filespace(ptr, parent->baseAddress);
+
+ int32_t dlistLength = ZDisplayList::GetDListLength(
+ parent->GetRawData(), dlistAddress,
+ Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
+ ZDisplayList* dlist = new ZDisplayList(parent);
+ dlist->ExtractFromBinary(dlistAddress, dlistLength);
+ dlist->SetName(dlist->GetDefaultName(prefix));
+ GenDListDeclarations(zRoom, parent, dlist);
+
+ return dlist;
+}
+
+/* BgImage */
+
+BgImage::BgImage(ZFile* nParent) : ZResource(nParent)
+{
+}
+
+BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, uint32_t nRawDataIndex,
ZFile* nParent)
+ : BgImage(nParent)
{
rawDataIndex = nRawDataIndex;
parent = nParent;
isSubStruct = nIsSubStruct;
- name = GetDefaultName(prefix.c_str(), rawDataIndex);
+ name = GetDefaultName(prefix);
ParseRawData();
sourceBackground = MakeBackground(source, prefix);
@@ -319,15 +277,15 @@ ZBackground* BgImage::MakeBackground(segptr_t ptr, const std::string& prefix)
return background;
}
-size_t BgImage::GetRawDataSize()
+size_t BgImage::GetRawDataSize() const
{
return 0x1C;
}
-std::string BgImage::GetBodySourceCode(bool arrayElement) const
+std::string BgImage::GetBodySourceCode() const
{
std::string bodyStr = " ";
- if (arrayElement)
+ if (!isSubStruct)
{
bodyStr += "{ \n ";
}
@@ -337,16 +295,14 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
bodyStr += StringHelper::Sprintf("0x%04X, ", unk_00);
bodyStr += StringHelper::Sprintf("%i, ", id);
bodyStr += "\n ";
- if (arrayElement)
- {
- bodyStr += " ";
- }
+ bodyStr += " ";
}
- std::string backgroundName = parent->GetDeclarationPtrName(source);
+ std::string backgroundName;
+ Globals::Instance->GetSegmentedPtrName(source, parent, "", backgroundName);
bodyStr += StringHelper::Sprintf("%s, ", backgroundName.c_str());
bodyStr += "\n ";
- if (arrayElement)
+ if (!isSubStruct)
{
bodyStr += " ";
}
@@ -354,7 +310,7 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
bodyStr += StringHelper::Sprintf("0x%08X, ", unk_0C);
bodyStr += StringHelper::Sprintf("0x%08X, ", tlut);
bodyStr += "\n ";
- if (arrayElement)
+ if (!isSubStruct)
{
bodyStr += " ";
}
@@ -362,7 +318,7 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
bodyStr += StringHelper::Sprintf("%i, ", width);
bodyStr += StringHelper::Sprintf("%i, ", height);
bodyStr += "\n ";
- if (arrayElement)
+ if (!isSubStruct)
{
bodyStr += " ";
}
@@ -370,14 +326,14 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
bodyStr += StringHelper::Sprintf("%i, ", fmt);
bodyStr += StringHelper::Sprintf("%i, ", siz);
bodyStr += "\n ";
- if (arrayElement)
+ if (!isSubStruct)
{
bodyStr += " ";
}
bodyStr += StringHelper::Sprintf("0x%04X, ", mode0);
bodyStr += StringHelper::Sprintf("0x%04X, ", tlutCount);
- if (arrayElement)
+ if (!isSubStruct)
{
bodyStr += " \n }, ";
}
@@ -389,41 +345,26 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
return bodyStr;
}
-std::string BgImage::GetDefaultName(const std::string& prefix, uint32_t address)
-{
- return StringHelper::Sprintf("%sBgImage_%06X", prefix.c_str(), address);
-}
-
-std::string BgImage::GetSourceTypeName()
+std::string BgImage::GetSourceTypeName() const
{
return "BgImage";
}
-std::string BgImage::GetName()
+ZResourceType BgImage::GetResourceType() const
{
- return name;
+ // TODO
+ return ZResourceType::Error;
}
/* PolygonType section */
-PolygonTypeBase::PolygonTypeBase(ZFile* nParent,
- [[maybe_unused]] const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex, ZRoom* nRoom)
- : rawDataIndex{nRawDataIndex}, parent{nParent}, zRoom{nRoom}
+PolygonTypeBase::PolygonTypeBase(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom)
+ : ZResource(nParent), zRoom{nRoom}
{
+ rawDataIndex = nRawDataIndex;
type = BitConverter::ToUInt8BE(parent->GetRawData(), rawDataIndex);
}
-void PolygonTypeBase::DeclareVar(const std::string& prefix, const std::string& bodyStr)
-{
- std::string auxName = name;
- if (name == "")
- auxName = GetDefaultName(prefix);
-
- parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
- GetSourceTypeName(), auxName, bodyStr);
-}
-
void PolygonTypeBase::DeclareAndGenerateOutputCode(const std::string& prefix)
{
std::string bodyStr = GetBodySourceCode();
@@ -454,25 +395,14 @@ std::string PolygonTypeBase::GetSourceTypeName() const
}
}
-std::string PolygonTypeBase::GetName() const
-{
- return name;
-}
-
-void PolygonTypeBase::SetName(const std::string& newName)
-{
- name = newName;
-}
-
-std::string PolygonTypeBase::GetDefaultName(const std::string& prefix) const
+ZResourceType PolygonTypeBase::GetResourceType() const
{
- return StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), GetSourceTypeName().c_str(),
- rawDataIndex);
+ // TODO
+ return ZResourceType::Error;
}
-PolygonType1::PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex, ZRoom* nRoom)
- : PolygonTypeBase(nParent, nRawData, nRawDataIndex, nRoom)
+PolygonType1::PolygonType1(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom)
+ : PolygonTypeBase(nParent, nRawDataIndex, nRoom), single(nParent)
{
}
@@ -491,10 +421,10 @@ void PolygonType1::ParseRawData()
if (dlist != 0)
{
- PolygonDlist polyGfxList(zRoom->GetName(), rawData,
- Seg2Filespace(dlist, parent->baseAddress), parent, zRoom);
+ PolygonDlist polyGfxList(parent);
+ polyGfxList.zRoom = zRoom;
polyGfxList.SetPolyType(type);
- polyGfxList.ParseRawData();
+ polyGfxList.ExtractFromFile(Seg2Filespace(dlist, parent->baseAddress));
polyGfxList.DeclareReferences(zRoom->GetName());
polyDLists.push_back(polyGfxList);
}
@@ -502,26 +432,27 @@ void PolygonType1::ParseRawData()
void PolygonType1::DeclareReferences(const std::string& prefix)
{
- polyDLists.at(0).DeclareAndGenerateOutputCode();
+ polyDLists.at(0).GetSourceOutputCode(prefix);
uint32_t listAddress;
std::string bgImageArrayBody;
switch (format)
{
case 1:
- single = BgImage(true, prefix, parent->GetRawData(), rawDataIndex + 0x08, parent);
+ single = BgImage(true, prefix, rawDataIndex + 0x08, parent);
break;
case 2:
if (list != 0)
{
listAddress = Seg2Filespace(list, parent->baseAddress);
+ uint32_t auxPtr = listAddress;
for (size_t i = 0; i < count; ++i)
{
- BgImage bg(false, prefix, parent->GetRawData(),
- listAddress + i * BgImage::GetRawDataSize(), parent);
+ BgImage bg(false, prefix, auxPtr, parent);
multiList.push_back(bg);
- bgImageArrayBody += bg.GetBodySourceCode(true);
+ auxPtr += bg.GetRawDataSize();
+ bgImageArrayBody += bg.GetBodySourceCode();
if (i + 1 < count)
{
bgImageArrayBody += "\n";
@@ -532,9 +463,9 @@ void PolygonType1::DeclareReferences(const std::string& prefix)
if (decl == nullptr)
{
parent->AddDeclarationArray(
- listAddress, DeclarationAlignment::Align4, count * BgImage::GetRawDataSize(),
- BgImage::GetSourceTypeName(), multiList.at(0).GetName().c_str(), count,
- bgImageArrayBody);
+ listAddress, DeclarationAlignment::Align4,
+ count * multiList.at(0).GetRawDataSize(), multiList.at(0).GetSourceTypeName(),
+ multiList.at(0).GetName().c_str(), count, bgImageArrayBody);
}
}
break;
@@ -566,26 +497,26 @@ std::string PolygonType1::GetBodySourceCode() const
bodyStr += "{ ";
bodyStr += StringHelper::Sprintf("%i, %i, ", type, format);
- std::string dlistStr = parent->GetDeclarationPtrName(dlist);
+ std::string dlistStr;
+ Globals::Instance->GetSegmentedPtrName(dlist, parent, "", dlistStr);
+
bodyStr += StringHelper::Sprintf("%s, ", dlistStr.c_str());
bodyStr += "}, \n";
std::string listStr = "NULL";
- // bodyStr += " { \n";
switch (format)
{
case 1:
- bodyStr += single.GetBodySourceCode(false);
+ bodyStr += single.GetBodySourceCode();
break;
case 2:
- listStr = parent->GetDeclarationPtrName(list);
+ Globals::Instance->GetSegmentedPtrName(list, parent, "BgImage", listStr);
bodyStr += StringHelper::Sprintf(" %i, %s, \n", count, listStr.c_str());
break;
default:
break;
}
- // bodyStr += " } \n";
return bodyStr;
}
@@ -604,9 +535,8 @@ std::string PolygonType1::GetSourceTypeName() const
// return "PolygonType1";
}
-PolygonType2::PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex, ZRoom* nRoom)
- : PolygonTypeBase(nParent, nRawData, nRawDataIndex, nRoom)
+PolygonType2::PolygonType2(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom)
+ : PolygonTypeBase(nParent, nRawDataIndex, nRoom)
{
}
@@ -622,9 +552,10 @@ void PolygonType2::ParseRawData()
uint32_t currentPtr = GETSEGOFFSET(start);
for (size_t i = 0; i < num; i++)
{
- PolygonDlist entry(zRoom->GetName(), rawData, currentPtr, parent, zRoom);
+ PolygonDlist entry(parent);
+ entry.zRoom = zRoom;
entry.SetPolyType(type);
- entry.ParseRawData();
+ entry.ExtractFromFile(currentPtr);
entry.DeclareReferences(zRoom->GetName());
polyDLists.push_back(entry);
currentPtr += entry.GetRawDataSize();
@@ -639,7 +570,8 @@ void PolygonType2::DeclareReferences(const std::string& prefix)
for (size_t i = 0; i < polyDLists.size(); i++)
{
- declaration += polyDLists.at(i).GetBodySourceCode(true);
+ declaration +=
+ StringHelper::Sprintf("\t{ %s },", polyDLists.at(i).GetBodySourceCode().c_str());
if (i + 1 < polyDLists.size())
declaration += "\n";
}
@@ -662,7 +594,8 @@ void PolygonType2::DeclareReferences(const std::string& prefix)
std::string PolygonType2::GetBodySourceCode() const
{
- std::string listName = parent->GetDeclarationPtrName(start);
+ std::string listName;
+ Globals::Instance->GetSegmentedPtrName(start, parent, "", listName);
std::string body = StringHelper::Sprintf("\n %i, %i,\n", type, polyDLists.size());
body += StringHelper::Sprintf(" %s,\n", listName.c_str());
@@ -675,3 +608,8 @@ size_t PolygonType2::GetRawDataSize() const
{
return 0x0C;
}
+
+DeclarationAlignment PolygonType2::GetDeclarationAlignment() const
+{
+ return DeclarationAlignment::Align4;
+}