Automap (client) [VS plugin mod]
Revision | 58d333c995a4d166182cd1ee7d72253cfce5f9a3 (tree) |
---|---|
Time | 2020-12-19 09:29:16 |
Author | melchior <melchior@user...> |
Commiter | melchior |
Added rudimentry Shard checking
@@ -43,10 +43,24 @@ namespace ShardProcessor | ||
43 | 43 | //#0 Command: Heightmaps (Generation from existing shard data) |
44 | 44 | string command = args[0]; |
45 | 45 | |
46 | - if (command == "--heightmap") { | |
47 | - Process_ShardData( ); | |
46 | + | |
47 | + switch (command) { | |
48 | + | |
49 | + case @"--heightmap": | |
50 | + Process_ShardData( ); | |
51 | + break; | |
52 | + | |
53 | + case @"--scan": | |
54 | + Scan_ShardData( ); | |
55 | + break; | |
56 | + | |
57 | + default: | |
58 | + Console.WriteLine("Unrecognized Command: {0}", command); | |
59 | + break; | |
48 | 60 | } |
49 | 61 | |
62 | + | |
63 | + | |
50 | 64 | } |
51 | 65 | |
52 | 66 | private static void Process_ShardData( ) |
@@ -79,7 +93,7 @@ namespace ShardProcessor | ||
79 | 93 | PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk; |
80 | 94 | ColumnMeta columnData = metadataFromPng.ChunkMetadata; |
81 | 95 | //columnData.HeightMap //Should be sane Heightmap... |
82 | - | |
96 | + | |
83 | 97 | |
84 | 98 | |
85 | 99 | } |
@@ -97,5 +111,81 @@ namespace ShardProcessor | ||
97 | 111 | |
98 | 112 | } |
99 | 113 | |
114 | + private static void Scan_ShardData( ) | |
115 | + { | |
116 | + var shardsDir = new DirectoryInfo(Path.Combine(mapPath, _chunkPath)); | |
117 | + ulong count = 0,errors = 0, flat = 0; | |
118 | + var shardFiles = shardsDir.GetFiles(chunkFile_filter); | |
119 | + | |
120 | + if (shardFiles.Length > 0) { | |
121 | + #if DEBUG | |
122 | + //Logger.VerboseDebug("Metadata reloading from {0} shards", shardFiles.Length); | |
123 | + #endif | |
124 | + | |
125 | + foreach (var shardFile in shardFiles) { | |
126 | + | |
127 | + if (shardFile.Length < 1024) { | |
128 | + Console.WriteLine("File: '{0}' too small to be valid; skipping!", shardFile.FullName); | |
129 | + errors++; | |
130 | + continue; | |
131 | + } | |
132 | + | |
133 | + var result = chunkShardRegex.Match(shardFile.Name); | |
134 | + if (!result.Success) continue; | |
135 | + | |
136 | + int X_chunk_pos = int.Parse(result.Groups["X"].Value); | |
137 | + int Z_chunk_pos = int.Parse(result.Groups["Z"].Value); | |
138 | + | |
139 | + try { | |
140 | + using (var fileStream = shardFile.OpenRead( )) { | |
141 | + | |
142 | + PngReader pngRead = new PngReader(fileStream); | |
143 | + pngRead.ReadSkippingAllRows( ); | |
144 | + pngRead.End( ); | |
145 | + //Parse PNG chunks for METADATA in shard | |
146 | + PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk; | |
147 | + ColumnMeta columnData = metadataFromPng.ChunkMetadata; | |
148 | + | |
149 | + Console.Write("X {0:D5} Y {1:D5} Days:{2:N1} ", columnData.Location.X, columnData.Location.Y, columnData.ChunkAge.TotalDays); | |
150 | + Console.Write("YMax:{0:D3} Size:{1} R.R#:{2} Air:{3:D7} NotAir:{4:D7} ", | |
151 | + columnData.YMax,columnData.ChunkSize , (columnData.RockRatio != null? columnData.RockRatio.Count.ToString("D"): "?"), columnData.AirBlocks, columnData.NonAirBlocks | |
152 | + ); | |
153 | + if (columnData.HeightMap != null) { | |
154 | + Console.Write("H.M [{0}] {1}x{2} ", columnData.HeightMap.Rank, columnData.HeightMap.GetLength(0), columnData.HeightMap.GetLength(1)); | |
155 | + ushort lowest = ushort.MaxValue, highest = 0; | |
156 | + ulong sum = 0; | |
157 | + foreach (var hmEntry in columnData.HeightMap) { | |
158 | + lowest = Math.Min(lowest, hmEntry); | |
159 | + highest = Math.Max(highest, hmEntry); | |
160 | + sum += hmEntry; | |
161 | + } | |
162 | + Console.Write("Max:{0}, Min:{1}, ", highest, lowest); | |
163 | + if (sum > 0) Console.Write("Avg:{0:F1}", ( float )sum / (columnData.ChunkSize * columnData.ChunkSize)); | |
164 | + Console.WriteLine( ); | |
165 | + if ( sum == 0 || columnData.YMax == 0) flat++; | |
166 | + } | |
167 | + else { | |
168 | + flat++; | |
169 | + } | |
170 | + | |
171 | + | |
172 | + } | |
173 | + | |
174 | + } catch (PngjException someEx) { | |
175 | + Console.WriteLine("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx); | |
176 | + errors++; | |
177 | + continue; | |
178 | + } catch (ProtoException protoEx) { | |
179 | + Console.WriteLine("ProtoBuf invalid! file:'{0}' - Reason: {1}", shardFile.Name, protoEx); | |
180 | + errors++; | |
181 | + continue; | |
182 | + } | |
183 | + count++; | |
184 | + } | |
185 | + } | |
186 | + | |
187 | + Console.WriteLine("Scanned {0} files, {1} errors, {2} FLAT entries", count, errors, flat); | |
188 | + } | |
189 | + | |
100 | 190 | } |
101 | 191 | } |