6 using Vintagestory.API.Client;
7 using Vintagestory.API.Common;
8 using Vintagestory.API.MathTools;
12 public class AlternateRenderer : AChunkRenderer
16 /// V.G.D:'s Alternative renderer
18 /// <param name="clientAPI">Client API.</param>
19 /// <param name="logger">Logger.</param>
20 public AlternateRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger)
25 public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, ref ColumnsMetadata allCols, out uint pixelCount)
28 BlockPos tmpPos = new BlockPos();
29 Vec2i localpos = new Vec2i();
30 var chunksColumn = new IWorldChunk[ClientAPI.World.BlockAccessor.MapSizeY / chunkSize];
32 int topChunkY = mc.YMax / chunkSize;//Heywaitaminute -- this isn't a highest FEATURE, if Rainmap isn't accurate!
33 //Metadata of DateTime chunk was edited, chunk coords.,world-seed? Y-Max feature height
34 //Grab a chunk COLUMN... Topmost Y down...
35 for (int chunkY = 0; chunkY <= topChunkY; chunkY++)
37 chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y);
38 //What to do if chunk is a void? invalid?
41 //pre-create PNG line slices...
42 ImageLine[] lines = Enumerable.Repeat(new object(), chunkSize).Select(l => new ImageLine(this.PngWriter.ImgInfo)).ToArray();
43 ushort[] allMapYs = mc.RainHeightMap;
44 for (int posIndex = 0; posIndex < (chunkSize * chunkSize); posIndex++)
46 int currY = allMapYs[posIndex];
47 int localChunkY = currY / chunkSize;
48 if (localChunkY >= (chunksColumn.Length)) continue; //Out of range!
49 if (chunksColumn[localChunkY] == null) continue;
51 MapUtil.PosInt2d(posIndex, chunkSize, localpos);
52 int localX = localpos.X;
53 int localZ = localpos.Y;
55 chunksColumn[localChunkY].Unpack();
56 int blockId = chunksColumn[localChunkY].Blocks[MapUtil.Index3d(localX, currY % chunkSize, localZ, chunkSize, chunkSize)];
58 Block block = ClientAPI.World.Blocks[blockId];
60 tmpPos.Set(chunkSize * chunkPos.X + localX, currY, chunkSize * chunkPos.Y + localZ);
66 //============ POI Population =================
67 if (BlockID_Designators.ContainsKey(blockId))
69 var desig = BlockID_Designators[blockId];
70 red = desig.OverwriteColor.R;
71 green = desig.OverwriteColor.G;
72 blue = desig.OverwriteColor.B;
75 ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue);
79 float b = GetSlope(localX, localZ, allMapYs);
81 int col = block.GetColor(ClientAPI, tmpPos);
82 int packedFormat = ColorUtil.ColorMultiply3Clamped(col, b);
84 red = ColorUtil.ColorB(packedFormat);
85 green = ColorUtil.ColorG(packedFormat);
86 blue = ColorUtil.ColorR(packedFormat);
87 ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue);
89 //chunkImage.SetPixel(localX, localZ, pixelColor);
93 for (int row = 0; row < this.PngWriter.ImgInfo.Rows; row++)
95 this.PngWriter.WriteRow(lines[row], row);
101 private float GetSlope(int x, int y, ushort[] heightMap)
103 int baseY = heightMap[MapUtil.Index2d(x, y, chunkSize)];
105 // check bounds. i hate this.
109 locIndex = MapUtil.Index2d(x - 1, y, chunkSize);
110 runningY += (baseY - heightMap[locIndex]);
112 if (x < chunkSize - 1)
114 locIndex = MapUtil.Index2d(x + 1, y, chunkSize);
115 runningY += (baseY - heightMap[locIndex]);
119 locIndex = MapUtil.Index2d(x, y - 1, chunkSize);
120 runningY += (baseY - heightMap[locIndex]);
122 if (y < chunkSize - 1)
124 locIndex = MapUtil.Index2d(x, y + 1, chunkSize);
125 runningY += (baseY - heightMap[locIndex]);
127 runningY /= 4; // average now
128 runningY /= 5; // idk