summaryrefslogtreecommitdiff
path: root/ZAPD/ZArray.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-10-05 13:55:55 -0300
committerGitHub <noreply@github.com>2021-10-05 12:55:55 -0400
commit4994e732406ffa2942f9c9ea6ff14c424cd0b896 (patch)
tree0b40b20db17139c58f5c205643940494c20cbc43 /ZAPD/ZArray.cpp
parent17fca1e0cdda5476c4158940ca405b7eb250ec72 (diff)
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
Diffstat (limited to 'ZAPD/ZArray.cpp')
-rw-r--r--ZAPD/ZArray.cpp68
1 files changed, 53 insertions, 15 deletions
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 <cassert>
+
#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();
+}