diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-10-16 18:55:56 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-16 17:55:56 -0400 |
| commit | e7a8a48cf361a7591b88592eb3e333ddf8d3ab34 (patch) | |
| tree | 4f63eac4c2136dd74e05593ea200b2c24c284a3f /ZAPD/ZRoom | |
| parent | 3e9ed72e202b1165152d42f7d160695f9f2f233a (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')
25 files changed, 259 insertions, 333 deletions
diff --git a/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp b/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp index c6bc136..ba31bc7 100644 --- a/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp +++ b/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp @@ -45,7 +45,7 @@ void SetActorCutsceneList::DeclareReferences(const std::string& prefix) std::string typeName = cutscenes.at(0).GetSourceTypeName(); parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::Align4, cutscenes.size() * 16, typeName, + segmentOffset, GetDeclarationAlignment(), cutscenes.size() * 16, typeName, StringHelper::Sprintf("%s%sList_%06X", prefix.c_str(), typeName.c_str(), segmentOffset), 0, declaration); } @@ -53,7 +53,8 @@ void SetActorCutsceneList::DeclareReferences(const std::string& prefix) std::string SetActorCutsceneList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "ActorCutscene", listName); return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_LIST(%i, %s)", cutscenes.size(), listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetActorList.cpp b/ZAPD/ZRoom/Commands/SetActorList.cpp index 3239cdc..919d86f 100644 --- a/ZAPD/ZRoom/Commands/SetActorList.cpp +++ b/ZAPD/ZRoom/Commands/SetActorList.cpp @@ -80,7 +80,8 @@ void SetActorList::DeclareReferencesLate(const std::string& prefix) std::string SetActorList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "ActorEntry", listName); if (numActors != actors.size()) { printf("%s: numActors(%i) ~ actors(%li)\n", parent->GetName().c_str(), numActors, diff --git a/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp b/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp index 2f16eac..016df12 100644 --- a/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp +++ b/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp @@ -1,5 +1,6 @@ #include "SetAlternateHeaders.h" +#include "Globals.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" #include "ZFile.h" @@ -10,8 +11,12 @@ SetAlternateHeaders::SetAlternateHeaders(ZFile* nParent) : ZRoomCommand(nParent) void SetAlternateHeaders::DeclareReferences([[maybe_unused]] const std::string& prefix) { - if (segmentOffset != 0) - parent->AddDeclarationPlaceholder(segmentOffset); + if (cmdArg2 != 0) + { + std::string varName = + StringHelper::Sprintf("%sAlternateHeaders0x%06X", prefix.c_str(), segmentOffset); + parent->AddDeclarationPlaceholder(segmentOffset, varName); + } } void SetAlternateHeaders::ParseRawDataLate() @@ -42,23 +47,26 @@ void SetAlternateHeaders::DeclareReferencesLate(const std::string& prefix) for (size_t i = 0; i < headers.size(); i++) { - declaration += StringHelper::Sprintf( - "\t%s,", parent->GetDeclarationPtrName(headers.at(i)).c_str()); + std::string altHeaderName; + Globals::Instance->GetSegmentedPtrName(headers.at(i), parent, "", altHeaderName); + + declaration += StringHelper::Sprintf("\t%s,", altHeaderName.c_str()); if (i + 1 < headers.size()) declaration += "\n"; } - parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::Align4, headers.size() * 4, "SceneCmd*", - StringHelper::Sprintf("%sAltHeader_%06X", prefix.c_str(), segmentOffset), 0, - declaration); + std::string varName = + StringHelper::Sprintf("%sAlternateHeaders0x%06X", prefix.c_str(), segmentOffset); + parent->AddDeclarationArray(segmentOffset, GetDeclarationAlignment(), headers.size() * 4, + "SceneCmd*", varName, 0, declaration); } } std::string SetAlternateHeaders::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "SceneCmd*", listName); return StringHelper::Sprintf("SCENE_CMD_ALTERNATE_HEADER_LIST(%s)", listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp b/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp index 4d588c0..0b9a67e 100644 --- a/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp +++ b/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp @@ -32,7 +32,8 @@ void SetAnimatedMaterialList::DeclareReferences(const std::string& prefix) std::string SetAnimatedMaterialList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "AnimatedMaterial", listName); return StringHelper::Sprintf("SCENE_CMD_ANIMATED_MATERIAL_LIST(%s)", listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.h b/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.h index 0f6cff3..3dbbf96 100644 --- a/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.h +++ b/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.h @@ -1,7 +1,5 @@ #pragma once -#include <memory> - #include "ZRoom/ZRoomCommand.h" #include "ZTextureAnimation.h" diff --git a/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp b/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp index 96196a5..03aaa4b 100644 --- a/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp +++ b/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp @@ -1,5 +1,6 @@ #include "SetCollisionHeader.h" +#include "Globals.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" #include "ZFile.h" @@ -12,20 +13,23 @@ SetCollisionHeader::SetCollisionHeader(ZFile* nParent) : ZRoomCommand(nParent) void SetCollisionHeader::ParseRawData() { ZRoomCommand::ParseRawData(); + collisionHeader = new ZCollisionHeader(parent); collisionHeader->SetName( StringHelper::Sprintf("%sCollisionHeader_%06X", parent->GetName().c_str(), segmentOffset)); collisionHeader->ExtractFromFile(segmentOffset); + parent->AddResource(collisionHeader); } -SetCollisionHeader::~SetCollisionHeader() +void SetCollisionHeader::DeclareReferences(const std::string& prefix) { - delete collisionHeader; + collisionHeader->DeclareVar(prefix, ""); } std::string SetCollisionHeader::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CollisionHeader", listName); return StringHelper::Sprintf("SCENE_CMD_COL_HEADER(%s)", listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetCollisionHeader.h b/ZAPD/ZRoom/Commands/SetCollisionHeader.h index b0a599f..f7d5ecf 100644 --- a/ZAPD/ZRoom/Commands/SetCollisionHeader.h +++ b/ZAPD/ZRoom/Commands/SetCollisionHeader.h @@ -9,9 +9,9 @@ public: ZCollisionHeader* collisionHeader; SetCollisionHeader(ZFile* nParent); - ~SetCollisionHeader(); void ParseRawData() override; + void DeclareReferences(const std::string& prefix) override; std::string GetBodySourceCode() const override; diff --git a/ZAPD/ZRoom/Commands/SetCsCamera.cpp b/ZAPD/ZRoom/Commands/SetCsCamera.cpp index 31bb6cf..5cf0a3d 100644 --- a/ZAPD/ZRoom/Commands/SetCsCamera.cpp +++ b/ZAPD/ZRoom/Commands/SetCsCamera.cpp @@ -1,5 +1,6 @@ #include "SetCsCamera.h" +#include "Globals.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" #include "ZFile.h" @@ -39,9 +40,6 @@ void SetCsCamera::ParseRawData() points.push_back(vec); } } - - if (segmentOffset != 0) - parent->AddDeclarationPlaceholder(segmentOffset); } void SetCsCamera::DeclareReferences(const std::string& prefix) @@ -52,9 +50,7 @@ void SetCsCamera::DeclareReferences(const std::string& prefix) size_t index = 0; for (auto& point : points) { - declaration += - StringHelper::Sprintf("\t%s, //0x%06X", point.GetBodySourceCode().c_str(), - cameras.at(0).segmentOffset + (index * 6)); + declaration += StringHelper::Sprintf("\t{ %s },", point.GetBodySourceCode().c_str()); if (index < points.size() - 1) declaration += "\n"; @@ -73,7 +69,9 @@ void SetCsCamera::DeclareReferences(const std::string& prefix) if (!cameras.empty()) { - std::string camPointsName = parent->GetDeclarationName(cameras.at(0).GetSegmentOffset()); + std::string camPointsName; + Globals::Instance->GetSegmentedPtrName(cameras.at(0).GetCamAddress(), parent, "Vec3s", + camPointsName); std::string declaration; size_t index = 0; @@ -104,7 +102,8 @@ void SetCsCamera::DeclareReferences(const std::string& prefix) std::string SetCsCamera::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CsCameraEntry", listName); return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_CAM_LIST(%i, %s)", cameras.size(), listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetCutscenes.cpp b/ZAPD/ZRoom/Commands/SetCutscenes.cpp index 785a938..e51e550 100644 --- a/ZAPD/ZRoom/Commands/SetCutscenes.cpp +++ b/ZAPD/ZRoom/Commands/SetCutscenes.cpp @@ -85,7 +85,8 @@ void SetCutscenes::ParseRawData() std::string SetCutscenes::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneData", listName); if (Globals::Instance->game == ZGame::MM_RETAIL) return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_LIST(%i, %s)", numCutscenes, diff --git a/ZAPD/ZRoom/Commands/SetEntranceList.cpp b/ZAPD/ZRoom/Commands/SetEntranceList.cpp index 468dc50..8099bac 100644 --- a/ZAPD/ZRoom/Commands/SetEntranceList.cpp +++ b/ZAPD/ZRoom/Commands/SetEntranceList.cpp @@ -1,5 +1,6 @@ #include "SetEntranceList.h" +#include "Globals.h" #include "SetStartPositionList.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" @@ -13,7 +14,11 @@ SetEntranceList::SetEntranceList(ZFile* nParent) : ZRoomCommand(nParent) void SetEntranceList::DeclareReferences([[maybe_unused]] const std::string& prefix) { if (segmentOffset != 0) - parent->AddDeclarationPlaceholder(segmentOffset); + { + std::string varName = + StringHelper::Sprintf("%sEntranceList0x%06X", prefix.c_str(), segmentOffset); + parent->AddDeclarationPlaceholder(segmentOffset, varName); + } } void SetEntranceList::ParseRawDataLate() @@ -40,25 +45,25 @@ void SetEntranceList::DeclareReferencesLate([[maybe_unused]] const std::string& size_t index = 0; for (const auto& entry : entrances) { - declaration += - StringHelper::Sprintf(" { %s }, //0x%06X", entry.GetBodySourceCode().c_str(), - segmentOffset + (index * 2)); + declaration += StringHelper::Sprintf(" { %s },", entry.GetBodySourceCode().c_str()); if (index + 1 < entrances.size()) declaration += "\n"; index++; } - parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::Align4, entrances.size() * 2, "EntranceEntry", - StringHelper::Sprintf("%sEntranceList0x%06X", prefix.c_str(), segmentOffset), - entrances.size(), declaration); + std::string varName = + StringHelper::Sprintf("%sEntranceList0x%06X", prefix.c_str(), segmentOffset); + parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, + entrances.size() * 2, "EntranceEntry", varName, + entrances.size(), declaration); } } std::string SetEntranceList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "EntranceEntry", listName); return StringHelper::Sprintf("SCENE_CMD_ENTRANCE_LIST(%s)", listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetExitList.cpp b/ZAPD/ZRoom/Commands/SetExitList.cpp index f491eb4..ddc4c5d 100644 --- a/ZAPD/ZRoom/Commands/SetExitList.cpp +++ b/ZAPD/ZRoom/Commands/SetExitList.cpp @@ -1,5 +1,6 @@ #include "SetExitList.h" +#include "Globals.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" #include "ZFile.h" @@ -12,7 +13,11 @@ SetExitList::SetExitList(ZFile* nParent) : ZRoomCommand(nParent) void SetExitList::DeclareReferences([[maybe_unused]] const std::string& prefix) { if (segmentOffset != 0) - parent->AddDeclarationPlaceholder(segmentOffset); + { + std::string varName = + StringHelper::Sprintf("%sExitList_%06X", prefix.c_str(), segmentOffset); + parent->AddDeclarationPlaceholder(segmentOffset, varName); + } } void SetExitList::ParseRawDataLate() @@ -43,16 +48,17 @@ void SetExitList::DeclareReferencesLate([[maybe_unused]] const std::string& pref declaration += "\n"; } - parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::Align4, exits.size() * 2, "u16", - StringHelper::Sprintf("%sExitList_%06X", prefix.c_str(), segmentOffset), exits.size(), - declaration); + std::string varName = + StringHelper::Sprintf("%sExitList_%06X", prefix.c_str(), segmentOffset); + parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, exits.size() * 2, + "u16", varName, exits.size(), declaration); } } std::string SetExitList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "u16", listName); return StringHelper::Sprintf("SCENE_CMD_EXIT_LIST(%s)", listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetLightList.cpp b/ZAPD/ZRoom/Commands/SetLightList.cpp index 8ad08a3..2e023ff 100644 --- a/ZAPD/ZRoom/Commands/SetLightList.cpp +++ b/ZAPD/ZRoom/Commands/SetLightList.cpp @@ -1,4 +1,6 @@ #include "SetLightList.h" + +#include "Globals.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" @@ -49,7 +51,8 @@ void SetLightList::DeclareReferences(const std::string& prefix) std::string SetLightList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "LightInfo", listName); return StringHelper::Sprintf("SCENE_CMD_LIGHT_LIST(%i, %s)", numLights, listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetLightingSettings.cpp b/ZAPD/ZRoom/Commands/SetLightingSettings.cpp index 9c32bc2..08cd83d 100644 --- a/ZAPD/ZRoom/Commands/SetLightingSettings.cpp +++ b/ZAPD/ZRoom/Commands/SetLightingSettings.cpp @@ -1,4 +1,6 @@ #include "SetLightingSettings.h" + +#include "Globals.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" #include "ZFile.h" @@ -25,9 +27,8 @@ void SetLightingSettings::DeclareReferences(const std::string& prefix) for (size_t i = 0; i < settings.size(); i++) { - declaration += StringHelper::Sprintf("\t{ %s }, // 0x%06X", - settings.at(i).GetBodySourceCode().c_str(), - segmentOffset + (i * 22)); + declaration += + StringHelper::Sprintf("\t{ %s },", settings.at(i).GetBodySourceCode().c_str()); if (i + 1 < settings.size()) declaration += "\n"; } @@ -42,7 +43,8 @@ void SetLightingSettings::DeclareReferences(const std::string& prefix) std::string SetLightingSettings::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "LightSettings", listName); return StringHelper::Sprintf("SCENE_CMD_ENV_LIGHT_SETTINGS(%i, %s)", settings.size(), listName.c_str()); } 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; +} diff --git a/ZAPD/ZRoom/Commands/SetMesh.h b/ZAPD/ZRoom/Commands/SetMesh.h index 6559196..566711a 100644 --- a/ZAPD/ZRoom/Commands/SetMesh.h +++ b/ZAPD/ZRoom/Commands/SetMesh.h @@ -5,9 +5,11 @@ #include "ZDisplayList.h" #include "ZRoom/ZRoomCommand.h" -class PolygonDlist +class PolygonDlist : public ZResource { public: + ZRoom* zRoom; + uint8_t polyType; int16_t x, y, z; // polyType == 2 @@ -19,35 +21,27 @@ public: ZDisplayList* opaDList = nullptr; // Gfx* ZDisplayList* xluDList = nullptr; // Gfx* - PolygonDlist() = default; - PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData, - uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom); + PolygonDlist(ZFile* nParent); - void ParseRawData(); - void DeclareReferences(const std::string& prefix); + void ParseRawData() override; + void DeclareReferences(const std::string& prefix) override; - size_t GetRawDataSize() const; - void SetPolyType(uint8_t nPolyType); + std::string GetBodySourceCode() const override; + + std::string GetSourceOutputCode(const std::string& prefix) override; - void DeclareVar(const std::string& prefix, const std::string& bodyStr); + std::string GetSourceTypeName() const override; + ZResourceType GetResourceType() const override; - std::string GetBodySourceCode(bool arrayElement); - void DeclareAndGenerateOutputCode(); + size_t GetRawDataSize() const override; - static std::string GetDefaultName(const std::string& prefix, uint32_t address); - std::string GetSourceTypeName(); - std::string GetName(); + void SetPolyType(uint8_t nPolyType); protected: - uint32_t rawDataIndex; - ZFile* parent; - ZRoom* zRoom; - std::string name; - ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix); }; -class BgImage +class BgImage : public ZResource { public: uint16_t unk_00; @@ -64,59 +58,39 @@ public: ZBackground* sourceBackground; - uint32_t rawDataIndex; - ZFile* parent; - std::string name; bool isSubStruct; -protected: - void ParseRawData(); - ZBackground* MakeBackground(segptr_t ptr, const std::string& prefix); + BgImage(ZFile* nParent); + BgImage(bool nIsSubStruct, const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent); -public: - BgImage() = default; - BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData, - uint32_t nRawDataIndex, ZFile* nParent); + void ParseRawData() override; - static size_t GetRawDataSize(); + std::string GetBodySourceCode() const override; - std::string GetBodySourceCode(bool arrayElement) const; + std::string GetSourceTypeName() const override; + ZResourceType GetResourceType() const override; - static std::string GetDefaultName(const std::string& prefix, uint32_t address); - static std::string GetSourceTypeName(); - std::string GetName(); + size_t GetRawDataSize() const override; + +protected: + ZBackground* MakeBackground(segptr_t ptr, const std::string& prefix); }; -class PolygonTypeBase +class PolygonTypeBase : public ZResource { public: uint8_t type; std::vector<PolygonDlist> polyDLists; - PolygonTypeBase(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, - ZRoom* nRoom); - virtual ~PolygonTypeBase() = default; - - virtual void ParseRawData() = 0; - virtual void DeclareReferences(const std::string& prefix) = 0; + PolygonTypeBase(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom); - virtual std::string GetBodySourceCode() const = 0; - void DeclareVar(const std::string& prefix, const std::string& bodyStr); void DeclareAndGenerateOutputCode(const std::string& prefix); - virtual std::string GetSourceTypeName() const; - - std::string GetName() const; - void SetName(const std::string& newName); - virtual size_t GetRawDataSize() const = 0; - - std::string GetDefaultName(const std::string& prefix) const; + std::string GetSourceTypeName() const override; + ZResourceType GetResourceType() const override; protected: - uint32_t rawDataIndex; - ZFile* parent; ZRoom* zRoom; - std::string name; }; class PolygonType1 : public PolygonTypeBase @@ -133,8 +107,7 @@ public: segptr_t list; // BgImage* std::vector<BgImage> multiList; - PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, - ZRoom* nRoom); + PolygonType1(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom); void ParseRawData() override; void DeclareReferences(const std::string& prefix) override; @@ -153,8 +126,7 @@ public: segptr_t start; segptr_t end; - PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, - ZRoom* nRoom); + PolygonType2(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom); void ParseRawData() override; void DeclareReferences(const std::string& prefix) override; @@ -162,8 +134,7 @@ public: std::string GetBodySourceCode() const override; size_t GetRawDataSize() const override; - -protected: + DeclarationAlignment GetDeclarationAlignment() const override; }; class SetMesh : public ZRoomCommand diff --git a/ZAPD/ZRoom/Commands/SetMinimapChests.cpp b/ZAPD/ZRoom/Commands/SetMinimapChests.cpp index 20a33ac..ec432b7 100644 --- a/ZAPD/ZRoom/Commands/SetMinimapChests.cpp +++ b/ZAPD/ZRoom/Commands/SetMinimapChests.cpp @@ -49,7 +49,8 @@ void SetMinimapChests::DeclareReferences(const std::string& prefix) std::string SetMinimapChests::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "MinimapChest", listName); return StringHelper::Sprintf("SCENE_CMD_MINIMAP_COMPASS_ICON_INFO(0x%02X, %s)", chests.size(), listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetMinimapList.cpp b/ZAPD/ZRoom/Commands/SetMinimapList.cpp index 8c9917a..be5d8f1 100644 --- a/ZAPD/ZRoom/Commands/SetMinimapList.cpp +++ b/ZAPD/ZRoom/Commands/SetMinimapList.cpp @@ -51,7 +51,8 @@ void SetMinimapList::DeclareReferences(const std::string& prefix) } { - std::string listName = parent->GetDeclarationPtrName(listSegmentAddr); + std::string listName; + Globals::Instance->GetSegmentedPtrName(listSegmentAddr, parent, "MinimapEntry", listName); std::string declaration = StringHelper::Sprintf("\n\t%s, 0x%08X\n", listName.c_str(), unk4); parent->AddDeclaration( @@ -63,7 +64,8 @@ void SetMinimapList::DeclareReferences(const std::string& prefix) std::string SetMinimapList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "MinimapList", listName); return StringHelper::Sprintf("SCENE_CMD_MINIMAP_INFO(%s)", listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetObjectList.cpp b/ZAPD/ZRoom/Commands/SetObjectList.cpp index 35c0d44..fdd41e6 100644 --- a/ZAPD/ZRoom/Commands/SetObjectList.cpp +++ b/ZAPD/ZRoom/Commands/SetObjectList.cpp @@ -23,9 +23,6 @@ void SetObjectList::ParseRawData() objects.push_back(objectIndex); currentPtr += 2; } - - if (segmentOffset != 0) - parent->AddDeclarationPlaceholder(segmentOffset); } void SetObjectList::DeclareReferences(const std::string& prefix) @@ -53,7 +50,8 @@ void SetObjectList::DeclareReferences(const std::string& prefix) std::string SetObjectList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "s16", listName); return StringHelper::Sprintf("SCENE_CMD_OBJECT_LIST(%i, %s)", objects.size(), listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetPathways.cpp b/ZAPD/ZRoom/Commands/SetPathways.cpp index 1649685..52d400a 100644 --- a/ZAPD/ZRoom/Commands/SetPathways.cpp +++ b/ZAPD/ZRoom/Commands/SetPathways.cpp @@ -13,7 +13,11 @@ SetPathways::SetPathways(ZFile* nParent) : ZRoomCommand(nParent), pathwayList(nP void SetPathways::DeclareReferences([[maybe_unused]] const std::string& prefix) { if (segmentOffset != 0) - parent->AddDeclarationPlaceholder(segmentOffset); + { + std::string varName = + StringHelper::Sprintf("%sPathway_%06X", prefix.c_str(), segmentOffset); + parent->AddDeclarationPlaceholder(segmentOffset, varName); + } } void SetPathways::ParseRawDataLate() @@ -29,14 +33,16 @@ void SetPathways::ParseRawDataLate() void SetPathways::DeclareReferencesLate(const std::string& prefix) { - pathwayList.SetName(StringHelper::Sprintf("%sPathway_%06X", prefix.c_str(), segmentOffset)); + std::string varName = StringHelper::Sprintf("%sPathway_%06X", prefix.c_str(), segmentOffset); + pathwayList.SetName(varName); pathwayList.DeclareReferences(prefix); pathwayList.GetSourceOutputCode(prefix); } std::string SetPathways::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "Path", listName); return StringHelper::Sprintf("SCENE_CMD_PATH_LIST(%s)", listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetRoomList.cpp b/ZAPD/ZRoom/Commands/SetRoomList.cpp index 507d0ab..e038139 100644 --- a/ZAPD/ZRoom/Commands/SetRoomList.cpp +++ b/ZAPD/ZRoom/Commands/SetRoomList.cpp @@ -33,8 +33,9 @@ void SetRoomList::DeclareReferences(const std::string& prefix) std::string SetRoomList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); - return StringHelper::Sprintf("SCENE_CMD_ROOM_LIST(%i, %s)", romfile->numRooms, + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "RomFile", listName); + return StringHelper::Sprintf("SCENE_CMD_ROOM_LIST(%i, %s)", romfile->rooms.size(), listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetRoomList.h b/ZAPD/ZRoom/Commands/SetRoomList.h index d4edc80..4fb2ced 100644 --- a/ZAPD/ZRoom/Commands/SetRoomList.h +++ b/ZAPD/ZRoom/Commands/SetRoomList.h @@ -38,7 +38,6 @@ public: class SetRoomList : public ZRoomCommand { public: - std::vector<RoomEntry> rooms; // Borrowed reference. Don't delete. RomFile* romfile = nullptr; diff --git a/ZAPD/ZRoom/Commands/SetStartPositionList.cpp b/ZAPD/ZRoom/Commands/SetStartPositionList.cpp index 69434a4..ad1d0a9 100644 --- a/ZAPD/ZRoom/Commands/SetStartPositionList.cpp +++ b/ZAPD/ZRoom/Commands/SetStartPositionList.cpp @@ -50,7 +50,8 @@ void SetStartPositionList::DeclareReferences(const std::string& prefix) std::string SetStartPositionList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "ActorEntry", listName); return StringHelper::Sprintf("SCENE_CMD_SPAWN_LIST(%i, %s)", actors.size(), listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp b/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp index 2eba064..d47ca34 100644 --- a/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp +++ b/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp @@ -51,7 +51,8 @@ void SetTransitionActorList::DeclareReferences(const std::string& prefix) std::string SetTransitionActorList::GetBodySourceCode() const { - std::string listName = parent->GetDeclarationPtrName(cmdArg2); + std::string listName; + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "TransitionActorEntry", listName); return StringHelper::Sprintf("SCENE_CMD_TRANSITION_ACTOR_LIST(%i, %s)", transitionActors.size(), listName.c_str()); } diff --git a/ZAPD/ZRoom/ZRoom.cpp b/ZAPD/ZRoom/ZRoom.cpp index af9122f..9f4d5a9 100644 --- a/ZAPD/ZRoom/ZRoom.cpp +++ b/ZAPD/ZRoom/ZRoom.cpp @@ -112,7 +112,6 @@ void ZRoom::ParseXML(tinyxml2::XMLElement* reader) std::string nodeName = std::string(reader->Name()); if (nodeName == "Scene") { - Globals::Instance->lastScene = this; zroomType = ZResourceType::Scene; } else if (nodeName == "Room") @@ -335,11 +334,11 @@ std::string ZRoom::GetDefaultName(const std::string& prefix) const */ void ZRoom::SyotesRoomHack() { - PolygonType2 poly(parent, parent->GetRawData(), 0, this); + PolygonType2 poly(parent, 0, this); poly.ParseRawData(); poly.DeclareReferences(GetName()); - parent->AddDeclaration(0, DeclarationAlignment::Align4, poly.GetRawDataSize(), + parent->AddDeclaration(0, poly.GetDeclarationAlignment(), poly.GetRawDataSize(), poly.GetSourceTypeName(), poly.GetDefaultName(GetName()), poly.GetBodySourceCode()); } @@ -393,32 +392,14 @@ size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd) return 0; } -std::string ZRoom::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix) -{ - return "\n" + extDefines + "\n\n"; -} - std::string ZRoom::GetSourceOutputCode([[maybe_unused]] const std::string& prefix) { - std::string sourceOutput; - - if (zroomType == ZResourceType::Scene || zroomType == ZResourceType::Room) - { - sourceOutput += "#include \"segment_symbols.h\"\n"; - sourceOutput += "#include \"command_macros_base.h\"\n"; - sourceOutput += "#include \"z64cutscene_commands.h\"\n"; - sourceOutput += "#include \"variables.h\"\n"; - - if (Globals::Instance->lastScene != nullptr) - sourceOutput += Globals::Instance->lastScene->parent->GetHeaderInclude(); - } - if (hackMode == "syotes_room") - return sourceOutput; + return ""; DeclareVar(prefix, GetBodySourceCode()); - return sourceOutput; + return ""; } size_t ZRoom::GetRawDataSize() const diff --git a/ZAPD/ZRoom/ZRoom.h b/ZAPD/ZRoom/ZRoom.h index cc4bc0c..0993a9d 100644 --- a/ZAPD/ZRoom/ZRoom.h +++ b/ZAPD/ZRoom/ZRoom.h @@ -14,8 +14,6 @@ public: std::vector<ZRoomCommand*> commands; int32_t roomCount; // Only valid for scenes - std::string extDefines; - std::string hackMode; ZResourceType zroomType = ZResourceType::Error; @@ -36,6 +34,8 @@ public: Declaration* DeclareVar(const std::string& prefix, const std::string& body) override; std::string GetBodySourceCode() const override; + std::string GetSourceOutputCode(const std::string& prefix) override; + std::string GetDefaultName(const std::string& prefix) const override; size_t GetDeclarationSizeFromNeighbor(uint32_t declarationAddress); size_t GetCommandSizeFromNeighbor(ZRoomCommand* cmd); @@ -46,7 +46,5 @@ public: ZResourceType GetResourceType() const override; protected: - std::string GetSourceOutputHeader(const std::string& prefix) override; - std::string GetSourceOutputCode(const std::string& prefix) override; void SyotesRoomHack(); }; |
