diff --git a/radiantcore/map/algorithm/Import.cpp b/radiantcore/map/algorithm/Import.cpp index f696319171..d7a448b81b 100644 --- a/radiantcore/map/algorithm/Import.cpp +++ b/radiantcore/map/algorithm/Import.cpp @@ -374,9 +374,12 @@ void importFromStream(std::istream& stream) } } -ComparisonResult::FingerprintsByType collectFingerprints(const scene::INodePtr& root) +using Fingerprints = std::map; +using FingerprintsByType = std::map; + +FingerprintsByType collectFingerprints(const scene::INodePtr& root) { - ComparisonResult::FingerprintsByType result; + FingerprintsByType result; root->foreachNode([&](const scene::INodePtr& node) { @@ -426,42 +429,32 @@ ComparisonResult::Ptr compareGraphs(const scene::IMapRootNodePtr& target, const for (const auto& sourceEntity : sourceFingerprints[scene::INode::Type::Entity]) { - // Create the collection to hold the of matching node pairs - auto& matchingNodeList = result->equivalentNodes.try_emplace(scene::INode::Type::Entity).first->second; - auto& differingNodes = result->differingNodes.try_emplace(scene::INode::Type::Entity).first->second; - // Check each source node for an equivalent node in the target auto matchingTargetNode = targetEntities.find(sourceEntity.first); if (matchingTargetNode != targetEntities.end()) { // Found an equivalent node - matchingNodeList.emplace_back(ComparisonResult::Match{ sourceEntity.first, sourceEntity.second, matchingTargetNode->second }); + result->equivalentEntities.emplace_back(ComparisonResult::Match{ sourceEntity.first, sourceEntity.second, matchingTargetNode->second }); } else { - differingNodes.emplace(sourceEntity.first, sourceEntity.second); + result->differingEntities.emplace_back(ComparisonResult::Mismatch{ sourceEntity.first, sourceEntity.second }); } } - for (const auto& pair : result->equivalentNodes) - { - rMessage() << "Equivalent Nodes of Type " << static_cast(pair.first) << ": " << pair.second.size() << std::endl; + rMessage() << "Equivalent Entities " << result->equivalentEntities.size() << std::endl; - for (const auto& fingerprintedNode : pair.second) - { - rMessage() << " - Equivalent Node: " << fingerprintedNode.sourceNode->name() << std::endl; - } + for (const auto& match: result->equivalentEntities) + { + rMessage() << " - Equivalent Entity: " << match.sourceNode->name() << std::endl; } - for (const auto& pair : result->differingNodes) - { - rMessage() << "Different Nodes of Type " << static_cast(pair.first) << ": " << pair.second.size() << std::endl; + rMessage() << "Mismatching Entities: " << result->differingEntities.size() << std::endl; - for (const auto& fingerprintedNode : pair.second) - { - rMessage() << " - Differing Node: " << fingerprintedNode.second->name() << std::endl; - } + for (const auto& mismatch : result->differingEntities) + { + rMessage() << " - Differing Entity " << mismatch.sourceNode->name() << std::endl; } return result; diff --git a/radiantcore/map/algorithm/Import.h b/radiantcore/map/algorithm/Import.h index b276016841..4cb80aa248 100644 --- a/radiantcore/map/algorithm/Import.h +++ b/radiantcore/map/algorithm/Import.h @@ -59,8 +59,6 @@ MapFormatPtr determineMapFormat(std::istream& stream); struct ComparisonResult { using Ptr = std::shared_ptr; - using Fingerprints = std::map; - using FingerprintsByType = std::map; // Represents a matching node pair struct Match @@ -70,11 +68,17 @@ struct ComparisonResult scene::INodePtr targetNode; }; - // The collection of nodes with the same fingerprint value, grouped by type - std::map> equivalentNodes; + struct Mismatch + { + std::size_t fingerPrint; + scene::INodePtr sourceNode; + }; + + // The collection of entities with the same fingerprint value + std::list equivalentEntities; - // The collection of nodes with differing fingerprint values, grouped by type - FingerprintsByType differingNodes; + // The collection of entities with differing fingerprint values + std::list differingEntities; }; // Runs a comparison of "source" (to be merged) against the "target" (merge target)