summaryrefslogtreecommitdiff
path: root/ZAPD/ZDisplayList.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-09-13 11:29:46 -0300
committerGitHub <noreply@github.com>2021-09-13 10:29:46 -0400
commit4d051c0fa036d245027a211bc7fd6a4afdce207f (patch)
treeeb1697990e40e60343971b777cbfe99c6eee548c /ZAPD/ZDisplayList.cpp
parent90662f3cbade844c8edc3943ab8252e334b6166a (diff)
ZRoom cleaning 3 (#140)
* Remove redundant scene member * altheaders clean * it is broken and I don't know why * fix VTXs * Fix the stuff I broke in SetRoomList * Add RoomAltHeader and SceneAltHeader * fix syotes again and set the size of each ZRoomCommand * Add SCENE_CMD_UNK_09 todo * Nuke HintSystem * run format * Remove `canHaveInner` from ZRoom since the HintSystem doesn't exists anymore * Remove sourceOutput member from ZResource * Update docs * run format * Add non 64-bits aligned textures warning * remove unused json library * Update SCENE_CMD_UNK_09 * Fix merge issues * run format * Clean up actorlist output * Fix merge conflicts * format * Fix actorlist extraction * Unify AltHeader * fix merge conflicts * Run formatter * minor style changes * fix using wrong symbols for extracted vtxs from overlays * format * fix makefile stuff * fix merge issue
Diffstat (limited to 'ZAPD/ZDisplayList.cpp')
-rw-r--r--ZAPD/ZDisplayList.cpp92
1 files changed, 41 insertions, 51 deletions
diff --git a/ZAPD/ZDisplayList.cpp b/ZAPD/ZDisplayList.cpp
index cac1be0..2f2e2d7 100644
--- a/ZAPD/ZDisplayList.cpp
+++ b/ZAPD/ZDisplayList.cpp
@@ -29,7 +29,6 @@ ZDisplayList::ZDisplayList(ZFile* nParent) : ZResource(nParent)
lastTexLoaded = false;
lastTexIsPalette = false;
name = "";
- scene = nullptr;
dListType = Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX;
}
@@ -81,8 +80,11 @@ void ZDisplayList::ParseRawData()
Declaration* ZDisplayList::DeclareVar([[maybe_unused]] const std::string& prefix,
const std::string& bodyStr)
{
- return parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
- GetSourceTypeName(), name, 0, bodyStr, true);
+ Declaration* decl =
+ parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
+ GetSourceTypeName(), name, 0, bodyStr);
+ decl->isExternal = true;
+ return decl;
}
void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, std::string prefix,
@@ -261,7 +263,6 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, st
ZDisplayList* nList = new ZDisplayList(
h & 0x00FFFFFF, GetDListLength(parent->GetRawData(), h & 0x00FFFFFF, dListType),
parent);
- nList->scene = scene;
otherDLists.push_back(nList);
i++;
@@ -423,12 +424,11 @@ int32_t ZDisplayList::GetDListLength(const std::vector<uint8_t>& rawData, uint32
{
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",
- "Raw data size: 0x%zX.\n",
- __PRETTY_FUNCTION__, rawDataIndex, 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",
+ "Raw data size: 0x%zX.\n", __PRETTY_FUNCTION__, rawDataIndex, rawDataSize));
throw std::runtime_error("");
}
@@ -477,7 +477,7 @@ int32_t ZDisplayList::OptimizationChecks(int32_t startIndex, std::string& output
int32_t ZDisplayList::OptimizationCheck_LoadTextureBlock(int32_t startIndex, std::string& output,
std::string prefix)
{
- if (scene == nullptr)
+ if (Globals::Instance->lastScene == nullptr)
{
return -1;
}
@@ -709,16 +709,7 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, std::string prefix, char* line)
GETSEGOFFSET(data), GetDListLength(parent->GetRawData(), GETSEGOFFSET(data), dListType),
parent);
- // if (scene != nullptr)
- {
- nList->scene = scene;
- otherDLists.push_back(nList);
- }
- // else
- //{
- // nList->SetName(StringHelper::Sprintf("%sDlist0x%06lX", prefix.c_str(),
- // SEG2FILESPACE(data))); nList->GetSourceOutputCode(prefix);
- //}
+ otherDLists.push_back(nList);
}
}
@@ -952,7 +943,8 @@ void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, std::string prefix, char* lin
else
{
sprintf(line, "gsDPSetTextureImage(%s, %s, %i, %sTex_%06lX),", fmtTbl[fmt].c_str(),
- sizTbl[siz].c_str(), www + 1, scene->GetName().c_str(), GETSEGOFFSET(data));
+ sizTbl[siz].c_str(), www + 1, Globals::Instance->lastScene->GetName().c_str(),
+ GETSEGOFFSET(data));
}
}
@@ -1741,7 +1733,6 @@ static int32_t GfxdCallback_DisplayList(uint32_t seg)
dListOffset,
self->GetDListLength(self->parent->GetRawData(), dListOffset, self->dListType),
self->parent);
- newDList->scene = self->scene;
newDList->parent = self->parent;
self->otherDLists.push_back(newDList);
}
@@ -1824,7 +1815,7 @@ std::string ZDisplayList::GetSourceOutputCode(const std::string& prefix)
}
}
- if (scene == nullptr) // TODO: Bit of a hack but it works for now...
+ if (Globals::Instance->lastScene == nullptr) // TODO: Bit of a hack but it works for now...
parent->defines += defines;
// Generate Vertex Declarations
@@ -1836,12 +1827,9 @@ std::string ZDisplayList::GetSourceOutputCode(const std::string& prefix)
for (auto vtx : item.second)
{
- if (curAddr != item.first)
- declaration += "\n";
-
- declaration += vtx.GetBodySourceCode();
+ declaration += StringHelper::Sprintf("\t%s,\n", vtx.GetBodySourceCode().c_str());
- curAddr += 16;
+ curAddr += vtx.GetRawDataSize();
}
vtxDeclarations[item.first] = declaration;
@@ -1857,8 +1845,8 @@ std::string ZDisplayList::GetSourceOutputCode(const std::string& prefix)
}
}
- if (scene != nullptr)
- defines += scene->extDefines;
+ if (Globals::Instance->lastScene != nullptr)
+ defines += Globals::Instance->lastScene->extDefines;
if (parent != nullptr)
{
@@ -1895,7 +1883,7 @@ std::string ZDisplayList::GetSourceOutputCode(const std::string& prefix)
}
}
- if (scene == nullptr) // TODO: Bit of a hack but it works for now...
+ if (Globals::Instance->lastScene == nullptr) // TODO: Bit of a hack but it works for now...
parent->defines += defines;
// Generate Vertex Declarations
@@ -1918,9 +1906,7 @@ std::string ZDisplayList::GetSourceOutputCode(const std::string& prefix)
if (curAddr != vtxKeys[i])
declaration += "\n";
- declaration +=
- StringHelper::Sprintf(" VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i),", vtx.x,
- vtx.y, vtx.z, vtx.s, vtx.t, vtx.r, vtx.g, vtx.b, vtx.a);
+ declaration += StringHelper::Sprintf("\t%s,", vtx.GetBodySourceCode().c_str());
curAddr += 16;
}
@@ -1934,8 +1920,13 @@ std::string ZDisplayList::GetSourceOutputCode(const std::string& prefix)
if (parent != nullptr)
{
- std::string vtxName =
- StringHelper::Sprintf("%sVtx_%06X", prefix.c_str(), vtxKeys[i]);
+ std::string vtxName;
+ ZResource* vtxRes = parent->FindResource(vtxKeys[i]);
+
+ if (vtxRes != nullptr)
+ vtxName = vtxRes->GetName();
+ else
+ vtxName = StringHelper::Sprintf("%sVtx_%06X", prefix.c_str(), vtxKeys[i]);
auto filepath = Globals::Instance->outputPath / vtxName;
std::string incStr = StringHelper::Sprintf("%s.%s.inc", filepath.c_str(), "vtx");
@@ -2037,7 +2028,7 @@ std::string ZDisplayList::ProcessGfxDis(const std::string& prefix)
void ZDisplayList::TextureGenCheck(std::string prefix)
{
- if (TextureGenCheck(scene, parent, prefix, lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg,
+ if (TextureGenCheck(parent, prefix, lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg,
lastTexFmt, lastTexSiz, lastTexLoaded, lastTexIsPalette, this))
{
lastTexAddr = 0;
@@ -2046,10 +2037,10 @@ void ZDisplayList::TextureGenCheck(std::string prefix)
}
}
-bool ZDisplayList::TextureGenCheck(ZRoom* scene, ZFile* parent, [[maybe_unused]] 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(ZFile* parent, [[maybe_unused]] 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);
@@ -2088,21 +2079,20 @@ bool ZDisplayList::TextureGenCheck(ZRoom* scene, ZFile* parent, [[maybe_unused]]
return true;
}
}
- else if (scene != nullptr)
+ else if (Globals::Instance->lastScene != nullptr)
{
- if (scene->parent->GetDeclaration(texAddr) == nullptr)
+ if (Globals::Instance->lastScene->parent->GetDeclaration(texAddr) == nullptr)
{
- ZTexture* tex = scene->parent->GetTextureResource(texAddr);
-
+ ZTexture* tex = Globals::Instance->lastScene->parent->GetTextureResource(texAddr);
if (tex != nullptr)
tex->isPalette = texIsPalette;
else
{
- tex = new ZTexture(scene->parent);
+ tex = new ZTexture(Globals::Instance->lastScene->parent);
tex->FromBinary(texAddr, texWidth, texHeight,
TexFormatToTexType(texFmt, texSiz), texIsPalette);
- scene->parent->AddTextureResource(texAddr, tex);
+ Globals::Instance->lastScene->parent->AddTextureResource(texAddr, tex);
}
if (!texIsPalette)
@@ -2114,9 +2104,9 @@ bool ZDisplayList::TextureGenCheck(ZRoom* scene, ZFile* parent, [[maybe_unused]]
Path::GetFileNameWithoutExtension(tex->GetName());
auto filename = StringHelper::Sprintf("%s.%s.inc.c", filepath.c_str(),
tex->GetExternalExtension().c_str());
- scene->parent->AddDeclarationIncludeArray(texAddr, filename, tex->GetRawDataSize(),
- tex->GetSourceTypeName(), tex->GetName(),
- 0);
+ Globals::Instance->lastScene->parent->AddDeclarationIncludeArray(
+ texAddr, filename, tex->GetRawDataSize(), tex->GetSourceTypeName(),
+ tex->GetName(), 0);
}
return true;
}