Skip to content

Commit

Permalink
#5643: Implemented layer addition handling, unit test case is green
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jun 24, 2021
1 parent fbe6af7 commit eeff905
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 31 additions & 3 deletions libs/scene/merge/ThreeWayLayerMerger.h
Expand Up @@ -316,18 +316,46 @@ class ThreeWayLayerMerger :
for (const auto& layerName : conflictingNames)
{
// Double-check the target layer, it might be 100% matching the imported one
// TODO
if (sourceAndTargetLayersAreEquivalent(layerName))
{
_log << "The layer " << layerName.get() << " turns out to be equivalent to the one in the target map, won't import" << std::endl;
continue;
}

// Layer name is in use, find a new name
auto newName = generateUnusedLayerName(_targetManager, layerName);
auto newName = GenerateUnusedLayerName(_targetManager, layerName);

// Layer name is not in use, accept this addition verbatim
_log << "Layer name " << layerName.get() << " is in use in target, will add this layer as " << newName << std::endl;
importLayerToTargetMap(layerName, newName);
}
}

std::string generateUnusedLayerName(ILayerManager& layerManager, const std::string& name)
bool sourceAndTargetLayersAreEquivalent(const std::string& layerName)
{
auto existingLayer = GetLayerMemberFingerprints(_targetRoot, _targetManager.getLayerID(layerName));
auto importedLayer = GetLayerMemberFingerprints(_sourceRoot, _sourceManager.getLayerID(layerName));

// Check the size of the maps, and compare all keys
if (existingLayer.size() != importedLayer.size())
{
return false; // size mismatch
}

// Size is the same, check every fingerprint
for (const auto& pair : importedLayer)
{
if (existingLayer.count(pair.first) != 1)
{
return false; // mismatch
}
}

// Every fingerprint matches, or the sets are both empty
return true;
}

static std::string GenerateUnusedLayerName(ILayerManager& layerManager, const std::string& name)
{
std::size_t suffix = 1;

Expand Down
2 changes: 1 addition & 1 deletion test/MapMerging.cpp
Expand Up @@ -2682,7 +2682,7 @@ TEST_F(ThreeWayLayerMergeTest, LayerAddedInSource)
EXPECT_NE(targetManager.getLayerID("NewLayer4"), -1);

// NewLayer5 should never be created, NewLayer3 might be renamed to this if the algorithm doesn't check 100% matches
EXPECT_NE(targetManager.getLayerID("NewLayer5"), -1);
EXPECT_EQ(targetManager.getLayerID("NewLayer5"), -1);

auto brush11 = algorithm::findFirstBrushWithMaterial(algorithm::findWorldspawn(merger->getTargetRoot()), "textures/numbers/11");
auto expandable = algorithm::getEntityByName(merger->getTargetRoot(), "expandable");
Expand Down

0 comments on commit eeff905

Please sign in to comment.