using System;
+using System.Collections;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
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;
namespace Automap
{
- [ProtoContract]
+ [ProtoContract(ImplicitFields = ImplicitFields.None)]
public struct ColumnMeta
{
[ProtoMember(1)]
public Vec2i Location;
+ [DisplayName(0, "Coords.")]
+ [ProtoIgnore]
+ public string PrettyLocation;
+
[ProtoMember(2)]
public TimeSpan ChunkAge;//OLDEST CHUNK. from chunk last edit
+ [DisplayName(1, "Age")]
+ [ProtoIgnore]
+ public string ShortChunkAge { get => ChunkAge.ToString("c"); }
+
+ [DisplayName(2, "Temp.")]
[ProtoMember(3)]
public float Temperature;// Temperature - surface
+ [DisplayName(3, "Y Max.")]
[ProtoMember(4)]
public ushort YMax;// Y feature height
[ProtoMember(5)]
public Dictionary<int, uint> RockRatio;//[Column] Geographic region (rock) Ratio. [BlockID * count]
+ //[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)]
- public float ForestDensity;
+ public float ForestDensity; // not given to client
+ [DisplayName(6, "Rain")]
[ProtoMember(8)]
public float Rainfall;
+ //[DisplayName(7, "Shrub")]
[ProtoMember(9)]
- public float ShrubDensity;
+ public float ShrubDensity; // not given to client
+ [DisplayName(8, "Air blocks")]
[ProtoMember(10)]
public uint AirBlocks;
+ [DisplayName(9, "Non-air")]
[ProtoMember(11)]
public uint NonAirBlocks;
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;
}
-
+ internal void ResetMetadata(int mapSizeY )
+ {
+ 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]
- private void PrepareData( )
+ private void PrepareData()
{
- if (HeightMap != null) {
- _flattened_HeightMap = new ushort[ChunkSize * ChunkSize];
- int flatIndex = 0;
+ if (HeightMap != null)
+ {
+ _flattened_HeightMap = new ushort[ChunkSize * ChunkSize];
+ int flatIndex = 0;
+
+ for (byte col = 0; col < ChunkSize; col++)
+ {
+ for (byte row = 0; row < ChunkSize; row++)
+ {
+ _flattened_HeightMap[flatIndex] = HeightMap[col, row];
+ flatIndex++;
+ }
+ }
- for (byte col = 0; col < ChunkSize; col++) {
- for (byte row = 0; row < ChunkSize; row++) {
- _flattened_HeightMap[flatIndex] = HeightMap[col, row];
- flatIndex++;
}
- }
-
- }
}
[ProtoAfterDeserialization]
- private void PostProcess( )
+ 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 (_flattened_HeightMap != null) {
- int col, row;
+ if (this.HeightMap == null || this.HeightMap.Length != (ChunkSize * ChunkSize)) {
+ this.HeightMap = new ushort[ChunkSize, ChunkSize];
+ }
- BitVector32 bitMasker = new BitVector32(0);
- var rowSection = BitVector32.CreateSection(( short )(ChunkSize - 1));
- var colSection = BitVector32.CreateSection(( short )(ChunkSize - 1), rowSection);
+ if (_flattened_HeightMap != null)
+ {
+ int col, row;
+ 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++)
+ {
+ bitMasker = new BitVector32(data: (int) rowcol);
+ row = bitMasker[rowSection];
+ col = bitMasker[colSection];
+ HeightMap[col, row] = _flattened_HeightMap[rowcol];
+ }
- for (uint rowcol = 0; rowcol < (ChunkSize * ChunkSize); 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( );
+ }
+ }
+
}
}
-