OSDN Git Service

RC.ZERO; Metadata persistence on PNG chunk shards
[automap/automap.git] / Automap / Data / ColumnMeta.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.Linq;
5
6 using Vintagestory.API.MathTools;
7
8 using ProtoBuf;
9
10 namespace Automap
11 {
12         [ProtoContract]
13         public struct ColumnMeta
14         {
15                 [ProtoMember(1)]
16                 public Vec2i Location;
17
18                 [ProtoMember(2)]
19                 public TimeSpan ChunkAge;//In game, calendar?
20
21                 [ProtoMember(3)]
22                 public float Temperature;// Temperature
23
24                 [ProtoMember(4)]
25                 public ushort YMax;// Y feature height
26
27                 [ProtoMember(5)]
28                 public Dictionary<int,uint> RockRatio;//(surface) Geographic region (rock) Ratio. [BlockID * count]
29
30                 [ProtoMember(6)]
31                 public float Fertility;
32
33                 [ProtoMember(7)]
34                 public float ForestDensity;
35
36                 [ProtoMember(8)]
37                 public float Rainfall;
38
39                 [ProtoMember(9)]
40                 public float ShrubDensity;
41
42                 public ColumnMeta(Vec2i loc)
43                 {
44                 Location = loc;
45                 ChunkAge = TimeSpan.Zero;
46                 Temperature = 0f;
47                 YMax = 0;
48                 RockRatio = new Dictionary<int, uint>( 10 );
49                 Fertility = 0f;
50                 ForestDensity = 0f;
51                 Rainfall = 0f;
52                 ShrubDensity = 0f;
53                 }
54         }
55
56         public class ColumnsMetadata : KeyedCollection<Vec2i, ColumnMeta>
57         {
58                 private ColumnsMetadata( )
59                 {
60                         throw new NotSupportedException();
61                 }
62
63                 public ColumnsMetadata(Vec2i startChunkColumn)
64                 {
65                 North_mostChunk = startChunkColumn.Y;
66                 South_mostChunk = startChunkColumn.Y;
67                 East_mostChunk = startChunkColumn.X;
68                 West_mostChunk = startChunkColumn.X;
69                 }
70
71                 public int North_mostChunk {
72                         get; private set;
73                 }
74
75                 public int South_mostChunk {
76                         get; private set;
77                 }
78
79                 public int East_mostChunk {
80                         get; private set;
81                 }
82
83                 public int West_mostChunk {
84                         get; private set;
85                 }
86
87                 protected override Vec2i GetKeyForItem(ColumnMeta item)
88                 {
89                 return item.Location;
90                 }
91
92                 internal void Update(ColumnMeta metaData)
93                 {
94                 if (this.Contains(metaData.Location)) {
95                 this.Remove(metaData.Location);
96                 this.Add(metaData);
97                 }
98                 else {
99                 this.Add(metaData);
100                 }
101
102                 }
103
104                 public new void Add(ColumnMeta newItem)
105                 {
106                 if (North_mostChunk > newItem.Location.Y) {
107                 North_mostChunk = newItem.Location.Y;
108                 }
109
110                 if (South_mostChunk < newItem.Location.Y) {
111                 South_mostChunk = newItem.Location.Y;
112                 }
113
114                 if (East_mostChunk < newItem.Location.X) {
115                 East_mostChunk = newItem.Location.X;
116                 }
117
118                 if (West_mostChunk > newItem.Location.X) {
119                 West_mostChunk = newItem.Location.X;
120                 }
121
122                 base.Add(newItem);
123                 }
124
125         }
126 }
127