From a8874cf4a6274ff3a0388fb08d43a91b620d3618 Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Fri, 5 May 2023 18:24:21 -0400 Subject: Refactor - Clean up ZTexture, ZFile, and Main (#292) * ZTexture and ZFile cleanup * Moved Exporter Set into its own file * Some minor renaming * Arguments handled through dictionary instead of if else chain * Build error fix --- ZAPD/ZFile.cpp | 85 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 40 deletions(-) (limited to 'ZAPD/ZFile.cpp') diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp index f364162..5087a24 100644 --- a/ZAPD/ZFile.cpp +++ b/ZAPD/ZFile.cpp @@ -1011,46 +1011,7 @@ std::string ZFile::ProcessDeclarations() // printf("RANGE START: 0x%06X - RANGE END: 0x%06X\n", rangeStart, rangeEnd); - // Optimization: See if there are any arrays side by side that can be merged... - std::vector> declarationKeys(declarations.begin(), - declarations.end()); - - std::pair lastItem = declarationKeys.at(0); - - for (size_t i = 1; i < declarationKeys.size(); i++) - { - std::pair curItem = declarationKeys[i]; - - if (curItem.second->isArray && lastItem.second->isArray) - { - if (curItem.second->declType == lastItem.second->declType) - { - if (!curItem.second->declaredInXml && !lastItem.second->declaredInXml) - { - // TEST: For now just do Vtx declarations... - if (lastItem.second->declType == "Vtx") - { - int32_t sizeDiff = curItem.first - (lastItem.first + lastItem.second->size); - - // Make sure there isn't an unaccounted inbetween these two - if (sizeDiff == 0) - { - lastItem.second->size += curItem.second->size; - lastItem.second->arrayItemCnt += curItem.second->arrayItemCnt; - lastItem.second->declBody += "\n" + curItem.second->declBody; - declarations.erase(curItem.first); - declarationKeys.erase(declarationKeys.begin() + i); - delete curItem.second; - i--; - continue; - } - } - } - } - } - - lastItem = curItem; - } + MergeNeighboringDeclarations(); for (std::pair item : declarations) ProcessDeclarationText(item.second); @@ -1107,6 +1068,50 @@ std::string ZFile::ProcessDeclarations() return output; } +void ZFile::MergeNeighboringDeclarations() +{ + // Optimization: See if there are any arrays side by side that can be merged... + std::vector> declarationKeys(declarations.begin(), + declarations.end()); + + std::pair lastItem = declarationKeys.at(0); + + for (size_t i = 1; i < declarationKeys.size(); i++) + { + std::pair curItem = declarationKeys[i]; + + if (curItem.second->isArray && lastItem.second->isArray) + { + if (curItem.second->declType == lastItem.second->declType) + { + if (!curItem.second->declaredInXml && !lastItem.second->declaredInXml) + { + // TEST: For now just do Vtx declarations... + if (lastItem.second->declType == "Vtx") + { + int32_t sizeDiff = curItem.first - (lastItem.first + lastItem.second->size); + + // Make sure there isn't an unaccounted inbetween these two + if (sizeDiff == 0) + { + lastItem.second->size += curItem.second->size; + lastItem.second->arrayItemCnt += curItem.second->arrayItemCnt; + lastItem.second->declBody += "\n" + curItem.second->declBody; + declarations.erase(curItem.first); + declarationKeys.erase(declarationKeys.begin() + i); + delete curItem.second; + i--; + continue; + } + } + } + } + } + + lastItem = curItem; + } +} + void ZFile::ProcessDeclarationText(Declaration* decl) { size_t refIndex = 0; -- cgit v1.2.3