diff options
| author | Nicholas Estelami <NEstelami@users.noreply.github.com> | 2023-05-05 18:24:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-05 18:24:21 -0400 |
| commit | a8874cf4a6274ff3a0388fb08d43a91b620d3618 (patch) | |
| tree | 3a1b6d995ab77b3b2649a74f7af169f96ea5f9cf /ZAPD/ZFile.cpp | |
| parent | ecc25616ec90e14f3ddcf3c703b7a29d6ccf1f95 (diff) | |
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
Diffstat (limited to 'ZAPD/ZFile.cpp')
| -rw-r--r-- | ZAPD/ZFile.cpp | 85 |
1 files changed, 45 insertions, 40 deletions
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<std::pair<int32_t, Declaration*>> declarationKeys(declarations.begin(), - declarations.end()); - - std::pair<int32_t, Declaration*> lastItem = declarationKeys.at(0); - - for (size_t i = 1; i < declarationKeys.size(); i++) - { - std::pair<int32_t, Declaration*> 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<uint32_t, Declaration*> 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<std::pair<int32_t, Declaration*>> declarationKeys(declarations.begin(), + declarations.end()); + + std::pair<int32_t, Declaration*> lastItem = declarationKeys.at(0); + + for (size_t i = 1; i < declarationKeys.size(); i++) + { + std::pair<int32_t, Declaration*> 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; |
