From e0b2265463b66cee55cc6f10cd9e84cb07b15411 Mon Sep 17 00:00:00 2001 From: melchior Date: Mon, 3 Feb 2020 21:46:57 -0500 Subject: [PATCH] W.I.P. IV: More reliable entity / block scanning (full depth chunk scan), rock stats too... Control panel GUI still not complete... --- Automap/Automap.csproj | 2 +- Automap/AutomapMod.cs | 2 - Automap/Data/ColumnMeta.cs | 6 +-- Automap/Designators/DefaultDesignators.cs | 4 ++ Automap/Subsystems/AutomapGUIDialog.cs | 17 +++++-- Automap/Subsystems/AutomapSystem.cs | 76 ++++++++++++++++++++++++++----- 6 files changed, 86 insertions(+), 21 deletions(-) diff --git a/Automap/Automap.csproj b/Automap/Automap.csproj index e120f82..99cec0d 100644 --- a/Automap/Automap.csproj +++ b/Automap/Automap.csproj @@ -67,7 +67,7 @@ False - Libs\Pngcs.dll + VS_libs\Pngcs.dll diff --git a/Automap/AutomapMod.cs b/Automap/AutomapMod.cs index b840d5a..a966a3d 100644 --- a/Automap/AutomapMod.cs +++ b/Automap/AutomapMod.cs @@ -51,8 +51,6 @@ namespace Automap return true; } - - } } diff --git a/Automap/Data/ColumnMeta.cs b/Automap/Data/ColumnMeta.cs index e1710dd..00d4b09 100644 --- a/Automap/Data/ColumnMeta.cs +++ b/Automap/Data/ColumnMeta.cs @@ -18,16 +18,16 @@ namespace Automap public Vec2i Location; [ProtoMember(2)] - public TimeSpan ChunkAge;//In game, calendar? + public TimeSpan ChunkAge;//OLDEST CHUNK. from chunk last edit [ProtoMember(3)] - public float Temperature;// Temperature + public float Temperature;// Temperature - surface [ProtoMember(4)] public ushort YMax;// Y feature height [ProtoMember(5)] - public Dictionary RockRatio;//(surface) Geographic region (rock) Ratio. [BlockID * count] + public Dictionary RockRatio;//[Column] Geographic region (rock) Ratio. [BlockID * count] [ProtoMember(6)] public float Fertility; diff --git a/Automap/Designators/DefaultDesignators.cs b/Automap/Designators/DefaultDesignators.cs index 8c88a89..a6b653f 100644 --- a/Automap/Designators/DefaultDesignators.cs +++ b/Automap/Designators/DefaultDesignators.cs @@ -83,7 +83,9 @@ namespace Automap internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block) { + #if DEBUG clientAPI.Logger.VerboseDebug("Sign Designator Invoked!"); + #endif //sign Text into a POI field... BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign; @@ -105,7 +107,9 @@ namespace Automap internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block) { + #if DEBUG clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!"); + #endif //sign post Text into a POI field... BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost; diff --git a/Automap/Subsystems/AutomapGUIDialog.cs b/Automap/Subsystems/AutomapGUIDialog.cs index 6c1dcf3..3958d03 100644 --- a/Automap/Subsystems/AutomapGUIDialog.cs +++ b/Automap/Subsystems/AutomapGUIDialog.cs @@ -27,6 +27,8 @@ namespace Automap SetupDialog( ); } + //Event for GUI status display + private void SetupDialog( ) { ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle); @@ -37,9 +39,9 @@ namespace Automap bgBounds.BothSizing = ElementSizing.FitToChildren; bgBounds.WithChildren(textBounds); - ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(3, 5, 5, 2); - toggleBounds.fixedHeight = 18; - toggleBounds.fixedWidth = 50; + ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(3, 26, 5, 2); + toggleBounds.fixedHeight = 24; + toggleBounds.fixedWidth = 64; ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 20, 2, 4); txtStatusBounds.fixedHeight = 16; @@ -53,6 +55,15 @@ namespace Automap .AddToggleButton("Run", CairoFont.ButtonText( ), RunToggle, toggleBounds, "btnRun") .AddStaticText("Idle.", CairoFont.WhiteSmallText( ).WithFontSize(12), txtStatusBounds, "txtStatus") .Compose( ); + + //Controls for ALL Block & Entity Designators (Enable/Disable) + //_automapSystem.BlockID_Designators + //_automapSystem.Entity_Designators + //Renderer selection + //Message verbosity? Speed? + + //A Button to add POI - notes manually (when AM running) + } private void OnTitleBarCloseClicked( ) diff --git a/Automap/Subsystems/AutomapSystem.cs b/Automap/Subsystems/AutomapSystem.cs index 200015b..faea6b5 100644 --- a/Automap/Subsystems/AutomapSystem.cs +++ b/Automap/Subsystems/AutomapSystem.cs @@ -16,6 +16,7 @@ using Hjg.Pngcs.Chunks; using Vintagestory.API.Client; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; +using Vintagestory.API.Config; using Vintagestory.API.MathTools; using Vintagestory.Common; @@ -41,6 +42,7 @@ namespace Automap internal Dictionary BlockID_Designators { get; private set;} internal Dictionary Entity_Designators { get; private set; } + internal Dictionary RockIdCodes { get; private set; } internal bool Enabled { get; set; } //Run status, Chunks processed, stats, center of map.... @@ -201,6 +203,7 @@ namespace Automap this.EOIs = new EntitiesOfInterest( ); this.BlockID_Designators = new Dictionary( ); this.Entity_Designators = new Dictionary( ); + this.RockIdCodes = Helpers.ArbitrarytBlockIdHunter(ClientAPI, new AssetLocation(GlobalConstants.DefaultDomain, "rock"), EnumBlockMaterial.Stone); //Add special marker types for BlockID's of "Interest", overwrite colour, and method @@ -476,7 +479,7 @@ namespace Automap foreach (var shardFile in files) { - if (shardFile.Length < 1000) continue; + if (shardFile.Length < 512) continue; var result = chunkShardRegex.Match(shardFile.Name); if (result.Success) { int X_chunk_pos = int.Parse(result.Groups["X"].Value ); @@ -537,24 +540,75 @@ namespace Automap /// Chunk metadata private void ProcessChunkBlocks(Vec2i key, IMapChunk mapChunk, ColumnMeta chunkMeta) { - //TODO: build stack of chunk(s) - surface down to bedrock - int topChunkY = mapChunk.YMax / chunkSize; - WorldChunk chunkData = ( Vintagestory.Common.WorldChunk )ClientAPI.World.BlockAccessor.GetChunk(key.X, topChunkY, key.Y); + int targetChunkY = mapChunk.YMax / chunkSize;//Surface ... + for (; targetChunkY > 0; targetChunkY--) { + WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk; + + if (chunkData == null || chunkData.BlockEntities == null) { + #if DEBUG + Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X,targetChunkY,key.Y); + #endif + continue; + } + + /*************** Chunk Entities Scanning *********************/ if (chunkData.BlockEntities != null && chunkData.BlockEntities.Length > 0) { #if DEBUG Logger.VerboseDebug("Surface@ {0} = BlockEntities: {1}", key, chunkData.BlockEntities.Length); + #endif - foreach (var blockEnt in chunkData.BlockEntities) { - if (BlockID_Designators.ContainsKey(blockEnt.Block.BlockId)) + foreach (var blockEnt in chunkData.BlockEntities) { + + if (blockEnt != null && blockEnt.Block != null && BlockID_Designators.ContainsKey(blockEnt.Block.BlockId)) { var designator = BlockID_Designators[blockEnt.Block.BlockId]; - designator.SpecialAction(ClientAPI, POIs, blockEnt.Pos.Copy(), blockEnt.Block); + designator.SpecialAction(ClientAPI, POIs, blockEnt.Pos.Copy( ), blockEnt.Block); } } - #endif + + } + /********************* Chunk/Column BLOCKs scanning ****************/ + //Heightmap, Stats, block tally + chunkData.Unpack( ); + + int X_index, Y_index, Z_index; + X_index = Y_index = Z_index = 0; + + do { + do { + do { + /* Encode packed indicie + (y * chunksize + z) * chunksize + x + */ + var indicie = Helpers.ChunkBlockIndicie16(X_index, Y_index, Z_index); + int aBlockId = chunkData.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)); } + + } + while (X_index++ < (chunkSize - 1)); + X_index = 0; + } + while (Z_index++ < (chunkSize - 1)); + Z_index = 0; + } + while (Y_index++ < (chunkSize - 1)); + + } } private void UpdateEntityMetadata( ) @@ -568,10 +622,8 @@ namespace Automap #endif var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Value.Code)); - if (dMatch.Value != null) { - if (dMatch.Value.Enabled) { - dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Value.LocalPos.AsBlockPos.Copy( ), loadedEntity.Value); - } + if (dMatch.Value != null) { + dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Value.LocalPos.AsBlockPos.Copy( ), loadedEntity.Value); } } -- 2.11.0