OSDN Git Service

W.I.P. fixed positioning errors, various tweaks
authormelchior <melchior@users.osdn.me>
Tue, 18 May 2021 19:27:30 +0000 (15:27 -0400)
committermelchior <melchior@users.osdn.me>
Tue, 18 May 2021 19:27:30 +0000 (15:27 -0400)
Automap/Data/ColumnCounter.cs
Automap/Helpers.cs
Automap/Renderers/StandardRenderer.cs
Automap/Subsystems/AutomapSystem.cs

index ae9c26f..506e0f1 100644 (file)
@@ -7,14 +7,15 @@ namespace Automap
 {
        public struct ColumnCounter
        {
-               public bool NewOrLoaded;
-               public byte[] EditTally;
+               private bool NewOrLoaded;
+               private byte[] EditTally;
+               private byte HeightCutoff; //CHUNK #
 
                public uint WeightedSum 
                {
                        get
-                       {//TODO: Rank deduction for lower chunks
-                               return ( uint )(EditTally.Sum(ed => ed)) + (NewOrLoaded ? 100u : 0u);
+                       {//TODO: Rank ZERO for deep sub-surface chunks
+                               return ( uint )(EditTally.Skip(HeightCutoff - 1).Sum(ed => ed)) + (NewOrLoaded ? 100u : 0u);
                        }
                }
 
@@ -22,12 +23,14 @@ namespace Automap
                {
                NewOrLoaded = false;
                EditTally = new byte[chunkSize];
+               HeightCutoff = 0;
                }
 
                public ColumnCounter(int chunkSize, bool editLoaded)
                {
                NewOrLoaded = editLoaded;
                EditTally = new byte[chunkSize];
+               HeightCutoff = 0;
                }
 
                public ColumnCounter(int chunkSize, bool editLoaded, Vec3i chunkCoord)
@@ -38,20 +41,28 @@ namespace Automap
                EditTally = new byte[chunkSize];
 
                EditTally[chunkY]++;
+               HeightCutoff = ( byte )chunkY;
                }
 
                public ColumnCounter Update(Vec3i chunkCoord, int chunkSize, bool partlyNewOrLoaded = false)
                {
                int chunkY = chunkCoord.Y % chunkSize;
-               EditTally[chunkY]++;
-               if (partlyNewOrLoaded) NewOrLoaded = true;;
+               if (EditTally[chunkY] < Byte.MaxValue) EditTally[chunkY]++;
+               if (partlyNewOrLoaded) NewOrLoaded = true;
 
                return this;
                }
 
+               public void SetCutoff(int height)
+               {
+
+               HeightCutoff = ( byte )height;  
+               
+               }
+
                public override string ToString( )
                {
-                       return $"{(NewOrLoaded?'N':'O')} W:{WeightedSum}";
+                       return $"{(NewOrLoaded?"NEW":"Old")} W:{WeightedSum}";
                }
 }
 }
index 2aa7d3b..842a648 100644 (file)
@@ -96,7 +96,8 @@ namespace Automap
 
                public static ushort RainHeight2DMap(this IMapChunk mapChunk, int x, int y, int chunkSize = 32)
                {
-                       int index = y % chunkSize * chunkSize + x % chunkSize;
+                       //int num = posZ % this.chunksize * this.chunksize + posX % this.chunksize;
+                       int index = (y % chunkSize) * chunkSize + (x % chunkSize);
                        return mapChunk.RainHeightMap[index];
                }
 
index 6ed2a1b..c8e11d1 100644 (file)
@@ -51,9 +51,11 @@ namespace Automap
                }
 
                // Prefetch map chunks, in pattern              
-               var corner_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y + 1);
+               var corner_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y - 1);
                var west_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y);
-               var north_pos = new Vec2i(chunkPos.X, chunkPos.Y + 1);                                  
+               var north_pos = new Vec2i(chunkPos.X, chunkPos.Y - 1);
+
+               uint missingRainmap = 0, missingHeightmap = 0;
 
                ColumnMeta north, northWest, west;
                /* 
@@ -77,29 +79,31 @@ namespace Automap
                overlapHeightmap[0, 0] = northWest.HeightMap[chunkSize - 1, chunkSize - 1];
                }
                else {
+               missingHeightmap++;
                var cornerMC = ClientAPI.World.BlockAccessor.GetMapChunk(corner_pos);
                if (cornerMC != null && cornerMC.RainHeightMap != null) 
                        {
-                       overlapHeightmap[0, 0] = cornerMC.RainHeight2DMap(chunkSize - 1, (chunkSize - 1) );
-                       }
-               }
+                       overlapHeightmap[0, 0] = cornerMC.RainHeight2DMap(chunkSize - 1, (chunkSize - 1));
+                       } else missingRainmap++;
+               } 
                
                if (allCols.Contains(north_pos) && allCols[north_pos].HeightMap != null) {
                north = allCols[north_pos];
 
                        for (int northEdgeIndex = 0; northEdgeIndex < chunkSize; northEdgeIndex++) 
                        {
-                       overlapHeightmap[1, northEdgeIndex + 1 ] = north.HeightMap[ (chunkSize - 1), northEdgeIndex];                   
+                       overlapHeightmap[0, northEdgeIndex + 1 ] = north.HeightMap[ (chunkSize - 1), northEdgeIndex];                   
                        }
                }               
                else {
+                       missingHeightmap++;
                        var northMC = ClientAPI.World.BlockAccessor.GetMapChunk(north_pos);
                        if (northMC != null && northMC.RainHeightMap != null) {
                                for (int northEdgeIndex = 0; northEdgeIndex < chunkSize; northEdgeIndex++) 
                                {
-                               overlapHeightmap[1, northEdgeIndex + 1] = northMC.RainHeight2DMap((chunkSize - 1), northEdgeIndex);
+                               overlapHeightmap[0, northEdgeIndex + 1] = northMC.RainHeight2DMap((chunkSize - 1), northEdgeIndex);
                                }
-                       }
+                       } else missingRainmap++;
                }
 
                if (allCols.Contains(west_pos) && allCols[west_pos].HeightMap != null) {
@@ -111,18 +115,24 @@ namespace Automap
                        }
                }               
                else {
+               missingHeightmap++;
                var westMC = ClientAPI.World.BlockAccessor.GetMapChunk(west_pos);
                if (westMC != null && westMC.RainHeightMap != null) {
-                       for (int westEdgeIndex = 0; westEdgeIndex < chunkSize; westEdgeIndex++) {
-                       overlapHeightmap[westEdgeIndex + 1, 0] = westMC.RainHeight2DMap(westEdgeIndex, chunkSize - 1);
-                       }
+               for (int westEdgeIndex = 0; westEdgeIndex < chunkSize; westEdgeIndex++) {
+               overlapHeightmap[westEdgeIndex + 1, 0] = westMC.RainHeight2DMap(westEdgeIndex, chunkSize - 1);
                }
+               } else missingRainmap++;
                }
                
-               var avgOverlap_Y = overlapHeightmap.OfType<ushort>( ).Average((ushort sel) => sel == 0 ? targetColMeta.YMax : sel);
+               ushort avgOverlap_Y = ( ushort )overlapHeightmap.OfType<ushort>( ).Average((ushort sel) => sel == 0 ? targetColMeta.YMax : sel);                                
                //TODO: Row - then - Column averaging at Edges?
-               
-               //      if (height == 0) height = ( ushort )avgOverlap_Y;
+
+               #if DEBUG
+               var badHeightData = overlapHeightmap.OfType<ushort>( ).Count((ushort arg) => arg == 0); 
+
+               if (badHeightData > 0)
+               Logger.VerboseDebug("H.M Zeros# {0} , Missing Rainmaps {1} Heightmaps {2}",badHeightData ,missingRainmap, missingHeightmap);
+               #endif
                
 
 
@@ -154,14 +164,14 @@ namespace Automap
                int up_X = localX;
                int low_X = localX + 1;
                int left_Z = localZ;
-               int right_Z = localZ + 1;                               
-               
+               int right_Z = localZ + 1;
+
                //topX = GameMath.Mod(topX, chunkSize + 1);
-               //leftZ = GameMath.Mod(leftZ, chunkSize + 1);
+               //leftZ = GameMath.Mod(leftZ, chunkSize + 1);           
 
-               leftTop  = Math.Sign(localY - overlapHeightmap[up_X, left_Z]);
-               rightTop = Math.Sign(localY - overlapHeightmap[up_X, right_Z]);
-               leftBot  = Math.Sign(localY - overlapHeightmap[low_X, left_Z]);
+               leftTop  = Math.Sign(localY - (overlapHeightmap[up_X, left_Z] == 0 ? avgOverlap_Y : overlapHeightmap[up_X, left_Z]));
+               rightTop = Math.Sign(localY - (overlapHeightmap[up_X, right_Z]== 0 ? avgOverlap_Y : overlapHeightmap[up_X, right_Z]));
+               leftBot  = Math.Sign(localY - (overlapHeightmap[low_X, left_Z]== 0 ? avgOverlap_Y : overlapHeightmap[low_X, left_Z]));
 
                float slopeness = (leftTop + rightTop + leftBot);
 
index 3482ded..3df21cd 100644 (file)
@@ -33,7 +33,7 @@ namespace Automap
 
                internal const string _mapPath = @"Maps";
                internal const string _chunkPath = @"Chunks";
-               internal const uint editThreshold = 1;
+               internal const uint editThreshold = 9;
                private const string _domain = @"automap";
                private const string chunkFile_filter = @"*_*.png";
                private const string poiFileName = @"poi_binary";
@@ -227,6 +227,7 @@ namespace Automap
                                                        #endif
                                                }
                                                ProcessChunkBlocks(mostActiveCol.Key, mapChunk, ref chunkMeta);
+                                               mostActiveCol.Value.SetCutoff(chunkMeta.YMax / chunkSize);
 
                                                ChunkRenderer.SetupPngImage(mostActiveCol.Key, path, _chunkPath, ref chunkMeta);
                                                ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, ref chunkTopMetadata, out updatedPixels);
@@ -342,7 +343,7 @@ namespace Automap
                        var airBlocksQuery = from airyBlock in ClientAPI.World.Blocks
                                                         where airyBlock.MatterState == EnumMatterState.Solid
                                                         where airyBlock.BlockMaterial == EnumBlockMaterial.Plant || airyBlock.BlockMaterial == EnumBlockMaterial.Leaves
-                                                        where airyBlock.CollisionBoxes == null || airyBlock.CollisionBoxes.Length == 0
+                                                        where airyBlock.CollisionBoxes == null || airyBlock.CollisionBoxes.Length == 0 ||airyBlock.RainPermeable == true                                                        
                                                         select airyBlock;                      
                        //^^ 'Solid' phase - 'Plant' Blocks without any boundg box ? Except water...
                        this.AiryIdCodes = airBlocksQuery.ToDictionary(aBlk => aBlk.BlockId, aBlk => aBlk.Code.Path);