2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.Collections.Specialized;
7 using Vintagestory.API.MathTools;
8 using Vintagestory.API.Common;
16 public struct ColumnMeta
19 public Vec2i Location;
22 public TimeSpan ChunkAge;//OLDEST CHUNK. from chunk last edit
25 public float Temperature;// Temperature - surface
28 public ushort YMax;// Y feature height
31 public Dictionary<int, uint> RockRatio;//[Column] Geographic region (rock) Ratio. [BlockID * count]
34 public float Fertility;
37 public float ForestDensity;
40 public float Rainfall;
43 public float ShrubDensity;
46 public uint AirBlocks;
49 public uint NonAirBlocks;
52 public byte ChunkSize;
56 public ushort[,] HeightMap;//Needs to be 'flattened' for Protocol-Buffer serialization
59 private ushort[ ] _flattened_HeightMap;
62 public ColumnMeta(Vec2i loc, byte chunkSize = 32)
65 ChunkAge = TimeSpan.Zero;
68 RockRatio = new Dictionary<int, uint>(10);
75 ChunkSize = chunkSize;
76 HeightMap = new ushort[ChunkSize, ChunkSize];
77 _flattened_HeightMap = null;
80 internal void UpdateFieldsFrom(ClimateCondition climate, IMapChunk mapChunk, TimeSpan chunkAge)
82 this.ChunkAge = chunkAge;
83 this.Temperature = climate.Temperature;
84 this.Fertility = climate.Fertility;
85 this.ForestDensity = climate.ForestDensity;
86 this.Rainfall = climate.Rainfall;
87 this.ShrubDensity = climate.ShrubDensity;
89 this.YMax = mapChunk.YMax;
94 [ProtoBeforeSerialization]
95 private void PrepareData( )
98 if (HeightMap != null) {
99 _flattened_HeightMap = new ushort[ChunkSize * ChunkSize];
102 for (byte col = 0; col < ChunkSize; col++) {
103 for (byte row = 0; row < ChunkSize; row++) {
104 _flattened_HeightMap[flatIndex] = HeightMap[col, row];
114 [ProtoAfterDeserialization]
115 private void PostProcess( )
117 if (this.HeightMap == null) this.HeightMap = new ushort[ChunkSize, ChunkSize];
119 if (_flattened_HeightMap != null) {
122 BitVector32 bitMasker = new BitVector32(0);
123 var rowSection = BitVector32.CreateSection(ChunkSize);
124 var colSection = BitVector32.CreateSection(ChunkSize, rowSection);
126 for (uint rowcol = 0; rowcol < (ChunkSize * ChunkSize); rowcol++) {
127 bitMasker = new BitVector32(data: ( int )rowcol);
128 row = bitMasker[rowSection];
129 col = bitMasker[colSection];
130 HeightMap[col, row] = _flattened_HeightMap[rowcol];
140 public class ColumnsMetadata : KeyedCollection<Vec2i, ColumnMeta>
142 private ColumnsMetadata()
144 throw new NotSupportedException();
147 public ColumnsMetadata(Vec2i startChunkColumn)
149 North_mostChunk = startChunkColumn.Y;
150 South_mostChunk = startChunkColumn.Y;
151 East_mostChunk = startChunkColumn.X;
152 West_mostChunk = startChunkColumn.X;
155 public int North_mostChunk
160 public int South_mostChunk
165 public int East_mostChunk
170 public int West_mostChunk
175 protected override Vec2i GetKeyForItem(ColumnMeta item)
177 return item.Location;
180 internal void Update(ColumnMeta metaData)
182 if (this.Contains(metaData.Location))
184 this.Remove(metaData.Location);
194 public new void Add(ColumnMeta newItem)
196 if (North_mostChunk > newItem.Location.Y)
198 North_mostChunk = newItem.Location.Y;
201 if (South_mostChunk < newItem.Location.Y)
203 South_mostChunk = newItem.Location.Y;
206 if (East_mostChunk < newItem.Location.X)
208 East_mostChunk = newItem.Location.X;
211 if (West_mostChunk > newItem.Location.X)
213 West_mostChunk = newItem.Location.X;