summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-06-04 12:52:38 -0400
committerGitHub <noreply@github.com>2021-06-04 12:52:38 -0400
commit726ff528a3ab66afde92b5b6e70a96f168fee041 (patch)
treeba3ff371bc2fd89a448ea6914b45dea10c8ca20c
parentca229f19b991c613c29afade3d70b100522cece1 (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
-rw-r--r--ZAPD/StringHelper.h12
-rw-r--r--ZAPD/ZAnimation.cpp15
-rw-r--r--ZAPD/ZAnimation.h3
-rw-r--r--ZAPD/ZArray.cpp2
-rw-r--r--ZAPD/ZBackground.cpp10
-rw-r--r--ZAPD/ZBackground.h7
-rw-r--r--ZAPD/ZBlob.cpp3
-rw-r--r--ZAPD/ZCollision.cpp33
-rw-r--r--ZAPD/ZCutscene.cpp9
-rw-r--r--ZAPD/ZCutscene.h3
-rw-r--r--ZAPD/ZCutsceneMM.cpp6
-rw-r--r--ZAPD/ZCutsceneMM.h3
-rw-r--r--ZAPD/ZDisplayList.cpp91
-rw-r--r--ZAPD/ZDisplayList.h20
-rw-r--r--ZAPD/ZFile.cpp2
-rw-r--r--ZAPD/ZLimb.cpp20
-rw-r--r--ZAPD/ZLimb.h7
-rw-r--r--ZAPD/ZMtx.cpp12
-rw-r--r--ZAPD/ZMtx.h6
-rw-r--r--ZAPD/ZPath.cpp6
-rw-r--r--ZAPD/ZPath.h3
-rw-r--r--ZAPD/ZResource.cpp17
-rw-r--r--ZAPD/ZResource.h8
-rw-r--r--ZAPD/ZRoom/Commands/SetAnimatedMaterialList.cpp15
-rw-r--r--ZAPD/ZRoom/Commands/SetCollisionHeader.cpp1
-rw-r--r--ZAPD/ZRoom/Commands/SetCsCamera.cpp1
-rw-r--r--ZAPD/ZRoom/Commands/SetCutscenes.cpp4
-rw-r--r--ZAPD/ZRoom/Commands/SetMesh.cpp24
-rw-r--r--ZAPD/ZRoom/Commands/SetMesh.h3
-rw-r--r--ZAPD/ZRoom/ZRoom.cpp16
-rw-r--r--ZAPD/ZRoom/ZRoom.h3
-rw-r--r--ZAPD/ZScalar.cpp1
-rw-r--r--ZAPD/ZSkeleton.cpp17
-rw-r--r--ZAPD/ZSkeleton.h5
-rw-r--r--ZAPD/ZString.cpp5
-rw-r--r--ZAPD/ZSymbol.cpp6
-rw-r--r--ZAPD/ZSymbol.h3
-rw-r--r--ZAPD/ZTexture.cpp29
-rw-r--r--ZAPD/ZTexture.h7
-rw-r--r--ZAPD/ZVector.cpp1
-rw-r--r--ZAPD/ZVtx.cpp3
41 files changed, 204 insertions, 238 deletions
diff --git a/ZAPD/StringHelper.h b/ZAPD/StringHelper.h
index b07a99f..26516d0 100644
--- a/ZAPD/StringHelper.h
+++ b/ZAPD/StringHelper.h
@@ -1,11 +1,19 @@
#pragma once
+#include <algorithm>
#include <cstring>
#include <numeric>
#include <stdarg.h>
#include <string>
#include <vector>
-#include <algorithm>
+
+#ifndef __PRETTY_FUNCTION__
+#ifdef _MSC_VER
+#define __PRETTY_FUNCTION__ __FUNCSIG__
+#else
+#define __PRETTY_FUNCTION__ __func__
+#endif
+#endif
class StringHelper
{
@@ -101,7 +109,7 @@ public:
static std::string BoolStr(bool b) { return b ? "true" : "false"; }
- static bool HasOnlyDigits(const std::string &str)
+ static bool HasOnlyDigits(const std::string& str)
{
return std::all_of(str.begin(), str.end(), ::isdigit);
}
diff --git a/ZAPD/ZAnimation.cpp b/ZAPD/ZAnimation.cpp
index 5f9f934..0e511f9 100644
--- a/ZAPD/ZAnimation.cpp
+++ b/ZAPD/ZAnimation.cpp
@@ -18,10 +18,9 @@ ZAnimation::ZAnimation(ZFile* nParent) : ZResource(nParent)
void ZAnimation::ParseRawData()
{
- const uint8_t* data = rawData.data();
+ ZResource::ParseRawData();
- // Read the header
- frameCount = BitConverter::ToInt16BE(data, rawDataIndex + 0);
+ frameCount = BitConverter::ToInt16BE(parent->GetRawData(), rawDataIndex + 0);
}
void ZAnimation::Save(const fs::path& outFolder)
@@ -119,7 +118,7 @@ void ZNormalAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
- const uint8_t* data = rawData.data();
+ const uint8_t* data = parent->GetRawData().data();
rotationValuesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 4) & 0x00FFFFFF;
rotationIndicesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 8) & 0x00FFFFFF;
@@ -185,7 +184,7 @@ void ZLinkAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
- const uint8_t* data = rawData.data();
+ const uint8_t* data = parent->GetRawData().data();
segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4));
}
@@ -249,6 +248,7 @@ void ZCurveAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
+ const auto& rawData = parent->GetRawData();
refIndex = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0);
transformData = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
copyValues = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
@@ -292,10 +292,9 @@ void ZCurveAnimation::ParseRawData()
}
}
-void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
- const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex)
+void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+ ZResource::ExtractFromXML(reader, nRawDataIndex);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(),
GetSourceTypeName(), name, "");
diff --git a/ZAPD/ZAnimation.h b/ZAPD/ZAnimation.h
index 2d23ddd..704d556 100644
--- a/ZAPD/ZAnimation.h
+++ b/ZAPD/ZAnimation.h
@@ -126,8 +126,7 @@ public:
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex) override;
+ void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
void DeclareReferences(const std::string& prefix) override;
size_t GetRawDataSize() const override;
diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp
index 3194eac..e904c99 100644
--- a/ZAPD/ZArray.cpp
+++ b/ZAPD/ZArray.cpp
@@ -46,7 +46,7 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader)
}
res->parent = parent;
res->SetInnerNode(true);
- res->ExtractFromXML(child, rawData, childIndex);
+ res->ExtractFromXML(child, childIndex);
childIndex += res->GetRawDataSize();
resList.push_back(res);
diff --git a/ZAPD/ZBackground.cpp b/ZAPD/ZBackground.cpp
index 94388bf..2bc4cbc 100644
--- a/ZAPD/ZBackground.cpp
+++ b/ZAPD/ZBackground.cpp
@@ -15,11 +15,9 @@ ZBackground::ZBackground(ZFile* nParent) : ZResource(nParent)
{
}
-ZBackground::ZBackground(const std::string& prefix, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex, ZFile* nParent)
+ZBackground::ZBackground(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent)
: ZResource(nParent)
{
- rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
name = GetDefaultName(prefix.c_str(), rawDataIndex);
outName = name;
@@ -31,6 +29,7 @@ void ZBackground::ParseRawData()
{
ZResource::ParseRawData();
+ const auto& rawData = parent->GetRawData();
size_t i = 0;
while (true)
{
@@ -61,10 +60,9 @@ void ZBackground::ParseBinaryFile(const std::string& inFolder, bool appendOutNam
CheckValidJpeg(filepath.generic_string());
}
-void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex)
+void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+ ZResource::ExtractFromXML(reader, nRawDataIndex);
DeclareVar("", "");
}
diff --git a/ZAPD/ZBackground.h b/ZAPD/ZBackground.h
index 3df5c79..292d8a4 100644
--- a/ZAPD/ZBackground.h
+++ b/ZAPD/ZBackground.h
@@ -11,12 +11,11 @@ protected:
public:
ZBackground(ZFile* nParent);
- ZBackground(const std::string& prefix, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex, ZFile* nParent);
+ ZBackground(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
+
void ParseRawData() override;
void ParseBinaryFile(const std::string& inFolder, bool appendOutName);
- 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 CheckValidJpeg(const std::string& filepath);
diff --git a/ZAPD/ZBlob.cpp b/ZAPD/ZBlob.cpp
index e377bcf..6964e4e 100644
--- a/ZAPD/ZBlob.cpp
+++ b/ZAPD/ZBlob.cpp
@@ -45,7 +45,8 @@ void ZBlob::ParseXML(tinyxml2::XMLElement* reader)
void ZBlob::ParseRawData()
{
- blobData.assign(rawData.data() + rawDataIndex, rawData.data() + rawDataIndex + blobSize);
+ blobData.assign(parent->GetRawData().begin() + rawDataIndex,
+ parent->GetRawData().begin() + rawDataIndex + blobSize);
}
std::string ZBlob::GetSourceOutputCode(const std::string& prefix)
diff --git a/ZAPD/ZCollision.cpp b/ZAPD/ZCollision.cpp
index 34d7ee1..822b365 100644
--- a/ZAPD/ZCollision.cpp
+++ b/ZAPD/ZCollision.cpp
@@ -21,26 +21,26 @@ ZCollisionHeader::~ZCollisionHeader()
void ZCollisionHeader::ParseRawData()
{
- const uint8_t* data = rawData.data();
+ const auto& rawData = parent->GetRawData();
- absMinX = BitConverter::ToInt16BE(data, rawDataIndex + 0);
- absMinY = BitConverter::ToInt16BE(data, rawDataIndex + 2);
- absMinZ = BitConverter::ToInt16BE(data, rawDataIndex + 4);
+ absMinX = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
+ absMinY = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
+ absMinZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
- absMaxX = BitConverter::ToInt16BE(data, rawDataIndex + 6);
- absMaxY = BitConverter::ToInt16BE(data, rawDataIndex + 8);
- absMaxZ = BitConverter::ToInt16BE(data, rawDataIndex + 10);
+ absMaxX = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
+ absMaxY = BitConverter::ToInt16BE(rawData, rawDataIndex + 8);
+ absMaxZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
- numVerts = BitConverter::ToUInt16BE(data, rawDataIndex + 12);
- vtxAddress = BitConverter::ToInt32BE(data, rawDataIndex + 16);
+ numVerts = BitConverter::ToUInt16BE(rawData, rawDataIndex + 12);
+ vtxAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 16);
- numPolygons = BitConverter::ToUInt16BE(data, rawDataIndex + 20);
- polyAddress = BitConverter::ToInt32BE(data, rawDataIndex + 24);
- polyTypeDefAddress = BitConverter::ToInt32BE(data, rawDataIndex + 28);
- camDataAddress = BitConverter::ToInt32BE(data, rawDataIndex + 32);
+ numPolygons = BitConverter::ToUInt16BE(rawData, rawDataIndex + 20);
+ polyAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 24);
+ polyTypeDefAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 28);
+ camDataAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 32);
- numWaterBoxes = BitConverter::ToUInt16BE(data, rawDataIndex + 36);
- waterBoxAddress = BitConverter::ToInt32BE(data, rawDataIndex + 40);
+ numWaterBoxes = BitConverter::ToUInt16BE(rawData, rawDataIndex + 36);
+ waterBoxAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 40);
vtxSegmentOffset = Seg2Filespace(vtxAddress, parent->baseAddress);
polySegmentOffset = Seg2Filespace(polyAddress, parent->baseAddress);
@@ -66,7 +66,8 @@ void ZCollisionHeader::ParseRawData()
}
for (uint16_t i = 0; i < highestPolyType + 1; i++)
- polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8)));
+ polygonTypes.push_back(
+ BitConverter::ToUInt64BE(rawData, polyTypeDefSegmentOffset + (i * 8)));
if (camDataAddress != 0)
camData = new CameraDataList(parent, name, rawData, camDataSegmentOffset,
diff --git a/ZAPD/ZCutscene.cpp b/ZAPD/ZCutscene.cpp
index 48e6a46..2c0f7d3 100644
--- a/ZAPD/ZCutscene.cpp
+++ b/ZAPD/ZCutscene.cpp
@@ -151,15 +151,18 @@ size_t ZCutscene::GetRawDataSize() const
return size;
}
-void ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
+void ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+ ZResource::ExtractFromXML(reader, nRawDataIndex);
DeclareVar(parent->GetName(), "");
}
void ZCutscene::ParseRawData()
{
+ ZResource::ParseRawData();
+
+ const auto& rawData = parent->GetRawData();
+
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
commands = std::vector<CutsceneCommand*>();
diff --git a/ZAPD/ZCutscene.h b/ZAPD/ZCutscene.h
index 4899c82..2167379 100644
--- a/ZAPD/ZCutscene.h
+++ b/ZAPD/ZCutscene.h
@@ -434,8 +434,7 @@ public:
ZResourceType GetResourceType() const override;
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex) override;
+ void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
protected:
int32_t numCommands;
diff --git a/ZAPD/ZCutsceneMM.cpp b/ZAPD/ZCutsceneMM.cpp
index bb67240..ed663da 100644
--- a/ZAPD/ZCutsceneMM.cpp
+++ b/ZAPD/ZCutsceneMM.cpp
@@ -58,16 +58,16 @@ size_t ZCutsceneMM::GetRawDataSize() const
return 8 + data.size() * 4;
}
-void ZCutsceneMM::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
+void ZCutsceneMM::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+ ZResource::ExtractFromXML(reader, nRawDataIndex);
DeclareVar(parent->GetName(), "");
}
void ZCutsceneMM::ParseRawData()
{
segmentOffset = rawDataIndex;
+ const auto& rawData = parent->GetRawData();
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
commands = std::vector<CutsceneCommand*>();
diff --git a/ZAPD/ZCutsceneMM.h b/ZAPD/ZCutsceneMM.h
index c0438ed..5cda5a1 100644
--- a/ZAPD/ZCutsceneMM.h
+++ b/ZAPD/ZCutsceneMM.h
@@ -24,8 +24,7 @@ public:
void ParseRawData() override;
ZResourceType GetResourceType() const override;
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex) override;
+ void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
protected:
int32_t numCommands;
diff --git a/ZAPD/ZDisplayList.cpp b/ZAPD/ZDisplayList.cpp
index de041f1..7f3e895 100644
--- a/ZAPD/ZDisplayList.cpp
+++ b/ZAPD/ZDisplayList.cpp
@@ -1,7 +1,9 @@
#include "ZDisplayList.h"
+
#include <File.h>
#include <Path.h>
#include <algorithm>
+#include <cassert>
#include <chrono>
#include <math.h>
#include "BitConverter.h"
@@ -41,46 +43,40 @@ ZDisplayList::~ZDisplayList()
}
// EXTRACT MODE
-void ZDisplayList::ExtractFromXML(tinyxml2::XMLElement* reader,
- const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
+void ZDisplayList::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
ParseXML(reader);
- fileData = nRawData;
int32_t rawDataSize = ZDisplayList::GetDListLength(
- nRawData, rawDataIndex,
+ parent->GetRawData(), rawDataIndex,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
- dlistRawData.assign(nRawData.data() + rawDataIndex,
- nRawData.data() + rawDataIndex + rawDataSize);
+ numInstructions = rawDataSize / 8;
ParseRawData();
DeclareVar("", "");
}
-ZDisplayList::ZDisplayList(std::vector<uint8_t> nRawData, uint32_t nRawDataIndex,
- int32_t rawDataSize, ZFile* nParent)
+ZDisplayList::ZDisplayList(uint32_t nRawDataIndex, int32_t rawDataSize, ZFile* nParent)
: ZDisplayList(nParent)
{
- rawData.assign(nRawData.begin(), nRawData.end());
- fileData = nRawData;
rawDataIndex = nRawDataIndex;
name = StringHelper::Sprintf("DL_%06X", rawDataIndex);
- dlistRawData.assign(nRawData.data() + rawDataIndex,
- nRawData.data() + rawDataIndex + rawDataSize);
+ numInstructions = rawDataSize / 8;
ParseRawData();
}
void ZDisplayList::ParseRawData()
{
- size_t numInstructions = dlistRawData.size() / 8;
-
+ const auto& rawData = parent->GetRawData();
instructions.reserve(numInstructions);
+ uint32_t ptr = rawDataIndex;
for (size_t i = 0; i < numInstructions; i++)
- instructions.push_back(BitConverter::ToUInt64BE(dlistRawData, (i * 8)));
+ {
+ instructions.push_back(BitConverter::ToUInt64BE(rawData, ptr));
+ ptr += 8;
+ }
}
Declaration* ZDisplayList::DeclareVar(const std::string& prefix, const std::string& bodyStr)
@@ -262,9 +258,9 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, st
sprintf(line, "gsSPBranchLessZraw(%sDlist0x%06X, 0x%02X, 0x%02X),", prefix.c_str(),
h & 0x00FFFFFF, (a / 5) | (b / 2), z);
- ZDisplayList* nList =
- new ZDisplayList(fileData, h & 0x00FFFFFF,
- GetDListLength(fileData, h & 0x00FFFFFF, dListType), parent);
+ ZDisplayList* nList = new ZDisplayList(
+ h & 0x00FFFFFF, GetDListLength(parent->GetRawData(), h & 0x00FFFFFF, dListType),
+ parent);
nList->scene = scene;
otherDLists.push_back(nList);
@@ -411,11 +407,9 @@ void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, std::string pre
}
}
-int32_t ZDisplayList::GetDListLength(std::vector<uint8_t> rawData, uint32_t rawDataIndex,
+int32_t ZDisplayList::GetDListLength(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
DListType dListType)
{
- int32_t i = 0;
-
uint8_t endDLOpcode;
if (dListType == DListType::F3DZEX)
@@ -423,13 +417,25 @@ int32_t ZDisplayList::GetDListLength(std::vector<uint8_t> rawData, uint32_t rawD
else
endDLOpcode = (uint8_t)F3DEXOpcode::G_ENDDL;
+ uint32_t ptr = rawDataIndex;
+ size_t rawDataSize = rawData.size();
while (true)
{
- uint8_t opcode = rawData.at(rawDataIndex + (i * 8));
- i++;
+ if (ptr > rawDataSize)
+ {
+ throw std::runtime_error(
+ StringHelper::Sprintf("%s: Fatal error.\n"
+ "\t End of file found when trying to find the end of the "
+ "DisplayList at offset: '0x%X'.\n",
+ __PRETTY_FUNCTION__, rawDataIndex));
+ throw std::runtime_error("");
+ }
+
+ uint8_t opcode = rawData.at(ptr);
+ ptr += 8;
if (opcode == endDLOpcode)
- return i * 8;
+ return ptr - rawDataIndex;
}
}
@@ -698,9 +704,9 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, std::string prefix, char* line)
}
else
{
- ZDisplayList* nList =
- new ZDisplayList(fileData, GETSEGOFFSET(data),
- GetDListLength(fileData, GETSEGOFFSET(data), dListType), parent);
+ ZDisplayList* nList = new ZDisplayList(
+ GETSEGOFFSET(data), GetDListLength(parent->GetRawData(), GETSEGOFFSET(data), dListType),
+ parent);
// if (scene != nullptr)
{
@@ -863,7 +869,6 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, char* line)
for (int32_t i = 0; i < nn; i++)
{
ZVtx vtx(parent);
- vtx.SetRawData(fileData);
vtx.SetRawDataIndex(currentPtr);
vtx.ParseRawData();
vtxList.push_back(vtx);
@@ -1633,7 +1638,6 @@ static int32_t GfxdCallback_Vtx(uint32_t seg, int32_t count)
for (int32_t i = 0; i < count; i++)
{
ZVtx vtx(self->parent);
- vtx.SetRawData(self->fileData);
vtx.SetRawDataIndex(currentPtr);
vtx.ParseRawData();
@@ -1733,8 +1737,9 @@ static int32_t GfxdCallback_DisplayList(uint32_t seg)
if ((dListSegNum <= 6) && Globals::Instance->HasSegment(dListSegNum))
{
ZDisplayList* newDList = new ZDisplayList(
- self->fileData, dListOffset,
- self->GetDListLength(self->fileData, dListOffset, self->dListType), self->parent);
+ dListOffset,
+ self->GetDListLength(self->parent->GetRawData(), dListOffset, self->dListType),
+ self->parent);
newDList->scene = self->scene;
newDList->parent = self->parent;
self->otherDLists.push_back(newDList);
@@ -1764,8 +1769,7 @@ static int32_t GfxdCallback_Matrix(uint32_t seg)
self->parent->GetDeclaration(Seg2Filespace(seg, self->parent->baseAddress));
if (decl == nullptr)
{
- ZMtx mtx(self->GetName(), self->fileData, Seg2Filespace(seg, self->parent->baseAddress),
- self->parent);
+ ZMtx mtx(self->GetName(), Seg2Filespace(seg, self->parent->baseAddress), self->parent);
mtx.GetSourceOutputCode(self->GetName());
self->mtxList.push_back(mtx);
@@ -2032,8 +2036,8 @@ std::string ZDisplayList::ProcessGfxDis(const std::string& prefix)
void ZDisplayList::TextureGenCheck(std::string prefix)
{
- if (TextureGenCheck(fileData, scene, parent, prefix, lastTexWidth, lastTexHeight, lastTexAddr,
- lastTexSeg, lastTexFmt, lastTexSiz, lastTexLoaded, lastTexIsPalette, this))
+ if (TextureGenCheck(scene, parent, prefix, lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg,
+ lastTexFmt, lastTexSiz, lastTexLoaded, lastTexIsPalette, this))
{
lastTexAddr = 0;
lastTexLoaded = false;
@@ -2041,11 +2045,10 @@ void ZDisplayList::TextureGenCheck(std::string prefix)
}
}
-bool ZDisplayList::TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene, ZFile* parent,
- std::string prefix, int32_t texWidth, int32_t texHeight,
- uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt,
- F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette,
- ZDisplayList* self)
+bool ZDisplayList::TextureGenCheck(ZRoom* scene, ZFile* parent, std::string prefix,
+ int32_t texWidth, int32_t texHeight, uint32_t texAddr,
+ uint32_t texSeg, F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz,
+ bool texLoaded, bool texIsPalette, ZDisplayList* self)
{
int32_t segmentNumber = GETSEGNUM(texSeg);
@@ -2071,7 +2074,7 @@ bool ZDisplayList::TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene,
else
{
tex = new ZTexture(parent);
- tex->FromBinary(fileData, texAddr, texWidth, texHeight,
+ tex->FromBinary(texAddr, texWidth, texHeight,
TexFormatToTexType(texFmt, texSiz), texIsPalette);
parent->AddTextureResource(texAddr, tex);
}
@@ -2094,7 +2097,7 @@ bool ZDisplayList::TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene,
else
{
tex = new ZTexture(scene->parent);
- tex->FromBinary(scene->GetRawData(), texAddr, texWidth, texHeight,
+ tex->FromBinary(texAddr, texWidth, texHeight,
TexFormatToTexType(texFmt, texSiz), texIsPalette);
scene->parent->AddTextureResource(texAddr, tex);
diff --git a/ZAPD/ZDisplayList.h b/ZAPD/ZDisplayList.h
index 091b4b2..09394b2 100644
--- a/ZAPD/ZDisplayList.h
+++ b/ZAPD/ZDisplayList.h
@@ -346,28 +346,24 @@ public:
std::vector<uint32_t> references;
std::string defines; // Hack for special cases where vertex arrays intersect...
- std::vector<uint8_t> fileData;
std::vector<ZMtx> mtxList;
ZDisplayList(ZFile* nParent);
- ZDisplayList(std::vector<uint8_t> nRawData, uint32_t rawDataIndex, int32_t rawDataSize,
- ZFile* nParent);
+ ZDisplayList(uint32_t rawDataIndex, int32_t rawDataSize, ZFile* nParent);
~ZDisplayList();
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex) override;
+ void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
void ParseRawData() override;
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr);
void TextureGenCheck(std::string prefix);
- static bool TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene, ZFile* parent,
- std::string prefix, int32_t texWidth, int32_t texHeight,
- uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt,
- F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette,
- ZDisplayList* self);
- static int32_t GetDListLength(std::vector<uint8_t> rawData, uint32_t rawDataIndex,
+ static bool TextureGenCheck(ZRoom* scene, ZFile* parent, std::string prefix, int32_t texWidth,
+ int32_t texHeight, uint32_t texAddr, uint32_t texSeg,
+ F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded,
+ bool texIsPalette, ZDisplayList* self);
+ static int32_t GetDListLength(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
DListType dListType);
size_t GetRawDataSize() const override;
@@ -384,5 +380,5 @@ public:
ZResourceType GetResourceType() const override;
protected:
- std::vector<uint8_t> dlistRawData;
+ size_t numInstructions;
};
diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp
index ed10615..38eba56 100644
--- a/ZAPD/ZFile.cpp
+++ b/ZAPD/ZFile.cpp
@@ -194,7 +194,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
ZResource* nRes = nodeMap[nodeName](this);
if (mode == ZFileMode::Extract)
- nRes->ExtractFromXML(child, rawData, rawDataIndex);
+ nRes->ExtractFromXML(child, rawDataIndex);
auto resType = nRes->GetResourceType();
if (resType == ZResourceType::Texture)
diff --git a/ZAPD/ZLimb.cpp b/ZAPD/ZLimb.cpp
index ffb61e2..472d825 100644
--- a/ZAPD/ZLimb.cpp
+++ b/ZAPD/ZLimb.cpp
@@ -217,7 +217,7 @@ std::string Struct_800A598C::GetSourceTypeName()
Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& nRawData,
uint32_t fileOffset)
- : parent(parent), rawData(nRawData)
+ : parent(parent)
{
unk_0 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x00);
unk_2 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x02);
@@ -282,9 +282,9 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
int32_t dlistLength = ZDisplayList::GetDListLength(
- rawData, unk_8_Offset,
+ parent->GetRawData(), unk_8_Offset,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
- unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength, parent);
+ unk_8_dlist = new ZDisplayList(unk_8_Offset, dlistLength, parent);
std::string dListStr =
StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
@@ -354,11 +354,9 @@ ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent)
RegisterOptionalAttribute("Type");
}
-ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex, ZFile* nParent)
+ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent)
: ZLimb(nParent)
{
- rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
type = limbType;
@@ -368,10 +366,9 @@ ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<ui
ParseRawData();
}
-void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
+void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+ ZResource::ExtractFromXML(reader, nRawDataIndex);
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), name, "");
@@ -429,6 +426,7 @@ void ZLimb::ParseRawData()
{
ZResource::ParseRawData();
+ const auto& rawData = parent->GetRawData();
if (type == ZLimbType::Curve)
{
childIndex = rawData.at(rawDataIndex + 0);
@@ -607,9 +605,9 @@ std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix,
StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), dListOffset);
int32_t dlistLength = ZDisplayList::GetDListLength(
- rawData, dListOffset,
+ parent->GetRawData(), dListOffset,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
- auto dList = new ZDisplayList(rawData, dListOffset, dlistLength, parent);
+ auto dList = new ZDisplayList(dListOffset, dlistLength, parent);
dList->SetName(dListStr);
dList->GetSourceOutputCode(prefix);
return dListStr;
diff --git a/ZAPD/ZLimb.h b/ZAPD/ZLimb.h
index 8172bef..5d944ae 100644
--- a/ZAPD/ZLimb.h
+++ b/ZAPD/ZLimb.h
@@ -93,7 +93,6 @@ class Struct_800A5E28
{
protected:
ZFile* parent;
- std::vector<uint8_t> rawData;
uint16_t unk_0; // Vtx count
uint16_t unk_2; // Length of unk_4
@@ -140,11 +139,9 @@ public:
uint8_t childIndex, siblingIndex;
ZLimb(ZFile* nParent);
- ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex, ZFile* nParent);
+ ZLimb(ZLimbType limbType, const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex) override;
+ void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
diff --git a/ZAPD/ZMtx.cpp b/ZAPD/ZMtx.cpp
index 7beadee..f92506c 100644
--- a/ZAPD/ZMtx.cpp
+++ b/ZAPD/ZMtx.cpp
@@ -9,12 +9,10 @@ ZMtx::ZMtx(ZFile* nParent) : ZResource(nParent)
{
}
-ZMtx::ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
- ZFile* nParent)
- : ZResource(nParent)
+ZMtx::ZMtx(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent) : ZResource(nParent)
{
name = GetDefaultName(prefix.c_str(), rawDataIndex);
- ExtractFromFile(nRawData, nRawDataIndex);
+ ExtractFromFile(nRawDataIndex);
DeclareVar("", "");
}
@@ -22,15 +20,15 @@ void ZMtx::ParseRawData()
{
ZResource::ParseRawData();
+ const auto& rawData = parent->GetRawData();
for (size_t i = 0; i < 4; ++i)
for (size_t j = 0; j < 4; ++j)
mtx[i][j] = BitConverter::ToInt32BE(rawData, rawDataIndex + (i * 4 + j) * 4);
}
-void ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex)
+void ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+ ZResource::ExtractFromXML(reader, nRawDataIndex);
DeclareVar("", "");
}
diff --git a/ZAPD/ZMtx.h b/ZAPD/ZMtx.h
index 0771f29..7a98650 100644
--- a/ZAPD/ZMtx.h
+++ b/ZAPD/ZMtx.h
@@ -8,12 +8,10 @@ class ZMtx : public ZResource
{
public:
ZMtx(ZFile* nParent);
- ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
- ZFile* nParent);
+ ZMtx(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
void ParseRawData() override;
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex) override;
+ void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
size_t GetRawDataSize() const override;
diff --git a/ZAPD/ZPath.cpp b/ZAPD/ZPath.cpp
index 39e06fb..890fa5e 100644
--- a/ZAPD/ZPath.cpp
+++ b/ZAPD/ZPath.cpp
@@ -13,10 +13,9 @@ ZPath::ZPath(ZFile* nParent) : ZResource(nParent)
RegisterOptionalAttribute("NumPaths", "1");
}
-void ZPath::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
+void ZPath::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+ ZResource::ExtractFromXML(reader, nRawDataIndex);
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, pathways.size() * 8,
GetSourceTypeName(), name, pathways.size(), "");
@@ -135,7 +134,6 @@ void PathwayEntry::ParseRawData()
for (int32_t i = 0; i < numPoints; i++)
{
ZVector vec(parent);
- vec.SetRawData(parentRawData);
vec.SetRawDataIndex(currentPtr);
vec.SetScalarType(ZScalarType::ZSCALAR_S16);
vec.SetDimensions(3);
diff --git a/ZAPD/ZPath.h b/ZAPD/ZPath.h
index 55fc17d..23e2933 100644
--- a/ZAPD/ZPath.h
+++ b/ZAPD/ZPath.h
@@ -32,8 +32,7 @@ class ZPath : public ZResource
public:
ZPath(ZFile* nParent);
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex);
+ void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex);
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
diff --git a/ZAPD/ZResource.cpp b/ZAPD/ZResource.cpp
index 55e142f..f64ce4a 100644
--- a/ZAPD/ZResource.cpp
+++ b/ZAPD/ZResource.cpp
@@ -21,10 +21,8 @@ ZResource::ZResource(ZFile* nParent)
RegisterOptionalAttribute("Custom");
}
-void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
+void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- rawData = nRawData;
rawDataIndex = nRawDataIndex;
if (reader != nullptr)
@@ -34,9 +32,8 @@ void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<u
CalcHash();
}
-void ZResource::ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex)
+void ZResource::ExtractFromFile(uint32_t nRawDataIndex)
{
- rawData = nRawData;
rawDataIndex = nRawDataIndex;
ParseRawData();
@@ -160,16 +157,6 @@ std::string ZResource::GetExternalExtension() const
return "";
}
-const std::vector<uint8_t>& ZResource::GetRawData() const
-{
- return rawData;
-}
-
-void ZResource::SetRawData(const std::vector<uint8_t>& nData)
-{
- rawData = nData;
-}
-
bool ZResource::WasDeclaredInXml() const
{
return declaredInXml;
diff --git a/ZAPD/ZResource.h b/ZAPD/ZResource.h
index 24f1f56..88660aa 100644
--- a/ZAPD/ZResource.h
+++ b/ZAPD/ZResource.h
@@ -69,9 +69,8 @@ public:
virtual ~ZResource() = default;
// Parsing from File
- virtual void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex);
- virtual void ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex);
+ virtual void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex);
+ virtual void ExtractFromFile(uint32_t nRawDataIndex);
// Misc
virtual void ParseXML(tinyxml2::XMLElement* reader);
@@ -101,15 +100,12 @@ public:
virtual uint32_t GetRawDataIndex() const;
virtual void SetRawDataIndex(uint32_t value);
virtual size_t GetRawDataSize() const = 0;
- virtual const std::vector<uint8_t>& GetRawData() const;
- virtual void SetRawData(const std::vector<uint8_t>& nData);
void SetInnerNode(bool inner);
bool WasDeclaredInXml() const;
protected:
std::string name;
std::string outName;
- std::vector<uint8_t> rawData;
uint32_t rawDataIndex;
std::string sourceOutput;
bool isInner = false; // Is this resource an inner node of another resource? inside of <Array>
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);
diff --git a/ZAPD/ZScalar.cpp b/ZAPD/ZScalar.cpp
index 797ac07..24b5cbc 100644
--- a/ZAPD/ZScalar.cpp
+++ b/ZAPD/ZScalar.cpp
@@ -137,6 +137,7 @@ size_t ZScalar::GetRawDataSize() const
void ZScalar::ParseRawData()
{
+ const auto& rawData = parent->GetRawData();
switch (scalarType)
{
case ZScalarType::ZSCALAR_S8:
diff --git a/ZAPD/ZSkeleton.cpp b/ZAPD/ZSkeleton.cpp
index dd5f8bd..5e599e7 100644
--- a/ZAPD/ZSkeleton.cpp
+++ b/ZAPD/ZSkeleton.cpp
@@ -16,10 +16,9 @@ ZSkeleton::ZSkeleton(ZFile* nParent) : ZResource(nParent)
}
ZSkeleton::ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix,
- const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, ZFile* nParent)
+ uint32_t nRawDataIndex, ZFile* nParent)
: ZSkeleton(nParent)
{
- rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
@@ -35,9 +34,10 @@ ZSkeleton::ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string
for (size_t i = 0; i < limbCount; i++)
{
- uint32_t ptr2 = Seg2Filespace(BitConverter::ToUInt32BE(rawData, ptr), parent->baseAddress);
+ uint32_t ptr2 =
+ Seg2Filespace(BitConverter::ToUInt32BE(parent->GetRawData(), ptr), parent->baseAddress);
- ZLimb* limb = new ZLimb(limbType, prefix, rawData, ptr2, parent);
+ ZLimb* limb = new ZLimb(limbType, prefix, ptr2, parent);
limbs.push_back(limb);
ptr += 4;
@@ -95,15 +95,15 @@ void ZSkeleton::ParseRawData()
{
ZResource::ParseRawData();
+ const auto& rawData = parent->GetRawData();
limbsArrayAddress = BitConverter::ToUInt32BE(rawData, rawDataIndex);
limbCount = BitConverter::ToUInt8BE(rawData, rawDataIndex + 4);
dListCount = BitConverter::ToUInt8BE(rawData, rawDataIndex + 8);
}
-void ZSkeleton::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
+void ZSkeleton::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+ ZResource::ExtractFromXML(reader, nRawDataIndex);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(),
GetSourceTypeName(), name, "");
@@ -112,6 +112,7 @@ void ZSkeleton::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<u
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress);
+ const auto& rawData = parent->GetRawData();
for (size_t i = 0; i < limbCount; i++)
{
uint32_t ptr2 = Seg2Filespace(BitConverter::ToUInt32BE(rawData, ptr), parent->baseAddress);
@@ -124,7 +125,7 @@ void ZSkeleton::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<u
ZLimb* limb = new ZLimb(parent);
limb->SetLimbType(limbType);
limb->SetName(limbName);
- limb->ExtractFromXML(nullptr, rawData, ptr2);
+ limb->ExtractFromXML(nullptr, ptr2);
limbs.push_back(limb);
ptr += 4;
diff --git a/ZAPD/ZSkeleton.h b/ZAPD/ZSkeleton.h
index 6841b82..3c354e6 100644
--- a/ZAPD/ZSkeleton.h
+++ b/ZAPD/ZSkeleton.h
@@ -26,11 +26,10 @@ public:
ZSkeleton(ZFile* nParent);
ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix,
- const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, ZFile* nParent);
+ uint32_t nRawDataIndex, ZFile* nParent);
~ZSkeleton();
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex) override;
+ void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
diff --git a/ZAPD/ZString.cpp b/ZAPD/ZString.cpp
index 24ef2d6..50545da 100644
--- a/ZAPD/ZString.cpp
+++ b/ZAPD/ZString.cpp
@@ -13,7 +13,8 @@ ZString::ZString(ZFile* nParent) : ZResource(nParent)
void ZString::ParseRawData()
{
size_t size = 0;
- uint8_t* rawDataArr = rawData.data();
+ const auto& rawData = parent->GetRawData();
+ const auto& rawDataArr = rawData.data();
size_t rawDataSize = rawData.size();
for (size_t i = rawDataIndex; i < rawDataSize; ++i)
{
@@ -43,7 +44,7 @@ std::string ZString::GetSourceOutputCode(const std::string& prefix)
std::string ZString::GetSourceOutputHeader(const std::string& prefix)
{
- return StringHelper::Sprintf("#define %s_macro \"%s\"", name.c_str(), rawData.data());
+ return StringHelper::Sprintf("#define %s_macro \"%s\"", name.c_str(), strData.data());
}
std::string ZString::GetSourceTypeName() const
diff --git a/ZAPD/ZSymbol.cpp b/ZAPD/ZSymbol.cpp
index 3ba69db..25a1e49 100644
--- a/ZAPD/ZSymbol.cpp
+++ b/ZAPD/ZSymbol.cpp
@@ -11,12 +11,6 @@ ZSymbol::ZSymbol(ZFile* nParent) : ZResource(nParent)
RegisterOptionalAttribute("Count");
}
-void ZSymbol::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
-{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
-}
-
void ZSymbol::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
diff --git a/ZAPD/ZSymbol.h b/ZAPD/ZSymbol.h
index ad818fe..1094a02 100644
--- a/ZAPD/ZSymbol.h
+++ b/ZAPD/ZSymbol.h
@@ -14,9 +14,6 @@ protected:
public:
ZSymbol(ZFile* nParent);
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex) override;
-
void ParseXML(tinyxml2::XMLElement* reader) override;
size_t GetRawDataSize() const override;
diff --git a/ZAPD/ZTexture.cpp b/ZAPD/ZTexture.cpp
index b47fd23..d396bd6 100644
--- a/ZAPD/ZTexture.cpp
+++ b/ZAPD/ZTexture.cpp
@@ -21,10 +21,9 @@ ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent)
RegisterOptionalAttribute("TlutOffset");
}
-void ZTexture::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex)
+void ZTexture::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+ ZResource::ExtractFromXML(reader, nRawDataIndex);
auto filepath = Globals::Instance->outputPath / fs::path(name).stem();
@@ -35,8 +34,8 @@ void ZTexture::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<ui
name, 0);
}
-void ZTexture::FromBinary(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
- int32_t nWidth, int32_t nHeight, TextureType nType, bool nIsPalette)
+void ZTexture::FromBinary(uint32_t nRawDataIndex, int32_t nWidth, int32_t nHeight,
+ TextureType nType, bool nIsPalette)
{
width = nWidth;
height = nHeight;
@@ -46,8 +45,6 @@ void ZTexture::FromBinary(const std::vector<uint8_t>& nRawData, uint32_t nRawDat
name = GetDefaultName(parent->GetName());
outName = name;
- rawData.assign(nRawData.begin(), nRawData.end());
-
ParseRawData();
CalcHash();
}
@@ -75,17 +72,17 @@ void ZTexture::ParseXML(tinyxml2::XMLElement* reader)
if (!StringHelper::HasOnlyDigits(widthXml))
{
- throw std::runtime_error(StringHelper::Sprintf(
- "ZTexture::ParseXML: Error in %s\n"
- "\t Value of 'Width' attribute has non-decimal digits: '%s'.\n",
- name.c_str(), widthXml.c_str()));
+ throw std::runtime_error(
+ StringHelper::Sprintf("ZTexture::ParseXML: Error in %s\n"
+ "\t Value of 'Width' attribute has non-decimal digits: '%s'.\n",
+ name.c_str(), widthXml.c_str()));
}
if (!StringHelper::HasOnlyDigits(heightXml))
{
- throw std::runtime_error(StringHelper::Sprintf(
- "ZTexture::ParseXML: Error in %s\n"
- "\t Value of 'Height' attribute has non-decimal digits: '%s'.\n",
- name.c_str(), heightXml.c_str()));
+ throw std::runtime_error(
+ StringHelper::Sprintf("ZTexture::ParseXML: Error in %s\n"
+ "\t Value of 'Height' attribute has non-decimal digits: '%s'.\n",
+ name.c_str(), heightXml.c_str()));
}
width = StringHelper::StrToL(widthXml);
@@ -348,7 +345,7 @@ void ZTexture::DeclareReferences(const std::string& prefix)
GetExternalExtension().c_str());
tlut = new ZTexture(parent);
- tlut->FromBinary(rawData, tlutOffset, tlutDim, tlutDim, TextureType::RGBA16bpp, true);
+ tlut->FromBinary(tlutOffset, tlutDim, tlutDim, TextureType::RGBA16bpp, true);
parent->AddTextureResource(tlutOffset, tlut);
parent->AddDeclarationIncludeArray(tlutOffset, incStr, tlut->GetRawDataSize(),
tlut->GetSourceTypeName(), tlut->GetName(), 0);
diff --git a/ZAPD/ZTexture.h b/ZAPD/ZTexture.h
index c17ed0b..807468a 100644
--- a/ZAPD/ZTexture.h
+++ b/ZAPD/ZTexture.h
@@ -58,10 +58,9 @@ public:
bool isPalette = false;
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- uint32_t nRawDataIndex) override;
- void FromBinary(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, int32_t nWidth,
- int32_t nHeight, TextureType nType, bool nIsPalette);
+ void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
+ void FromBinary(uint32_t nRawDataIndex, int32_t nWidth, int32_t nHeight, TextureType nType,
+ bool nIsPalette);
void FromPNG(const fs::path& pngFilePath, TextureType texType);
void FromHLTexture(HLTexture* hlTex);
diff --git a/ZAPD/ZVector.cpp b/ZAPD/ZVector.cpp
index 3584580..d1aef44 100644
--- a/ZAPD/ZVector.cpp
+++ b/ZAPD/ZVector.cpp
@@ -35,7 +35,6 @@ void ZVector::ParseRawData()
{
ZScalar scalar(scalarType, parent);
scalar.rawDataIndex = currentRawDataIndex;
- scalar.rawData = rawData;
scalar.ParseRawData();
currentRawDataIndex += scalar.GetRawDataSize();
diff --git a/ZAPD/ZVtx.cpp b/ZAPD/ZVtx.cpp
index d56f4fa..bead96f 100644
--- a/ZAPD/ZVtx.cpp
+++ b/ZAPD/ZVtx.cpp
@@ -21,6 +21,9 @@ ZVtx::ZVtx(ZFile* nParent) : ZResource(nParent)
void ZVtx::ParseRawData()
{
+ ZResource::ParseRawData();
+
+ const auto& rawData = parent->GetRawData();
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
y = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
z = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);