Missed RLE
This commit is contained in:
@@ -39,7 +39,39 @@ public class DungeonLayout
|
|||||||
}
|
}
|
||||||
return string.Join("\n", rows);
|
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)
|
public void DeserializeTiles(string data)
|
||||||
{
|
{
|
||||||
var rows = data.Split('\n');
|
var rows = data.Split('\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user