From 0dac6be4bc39d85b3c19c8fe644b62630dea452f Mon Sep 17 00:00:00 2001 From: melchior Date: Sat, 10 Oct 2020 18:12:59 -0400 Subject: [PATCH] W.I.P. Inelegant fixes for a thorny problem...apparently working --- Automap/Renderers/AChunkRenderer.cs | 13 +++- Automap/Subsystems/AutomapSystem.cs | 106 ++++++++++++++++++------------ ShardProcessor/Program.cs | 12 ++++ ShardProcessor/Properties/AssemblyInfo.cs | 27 ++++++++ ShardProcessor/ShardProcessor.csproj | 37 +++++++++++ 5 files changed, 151 insertions(+), 44 deletions(-) create mode 100644 ShardProcessor/Program.cs create mode 100644 ShardProcessor/Properties/AssemblyInfo.cs create mode 100644 ShardProcessor/ShardProcessor.csproj diff --git a/Automap/Renderers/AChunkRenderer.cs b/Automap/Renderers/AChunkRenderer.cs index 392e43d..d44427f 100644 --- a/Automap/Renderers/AChunkRenderer.cs +++ b/Automap/Renderers/AChunkRenderer.cs @@ -41,10 +41,21 @@ namespace Automap this.PngWriter = FileHelper.CreatePngWriter(filename, imageInf, true); PngMetadata meta = this.PngWriter.GetMetadata( ); - meta.SetTimeNow( ); + meta.SetTimeYMDHMS( + DateTime.UtcNow.Year, + DateTime.UtcNow.Month, + DateTime.UtcNow.Day, + DateTime.UtcNow.Hour, + DateTime.UtcNow.Minute, + DateTime.UtcNow.Second); meta.SetText("Chunk_X", coord.X.ToString("D")); meta.SetText("Chunk_Y", coord.Y.ToString("D")); meta.SetText("PxSz", "1"); + var transparencyChunk = meta.CreateTRNSChunk( ); + transparencyChunk.SetRGB(0, 0, 0);//Same as Snapshots + string gameDate = $"{ClientAPI.World.Calendar.DayOfYear:D3}-{ClientAPI.World.Calendar.Year}"; + meta.SetText("GameDY", gameDate); + //Setup specialized meta-data PNG chunks here... PngMetadataChunk pngChunkMeta = new PngMetadataChunk(this.PngWriter.ImgInfo) { ChunkMetadata = metadata diff --git a/Automap/Subsystems/AutomapSystem.cs b/Automap/Subsystems/AutomapSystem.cs index c1b3956..11b573a 100644 --- a/Automap/Subsystems/AutomapSystem.cs +++ b/Automap/Subsystems/AutomapSystem.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -194,6 +195,7 @@ namespace Automap if (mapChunk == null) { + //TODO: REVISIT THIS CHUNK! Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key); nullMapCount++; columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); @@ -204,16 +206,16 @@ namespace Automap if (chunkTopMetadata.Contains(mostActiveCol.Key)) { chunkMeta = chunkTopMetadata[mostActiveCol.Key]; -#if DEBUG - Logger.VerboseDebug("Loaded chunk {0}", mostActiveCol.Key); -#endif + #if DEBUG + Logger.VerboseDebug("Loaded meta-chunk {0}", mostActiveCol.Key); + #endif } else { chunkMeta = CreateColumnMetadata(mostActiveCol, mapChunk); -#if DEBUG - Logger.VerboseDebug("Created chunk {0}", mostActiveCol.Key); -#endif + #if DEBUG + Logger.VerboseDebug("Created meta-chunk {0}", mostActiveCol.Key); + #endif } ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta); @@ -222,9 +224,9 @@ namespace Automap if (updatedPixels > 0) { -#if DEBUG - Logger.VerboseDebug("Wrote chunk shard: ({0}) - Edits#:{1}, Pixels#:{2}", mostActiveCol.Key, mostActiveCol.Value, updatedPixels); -#endif + #if DEBUG + Logger.VerboseDebug("Wrote top-chunk shard: ({0}) - Edits#:{1}, Pixels#:{2}", mostActiveCol.Key, mostActiveCol.Value, updatedPixels); + #endif updatedChunks++; chunkTopMetadata.Update(chunkMeta); columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); @@ -232,9 +234,9 @@ namespace Automap else { columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); -#if DEBUG - Logger.VerboseDebug("Un-painted chunk: ({0}) ", mostActiveCol.Key); -#endif + #if DEBUG + Logger.VerboseDebug("Un-painted chun shard: ({0}) ", mostActiveCol.Key); + #endif } } //Cleanup persisted Metadata... @@ -549,14 +551,18 @@ namespace Automap nullChunkCount++; continue; } - worldChunk.Unpack( );//RESEARCH: Thread Unsafe? + if (worldChunk.IsPacked()) + { + Logger.VerboseDebug("WORLD chunk: Compressed: X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y); + worldChunk.Unpack( );//RESEARCH: Thread Unsafe? + } /*************** Chunk Entities Scanning *********************/ if (worldChunk.BlockEntities != null && worldChunk.BlockEntities.Count > 0) { #if DEBUG - Logger.VerboseDebug("Surface@ {0} = BlockEntities: {1}", key, worldChunk.BlockEntities.Count); + Logger.VerboseDebug("Scan pos.({0}) for BlockEntities# {1}", key, worldChunk.BlockEntities.Count); #endif foreach (var blockEnt in worldChunk.BlockEntities) @@ -569,6 +575,8 @@ namespace Automap } } + //NOTE: Temporary; remove - replace later + if (chunkMeta.ColumnPresense == null) { chunkMeta.ColumnPresense = new BitArray((ClientAPI.World.BlockAccessor.MapSizeY / chunkSize), false); } chunkMeta.ColumnPresense[targetChunkY] = true; /********************* Chunk/Column BLOCKs scanning ****************/ @@ -580,44 +588,56 @@ namespace Automap if (chunkMeta.HeightMap == null) { chunkMeta.HeightMap = new ushort[chunkSize, chunkSize]; } if (chunkMeta.RockRatio == null) { chunkMeta.RockRatio = new Dictionary(10); } + //First Chance fail-safe; + if (worldChunk.Blocks == null || worldChunk.Blocks.Length <= 0) { + Logger.VerboseDebug("WORLD chunk; Missing block DATA⁈ X{0} Y{1} Z{2} ⁈", key.X, targetChunkY, key.Y); + continue; + } + for (Y_index = 0; Y_index < chunkSize - 1; Y_index++) { for (Z_index = 0; Z_index < chunkSize - 1; Z_index++) { for (X_index = 0; X_index < chunkSize - 1; X_index++) { - /* Encode packed indicie - (y * chunksize + z) * chunksize + x - */ - var indicie = Helpers.ChunkBlockIndicie16(X_index, Y_index, Z_index); - int aBlockId = worldChunk.Blocks[indicie]; - - if (aBlockId == 0) - {//Air - chunkMeta.AirBlocks++; - continue; - } - - if (RockIdCodes.ContainsKey(aBlockId)) - { - if (chunkMeta.RockRatio.ContainsKey(aBlockId)) - chunkMeta.RockRatio[aBlockId]++; - else - chunkMeta.RockRatio.Add(aBlockId, 1); - } - - chunkMeta.NonAirBlocks++; - - //Heightmap - if (chunkMeta.HeightMap[X_index, Z_index] == 0) - { - chunkMeta.HeightMap[X_index, Z_index] = (ushort) (Y_index + (targetChunkY * chunkSize)); - } + /* Encode packed indicie + (y * chunksize + z) * chunksize + x + */ + var indicie = Helpers.ChunkBlockIndicie16(X_index, Y_index, Z_index); + + //'Last' Chance fail-safe; + if (worldChunk.Blocks == null || worldChunk.Blocks.Length <= 0) { + Logger.VerboseDebug("Processing Block: Missing block DATA⁈ X{0} Y{1} Z{2} ⁈", X_index, Y_index, Z_index); + goto loop_bustout;; } - } + + int aBlockId = worldChunk.Blocks[indicie]; - } + if (aBlockId == 0) + {//Air + chunkMeta.AirBlocks++; + continue; + } + + if (RockIdCodes.ContainsKey(aBlockId)) + { + if (chunkMeta.RockRatio.ContainsKey(aBlockId)) + chunkMeta.RockRatio[aBlockId]++; + else + chunkMeta.RockRatio.Add(aBlockId, 1); + } + chunkMeta.NonAirBlocks++; + + //Heightmap + if (chunkMeta.HeightMap[X_index, Z_index] == 0) + { + chunkMeta.HeightMap[X_index, Z_index] = (ushort) (Y_index + (targetChunkY * chunkSize)); + } + } + } + } + loop_bustout:; } } diff --git a/ShardProcessor/Program.cs b/ShardProcessor/Program.cs new file mode 100644 index 0000000..1db0de8 --- /dev/null +++ b/ShardProcessor/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ShardProcessor +{ + class MainClass + { + public static void Main(string[ ] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/ShardProcessor/Properties/AssemblyInfo.cs b/ShardProcessor/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d0a4cad --- /dev/null +++ b/ShardProcessor/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("ShardProcessor")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("librarian")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/ShardProcessor/ShardProcessor.csproj b/ShardProcessor/ShardProcessor.csproj new file mode 100644 index 0000000..992af68 --- /dev/null +++ b/ShardProcessor/ShardProcessor.csproj @@ -0,0 +1,37 @@ + + + + Debug + AnyCPU + {837EE90B-7C03-413B-B54D-B50B2ED1EC00} + Exe + ShardProcessor + ShardProcessor + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + + + true + bin\Release + prompt + 4 + true + + + + + + + + + + \ No newline at end of file -- 2.11.0