12 #ifdef NOISE_IN_SUBDIR
13 #include <noise/noise.h>
27 srand(
static_cast<unsigned int>(time(0)));
31 noise::module::Perlin terrainHeightPerlin;
33 terrainHeightPerlin.SetFrequency(0.003 / 32);
34 terrainHeightPerlin.SetLacunarity(1.5);
35 terrainHeightPerlin.SetOctaveCount(16);
36 noise::module::ScaleBias terrainHeightPerlinScaled;
37 terrainHeightPerlinScaled.SetSourceModule(0, terrainHeightPerlin);
38 terrainHeightPerlinScaled.SetScale(0.25);
39 terrainHeightPerlinScaled.SetBias(-0.5);
41 noise::module::RidgedMulti terrainHeightFractal;
43 terrainHeightFractal.SetFrequency(0.005 / 32);
44 terrainHeightFractal.SetLacunarity(2);
45 noise::module::ScaleBias terrainHeightFractalScaled;
46 terrainHeightFractalScaled.SetSourceModule(0, terrainHeightFractal);
49 terrainHeightFractalScaled.SetBias(0.5);
51 noise::module::Perlin terrainHeightBlendPerlin;
53 terrainHeightBlendPerlin.SetFrequency(0.005 / 32);
54 noise::module::ScaleBias terrainHeightBlendScale;
55 terrainHeightBlendScale.SetSourceModule(0, terrainHeightBlendPerlin);
56 terrainHeightBlendScale.SetScale(2.0);
58 noise::module::Clamp terrainHeightBlendControl;
59 terrainHeightBlendControl.SetSourceModule(0, terrainHeightBlendScale);
60 terrainHeightBlendControl.SetBounds(0, 1);
62 noise::module::Blend terrainHeightBlend;
63 terrainHeightBlend.SetSourceModule(0, terrainHeightPerlinScaled);
64 terrainHeightBlend.SetSourceModule(1, terrainHeightFractalScaled);
65 terrainHeightBlend.SetControlModule(terrainHeightBlendControl);
67 noise::module::ScaleBias terrainHeightScale;
68 terrainHeightScale.SetSourceModule(0, terrainHeightBlend);
69 terrainHeightScale.SetScale(20.0);
70 terrainHeightScale.SetBias(4.0);
72 noise::module::Clamp terrainHeight;
73 terrainHeight.SetSourceModule(0, terrainHeightScale);
74 terrainHeight.SetBounds(0, 255);
77 noise::module::Perlin foliageDensityPerlin;
79 foliageDensityPerlin.SetFrequency(0.05 / 32);
82 noise::module::Perlin highFrequencyNoise;
84 highFrequencyNoise.SetFrequency(1);
87 const size_t vectorSize =
static_cast<size_t>(mapSize * mapSize);
88 mapNodes.reserve(vectorSize);
91 std:: minstd_rand riverRand;
98 for (
int x = 0; x < mapSize; x++)
100 for (
int y = 0; y < mapSize; y++)
103 double rawHeight = terrainHeight.GetValue(x * 32, y * 32, 0.5);
104 int height =
static_cast<int>(rawHeight);
113 const double foliageDensity = foliageDensityPerlin.GetValue(x * 32, y * 32, height / 32.0);
118 int tileIndex =
static_cast<int>(std::abs(round(highFrequencyNoise.GetValue(x * 32, y * 32, height / 32.0) * 200.0)));
120 if (foliageDensity < 0.1)
124 tileIndex = tileIndex %
static_cast<int>(
m_biomeInformation[currentBiome].treesLight.size());
130 else if (foliageDensity < 0.25)
134 tileIndex = tileIndex %
static_cast<int>(
m_biomeInformation[currentBiome].treesMedium.size());
140 else if (foliageDensity < 1.0 && tileIndex < 95)
142 tileIndex = tileIndex %
static_cast<int>(
m_biomeInformation[currentBiome].treesDense.size());
168 for (
int y = mapSize - 1; y >= 0; y--)
170 for (
int x = 0; x < mapSize; x++)
173 mapNodes[x * mapSize + y].setZIndex(z);
174 mapNodesInDrawingOrder.push_back(&mapNodes[x * mapSize + y]);
181 std::unordered_set<Point> riverNodes;
182 std::vector<Point> neighbors;
183 Point curPoint, nextPoint;
184 double curHeight, nextHeight, neighborHeight;
190 curHeight = mapNodes[curPoint.
toIndex()].getCoordinates().rawHeight;
194 if (riverNodes.find(curPoint) != riverNodes.end())
195 riverNodes.insert(curPoint);
200 for (
int j = 0; j < neighbors.size(); ++j)
202 if (riverNodes.find(neighbors[j]) != riverNodes.end())
204 neighborHeight = mapNodes[neighbors[j].toIndex()].getCoordinates().rawHeight;
205 if (neighborHeight < nextHeight)
207 nextHeight = neighborHeight;
208 nextPoint = neighbors[j];
213 for (
int j = 0; j < neighbors.size(); ++j)
215 neighborHeight = mapNodes[neighbors[j].toIndex()].getCoordinates().
rawHeight;
216 if (neighborHeight <= nextHeight + 0.005 && (riverNodes.find(neighbors[j]) == riverNodes.end()))
218 riverNodes.insert(neighbors[j]);
225 for (
Point point: riverNodes)
227 MapNode *node = &(mapNodes[point.toIndex()]);
236 if (nextHeight > curHeight + 0.03)
242 curPoint = nextPoint;
243 curHeight = nextHeight;
247 LOG(
LOG_INFO) << __func__ << __LINE__ <<
"Number of rivers: " << riverNumber;
253 json biomeDataJsonObject = json::parse(jsonFileContent,
nullptr,
false);
256 if (biomeDataJsonObject.is_discarded())
260 for (
const auto &it : biomeDataJsonObject.items())