summaryrefslogtreecommitdiff
path: root/ZAPD/ZVector.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/ZVector.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/ZVector.cpp')
-rw-r--r--ZAPD/ZVector.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/ZAPD/ZVector.cpp b/ZAPD/ZVector.cpp
index 31d5dc4..29bf3bf 100644
--- a/ZAPD/ZVector.cpp
+++ b/ZAPD/ZVector.cpp
@@ -1,5 +1,7 @@
#include "ZVector.h"
-#include <assert.h>
+
+#include <cassert>
+
#include "Globals.h"
#include "Utils/BitConverter.h"
#include "Utils/File.h"
@@ -17,6 +19,16 @@ ZVector::ZVector(ZFile* nParent) : ZResource(nParent)
RegisterRequiredAttribute("Dimensions");
}
+void ZVector::ExtractFromBinary(uint32_t nRawDataIndex, ZScalarType nScalarType,
+ uint32_t nDimensions)
+{
+ rawDataIndex = nRawDataIndex;
+ scalarType = nScalarType;
+ dimensions = nDimensions;
+
+ ParseRawData();
+}
+
void ZVector::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
@@ -34,9 +46,8 @@ void ZVector::ParseRawData()
for (uint32_t i = 0; i < dimensions; i++)
{
- ZScalar scalar(scalarType, parent);
- scalar.rawDataIndex = currentRawDataIndex;
- scalar.ParseRawData();
+ ZScalar scalar(parent);
+ scalar.ExtractFromBinary(currentRawDataIndex, scalarType);
currentRawDataIndex += scalar.GetRawDataSize();
scalars.push_back(scalar);
@@ -86,20 +97,15 @@ std::string ZVector::GetBodySourceCode() const
{
std::string body = "";
- for (size_t i = 0; i < this->scalars.size(); i++)
- body += StringHelper::Sprintf("%6s, ", scalars[i].GetBodySourceCode().c_str());
-
- return "{ " + body + "}";
-}
+ for (size_t i = 0; i < scalars.size(); i++)
+ {
+ body += StringHelper::Sprintf("%6s", scalars[i].GetBodySourceCode().c_str());
-std::string ZVector::GetSourceOutputCode([[maybe_unused]] const std::string& prefix)
-{
- Declaration* decl =
- parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
- GetSourceTypeName(), GetName(), GetBodySourceCode());
- decl->staticConf = staticConf;
+ if (i + 1 < scalars.size())
+ body += ", ";
+ }
- return "";
+ return body;
}
ZResourceType ZVector::GetResourceType() const
@@ -107,12 +113,7 @@ ZResourceType ZVector::GetResourceType() const
return ZResourceType::Vector;
}
-void ZVector::SetScalarType(ZScalarType type)
-{
- scalarType = type;
-}
-
-void ZVector::SetDimensions(uint32_t dim)
+DeclarationAlignment ZVector::GetDeclarationAlignment() const
{
- dimensions = dim;
+ return scalars.at(0).GetDeclarationAlignment();
}