using System;
+using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
+using System.Diagnostics;
+using System.Collections.ObjectModel;
using Vintagestory.API.MathTools;
using Vintagestory.API.Common;
+using Vintagestory.API.Client;
using ProtoBuf;
-using System.IO;
-using System.Collections.ObjectModel;
-using System.Text;
-using Vintagestory.API.Client;
+
namespace Automap
{
- [ProtoContract]
+ [ProtoContract(ImplicitFields = ImplicitFields.None)]
public struct ColumnMeta
{
[ProtoMember(1)]
- [DisplayName(0, "Coords.")]
public Vec2i Location;
+ [DisplayName(0, "Coords.")]
+ [ProtoIgnore]
+ public string PrettyLocation;
+
[ProtoMember(2)]
- [DisplayName(1, "Age")]
public TimeSpan ChunkAge;//OLDEST CHUNK. from chunk last edit
- [ProtoMember(3)]
+ [DisplayName(1, "Age")]
+ [ProtoIgnore]
+ public string ShortChunkAge { get => ChunkAge.ToString("c"); }
+
[DisplayName(2, "Temp.")]
+ [ProtoMember(3)]
public float Temperature;// Temperature - surface
- [ProtoMember(4)]
[DisplayName(3, "Y Max.")]
+ [ProtoMember(4)]
public ushort YMax;// Y feature height
[ProtoMember(5)]
- //[DisplayName(10, "Rocks")]
public Dictionary<int, uint> RockRatio;//[Column] Geographic region (rock) Ratio. [BlockID * count]
- [ProtoMember(6)]
+ //[DisplayName(10, "Rocks")]
+ //public JArray FlatRocks
+ //{
+ // get {
+ // string[] rocks = new string[this.RockRatio.Count];
+ // int i = 0;
+ // foreach (var roc in RockRatio)
+ // {
+ // rocks[i++] = $"\"{roc.Key}\":\"{roc.Value}\"";
+ // }
+ // return new JArray(rocks);
+ // }
+ //}
+
+
[DisplayName(4, "Fert.")]
+ [ProtoMember(6)]
public float Fertility;
+ //[DisplayName(5, "Forest")]
[ProtoMember(7)]
- [DisplayName(5, "Forest")]
- public float ForestDensity;
+ public float ForestDensity; // not given to client
- [ProtoMember(8)]
[DisplayName(6, "Rain")]
+ [ProtoMember(8)]
public float Rainfall;
+ //[DisplayName(7, "Shrub")]
[ProtoMember(9)]
- [DisplayName(7, "Shrub")]
- public float ShrubDensity;
+ public float ShrubDensity; // not given to client
- [ProtoMember(10)]
[DisplayName(8, "Air blocks")]
+ [ProtoMember(10)]
public uint AirBlocks;
- [ProtoMember(11)]
[DisplayName(9, "Non-air")]
+ [ProtoMember(11)]
public uint NonAirBlocks;
[ProtoMember(12)]
public ushort[,] HeightMap;//Needs to be 'flattened' for Protocol-Buffer serialization
[ProtoMember(13)]
- private ushort[] _flattened_HeightMap;
+ private ushort[] _flattened_HeightMap;
+ /// <summary>
+ /// Column Presense Bitmap
+ /// </summary>
+ [ProtoIgnore]
+ public BitArray ColumnPresense;
- public ColumnMeta(Vec2i loc, byte chunkSize = 32)
+ public ColumnMeta(Vec2i loc, ICoreClientAPI clientAPI, byte chunkSize = 32, int maxChunkHeight = 16)
{
Location = loc;
+ PrettyLocation = loc.PrettyCoords(clientAPI);
ChunkAge = TimeSpan.Zero;
Temperature = 0f;
YMax = 0;
ChunkSize = chunkSize;
HeightMap = new ushort[ChunkSize, ChunkSize];
_flattened_HeightMap = null;
+ ColumnPresense = new BitArray(maxChunkHeight, false);//TODO: get real chunk height MAX
}
internal void UpdateFieldsFrom(ClimateCondition climate, IMapChunk mapChunk, TimeSpan chunkAge)
this.YMax = mapChunk.YMax;
}
- public void Write(StreamWriter stream, ICoreClientAPI ClientApi)
+ internal void ResetMetadata(int mapSizeY )
{
- // 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("]]");
+ if (this.ColumnPresense == null) { this.ColumnPresense = new BitArray((mapSizeY / this.ChunkSize), false); }
+
+ //Start fresh...
+ HeightMap = new ushort[ChunkSize, ChunkSize];
+ RockRatio = new Dictionary<int, uint>(this.RockRatio.Count);
+ AirBlocks = 0;
+ NonAirBlocks = 0;
+ YMax = 0;
}
[ProtoBeforeSerialization]
[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];
}
+ internal void ClearMetadata( )
+ {
+ this.HeightMap = null;
+ this.RockRatio = null;
+ this._flattened_HeightMap = null;
+ }
+ internal ColumnMeta Reload(ICoreClientAPI clientAPI)
+ {
+ this.PrettyLocation = Location.PrettyCoords(clientAPI);
+ Debug.Write(PrettyLocation == null ? "*" : ",");
+ return this;
+ }
}
public class ColumnsMetadata : KeyedCollection<Vec2i, ColumnMeta>
base.Add(newItem);
}
+ public void ClearMetadata( )
+ {
+ for (int i = 0, maxItemsCount = this.Items.Count; i < maxItemsCount; i++) {
+ ColumnMeta entry = this.Items[i];
+ entry.ClearMetadata( );
+ }
+ }
+
}
-}
\ No newline at end of file
+}