Missed RLE

This commit is contained in:
dingo
2025-12-17 20:24:04 -05:00
parent 54ac5feafb
commit 29dbe6974e
+33 -1
View File
@@ -39,7 +39,39 @@ public class DungeonLayout
}
return string.Join("\n", rows);
}
/// <summary>
/// Serialize tiles with run-length encoding for network transmission
/// Format: "tile,count;tile,count;..." where tile is 0 or 1
/// Much more compact for large dungeons
/// </summary>
public string SerializeTilesRLE()
{
var sb = new System.Text.StringBuilder();
int lastTile = Tiles[0, 0];
int count = 0;
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
{
int tile = Tiles[x, y];
if (tile == lastTile)
{
count++;
}
else
{
sb.Append(lastTile).Append(',').Append(count).Append(';');
lastTile = tile;
count = 1;
}
}
}
// Don't forget the last run
sb.Append(lastTile).Append(',').Append(count);
return sb.ToString();
}
public void DeserializeTiles(string data)
{
var rows = data.Split('\n');