summaryrefslogtreecommitdiff
path: root/ZAPD/ZPath.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-05-10 12:25:39 -0400
committerGitHub <noreply@github.com>2021-05-10 12:25:39 -0400
commit769f5702a422d14bfb0a60a39319da4b4bf9ec1f (patch)
tree11e12a20fb2880792722babdee0b5222ea86504f /ZAPD/ZPath.cpp
parenta357277e412b5e8f0f2f0578c7d7d213e8744c8d (diff)
ZRoom refactor (#124)
* Remove redundant methods * first pass os cleaning * More cleaning * Fix compilation errors * Fix dumb crashes * Fix dumb issues * Removing most uses of GenerateSourceCodePass1 * more cleanup * Move segmentOffset to ZRoomCommand * Half of ParseRawData * somehow broken... * fix broken stuff * This may or may not be broken * More cleaning * Remove GenerateSourceCodePass2 * More cleanup and pointer removal * Use PolygonType2 in SetMesh * another small cleanup * Merge PolygonDlist and PolygonDlist2 * More code merging * GetDeclarationPtrName * Remove most repeated externs and a bit of redundant code * Dumb MM fixes * small fix (cherry picked from commit 0813fd69538491c5aceb00d79d19bf59fd082ca7) * Another dumb fix * Remove GenerateExterns * Change DeclareReferences signature * Refactor SetAnimatedTextureList * const std::vector<uint8_t>& * another small bunch of changes * last parserawdata and declarereferences separation probably * Move parserawdata * Remove GenerateSourceCodePass1 * Use macros for commands * Make ZRoomCommand inherit ZResource * shrink scenes tluts * ProcessTextureIntersections * small output improvements * Small changes * run format * SCENE_CMD -> SCENECMD * fix merge errors * run format * fix some warnings * update macros names * Add again different commands for each game ni SCENE_CMD_ROOM_BEHAVIOR * macro update * More booleans * Move declaration to its own file * minor changes * Update according to latest reviews in oot * run format * Yet another cutscene change * Remove special scene/room segment code * This is crashing and I don't know why * remove includeFilePrefix * fix merge issues * always pass a parent to zresource * move path to its own zclass and properly implement parserawdata in commands * Fix GetDeclarationPtrName uses * Some ZPath fixes (still broken tho) * Fix ZPath declarations * Fix weird problem * Add `Path` to the docs * run format * clean syotes code * A bunch of changes for MM * run format
Diffstat (limited to 'ZAPD/ZPath.cpp')
-rw-r--r--ZAPD/ZPath.cpp201
1 files changed, 201 insertions, 0 deletions
diff --git a/ZAPD/ZPath.cpp b/ZAPD/ZPath.cpp
new file mode 100644
index 0000000..63970ae
--- /dev/null
+++ b/ZAPD/ZPath.cpp
@@ -0,0 +1,201 @@
+#include "ZPath.h"
+
+#include "BitConverter.h"
+#include "Globals.h"
+#include "StringHelper.h"
+#include "ZFile.h"
+
+REGISTER_ZFILENODE(Path, ZPath);
+
+ZPath::ZPath(ZFile* nParent) : ZResource(nParent)
+{
+ numPaths = 1;
+}
+
+void ZPath::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
+ const uint32_t nRawDataIndex)
+{
+ ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
+
+ parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, pathways.size() * 8,
+ GetSourceTypeName(), name, pathways.size(), "");
+}
+
+void ZPath::ParseXML(tinyxml2::XMLElement* reader)
+{
+ ZResource::ParseXML(reader);
+
+ const char* numPathsXml = reader->Attribute("NumPaths");
+ if (numPathsXml != nullptr)
+ {
+ numPaths = StringHelper::StrToL(std::string(numPathsXml));
+ if (numPaths < 1)
+ throw std::runtime_error(
+ StringHelper::Sprintf("ZPath::ParseXML: Fatal error in '%s'.\n"
+ "\t Invalid value for attribute 'NumPaths': '%i'\n",
+ name.c_str(), numPaths));
+ }
+}
+
+void ZPath::ParseRawData()
+{
+ ZResource::ParseRawData();
+
+ uint32_t currentPtr = rawDataIndex;
+
+ for (size_t pathIndex = 0; pathIndex < numPaths; pathIndex++)
+ {
+ PathwayEntry path(parent);
+ path.SetRawDataIndex(currentPtr);
+ path.ParseRawData();
+
+ if (path.GetListAddress() == 0)
+ break;
+
+ currentPtr += path.GetRawDataSize();
+ pathways.push_back(path);
+ }
+}
+
+void ZPath::DeclareReferences(const std::string& prefix)
+{
+ ZResource::DeclareReferences(prefix);
+
+ for (auto& entry : pathways)
+ entry.DeclareReferences(prefix);
+}
+
+std::string ZPath::GetBodySourceCode() const
+{
+ std::string declaration = "";
+
+ size_t index = 0;
+ for (const auto& entry : pathways)
+ {
+ declaration += entry.GetBodySourceCode();
+
+ if (index < pathways.size() - 1)
+ declaration += "\n";
+
+ index++;
+ }
+
+ return declaration;
+}
+
+std::string ZPath::GetSourceOutputCode(const std::string& prefix)
+{
+ std::string declaration = GetBodySourceCode();
+
+ Declaration* decl = parent->GetDeclaration(rawDataIndex);
+ if (decl == nullptr || decl->isPlaceholder)
+ parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, pathways.size() * 8,
+ GetSourceTypeName(), name, pathways.size(), declaration);
+ else
+ decl->text = declaration;
+
+ return "";
+}
+
+std::string ZPath::GetSourceTypeName() const
+{
+ return "Path";
+}
+
+size_t ZPath::GetRawDataSize() const
+{
+ return pathways.size() * pathways.at(0).GetRawDataSize();
+}
+
+void ZPath::SetNumPaths(uint32_t nNumPaths)
+{
+ numPaths = nNumPaths;
+}
+
+/* PathwayEntry */
+
+PathwayEntry::PathwayEntry(ZFile* nParent) : ZResource(nParent)
+{
+}
+
+void PathwayEntry::ParseRawData()
+{
+ ZResource::ParseRawData();
+ auto parentRawData = parent->GetRawData();
+ numPoints = parentRawData.at(rawDataIndex + 0);
+ unk1 = parentRawData.at(rawDataIndex + 1);
+ unk2 = BitConverter::ToInt16BE(parentRawData, rawDataIndex + 2);
+ listSegmentAddress = BitConverter::ToInt32BE(parentRawData, rawDataIndex + 4);
+
+ uint32_t currentPtr = GETSEGOFFSET(listSegmentAddress);
+
+ 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);
+ vec.ParseRawData();
+
+ currentPtr += vec.GetRawDataSize();
+ points.push_back(vec);
+ }
+}
+
+void PathwayEntry::DeclareReferences(const std::string& prefix)
+{
+ ZResource::DeclareReferences(prefix);
+ if (points.empty())
+ return;
+
+ std::string declaration = "";
+
+ size_t index = 0;
+ for (const auto& point : points)
+ {
+ declaration += StringHelper::Sprintf("\t%s,", point.GetBodySourceCode().c_str());
+
+ if (index < points.size() - 1)
+ declaration += "\n";
+
+ index++;
+ }
+
+ Declaration* decl = parent->GetDeclaration(GETSEGOFFSET(listSegmentAddress));
+ if (decl == nullptr)
+ {
+ parent->AddDeclarationArray(GETSEGOFFSET(listSegmentAddress), DeclarationAlignment::Align4,
+ DeclarationPadding::Pad4, points.size() * 6,
+ points.at(0).GetSourceTypeName(),
+ StringHelper::Sprintf("%sPathwayList0x%06X", prefix.c_str(),
+ GETSEGOFFSET(listSegmentAddress)),
+ points.size(), declaration);
+ }
+ else
+ decl->text = declaration;
+}
+
+std::string PathwayEntry::GetBodySourceCode() const
+{
+ std::string declaration = "";
+ std::string listName = parent->GetDeclarationPtrName(listSegmentAddress);
+
+ if (Globals::Instance->game == ZGame::MM_RETAIL)
+ declaration +=
+ StringHelper::Sprintf(" { %i, %i, %i, %s },", numPoints, unk1, unk2, listName.c_str());
+ else
+ declaration += StringHelper::Sprintf(" { %i, %s },", numPoints, listName.c_str());
+
+ return declaration;
+}
+
+size_t PathwayEntry::GetRawDataSize() const
+{
+ return 0x08;
+}
+
+segptr_t PathwayEntry::GetListAddress() const
+{
+ return listSegmentAddress;
+}