diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-06-04 12:52:38 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-04 12:52:38 -0400 |
| commit | 726ff528a3ab66afde92b5b6e70a96f168fee041 (patch) | |
| tree | ba3ff371bc2fd89a448ea6914b45dea10c8ca20c /ZAPD/ZRoom | |
| parent | ca229f19b991c613c29afade3d70b100522cece1 (diff) | |
Optimize RAM usage and performance by removing redundant `rawData` (#148)
* Remove rawData from ZResource
* Remove dlistRawData and some leftovers extra params
* Run format
* Unused variable warning
Diffstat (limited to 'ZAPD/ZRoom')
| -rw-r--r-- | ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp | 15 | ||||
| -rw-r--r-- | ZAPD/ZRoom/Commands/SetCollisionHeader.cpp | 1 | ||||
| -rw-r--r-- | ZAPD/ZRoom/Commands/SetCsCamera.cpp | 1 | ||||
| -rw-r--r-- | ZAPD/ZRoom/Commands/SetCutscenes.cpp | 4 | ||||
| -rw-r--r-- | ZAPD/ZRoom/Commands/SetMesh.cpp | 24 | ||||
| -rw-r--r-- | ZAPD/ZRoom/Commands/SetMesh.h | 3 | ||||
| -rw-r--r-- | ZAPD/ZRoom/ZRoom.cpp | 16 | ||||
| -rw-r--r-- | ZAPD/ZRoom/ZRoom.h | 3 |
8 files changed, 33 insertions, 34 deletions
diff --git a/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp b/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp index de0d05b..6bf8c8a 100644 --- a/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp +++ b/ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp @@ -255,12 +255,12 @@ std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddre index++; } - zRoom->parent->AddDeclarationArray( - primColorSegmentOffset, DeclarationAlignment::Align4, primColors.size() * 5, - "F3DPrimColor", - StringHelper::Sprintf("%sAnimatedMaterialPrimColor_%06X", zRoom->GetName().c_str(), - primColorSegmentOffset), - primColors.size(), declaration); + zRoom->parent->AddDeclarationArray(primColorSegmentOffset, DeclarationAlignment::Align4, + primColors.size() * 5, "F3DPrimColor", + StringHelper::Sprintf("%sAnimatedMaterialPrimColor_%06X", + zRoom->GetName().c_str(), + primColorSegmentOffset), + primColors.size(), declaration); } if (envColorSegmentOffset != 0) @@ -400,7 +400,8 @@ std::string AnimatedMatTexCycleParams::GenerateSourceCode(ZRoom* zRoom, uint32_t textureIndices.size(), declaration); } - std::string segmName = zRoom->parent->GetDeclarationPtrName(textureSegmentOffsetsSegmentAddress); + std::string segmName = + zRoom->parent->GetDeclarationPtrName(textureSegmentOffsetsSegmentAddress); std::string indexesName = zRoom->parent->GetDeclarationPtrName(textureIndicesSegmentAddress); return StringHelper::Sprintf("%i, %s, %s", cycleLength, segmName.c_str(), indexesName.c_str()); diff --git a/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp b/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp index 1eb13f6..569a7c0 100644 --- a/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp +++ b/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp @@ -13,7 +13,6 @@ void SetCollisionHeader::ParseRawData() { ZRoomCommand::ParseRawData(); collisionHeader = new ZCollisionHeader(parent); - collisionHeader->SetRawData(parent->GetRawData()); collisionHeader->SetRawDataIndex(segmentOffset); collisionHeader->SetName( StringHelper::Sprintf("%sCollisionHeader_%06X", parent->GetName().c_str(), segmentOffset)); diff --git a/ZAPD/ZRoom/Commands/SetCsCamera.cpp b/ZAPD/ZRoom/Commands/SetCsCamera.cpp index 02e2e61..0402d93 100644 --- a/ZAPD/ZRoom/Commands/SetCsCamera.cpp +++ b/ZAPD/ZRoom/Commands/SetCsCamera.cpp @@ -33,7 +33,6 @@ void SetCsCamera::ParseRawData() for (int32_t i = 0; i < numPoints; i++) { ZVector vec(parent); - vec.SetRawData(parent->GetRawData()); vec.SetRawDataIndex(currentPtr); vec.SetScalarType(ZScalarType::ZSCALAR_S16); vec.SetDimensions(3); diff --git a/ZAPD/ZRoom/Commands/SetCutscenes.cpp b/ZAPD/ZRoom/Commands/SetCutscenes.cpp index 8007ac0..d9ecb79 100644 --- a/ZAPD/ZRoom/Commands/SetCutscenes.cpp +++ b/ZAPD/ZRoom/Commands/SetCutscenes.cpp @@ -19,7 +19,7 @@ void SetCutscenes::ParseRawData() if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97) { ZCutscene* cutscene = new ZCutscene(parent); - cutscene->ExtractFromFile(parent->GetRawData(), segmentOffset); + cutscene->ExtractFromFile(segmentOffset); auto decl = parent->GetDeclaration(segmentOffset); if (decl == nullptr) @@ -48,7 +48,7 @@ void SetCutscenes::ParseRawData() declaration += "\n"; ZCutsceneMM* cutscene = new ZCutsceneMM(parent); - cutscene->ExtractFromFile(parent->GetRawData(), entry.segmentOffset); + cutscene->ExtractFromFile(entry.segmentOffset); cutscenes.push_back(cutscene); } diff --git a/ZAPD/ZRoom/Commands/SetMesh.cpp b/ZAPD/ZRoom/Commands/SetMesh.cpp index 2635e7f..f2a9676 100644 --- a/ZAPD/ZRoom/Commands/SetMesh.cpp +++ b/ZAPD/ZRoom/Commands/SetMesh.cpp @@ -116,7 +116,6 @@ RoomCommand SetMesh::GetRoomCommand() const PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom) { - rawData.assign(nRawData.begin(), nRawData.end()); rawDataIndex = nRawDataIndex; parent = nParent; zRoom = nRoom; @@ -126,6 +125,7 @@ PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector<uint8_t> void PolygonDlist::ParseRawData() { + const auto& rawData = parent->GetRawData(); switch (polyType) { case 2: @@ -161,9 +161,9 @@ ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, const std::string& prefix) uint32_t dlistAddress = Seg2Filespace(ptr, parent->baseAddress); int32_t dlistLength = ZDisplayList::GetDListLength( - rawData, dlistAddress, + parent->GetRawData(), dlistAddress, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); - ZDisplayList* dlist = new ZDisplayList(rawData, dlistAddress, dlistLength, parent); + ZDisplayList* dlist = new ZDisplayList(dlistAddress, dlistLength, parent); GenDListDeclarations(zRoom, parent, dlist); return dlist; @@ -271,7 +271,6 @@ std::string PolygonDlist::GetName() BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, ZFile* nParent) { - rawData.assign(nRawData.begin(), nRawData.end()); rawDataIndex = nRawDataIndex; parent = nParent; isSubStruct = nIsSubStruct; @@ -285,6 +284,7 @@ BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector void BgImage::ParseRawData() { size_t pad = 0x00; + const auto& rawData = parent->GetRawData(); if (!isSubStruct) { pad = 0x04; @@ -312,7 +312,7 @@ ZBackground* BgImage::MakeBackground(segptr_t ptr, const std::string& prefix) uint32_t backAddress = Seg2Filespace(ptr, parent->baseAddress); - ZBackground* background = new ZBackground(prefix, rawData, backAddress, parent); + ZBackground* background = new ZBackground(prefix, backAddress, parent); background->DeclareVar(prefix, ""); parent->resources.push_back(background); @@ -408,9 +408,9 @@ std::string BgImage::GetName() PolygonTypeBase::PolygonTypeBase(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, ZRoom* nRoom) - : rawData{nRawData}, rawDataIndex{nRawDataIndex}, parent{nParent}, zRoom{nRoom} + : rawDataIndex{nRawDataIndex}, parent{nParent}, zRoom{nRoom} { - type = BitConverter::ToUInt8BE(rawData, rawDataIndex); + type = BitConverter::ToUInt8BE(parent->GetRawData(), rawDataIndex); } void PolygonTypeBase::DeclareVar(const std::string& prefix, const std::string& bodyStr) @@ -477,6 +477,8 @@ PolygonType1::PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData, void PolygonType1::ParseRawData() { + const auto& rawData = parent->GetRawData(); + format = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01); dlist = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04); @@ -506,7 +508,7 @@ void PolygonType1::DeclareReferences(const std::string& prefix) switch (format) { case 1: - single = BgImage(true, prefix, rawData, rawDataIndex + 0x08, parent); + single = BgImage(true, prefix, parent->GetRawData(), rawDataIndex + 0x08, parent); break; case 2: @@ -515,8 +517,8 @@ void PolygonType1::DeclareReferences(const std::string& prefix) listAddress = Seg2Filespace(list, parent->baseAddress); for (size_t i = 0; i < count; ++i) { - BgImage bg(false, prefix, rawData, listAddress + i * BgImage::GetRawDataSize(), - parent); + BgImage bg(false, prefix, parent->GetRawData(), + listAddress + i * BgImage::GetRawDataSize(), parent); multiList.push_back(bg); bgImageArrayBody += bg.GetBodySourceCode(true); if (i + 1 < count) @@ -609,6 +611,8 @@ PolygonType2::PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData, void PolygonType2::ParseRawData() { + const auto& rawData = parent->GetRawData(); + num = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01); start = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04); diff --git a/ZAPD/ZRoom/Commands/SetMesh.h b/ZAPD/ZRoom/Commands/SetMesh.h index fb99dbd..20ec9c3 100644 --- a/ZAPD/ZRoom/Commands/SetMesh.h +++ b/ZAPD/ZRoom/Commands/SetMesh.h @@ -39,7 +39,6 @@ protected: ZDisplayList* opaDList = nullptr; // Gfx* ZDisplayList* xluDList = nullptr; // Gfx* - std::vector<uint8_t> rawData; uint32_t rawDataIndex; ZFile* parent; ZRoom* zRoom; @@ -65,7 +64,6 @@ protected: ZBackground* sourceBackground; - std::vector<uint8_t> rawData; uint32_t rawDataIndex; ZFile* parent; std::string name; @@ -114,7 +112,6 @@ protected: std::vector<PolygonDlist> polyDLists; - std::vector<uint8_t> rawData; uint32_t rawDataIndex; ZFile* parent; ZRoom* zRoom; diff --git a/ZAPD/ZRoom/ZRoom.cpp b/ZAPD/ZRoom/ZRoom.cpp index 936b014..e4cb0e8 100644 --- a/ZAPD/ZRoom/ZRoom.cpp +++ b/ZAPD/ZRoom/ZRoom.cpp @@ -60,10 +60,9 @@ ZRoom::~ZRoom() delete cmd; } -void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, - const uint32_t nRawDataIndex) +void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) { - ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex); + ZResource::ExtractFromXML(reader, nRawDataIndex); scene = Globals::Instance->lastScene; @@ -97,8 +96,8 @@ void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8 int32_t address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); ZDisplayList* dList = new ZDisplayList( - rawData, address, - ZDisplayList::GetDListLength(rawData, address, + address, + ZDisplayList::GetDListLength(parent->GetRawData(), address, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX), @@ -115,7 +114,7 @@ void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8 ZCutscene* cutscene = new ZCutscene(parent); cutscene->SetInnerNode(true); - cutscene->ExtractFromXML(child, rawData, address); + cutscene->ExtractFromXML(child, address); cutscene->GetSourceOutputCode(name); @@ -174,6 +173,7 @@ void ZRoom::ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet co uint32_t commandsLeft = commandSet.commandCount; + const auto& rawData = parent->GetRawData(); while (shouldContinue) { if (commandsLeft <= 0) @@ -392,7 +392,7 @@ size_t ZRoom::GetDeclarationSizeFromNeighbor(uint32_t declarationAddress) auto nextDecl = currentDecl; std::advance(nextDecl, 1); if (nextDecl == parent->declarations.end()) - return rawData.size() - currentDecl->first; + return parent->GetRawData().size() - currentDecl->first; return nextDecl->first - currentDecl->first; } @@ -415,7 +415,7 @@ size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd) if (cmdIndex + 1 < (int32_t)commands.size()) return commands[cmdIndex + 1]->cmdAddress - commands[cmdIndex]->cmdAddress; else - return rawData.size() - commands[cmdIndex]->cmdAddress; + return parent->GetRawData().size() - commands[cmdIndex]->cmdAddress; } return 0; diff --git a/ZAPD/ZRoom/ZRoom.h b/ZAPD/ZRoom/ZRoom.h index 43f12ed..518ca82 100644 --- a/ZAPD/ZRoom/ZRoom.h +++ b/ZAPD/ZRoom/ZRoom.h @@ -36,8 +36,7 @@ public: ZRoom(ZFile* nParent); virtual ~ZRoom(); - void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, - uint32_t nRawDataIndex) override; + void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override; void ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet commandSet); size_t GetDeclarationSizeFromNeighbor(uint32_t declarationAddress); |
