}
- 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( );
}
}
- // 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;
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)];