OSDN Git Service

Potential fix for Memory leak - Clear (some) Metadata post persist
[automap/automap.git] / Automap / Data / ColumnMeta.cs
index 9fd9aef..b767066 100644 (file)
@@ -102,26 +102,6 @@ namespace Automap
                        this.YMax = mapChunk.YMax;
                }
 
-               public void Write(StreamWriter stream, ICoreClientAPI ClientApi)
-               {
-                       // this is gross i hate this
-                       stream.Write("['{0}_{1}',[",
-                               Location.X,
-                               Location.Y
-                               );
-                       stream.Write("'{0}',", Location.PrettyCoords(ClientApi));
-                       stream.Write("'{0}',", ChunkAge);
-                       stream.Write("'{0}',", Temperature.ToString("F3"));
-                       stream.Write("'{0}',", YMax);
-                       stream.Write("'{0}',", Fertility.ToString("F3"));
-                       stream.Write("'{0}',", ForestDensity.ToString("F3"));
-                       stream.Write("'{0}',", Rainfall.ToString("F3"));
-                       stream.Write("'{0}',", ShrubDensity.ToString("F3"));
-                       stream.Write("'{0}',", AirBlocks);
-                       stream.Write("'{0}',", NonAirBlocks);
-                       stream.Write("]]");
-               }
-
                [ProtoBeforeSerialization]
                private void PrepareData()
                {
@@ -148,18 +128,22 @@ namespace Automap
                [ProtoAfterDeserialization]
                private void PostProcess()
                {
-                       if (this.HeightMap == null) this.HeightMap = new ushort[ChunkSize, ChunkSize];
+                       ChunkSize = (ChunkSize == byte.MinValue) ? (byte)32 : ChunkSize;//Not good - if chunk wasn't 32 orignally!
+
+                       if (this.HeightMap == null || this.HeightMap.Length != (ChunkSize * ChunkSize)) {
+                       this.HeightMap = new ushort[ChunkSize, ChunkSize];
+                       }
 
                        if (_flattened_HeightMap != null)
                        {
                                int col, row;
-                               _ = new BitVector32(0);
+                               var bitMasker = new BitVector32(0);
                                var rowSection = BitVector32.CreateSection((short) (ChunkSize - 1));
                                var colSection = BitVector32.CreateSection((short) (ChunkSize - 1), rowSection);
 
                                for (uint rowcol = 0; rowcol < (ChunkSize * ChunkSize); rowcol++)
                                {
-                                       BitVector32 bitMasker = new BitVector32(data: (int) rowcol);
+                                       bitMasker = new BitVector32(data: (int) rowcol);
                                        row = bitMasker[rowSection];
                                        col = bitMasker[colSection];
                                        HeightMap[col, row] = _flattened_HeightMap[rowcol];
@@ -251,5 +235,14 @@ namespace Automap
                        base.Add(newItem);
                }
 
+               public void ClearMetadata( )
+               {
+               for (int i = 0, maxItemsCount = this.Items.Count; i < maxItemsCount; i++) {
+               ColumnMeta entry = this.Items[i];
+               entry.HeightMap = null;
+               entry.RockRatio = null;//Also regenerated when any chunk in a column is changed...
+               }
+               }
+
        }
-}
\ No newline at end of file
+}