Switch wall autotiling to strict floor-touch pattern classification
- Replace broad cardinal HashSet matching with deterministic mask-based bucket candidates - Prevent corner buckets on straight one-side walls - Route adjacent-two elbow masks only through corner bucket families - Keep complex/opposite masks on full/8-dir bucket families to avoid impossible placements
This commit is contained in:
@@ -534,48 +534,16 @@ public class DungeonGeneratorVNext
|
|||||||
foreach (var cell in wallCells)
|
foreach (var cell in wallCells)
|
||||||
{
|
{
|
||||||
int mask4 = ComputeCardinalMask(layout, cell.X, cell.Y);
|
int mask4 = ComputeCardinalMask(layout, cell.X, cell.Y);
|
||||||
string? bucketName = ResolveCardinalBucketName(mask4);
|
|
||||||
if (string.IsNullOrEmpty(bucketName))
|
|
||||||
{
|
|
||||||
unresolved.Add(cell);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this cell has a specific 8-direction corner/diagonal match that exists in the
|
|
||||||
// current palette, defer to pass 2 so corners do not get flattened by broad cardinal buckets.
|
|
||||||
int mask8 = ComputeEightDirectionMask(layout, cell.X, cell.Y);
|
int mask8 = ComputeEightDirectionMask(layout, cell.X, cell.Y);
|
||||||
string? specific8Bucket = ResolveEightDirectionBucketName(mask8);
|
|
||||||
if (!string.IsNullOrEmpty(specific8Bucket) &&
|
|
||||||
CornerPriorityEightBuckets.Contains(specific8Bucket) &&
|
|
||||||
tileContext.WallDefinitionsByCanonicalBucket.TryGetValue(specific8Bucket, out var defs8) &&
|
|
||||||
defs8.Count > 0)
|
|
||||||
{
|
|
||||||
unresolved.Add(cell);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TileDefinition? wallDef = null;
|
TileDefinition? wallDef = null;
|
||||||
|
|
||||||
// Elbow masks should prefer corner buckets before broad cardinal buckets.
|
// Strict geometry-driven bucket candidate order based on floor adjacency.
|
||||||
foreach (var elbowBucket in ResolveElbowBucketCandidates(mask4))
|
foreach (var bucketCandidate in ResolveWallBucketCandidates(mask4, mask8))
|
||||||
{
|
{
|
||||||
wallDef = SelectWallDefinitionForBucket(tileContext, elbowBucket);
|
wallDef = SelectWallDefinitionForBucket(tileContext, bucketCandidate);
|
||||||
if (wallDef != null) break;
|
if (wallDef != null) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wallDef ??= SelectWallDefinitionForBucket(tileContext, bucketName);
|
|
||||||
|
|
||||||
if (wallDef == null)
|
|
||||||
{
|
|
||||||
// Try any 8-direction bucket before deferring to pass 2.
|
|
||||||
int fallbackMask8 = ComputeEightDirectionMask(layout, cell.X, cell.Y);
|
|
||||||
string? any8Bucket = ResolveEightDirectionBucketName(fallbackMask8);
|
|
||||||
if (!string.IsNullOrEmpty(any8Bucket))
|
|
||||||
{
|
|
||||||
wallDef = SelectWallDefinitionForBucket(tileContext, any8Bucket);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wallDef == null)
|
if (wallDef == null)
|
||||||
{
|
{
|
||||||
unresolved.Add(cell);
|
unresolved.Add(cell);
|
||||||
@@ -859,25 +827,22 @@ public class DungeonGeneratorVNext
|
|||||||
return layout.Walkable![x, y];
|
return layout.Walkable![x, y];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? ResolveCardinalBucketName(int mask4)
|
private static IReadOnlyList<string> ResolveWallBucketCandidates(int mask4, int mask8)
|
||||||
{
|
|
||||||
foreach (var mapping in CardinalBucketMasks)
|
|
||||||
{
|
|
||||||
if (mapping.Value.Contains(mask4))
|
|
||||||
{
|
|
||||||
return mapping.Key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IReadOnlyList<string> ResolveElbowBucketCandidates(int mask4)
|
|
||||||
{
|
{
|
||||||
// mask4 bit order: N,E,S,W
|
// mask4 bit order: N,E,S,W
|
||||||
|
// Strict selection to avoid impossible tiles:
|
||||||
|
// - one-side touch => straight wall bucket
|
||||||
|
// - adjacent-two => corner buckets only
|
||||||
|
// - opposite-two/all-three/all-four => full/complex buckets
|
||||||
return mask4 switch
|
return mask4 switch
|
||||||
{
|
{
|
||||||
// For a cell touching floor on E+S, the visible cap points down-right.
|
// One cardinal neighbor.
|
||||||
|
0b0010 => new[] { "WallTop" }, // S
|
||||||
|
0b0001 => new[] { "WallSideRight" }, // W
|
||||||
|
0b0100 => new[] { "WallSideLeft" }, // E
|
||||||
|
0b1000 => new[] { "WallBottom" }, // N
|
||||||
|
|
||||||
|
// Adjacent two-neighbor elbows must use corner families.
|
||||||
0b0110 => new[]
|
0b0110 => new[]
|
||||||
{
|
{
|
||||||
"WallDiagonalCornerDownRight",
|
"WallDiagonalCornerDownRight",
|
||||||
@@ -885,7 +850,6 @@ public class DungeonGeneratorVNext
|
|||||||
"WallDiagonalCornerUpLeft",
|
"WallDiagonalCornerUpLeft",
|
||||||
"WallInnerCornerDownLeft"
|
"WallInnerCornerDownLeft"
|
||||||
},
|
},
|
||||||
// Floor on S+W -> cap points down-left.
|
|
||||||
0b0011 => new[]
|
0b0011 => new[]
|
||||||
{
|
{
|
||||||
"WallDiagonalCornerDownLeft",
|
"WallDiagonalCornerDownLeft",
|
||||||
@@ -893,7 +857,6 @@ public class DungeonGeneratorVNext
|
|||||||
"WallDiagonalCornerUpRight",
|
"WallDiagonalCornerUpRight",
|
||||||
"WallInnerCornerDownRight"
|
"WallInnerCornerDownRight"
|
||||||
},
|
},
|
||||||
// Floor on N+E -> cap points up-right.
|
|
||||||
0b1100 => new[]
|
0b1100 => new[]
|
||||||
{
|
{
|
||||||
"WallDiagonalCornerUpRight",
|
"WallDiagonalCornerUpRight",
|
||||||
@@ -901,7 +864,6 @@ public class DungeonGeneratorVNext
|
|||||||
"WallDiagonalCornerDownLeft",
|
"WallDiagonalCornerDownLeft",
|
||||||
"WallInnerCornerDownLeft"
|
"WallInnerCornerDownLeft"
|
||||||
},
|
},
|
||||||
// Floor on N+W -> cap points up-left.
|
|
||||||
0b1001 => new[]
|
0b1001 => new[]
|
||||||
{
|
{
|
||||||
"WallDiagonalCornerUpLeft",
|
"WallDiagonalCornerUpLeft",
|
||||||
@@ -909,10 +871,23 @@ public class DungeonGeneratorVNext
|
|||||||
"WallDiagonalCornerDownRight",
|
"WallDiagonalCornerDownRight",
|
||||||
"WallInnerCornerDownRight"
|
"WallInnerCornerDownRight"
|
||||||
},
|
},
|
||||||
_ => Array.Empty<string>()
|
|
||||||
|
// Opposite-two / three / four neighbors: use complex/full buckets.
|
||||||
|
_ => ResolveComplexBucketCandidates(mask8)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IReadOnlyList<string> ResolveComplexBucketCandidates(int mask8)
|
||||||
|
{
|
||||||
|
string? exact8 = ResolveEightDirectionBucketName(mask8);
|
||||||
|
if (!string.IsNullOrEmpty(exact8))
|
||||||
|
{
|
||||||
|
return new[] { exact8, "WallFullEightDirections", "WallFull", "WallTop" };
|
||||||
|
}
|
||||||
|
|
||||||
|
return new[] { "WallFullEightDirections", "WallFull", "WallTop" };
|
||||||
|
}
|
||||||
|
|
||||||
private static string? ResolveEightDirectionBucketName(int mask8)
|
private static string? ResolveEightDirectionBucketName(int mask8)
|
||||||
{
|
{
|
||||||
foreach (var mapping in EightDirectionBucketMasks)
|
foreach (var mapping in EightDirectionBucketMasks)
|
||||||
|
|||||||
Reference in New Issue
Block a user