From 4994e732406ffa2942f9c9ea6ff14c424cd0b896 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Tue, 5 Oct 2021 13:55:55 -0300 Subject: ZResource cleanup (#178) * Add some general use methods to ZResource * change zarray * adapt ztexture * Clean up ZCollision, ZPath, ZScalar and ZVector * cleanup background * cleanup zmtx * Clean up skeleton and limb * mark GetSourceTypeName as abstract * Remove redundant ExtractFromXML * Reorder stuff to minimize changes in github * remove extra ZDisplayList constructor * Remove using namespace tinyxml2; * run formatter * Add some brief descriptions, and remove some methods * Remove trivials GetSourceOutputCode and a bit of cleanup * Add more descriptions to methods * Fix blob build * improve descriptions a bit * Run formatter * Now builds * Add attributes and fix some warnings * format * fix merge issues * fix merge issues and some clang warnings * format * Run formatter * Fix merge issues * Format * add SEGMENTED_NULL * Fix merge issues * Run format * dumb fix * whoops * format * whoops --- ZAPD/ZArray.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 15 deletions(-) (limited to 'ZAPD/ZArray.cpp') diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp index f46ee8d..9c562f0 100644 --- a/ZAPD/ZArray.cpp +++ b/ZAPD/ZArray.cpp @@ -1,5 +1,7 @@ #include "ZArray.h" + #include + #include "Globals.h" #include "Utils/StringHelper.h" #include "ZFile.h" @@ -53,30 +55,56 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader) } } -std::string ZArray::GetSourceOutputCode([[maybe_unused]] const std::string& prefix) +Declaration* ZArray::DeclareVar(const std::string& prefix, const std::string& bodyStr) { - std::string output = ""; + std::string auxName = name; - for (size_t i = 0; i < arrayCnt; i++) - { - output += resList.at(i)->GetBodySourceCode(); - output += ","; + if (name == "") + auxName = GetDefaultName(prefix); - if (i < arrayCnt - 1) - output += "\n"; + ZResource* res = resList.at(0); + Declaration* decl; + if (res->IsExternalResource()) + { + auto filepath = Globals::Instance->outputPath / name; + std::string includePath = StringHelper::Sprintf("%s.%s.inc", filepath.c_str(), + res->GetExternalExtension().c_str()); + decl = parent->AddDeclarationIncludeArray(rawDataIndex, includePath, GetRawDataSize(), + GetSourceTypeName(), name, arrayCnt); + decl->text = bodyStr; + decl->isExternal = true; + } + else + { + decl = + parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(), + GetSourceTypeName(), name, arrayCnt, bodyStr); } - Declaration* decl = - parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(), - resList.at(0)->GetSourceTypeName(), name, arrayCnt, output); decl->staticConf = staticConf; - - return ""; + return decl; } -std::string ZArray::GetSourceTypeName() const +std::string ZArray::GetBodySourceCode() const { - return resList.at(0)->GetSourceTypeName(); + std::string output = ""; + + for (size_t i = 0; i < arrayCnt; i++) + { + const auto& res = resList[i]; + output += "\t"; + + if (res->GetResourceType() == ZResourceType::Scalar || + res->GetResourceType() == ZResourceType::Vertex) + output += resList.at(i)->GetBodySourceCode(); + else + output += StringHelper::Sprintf("{ %s }", resList.at(i)->GetBodySourceCode().c_str()); + + if (i < arrayCnt - 1 || res->IsExternalResource()) + output += ",\n"; + } + + return output; } size_t ZArray::GetRawDataSize() const @@ -87,7 +115,17 @@ size_t ZArray::GetRawDataSize() const return size; } +std::string ZArray::GetSourceTypeName() const +{ + return resList.at(0)->GetSourceTypeName(); +} + ZResourceType ZArray::GetResourceType() const { return ZResourceType::Array; } + +DeclarationAlignment ZArray::GetDeclarationAlignment() const +{ + return resList.at(0)->GetDeclarationAlignment(); +} -- cgit v1.2.3