Add safe fallback bucket resolution for rare unmapped wall masks
- Keep exact 8-direction bucket matching as primary selection - For unmatched masks, derive deterministic fallback candidates from cardinal/diagonal bits - Prevent isolated untiled wall cells in complex junction edge cases
This commit is contained in:
@@ -532,13 +532,24 @@ public class DungeonGeneratorVNext
|
||||
foreach (var cell in wallCells)
|
||||
{
|
||||
int mask8 = ComputeEightDirectionMask(layout, cell.X, cell.Y);
|
||||
TileDefinition? wallDef = null;
|
||||
string? directionalBucket = ResolveDirectionalWallBucket(mask8);
|
||||
if (string.IsNullOrEmpty(directionalBucket))
|
||||
if (!string.IsNullOrEmpty(directionalBucket))
|
||||
{
|
||||
continue;
|
||||
wallDef = SelectWallDefinitionForBucket(tileContext, directionalBucket);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var fallbackBucket in ResolveDirectionalFallbackBuckets(mask8))
|
||||
{
|
||||
wallDef = SelectWallDefinitionForBucket(tileContext, fallbackBucket);
|
||||
if (wallDef != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TileDefinition? wallDef = SelectWallDefinitionForBucket(tileContext, directionalBucket);
|
||||
if (wallDef == null)
|
||||
{
|
||||
continue;
|
||||
@@ -823,6 +834,46 @@ public class DungeonGeneratorVNext
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IEnumerable<string> ResolveDirectionalFallbackBuckets(int mask8)
|
||||
{
|
||||
// Bit order N, NE, E, SE, S, SW, W, NW.
|
||||
bool n = (mask8 & 0b1000_0000) != 0;
|
||||
bool e = (mask8 & 0b0010_0000) != 0;
|
||||
bool s = (mask8 & 0b0000_1000) != 0;
|
||||
bool w = (mask8 & 0b0000_0010) != 0;
|
||||
bool ne = (mask8 & 0b0100_0000) != 0;
|
||||
bool se = (mask8 & 0b0001_0000) != 0;
|
||||
bool sw = (mask8 & 0b0000_0100) != 0;
|
||||
bool nw = (mask8 & 0b0000_0001) != 0;
|
||||
|
||||
// Prefer large corner profiles if adjacent cardinals exist.
|
||||
if (n && w) yield return "NWCornerLarge";
|
||||
if (n && e) yield return "NECornerLarge";
|
||||
if (s && e) yield return "SECornerLarge";
|
||||
if (s && w) yield return "SWCornerLarge";
|
||||
|
||||
// Cardinal fallbacks for 3-way / complex masks.
|
||||
if (n) yield return "Wall_N";
|
||||
if (e) yield return "Wall_E";
|
||||
if (s) yield return "Wall_S";
|
||||
if (w) yield return "Wall_W";
|
||||
|
||||
// If no cardinal bits exist, allow single-diagonal corners.
|
||||
if (!n && !e && !s && !w)
|
||||
{
|
||||
if (nw) yield return "NWCornerSingle";
|
||||
if (ne) yield return "NECornerSingle";
|
||||
if (se) yield return "SECornerSingle";
|
||||
if (sw) yield return "SWCornerSingle";
|
||||
}
|
||||
|
||||
// Last-resort directional defaults to avoid untiled wall cells.
|
||||
yield return "Wall_N";
|
||||
yield return "Wall_E";
|
||||
yield return "Wall_S";
|
||||
yield return "Wall_W";
|
||||
}
|
||||
|
||||
private sealed record TileBuildContext(
|
||||
Dictionary<int, TileMapSheet> SheetsById,
|
||||
List<TileDefinition> FloorCandidates,
|
||||
|
||||
Reference in New Issue
Block a user