diff options
Diffstat (limited to 'ZAPD/ZPath.cpp')
| -rw-r--r-- | ZAPD/ZPath.cpp | 68 |
1 files changed, 24 insertions, 44 deletions
diff --git a/ZAPD/ZPath.cpp b/ZAPD/ZPath.cpp index b57b3cc..7311a4a 100644 --- a/ZAPD/ZPath.cpp +++ b/ZAPD/ZPath.cpp @@ -13,16 +13,6 @@ ZPath::ZPath(ZFile* nParent) : ZResource(nParent) RegisterOptionalAttribute("NumPaths", "1"); } -void ZPath::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) -{ - ZResource::ExtractFromXML(reader, nRawDataIndex); - - Declaration* decl = - parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, pathways.size() * 8, - GetSourceTypeName(), name, pathways.size(), ""); - decl->staticConf = staticConf; -} - void ZPath::ParseXML(tinyxml2::XMLElement* reader) { ZResource::ParseXML(reader); @@ -45,8 +35,7 @@ void ZPath::ParseRawData() for (size_t pathIndex = 0; pathIndex < numPaths; pathIndex++) { PathwayEntry path(parent); - path.SetRawDataIndex(currentPtr); - path.ParseRawData(); + path.ExtractFromFile(currentPtr); if (path.GetListAddress() == 0) break; @@ -64,6 +53,20 @@ void ZPath::DeclareReferences(const std::string& prefix) entry.DeclareReferences(prefix); } +Declaration* ZPath::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + + if (name == "") + auxName = GetDefaultName(prefix); + + Declaration* decl = + parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(), + GetSourceTypeName(), name, pathways.size(), bodyStr); + decl->staticConf = staticConf; + return decl; +} + std::string ZPath::GetBodySourceCode() const { std::string declaration = ""; @@ -82,22 +85,6 @@ std::string ZPath::GetBodySourceCode() const return declaration; } -std::string ZPath::GetSourceOutputCode([[maybe_unused]] const std::string& prefix) -{ - std::string declaration = GetBodySourceCode(); - - Declaration* decl = parent->GetDeclaration(rawDataIndex); - if (decl == nullptr || decl->isPlaceholder) - decl = parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, - pathways.size() * 8, GetSourceTypeName(), name, - pathways.size(), declaration); - else - decl->text = declaration; - decl->staticConf = staticConf; - - return ""; -} - std::string ZPath::GetSourceTypeName() const { return "Path"; @@ -138,10 +125,7 @@ void PathwayEntry::ParseRawData() for (int32_t i = 0; i < numPoints; i++) { ZVector vec(parent); - vec.SetRawDataIndex(currentPtr); - vec.SetScalarType(ZScalarType::ZSCALAR_S16); - vec.SetDimensions(3); - vec.ParseRawData(); + vec.ExtractFromBinary(currentPtr, ZScalarType::ZSCALAR_S16, 3); currentPtr += vec.GetRawDataSize(); points.push_back(vec); @@ -154,12 +138,14 @@ void PathwayEntry::DeclareReferences(const std::string& prefix) if (points.empty()) return; + std::string pointsName = ""; + std::string declaration = ""; size_t index = 0; for (const auto& point : points) { - declaration += StringHelper::Sprintf("\t%s,", point.GetBodySourceCode().c_str()); + declaration += StringHelper::Sprintf("\t{ %s },", point.GetBodySourceCode().c_str()); if (index < points.size() - 1) declaration += "\n"; @@ -167,17 +153,11 @@ void PathwayEntry::DeclareReferences(const std::string& prefix) index++; } - Declaration* decl = parent->GetDeclaration(GETSEGOFFSET(listSegmentAddress)); - if (decl == nullptr) - { - parent->AddDeclarationArray(GETSEGOFFSET(listSegmentAddress), DeclarationAlignment::Align4, - points.size() * 6, points.at(0).GetSourceTypeName(), - StringHelper::Sprintf("%sPathwayList0x%06X", prefix.c_str(), - GETSEGOFFSET(listSegmentAddress)), - points.size(), declaration); - } - else - decl->text = declaration; + uint32_t pointsOffset = Seg2Filespace(listSegmentAddress, parent->baseAddress); + pointsName = StringHelper::Sprintf("%sPathwayList_%06X", prefix.c_str(), pointsOffset); + parent->AddDeclarationArray(pointsOffset, points.at(0).GetDeclarationAlignment(), + points.size() * 6, points.at(0).GetSourceTypeName(), pointsName, + points.size(), declaration); } std::string PathwayEntry::GetBodySourceCode() const |
