Sorry if this title is not very descriptive. Anyway, I'm working on randomly creating landscapes. I made lakes, but because of how they are made, they often cause straight edges / outliers, which are undesirable. I try to smooth it out (immediately after the creation of the lake, if possible) by determining the maximum variation (so that the height of the earth cannot be greater than it), and let it correct the earth if it varies a lot, and leave if it well.
Problem:

My attempt to fix:

As you can see ... this did not work. This is also the case for me, I think it would break if he had to go down, although this case should not happen, because the lakes only ever lower the landscape. Anyway, here is the source of my attempt:
//smoothing land nearby int maxVariation = 2; //similar to the max height variation when the land is generated //going right for (int xPos = rightBound + 1, previousHeight = 0; ; ++xPos) { if (previousHeight == 0) for (; previousHeight < size.y; ++previousHeight) if (grid[0][rightBound][previousHeight] != BlockColor::DIRT && grid[0][rightBound][previousHeight] != BlockColor::GRASS) { --previousHeight; break; } for (int y = 0; y < size.y; ++y) if (grid[0][xPos][y] == BlockColor::WATER) goto done_smoothing_right; int height; for (height = 0; height < size.y; ++height) if (grid[0][xPos][height] != BlockColor::DIRT && grid[0][xPos][height] != BlockColor::GRASS) { --height; break; } int difference = std::abs(height - previousHeight); previousHeight = height; if (difference > maxVariation) { for (int j = 0; j < size.y; ++j) { int toMove = difference; while (j + toMove >= size.y) --toMove; grid[0][xPos][j] = grid[0][xPos][j + toMove]; } } else goto done_smoothing_right; } done_smoothing_right: int tomakegotowork;
Note that this is only the right side, but the left should be approximately the same. How can I do it right?
Thanks if you can help.
EDIT:
I have never solved this problem. Instead, I made a recursive function to measure air (from a certain height) and, if there was a sufficient supply of air (formed by the ground) to fill with water. This has the advantage that the earth looks smooth because it does not change.
user1533320
source share