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/ZVector.cpp | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'ZAPD/ZVector.cpp') 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 + +#include + #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(); } -- cgit v1.2.3