From a42f75c85ed6f48704e3da05bf3fcfc9d9b47065 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 28 Mar 2021 12:21:47 +0200 Subject: [PATCH] Respect gdt parents when converting to infostring --- src/ObjCommon/InfoString/InfoString.cpp | 37 ++++++++++++++----- src/ObjCommon/InfoString/InfoString.h | 2 +- .../AssetLoaderPhysConstraints.cpp | 2 +- .../T6/AssetLoaders/AssetLoaderPhysPreset.cpp | 2 +- .../T6/AssetLoaders/AssetLoaderTracer.cpp | 2 +- .../T6/AssetLoaders/AssetLoaderVehicle.cpp | 2 +- .../T6/AssetLoaders/AssetLoaderWeapon.cpp | 2 +- .../AssetLoaderWeaponAttachment.cpp | 2 +- .../AssetLoaderWeaponAttachmentUnique.cpp | 2 +- .../T6/AssetLoaders/AssetLoaderZBarrier.cpp | 2 +- 10 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/ObjCommon/InfoString/InfoString.cpp b/src/ObjCommon/InfoString/InfoString.cpp index 89b8217c..449898a1 100644 --- a/src/ObjCommon/InfoString/InfoString.cpp +++ b/src/ObjCommon/InfoString/InfoString.cpp @@ -2,6 +2,7 @@ #include #include +#include const std::string InfoString::EMPTY_VALUE; @@ -196,19 +197,37 @@ bool InfoString::FromStream(const std::string& prefix, std::istream& stream) return true; } -bool InfoString::FromGdtProperties(const std::string& prefix, const GdtEntry& gdtEntry) +bool InfoString::FromGdtProperties(const GdtEntry& gdtEntry) { - const auto foundPrefixEntry = gdtEntry.m_properties.find(GDT_PREFIX_FIELD); - if (foundPrefixEntry == gdtEntry.m_properties.end() || foundPrefixEntry->second != prefix) - return false; + std::stack entryStack; - for(const auto& [key, value] : gdtEntry.m_properties) { - if(key == GDT_PREFIX_FIELD) - continue; + const auto* currentEntry = &gdtEntry; + while (currentEntry) + { + entryStack.push(&gdtEntry); + currentEntry = gdtEntry.m_parent; + } + } - m_keys_by_insertion.push_back(key); - m_values.emplace(std::make_pair(key, value)); + while(!entryStack.empty()) + { + const auto* currentEntry = entryStack.top(); + entryStack.pop(); + + for (const auto& [key, value] : currentEntry->m_properties) + { + auto existingEntry = m_values.find(key); + if(existingEntry == m_values.end()) + { + m_keys_by_insertion.push_back(key); + m_values.emplace(std::make_pair(key, value)); + } + else + { + existingEntry->second = value; + } + } } return true; diff --git a/src/ObjCommon/InfoString/InfoString.h b/src/ObjCommon/InfoString/InfoString.h index 3a43aef3..096a3088 100644 --- a/src/ObjCommon/InfoString/InfoString.h +++ b/src/ObjCommon/InfoString/InfoString.h @@ -28,5 +28,5 @@ public: bool FromStream(std::istream& stream); bool FromStream(const std::string& prefix, std::istream& stream); - bool FromGdtProperties(const std::string& prefix, const GdtEntry& gdtEntry); + bool FromGdtProperties(const GdtEntry& gdtEntry); }; \ No newline at end of file diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.cpp index 7925ad2c..6af31c51 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysConstraints.cpp @@ -113,7 +113,7 @@ bool AssetLoaderPhysConstraints::LoadFromGdt(const std::string& assetName, IGdtQ return false; InfoString infoString; - if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, *gdtEntry)) + if (!infoString.FromGdtProperties(*gdtEntry)) { std::cout << "Failed to read phys constraints gdt entry: \"" << assetName << "\"" << std::endl; return true; diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.cpp index 0eb935c3..26aae976 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderPhysPreset.cpp @@ -96,7 +96,7 @@ bool AssetLoaderPhysPreset::LoadFromGdt(const std::string& assetName, IGdtQuerya return false; InfoString infoString; - if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_PRESET, *gdtEntry)) + if (!infoString.FromGdtProperties(*gdtEntry)) { std::cout << "Failed to read phys preset gdt entry: \"" << assetName << "\"" << std::endl; return true; diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.cpp index a9af4986..d786d25e 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderTracer.cpp @@ -80,7 +80,7 @@ bool AssetLoaderTracer::LoadFromGdt(const std::string& assetName, IGdtQueryable* return false; InfoString infoString; - if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_TRACER, *gdtEntry)) + if (!infoString.FromGdtProperties(*gdtEntry)) { std::cout << "Failed to read tracer gdt entry: \"" << assetName << "\"" << std::endl; return true; diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.cpp index ca42c3f7..13e99db5 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderVehicle.cpp @@ -136,7 +136,7 @@ bool AssetLoaderVehicle::LoadFromGdt(const std::string& assetName, IGdtQueryable return false; InfoString infoString; - if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_VEHICLE, *gdtEntry)) + if (!infoString.FromGdtProperties(*gdtEntry)) { std::cout << "Failed to read vehicle gdt entry: \"" << assetName << "\"" << std::endl; return true; diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp index 6ac279fc..ed7fcf9a 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeapon.cpp @@ -552,7 +552,7 @@ bool AssetLoaderWeapon::LoadFromGdt(const std::string& assetName, IGdtQueryable* return false; InfoString infoString; - if(!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON, *gdtEntry)) + if(!infoString.FromGdtProperties(*gdtEntry)) { std::cout << "Failed to read weapon gdt entry: \"" << assetName << "\"" << std::endl; return true; diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.cpp index b2801293..6f1cf1ba 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachment.cpp @@ -132,7 +132,7 @@ bool AssetLoaderWeaponAttachment::LoadFromGdt(const std::string& assetName, IGdt return false; InfoString infoString; - if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT, *gdtEntry)) + if (!infoString.FromGdtProperties(*gdtEntry)) { std::cout << "Failed to read attachment gdt entry: \"" << assetName << "\"" << std::endl; return true; diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.cpp index cfefa81e..1fd65a4b 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderWeaponAttachmentUnique.cpp @@ -236,7 +236,7 @@ bool AssetLoaderWeaponAttachmentUnique::LoadFromGdt(const std::string& assetName return false; InfoString infoString; - if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_WEAPON_ATTACHMENT_UNIQUE, *gdtEntry)) + if (!infoString.FromGdtProperties(*gdtEntry)) { std::cout << "Failed to read attachment unique gdt entry: \"" << assetName << "\"" << std::endl; return true; diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.cpp index 80d9e0d1..e4f5fe4f 100644 --- a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.cpp +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderZBarrier.cpp @@ -93,7 +93,7 @@ bool AssetLoaderZBarrier::LoadFromGdt(const std::string& assetName, IGdtQueryabl return false; InfoString infoString; - if (!infoString.FromGdtProperties(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, *gdtEntry)) + if (!infoString.FromGdtProperties(*gdtEntry)) { std::cout << "Failed to read zbarrier gdt entry: \"" << assetName << "\"" << std::endl; return true;