OSDN Git Service

W.I.P. Improved slope shading
authormelchior <melchior@users.osdn.me>
Sun, 16 May 2021 22:40:57 +0000 (18:40 -0400)
committermelchior <melchior@users.osdn.me>
Sun, 16 May 2021 22:40:57 +0000 (18:40 -0400)
Automap/Automap.csproj
Automap/Data/ColumnMeta.cs
Automap/Helpers.cs
Automap/Renderers/StandardRenderer.cs
Automap/modinfo.json

index 9e31c23..5a16538 100644 (file)
@@ -20,7 +20,7 @@
     <ConsolePause>false</ConsolePause>
     <CustomCommands>
       <CustomCommands>
-        <Command type="AfterBuild" command="7z -tzip a ${ProjectName}_${ProjectConfig}.zip" workingdir="${TargetDir}" />
+        <Command type="AfterBuild" command="7z a -tzip -x!*.zip -aoa ${ProjectName}_${ProjectConfig}.zip" workingdir="${TargetDir}" />
         <Command type="AfterClean" command="rm -f *.zip" workingdir="${TargetDir}" />
       </CustomCommands>
     </CustomCommands>
index 4652644..2f8233f 100644 (file)
@@ -149,6 +149,9 @@ namespace Automap
                        if (HeightMap != null)
                        {
                                _flattened_HeightMap = new ushort[ChunkSize * ChunkSize];
+
+                               //Buffer.BlockCopy(HeightMap, 0, _flattened_HeightMap, 0, HeightMap.Length * sizeof(ushort));
+
                                int flatIndex = 0;
 
                                for (byte col = 0; col < ChunkSize; col++)
index 2d387aa..2aa7d3b 100644 (file)
@@ -94,6 +94,11 @@ namespace Automap
             return whichever;
         }
 
+               public static ushort RainHeight2DMap(this IMapChunk mapChunk, int x, int y, int chunkSize = 32)
+               {
+                       int index = y % chunkSize * chunkSize + x % chunkSize;
+                       return mapChunk.RainHeightMap[index];
+               }
 
 
         /// <summary>
index 3dd9578..433f411 100644 (file)
@@ -25,7 +25,7 @@ namespace Automap
                        
                }
 
-               public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta targetColMeta, ref ColumnsMetadata allCols, out uint pixelCount)
+               public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta targetColMeta, ref ColumnsMetadata allCols, out uint pixelCount)
                {
                pixelCount = 0;
                BlockPos tmpPos = new BlockPos( );
@@ -50,46 +50,85 @@ namespace Automap
                }
                }
 
-               // Prefetch map chunks, in pattern
-               var mapCornerChunks = new List<ColumnMeta>(3);
-
-               var south_west = new Vec2i(chunkPos.X - 1, chunkPos.Y - 1);
-               var west = new Vec2i(chunkPos.X - 1, chunkPos.Y);
-               var south = new Vec2i(chunkPos.X, chunkPos.Y - 1);
-
-               bool nullSouthWest = false, nullSouth = false, nullWest = false;
+               // Prefetch map chunks, in pattern              
+               var corner_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y - 1);
+               var west_pos = new Vec2i(chunkPos.X - 1, chunkPos.Y);
+               var south_pos = new Vec2i(chunkPos.X, chunkPos.Y - 1);
+                                       
 
+               ColumnMeta south, southWest, west;
                /* 
-               For missing corners / cardinal heightmaps...
-               make fake heightmap dummy
+                 "Overlap" Heightmap for Slope (height) values; covers 1 whole + 2 chunk edges, and corner block,
+                  substitute ZERO with Average Height....better than nothing even if its wrong?
                */
+               var overlapHeightmap = new ushort[chunkSize + 1, chunkSize + 1];
 
-               if (allCols.Contains(south_west)) {
-               mapCornerChunks.Add(allCols[south_west]);               
-               }
-               else {
-               nullSouthWest = true;
-               mapCornerChunks.Add(targetColMeta);//Temporary!
+               //Ofset copy of Heightmap...
+               for (int copyX = 0; copyX < chunkSize; copyX++)
+               {
+                       for (int copyY = 0; copyY < chunkSize; copyY++) {
+                               overlapHeightmap[copyX + 1, copyY] = targetColMeta.HeightMap[copyX, copyY];
+                       }                       
                }
 
-               if (allCols.Contains(south)) {
-               mapCornerChunks.Add(allCols[south]);
+
+
+               if (allCols.Contains(corner_pos) && allCols[corner_pos].HeightMap != null) {
+               southWest = allCols[corner_pos];
+               overlapHeightmap[0, 32] = southWest.HeightMap[0, chunkSize - 1];
                }
                else {
-               nullSouth = true;
-               mapCornerChunks.Add(targetColMeta);//Temporary!
+               var cornerMC = ClientAPI.World.BlockAccessor.GetMapChunk(corner_pos);
+               if (cornerMC != null && cornerMC.RainHeightMap != null) 
+                       {
+                       overlapHeightmap[0, 32] = cornerMC.RainHeight2DMap(0, (chunkSize - 1) );
+                       }
                }
+               
+               if (allCols.Contains(south_pos) && allCols[south_pos].HeightMap != null) {
+               south = allCols[south_pos];
 
-               if (allCols.Contains(west)) {
-               mapCornerChunks.Add(allCols[west]);
+                       for (int southEdgeIndex = 0; southEdgeIndex < chunkSize; southEdgeIndex++) 
+                       {
+                       overlapHeightmap[32, southEdgeIndex + 1] = south.HeightMap[0, southEdgeIndex];                  
+                       }
+               }               
+               else {
+                       var southMC = ClientAPI.World.BlockAccessor.GetMapChunk(south_pos);
+                       if (southMC != null && southMC.RainHeightMap != null) {
+                               for (int southEdgeIndex = 0; southEdgeIndex < chunkSize; southEdgeIndex++) 
+                               {
+                               overlapHeightmap[32, southEdgeIndex] = southMC.RainHeight2DMap(0, southEdgeIndex);
+                               }
+                       }
                }
+
+               if (allCols.Contains(west_pos) && allCols[west_pos].HeightMap != null) {
+               west = allCols[west_pos];
+
+                       for (int westEdgeIndex = 0; westEdgeIndex < chunkSize; westEdgeIndex++) 
+                       {
+                       overlapHeightmap[westEdgeIndex, 0] = west.HeightMap[westEdgeIndex, chunkSize - 1];
+                       }
+               }               
                else {
-               nullWest = true;
-               mapCornerChunks.Add(targetColMeta);//Temporary!
+               var westMC = ClientAPI.World.BlockAccessor.GetMapChunk(south_pos);
+               if (westMC != null && westMC.RainHeightMap != null) {
+                       for (int westEdgeIndex = 0; westEdgeIndex < chunkSize; westEdgeIndex++) {
+                       overlapHeightmap[westEdgeIndex, 0] = westMC.RainHeight2DMap(westEdgeIndex, chunkSize - 1);
+                       }
+               }
                }
+               
+               var avgOverlap_Y = 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;
+               
 
 
                for (int pixelIndex = 0; pixelIndex < (chunkSize * chunkSize); pixelIndex++) {
+               /********* PIXEL RENDERING LOOP **********/
                MapUtil.PosInt2d(pixelIndex, chunkSize, localpos);
                int localX = localpos.X;
                int localZ = localpos.Y;
@@ -97,57 +136,40 @@ namespace Automap
 
                int localChunkY = localY / chunkSize;
                if (localChunkY >= (chunksColumn.Length)) continue;//Out of range!
-               if (chunksColumn[localChunkY] == null) continue;//BIG Gaps!
+               if (chunksColumn[localChunkY] == null) 
+               {
+               #if DEBUG
+               Logger.VerboseDebug("Gap in chunk-column at render time Chunk-Y:{0}", localChunkY);
+               #endif
+               continue;
+               }
+
                //if (mapCornerChunks.Any(chks => chks == null)) {
                //Logger.Warning("mapCornerChunks A.W.O.L. near : X{0} Y{1} Z{2}        - ", localX, localY, localZ);
                //continue;
                //}
 
                float slopeBoost = 1f;
-               int leftTop, rightTop, leftBot;
+               int leftTop, rightTop, leftBot;                                         
 
-               ColumnMeta leftTopMapChunk = targetColMeta;
-               ColumnMeta rightTopMapChunk = targetColMeta;
-               ColumnMeta leftBotMapChunk = targetColMeta;
+               int topX = localX;
+               int botX = localX + 1;
+               int leftZ = localZ + 1;
+               int rightZ = localZ;            
 
-               int topX = localX - 1;
-               int botX = localX;
-               int leftZ = localZ - 1;
-               int rightZ = localZ;
-
-               if (topX < 0 && leftZ < 0) {
-               leftTopMapChunk = mapCornerChunks[0];
-               rightTopMapChunk = mapCornerChunks[1];
-               leftBotMapChunk = mapCornerChunks[2];
-               }
-               else {
-               if (topX < 0) {
-               leftTopMapChunk = mapCornerChunks[1];
-               rightTopMapChunk = mapCornerChunks[1];
-               }
-               if (leftZ < 0) {
-               leftTopMapChunk = mapCornerChunks[2];
-               leftBotMapChunk = mapCornerChunks[2];
-               }
-               }
-
-               topX = GameMath.Mod(topX, chunkSize);
-               leftZ = GameMath.Mod(leftZ, chunkSize);
+               topX  = GameMath.Mod(topX, chunkSize + 1);
+               leftZ = GameMath.Mod(leftZ, chunkSize + 1);
                
-               leftTop = nullSouthWest ? 0 : Math.Sign(localY - leftTopMapChunk.HeightMap[topX, leftZ]);
-               rightTop = nullSouth ? 0 : Math.Sign(localY - rightTopMapChunk.HeightMap[topX, rightZ]);
-               leftBot = nullWest ? 0 : Math.Sign(localY - leftBotMapChunk.HeightMap[botX, leftZ]);
+               leftTop  = Math.Sign(localY - overlapHeightmap[topX, leftZ]);
+               rightTop = Math.Sign(localY - overlapHeightmap[topX, rightZ]);
+               leftBot  = Math.Sign(localY - overlapHeightmap[botX, leftZ]);
 
                float slopeness = (leftTop + rightTop + leftBot);
 
                if (slopeness > 0) slopeBoost = 1.2f;
                if (slopeness < 0) slopeBoost = 0.8f;
                if (Math.Abs(slopeness) <= float.Epsilon) slopeBoost = 1.0f;//Same height
-               //slopeBoost -= 0.15f; //Slope boost value 
-
-               //FIXME: disable slopes on edges...for now
-               if (localX == 0 || localX == 31) slopeBoost= 1.0f;
-               if (localZ == 0 || localZ == 31) slopeBoost= 1.0f;
+               //slopeBoost -= 0.15f; //Slope boost value                                              
 
                int blockId = chunksColumn[localChunkY].MaybeBlocks[MapUtil.Index3d(localX, (localY % chunkSize), localZ, chunkSize, chunkSize)];
 
index 12de595..6ff2b19 100644 (file)
@@ -4,10 +4,10 @@
   "description" : "Automap; Generates a static HTML5 map dynamically, with P.O.I. Tracking & more.",
   "authors": ["Melchior","VeryGoodDog"],
   "contributors":["VeryGoodDog"],
-  "version": "0.1.5",
+  "version": "0.1.6",
     "side":"Client",
   "dependencies": { 
-       "game": "1.14.0"        
+       "game": "1.14.10"       
   },
   "website": "http://nowebsite.nope"
 }
\ No newline at end of file