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;
92 [ProtoBeforeSerialization]
93 private void PrepareData( )
96 if (HeightMap != null) {
97 _flattened_HeightMap = new ushort[ChunkSize * ChunkSize];
100 for (byte col = 0; col < ChunkSize; col++) {
101 for (byte row = 0; row < ChunkSize; row++) {
102 _flattened_HeightMap[flatIndex] = HeightMap[col, row];
112 [ProtoAfterDeserialization]
113 private void PostProcess( )
115 if (this.HeightMap == null) this.HeightMap = new ushort[ChunkSize, ChunkSize];
117 if (_flattened_HeightMap != null) {
120 BitVector32 bitMasker = new BitVector32(0);
121 var rowSection = BitVector32.CreateSection(ChunkSize);
122 var colSection = BitVector32.CreateSection(ChunkSize, rowSection);
124 for (uint rowcol = 0; rowcol < (ChunkSize * ChunkSize); rowcol++) {
125 bitMasker = new BitVector32(data: ( int )rowcol);
126 row = bitMasker[rowSection];
127 col = bitMasker[colSection];
128 HeightMap[col, row] = _flattened_HeightMap[rowcol];
138 public class ColumnsMetadata : KeyedCollection<Vec2i, ColumnMeta>
140 private ColumnsMetadata()
142 throw new NotSupportedException();
145 public ColumnsMetadata(Vec2i startChunkColumn)
147 North_mostChunk = startChunkColumn.Y;
148 South_mostChunk = startChunkColumn.Y;
149 East_mostChunk = startChunkColumn.X;
150 West_mostChunk = startChunkColumn.X;
153 public int North_mostChunk
158 public int South_mostChunk
163 public int East_mostChunk
168 public int West_mostChunk
173 protected override Vec2i GetKeyForItem(ColumnMeta item)
175 return item.Location;
178 internal void Update(ColumnMeta metaData)
180 if (this.Contains(metaData.Location))
182 this.Remove(metaData.Location);
192 public new void Add(ColumnMeta newItem)
194 if (North_mostChunk > newItem.Location.Y)
196 North_mostChunk = newItem.Location.Y;
199 if (South_mostChunk < newItem.Location.Y)
201 South_mostChunk = newItem.Location.Y;
204 if (East_mostChunk < newItem.Location.X)
206 East_mostChunk = newItem.Location.X;
209 if (West_mostChunk > newItem.Location.X)
211 West_mostChunk = newItem.Location.X;