using System;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Vintagestory.API.Common;
using ProtoBuf;
-
+using System.IO;
+using System.Collections.ObjectModel;
+using System.Text;
+using Vintagestory.API.Client;
namespace Automap
{
public struct ColumnMeta
{
[ProtoMember(1)]
+ [DisplayName(0, "Coords.")]
public Vec2i Location;
[ProtoMember(2)]
+ [DisplayName(1, "Age")]
public TimeSpan ChunkAge;//OLDEST CHUNK. from chunk last edit
[ProtoMember(3)]
+ [DisplayName(2, "Temp.")]
public float Temperature;// Temperature - surface
[ProtoMember(4)]
+ [DisplayName(3, "Y Max.")]
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(4, "Fert.")]
public float Fertility;
[ProtoMember(7)]
+ [DisplayName(5, "Forest")]
public float ForestDensity;
[ProtoMember(8)]
+ [DisplayName(6, "Rain")]
public float Rainfall;
[ProtoMember(9)]
+ [DisplayName(7, "Shrub")]
public float ShrubDensity;
[ProtoMember(10)]
+ [DisplayName(8, "Air blocks")]
public uint AirBlocks;
[ProtoMember(11)]
+ [DisplayName(9, "Non-air")]
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;
public ColumnMeta(Vec2i loc, byte chunkSize = 32)
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( )
+ 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];
-
- if (_flattened_HeightMap != null) {
- int col, row;
+ if (this.HeightMap == null) 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);
-
- 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];
- }
+ if (_flattened_HeightMap != null)
+ {
+ int col, row;
+ _ = 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);
+ row = bitMasker[rowSection];
+ col = bitMasker[colSection];
+ HeightMap[col, row] = _flattened_HeightMap[rowcol];
+ }
- }
+ }
}
}
}
-}
-
+}
\ No newline at end of file