public void Flush() { lock (UndoSaveLock) { int count = _undoTiles.Count; var tiles = UndoTiles.ToArray(); _undoTiles.RemoveRange(0, count); Debug.WriteLine("Flushing Undo Buffer: {0} Tiles", count); for (int i = 0; i < count; i++) { var tile = tiles[i]; if (tile == null || tile.Tile == null) { continue; } _writer.Write(tile.Location.X); _writer.Write(tile.Location.Y); int dataIndex; int headerIndex; byte[] tileData = World.SerializeTileData(tile.Tile, out dataIndex, out headerIndex); _writer.Write(tileData, headerIndex, dataIndex - headerIndex); } Count += count; } }
public void SaveTileData() { var world = ViewModelLocator.WorldViewModel?.CurrentWorld; var version = world?.Version ?? World.CompatibleVersion; var tileFrameImportant = ViewModelLocator.WorldViewModel?.CurrentWorld?.TileFrameImportant ?? World.SettingsTileFrameImportant; lock (UndoSaveLock) { int count = _undoTiles.Count; var tiles = UndoTiles.ToArray(); _undoTiles.RemoveRange(0, count); Debug.WriteLine("Flushing Undo Buffer: {0} Tiles", count); for (int i = 0; i < count; i++) { var tile = tiles[i]; if (tile == null || tile.Tile == null) { continue; } _writer.Write(tile.Location.X); _writer.Write(tile.Location.Y); int dataIndex; int headerIndex; byte[] tileData = World.SerializeTileData(tile.Tile, (int)version, tileFrameImportant, out dataIndex, out headerIndex); _writer.Write(tileData, headerIndex, dataIndex - headerIndex); } Count += count; } }