From 769f5702a422d14bfb0a60a39319da4b4bf9ec1f Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Mon, 10 May 2021 12:25:39 -0400 Subject: ZRoom refactor (#124) * Remove redundant methods * first pass os cleaning * More cleaning * Fix compilation errors * Fix dumb crashes * Fix dumb issues * Removing most uses of GenerateSourceCodePass1 * more cleanup * Move segmentOffset to ZRoomCommand * Half of ParseRawData * somehow broken... * fix broken stuff * This may or may not be broken * More cleaning * Remove GenerateSourceCodePass2 * More cleanup and pointer removal * Use PolygonType2 in SetMesh * another small cleanup * Merge PolygonDlist and PolygonDlist2 * More code merging * GetDeclarationPtrName * Remove most repeated externs and a bit of redundant code * Dumb MM fixes * small fix (cherry picked from commit 0813fd69538491c5aceb00d79d19bf59fd082ca7) * Another dumb fix * Remove GenerateExterns * Change DeclareReferences signature * Refactor SetAnimatedTextureList * const std::vector& * another small bunch of changes * last parserawdata and declarereferences separation probably * Move parserawdata * Remove GenerateSourceCodePass1 * Use macros for commands * Make ZRoomCommand inherit ZResource * shrink scenes tluts * ProcessTextureIntersections * small output improvements * Small changes * run format * SCENE_CMD -> SCENECMD * fix merge errors * run format * fix some warnings * update macros names * Add again different commands for each game ni SCENE_CMD_ROOM_BEHAVIOR * macro update * More booleans * Move declaration to its own file * minor changes * Update according to latest reviews in oot * run format * Yet another cutscene change * Remove special scene/room segment code * This is crashing and I don't know why * remove includeFilePrefix * fix merge issues * always pass a parent to zresource * move path to its own zclass and properly implement parserawdata in commands * Fix GetDeclarationPtrName uses * Some ZPath fixes (still broken tho) * Fix ZPath declarations * Fix weird problem * Add `Path` to the docs * run format * clean syotes code * A bunch of changes for MM * run format --- ZAPD/ZVector.cpp | 72 ++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 38 deletions(-) (limited to 'ZAPD/ZVector.cpp') diff --git a/ZAPD/ZVector.cpp b/ZAPD/ZVector.cpp index 011ed2a..51c8452 100644 --- a/ZAPD/ZVector.cpp +++ b/ZAPD/ZVector.cpp @@ -10,22 +10,8 @@ REGISTER_ZFILENODE(Vector, ZVector); ZVector::ZVector(ZFile* nParent) : ZResource(nParent) { - scalars = std::vector(); - this->scalarType = ZSCALAR_NONE; - this->dimensions = 0; -} - -ZVector::~ZVector() -{ - ClearScalars(); -} - -void ZVector::ClearScalars() -{ - for (auto s : scalars) - delete s; - - scalars.clear(); + scalarType = ZScalarType::ZSCALAR_NONE; + dimensions = 0; } void ZVector::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, @@ -47,23 +33,23 @@ void ZVector::ParseXML(tinyxml2::XMLElement* reader) void ZVector::ParseRawData() { - int32_t currentRawDataIndex = this->rawDataIndex; - - ClearScalars(); + int32_t currentRawDataIndex = rawDataIndex; + // TODO: this shouldn't be necessary. + scalars.clear(); - for (uint32_t i = 0; i < this->dimensions; i++) + for (uint32_t i = 0; i < dimensions; i++) { - ZScalar* scalar = new ZScalar(this->scalarType, this->parent); - scalar->rawDataIndex = currentRawDataIndex; - scalar->rawData = this->rawData; - scalar->ParseRawData(); - currentRawDataIndex += scalar->GetRawDataSize(); + ZScalar scalar(scalarType, parent); + scalar.rawDataIndex = currentRawDataIndex; + scalar.rawData = rawData; + scalar.ParseRawData(); + currentRawDataIndex += scalar.GetRawDataSize(); - this->scalars.push_back(scalar); + scalars.push_back(scalar); } // Ensure the scalars vector has the same number of elements as the vector dimension. - assert(this->scalars.size() == this->dimensions); + assert(scalars.size() == dimensions); } size_t ZVector::GetRawDataSize() const @@ -71,7 +57,7 @@ size_t ZVector::GetRawDataSize() const size_t size = 0; for (size_t i = 0; i < this->scalars.size(); i++) - size += this->scalars[i]->GetRawDataSize(); + size += this->scalars[i].GetRawDataSize(); return size; } @@ -83,11 +69,11 @@ bool ZVector::DoesSupportArray() const std::string ZVector::GetSourceTypeName() const { - if (dimensions == 3 && scalarType == ZSCALAR_F32) + if (dimensions == 3 && scalarType == ZScalarType::ZSCALAR_F32) return "Vec3f"; - else if (dimensions == 3 && scalarType == ZSCALAR_S16) + else if (dimensions == 3 && scalarType == ZScalarType::ZSCALAR_S16) return "Vec3s"; - else if (dimensions == 3 && scalarType == ZSCALAR_S32) + else if (dimensions == 3 && scalarType == ZScalarType::ZSCALAR_S32) return "Vec3i"; else { @@ -95,28 +81,28 @@ std::string ZVector::GetSourceTypeName() const "Encountered unsupported vector type: %d dimensions, %s type", dimensions, ZScalar::MapScalarTypeToOutputType(scalarType).c_str()); - if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) + if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG) printf("%s\n", output.c_str()); throw std::runtime_error(output); } } -std::string ZVector::GetSourceValue() const +std::string ZVector::GetBodySourceCode() const { - std::vector strings = std::vector(); + std::string body = ""; for (size_t i = 0; i < this->scalars.size(); i++) - strings.push_back(scalars[i]->GetSourceValue()); + body += StringHelper::Sprintf("%6s, ", scalars[i].GetBodySourceCode().c_str()); - return "{ " + StringHelper::Implode(strings, ", ") + " }"; + return "{ " + body + "}"; } std::string ZVector::GetSourceOutputCode(const std::string& prefix) { if (parent != nullptr) parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), - GetSourceTypeName(), GetName(), GetSourceValue()); + GetSourceTypeName(), GetName(), GetBodySourceCode()); return ""; } @@ -124,4 +110,14 @@ std::string ZVector::GetSourceOutputCode(const std::string& prefix) ZResourceType ZVector::GetResourceType() const { return ZResourceType::Vector; -} \ No newline at end of file +} + +void ZVector::SetScalarType(ZScalarType type) +{ + scalarType = type; +} + +void ZVector::SetDimensions(uint32_t dim) +{ + dimensions = dim; +} -- cgit v1.2.3