//#0 Command: Heightmaps (Generation from existing shard data)
string command = args[0];
- if (command == "--heightmap") {
- Process_ShardData( );
+
+ switch (command) {
+
+ case @"--heightmap":
+ Process_ShardData( );
+ break;
+
+ case @"--scan":
+ Scan_ShardData( );
+ break;
+
+ default:
+ Console.WriteLine("Unrecognized Command: {0}", command);
+ break;
}
+
+
}
private static void Process_ShardData( )
PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk;
ColumnMeta columnData = metadataFromPng.ChunkMetadata;
//columnData.HeightMap //Should be sane Heightmap...
-
+
}
}
+ private static void Scan_ShardData( )
+ {
+ var shardsDir = new DirectoryInfo(Path.Combine(mapPath, _chunkPath));
+ ulong count = 0,errors = 0, flat = 0;
+ var shardFiles = shardsDir.GetFiles(chunkFile_filter);
+
+ if (shardFiles.Length > 0) {
+ #if DEBUG
+ //Logger.VerboseDebug("Metadata reloading from {0} shards", shardFiles.Length);
+ #endif
+
+ foreach (var shardFile in shardFiles) {
+
+ if (shardFile.Length < 1024) {
+ Console.WriteLine("File: '{0}' too small to be valid; skipping!", shardFile.FullName);
+ errors++;
+ continue;
+ }
+
+ var result = chunkShardRegex.Match(shardFile.Name);
+ if (!result.Success) continue;
+
+ int X_chunk_pos = int.Parse(result.Groups["X"].Value);
+ int Z_chunk_pos = int.Parse(result.Groups["Z"].Value);
+
+ try {
+ using (var fileStream = shardFile.OpenRead( )) {
+
+ PngReader pngRead = new PngReader(fileStream);
+ pngRead.ReadSkippingAllRows( );
+ pngRead.End( );
+ //Parse PNG chunks for METADATA in shard
+ PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk;
+ ColumnMeta columnData = metadataFromPng.ChunkMetadata;
+
+ Console.Write("X {0:D5} Y {1:D5} Days:{2:N1} ", columnData.Location.X, columnData.Location.Y, columnData.ChunkAge.TotalDays);
+ Console.Write("YMax:{0:D3} Size:{1} R.R#:{2} Air:{3:D7} NotAir:{4:D7} ",
+ columnData.YMax,columnData.ChunkSize , (columnData.RockRatio != null? columnData.RockRatio.Count.ToString("D"): "?"), columnData.AirBlocks, columnData.NonAirBlocks
+ );
+ if (columnData.HeightMap != null) {
+ Console.Write("H.M [{0}] {1}x{2} ", columnData.HeightMap.Rank, columnData.HeightMap.GetLength(0), columnData.HeightMap.GetLength(1));
+ ushort lowest = ushort.MaxValue, highest = 0;
+ ulong sum = 0;
+ foreach (var hmEntry in columnData.HeightMap) {
+ lowest = Math.Min(lowest, hmEntry);
+ highest = Math.Max(highest, hmEntry);
+ sum += hmEntry;
+ }
+ Console.Write("Max:{0}, Min:{1}, ", highest, lowest);
+ if (sum > 0) Console.Write("Avg:{0:F1}", ( float )sum / (columnData.ChunkSize * columnData.ChunkSize));
+ Console.WriteLine( );
+ if ( sum == 0 || columnData.YMax == 0) flat++;
+ }
+ else {
+ flat++;
+ }
+
+
+ }
+
+ } catch (PngjException someEx) {
+ Console.WriteLine("PNG Corruption file '{0}' - Reason: {1}", shardFile.Name, someEx);
+ errors++;
+ continue;
+ } catch (ProtoException protoEx) {
+ Console.WriteLine("ProtoBuf invalid! file:'{0}' - Reason: {1}", shardFile.Name, protoEx);
+ errors++;
+ continue;
+ }
+ count++;
+ }
+ }
+
+ Console.WriteLine("Scanned {0} files, {1} errors, {2} FLAT entries", count, errors, flat);
+ }
+
}
}