diff options
author | Alexander Harkness <me@bearbin.net> | 2024-11-02 22:27:47 +0100 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2024-11-02 22:27:47 +0100 |
commit | cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a (patch) | |
tree | f647b20e1823f1846af88e832cf82a4a02e96e69 /src/Generating | |
parent | Improve clang-format config file, remove automatically enforced code style from contrib guide. (diff) | |
download | cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.gz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.bz2 cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.lz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.xz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.zst cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.zip |
Diffstat (limited to 'src/Generating')
66 files changed, 7789 insertions, 4640 deletions
diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index b71259f08..ddc818c2d 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -35,9 +35,9 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile) AString defaultBiome; switch (StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld"))) { - case dimOverworld: defaultBiome = "Plains"; break; - case dimNether: defaultBiome = "Nether"; break; - case dimEnd: defaultBiome = "End"; break; + case dimOverworld: defaultBiome = "Plains"; break; + case dimNether: defaultBiome = "Nether"; break; + case dimEnd: defaultBiome = "End"; break; case dimNotSet: defaultBiome = "Swampland"; break; } AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", defaultBiome); @@ -57,11 +57,7 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile) // cBioGenCache: cBioGenCache::cBioGenCache(cBiomeGen & a_BioGenToCache, size_t a_CacheSize) : - m_BioGenToCache(a_BioGenToCache), - m_CacheSize(a_CacheSize), - m_NumHits(0), - m_NumMisses(0), - m_TotalChain(0) + m_BioGenToCache(a_BioGenToCache), m_CacheSize(a_CacheSize), m_NumHits(0), m_NumMisses(0), m_TotalChain(0) { m_CacheData.resize(m_CacheSize); m_CacheOrder.resize(m_CacheSize); @@ -79,8 +75,9 @@ void cBioGenCache::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a { if (((m_NumHits + m_NumMisses) % 1024) == 10) { - // LOGD("BioGenCache: %u hits, %u misses, saved %.2f %%", static_cast<unsigned>(m_NumHits), static_cast<unsigned>(m_NumMisses), 100.0 * m_NumHits / (m_NumHits + m_NumMisses)); - // LOGD("BioGenCache: Avg cache chain length: %.2f", static_cast<double>(m_TotalChain) / m_NumHits); + // LOGD("BioGenCache: %u hits, %u misses, saved %.2f %%", static_cast<unsigned>(m_NumHits), + // static_cast<unsigned>(m_NumMisses), 100.0 * m_NumHits / (m_NumHits + m_NumMisses)); LOGD("BioGenCache: Avg + // cache chain length: %.2f", static_cast<double>(m_TotalChain) / m_NumHits); } for (size_t i = 0; i < m_CacheSize; i++) @@ -138,9 +135,12 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cBioGenMulticache: -cBioGenMulticache::cBioGenMulticache(std::unique_ptr<cBiomeGen> a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches) : - m_NumSubCaches(a_NumSubCaches), - m_Underlying(std::move(a_BioGenToCache)) +cBioGenMulticache::cBioGenMulticache( + std::unique_ptr<cBiomeGen> a_BioGenToCache, + size_t a_SubCacheSize, + size_t a_NumSubCaches +) : + m_NumSubCaches(a_NumSubCaches), m_Underlying(std::move(a_BioGenToCache)) { m_Caches.reserve(a_NumSubCaches); for (size_t i = 0; i < a_NumSubCaches; i++) @@ -156,7 +156,9 @@ cBioGenMulticache::cBioGenMulticache(std::unique_ptr<cBiomeGen> a_BioGenToCache, void cBioGenMulticache::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { const size_t coefficient = 3; - const size_t cacheIdx = (static_cast<size_t>(a_ChunkCoords.m_ChunkX) + coefficient * static_cast<size_t>(a_ChunkCoords.m_ChunkZ)) % m_NumSubCaches; + const size_t cacheIdx = + (static_cast<size_t>(a_ChunkCoords.m_ChunkX) + coefficient * static_cast<size_t>(a_ChunkCoords.m_ChunkZ)) % + m_NumSubCaches; m_Caches[cacheIdx]->GenBiomes(a_ChunkCoords, a_BiomeMap); } @@ -221,30 +223,11 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes) } // There were no biomes, add default biomes: - static EMCSBiome Biomes[] = - { - biOcean, - biPlains, - biDesert, - biExtremeHills, - biForest, - biTaiga, - biSwampland, - biRiver, - biFrozenOcean, - biFrozenRiver, - biIcePlains, - biIceMountains, - biMushroomIsland, - biMushroomShore, - biBeach, - biDesertHills, - biForestHills, - biTaigaHills, - biExtremeHillsEdge, - biJungle, - biJungleHills, - } ; + static EMCSBiome Biomes[] = { + biOcean, biPlains, biDesert, biExtremeHills, biForest, biTaiga, biSwampland, + biRiver, biFrozenOcean, biFrozenRiver, biIcePlains, biIceMountains, biMushroomIsland, biMushroomShore, + biBeach, biDesertHills, biForestHills, biTaigaHills, biExtremeHillsEdge, biJungle, biJungleHills, + }; m_Biomes.reserve(ARRAYCOUNT(Biomes)); for (size_t i = 0; i < ARRAYCOUNT(Biomes); i++) { @@ -268,7 +251,9 @@ void cBioGenCheckerboard::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::Biome for (int x = 0; x < cChunkDef::Width; x++) { int Add = cChunkDef::Width * a_ChunkCoords.m_ChunkX + x; - size_t BiomeIdx = static_cast<size_t>((((Base + Add / m_BiomeSize) % m_BiomesCount) + m_BiomesCount) % m_BiomesCount); // Need to add and modulo twice because of negative numbers + size_t BiomeIdx = static_cast<size_t>( + (((Base + Add / m_BiomeSize) % m_BiomesCount) + m_BiomesCount) % m_BiomesCount + ); // Need to add and modulo twice because of negative numbers a_BiomeMap[x + cChunkDef::Width * z] = m_Biomes[BiomeIdx]; } } @@ -281,8 +266,8 @@ void cBioGenCheckerboard::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::Biome void cBioGenCheckerboard::InitializeBiomeGen(cIniFile & a_IniFile) { Super::InitializeBiomeGen(a_IniFile); - AString Biomes = a_IniFile.GetValueSet ("Generator", "CheckerBoardBiomes", ""); - m_BiomeSize = a_IniFile.GetValueSetI("Generator", "CheckerboardBiomeSize", 64); + AString Biomes = a_IniFile.GetValueSet("Generator", "CheckerBoardBiomes", ""); + m_BiomeSize = a_IniFile.GetValueSetI("Generator", "CheckerboardBiomeSize", 64); m_BiomeSize = (m_BiomeSize < 8) ? 8 : m_BiomeSize; InitializeBiomes(Biomes); } @@ -316,13 +301,13 @@ void cBioGenVoronoi::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & void cBioGenVoronoi::InitializeBiomeGen(cIniFile & a_IniFile) { Super::InitializeBiomeGen(a_IniFile); - int CellSize = a_IniFile.GetValueSetI("Generator", "VoronoiCellSize", 128); - int JitterSize = a_IniFile.GetValueSetI("Generator", "VoronoiJitterSize", CellSize); + int CellSize = a_IniFile.GetValueSetI("Generator", "VoronoiCellSize", 128); + int JitterSize = a_IniFile.GetValueSetI("Generator", "VoronoiJitterSize", CellSize); int OddRowOffset = a_IniFile.GetValueSetI("Generator", "VoronoiOddRowOffset", 0); m_Voronoi.SetCellSize(CellSize); m_Voronoi.SetJitterSize(JitterSize); m_Voronoi.SetOddRowOffset(OddRowOffset); - InitializeBiomes(a_IniFile.GetValueSet ("Generator", "VoronoiBiomes", "")); + InitializeBiomes(a_IniFile.GetValueSet("Generator", "VoronoiBiomes", "")); } @@ -340,10 +325,11 @@ void cBioGenDistortedVoronoi::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::B // Distortions for linear interpolation: int DistortX[cChunkDef::Width + 1][cChunkDef::Width + 1]; int DistortZ[cChunkDef::Width + 1][cChunkDef::Width + 1]; - for (int x = 0; x <= 4; x++) for (int z = 0; z <= 4; z++) - { - Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z]); - } + for (int x = 0; x <= 4; x++) + for (int z = 0; z <= 4; z++) + { + Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z]); + } LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortX[0][0]); LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortZ[0][0]); @@ -376,12 +362,40 @@ void cBioGenDistortedVoronoi::InitializeBiomeGen(cIniFile & a_IniFile) void cBioGenDistortedVoronoi::Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ) { - double NoiseX = m_Noise.CubicNoise3D(static_cast<float>(a_BlockX / m_CellSize), static_cast<float>(a_BlockZ / m_CellSize), 1000); - NoiseX += 0.5 * m_Noise.CubicNoise3D(2 * static_cast<float>(a_BlockX / m_CellSize), 2 * static_cast<float>(a_BlockZ / m_CellSize), 2000); - NoiseX += 0.08 * m_Noise.CubicNoise3D(16 * static_cast<float>(a_BlockX / m_CellSize), 16 * static_cast<float>(a_BlockZ / m_CellSize), 3000); - double NoiseZ = m_Noise.CubicNoise3D(static_cast<float>(a_BlockX / m_CellSize), static_cast<float>(a_BlockZ / m_CellSize), 4000); - NoiseZ += 0.5 * m_Noise.CubicNoise3D(2 * static_cast<float>(a_BlockX / m_CellSize), 2 * static_cast<float>(a_BlockZ / m_CellSize), 5000); - NoiseZ += 0.08 * m_Noise.CubicNoise3D(16 * static_cast<float>(a_BlockX / m_CellSize), 16 * static_cast<float>(a_BlockZ / m_CellSize), 6000); + double NoiseX = m_Noise.CubicNoise3D( + static_cast<float>(a_BlockX / m_CellSize), + static_cast<float>(a_BlockZ / m_CellSize), + 1000 + ); + NoiseX += 0.5 * + m_Noise.CubicNoise3D( + 2 * static_cast<float>(a_BlockX / m_CellSize), + 2 * static_cast<float>(a_BlockZ / m_CellSize), + 2000 + ); + NoiseX += 0.08 * + m_Noise.CubicNoise3D( + 16 * static_cast<float>(a_BlockX / m_CellSize), + 16 * static_cast<float>(a_BlockZ / m_CellSize), + 3000 + ); + double NoiseZ = m_Noise.CubicNoise3D( + static_cast<float>(a_BlockX / m_CellSize), + static_cast<float>(a_BlockZ / m_CellSize), + 4000 + ); + NoiseZ += 0.5 * + m_Noise.CubicNoise3D( + 2 * static_cast<float>(a_BlockX / m_CellSize), + 2 * static_cast<float>(a_BlockZ / m_CellSize), + 5000 + ); + NoiseZ += 0.08 * + m_Noise.CubicNoise3D( + 16 * static_cast<float>(a_BlockX / m_CellSize), + 16 * static_cast<float>(a_BlockZ / m_CellSize), + 6000 + ); a_DistortedX = a_BlockX + static_cast<int>(m_CellSize * 0.5 * NoiseX); a_DistortedZ = a_BlockZ + static_cast<int>(m_CellSize * 0.5 * NoiseZ); @@ -416,11 +430,13 @@ cBioGenMultiStepMap::cBioGenMultiStepMap(int a_Seed) : void cBioGenMultiStepMap::InitializeBiomeGen(cIniFile & a_IniFile) { - m_OceanCellSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapOceanCellSize", m_OceanCellSize); - m_MushroomIslandSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapMushroomIslandSize", m_MushroomIslandSize); - m_RiverCellSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapRiverCellSize", m_RiverCellSize); - m_RiverWidthThreshold = a_IniFile.GetValueSetF("Generator", "MultiStepMapRiverWidth", m_RiverWidthThreshold); - m_LandBiomesSize = static_cast<float>(a_IniFile.GetValueSetI("Generator", "MultiStepMapLandBiomeSize", static_cast<int>(m_LandBiomesSize))); + m_OceanCellSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapOceanCellSize", m_OceanCellSize); + m_MushroomIslandSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapMushroomIslandSize", m_MushroomIslandSize); + m_RiverCellSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapRiverCellSize", m_RiverCellSize); + m_RiverWidthThreshold = a_IniFile.GetValueSetF("Generator", "MultiStepMapRiverWidth", m_RiverWidthThreshold); + m_LandBiomesSize = static_cast<float>( + a_IniFile.GetValueSetI("Generator", "MultiStepMapLandBiomeSize", static_cast<int>(m_LandBiomesSize)) + ); } @@ -448,10 +464,11 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(cChunkCoords a_ChunkCoords, cC int DistortX[cChunkDef::Width + 1][cChunkDef::Width + 1]; int DistortZ[cChunkDef::Width + 1][cChunkDef::Width + 1]; int DistortSize = m_OceanCellSize / 2; - for (int x = 0; x <= 4; x++) for (int z = 0; z <= 4; z++) - { - Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z], DistortSize); - } + for (int x = 0; x <= 4; x++) + for (int z = 0; z <= 4; z++) + { + Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z], DistortSize); + } LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortX[0][0]); LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortZ[0][0]); @@ -471,31 +488,30 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(cChunkCoords a_ChunkCoords, cC { int RealCellZ = zc + CellZ - NEIGHBORHOOD_SIZE; int CellBlockZ = RealCellZ * m_OceanCellSize; - int OffsetX = (m_Noise2.IntNoise3DInt(RealCellX, 16 * RealCellX + 32 * RealCellZ, RealCellZ) / 8) % m_OceanCellSize; - int OffsetZ = (m_Noise4.IntNoise3DInt(RealCellX, 32 * RealCellX - 16 * RealCellZ, RealCellZ) / 8) % m_OceanCellSize; + int OffsetX = + (m_Noise2.IntNoise3DInt(RealCellX, 16 * RealCellX + 32 * RealCellZ, RealCellZ) / 8) % m_OceanCellSize; + int OffsetZ = + (m_Noise4.IntNoise3DInt(RealCellX, 32 * RealCellX - 16 * RealCellZ, RealCellZ) / 8) % m_OceanCellSize; SeedX[xc][zc] = CellBlockX + OffsetX; SeedZ[xc][zc] = CellBlockZ + OffsetZ; - SeedV[xc][zc] = (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) ? biOcean : (biInvalidBiome); + SeedV[xc][zc] = + (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) + ? biOcean + : (biInvalidBiome); } // for z } // for x - for (int xc = 1; xc < 2 * NEIGHBORHOOD_SIZE; xc++) for (int zc = 1; zc < 2 * NEIGHBORHOOD_SIZE; zc++) - { - if ( - (SeedV[xc ][zc] == biOcean) && - (SeedV[xc - 1][zc] == biOcean) && - (SeedV[xc + 1][zc] == biOcean) && - (SeedV[xc ][zc - 1] == biOcean) && - (SeedV[xc ][zc + 1] == biOcean) && - (SeedV[xc - 1][zc - 1] == biOcean) && - (SeedV[xc + 1][zc - 1] == biOcean) && - (SeedV[xc - 1][zc + 1] == biOcean) && - (SeedV[xc + 1][zc + 1] == biOcean) - ) - { - SeedV[xc][zc] = biMushroomIsland; + for (int xc = 1; xc < 2 * NEIGHBORHOOD_SIZE; xc++) + for (int zc = 1; zc < 2 * NEIGHBORHOOD_SIZE; zc++) + { + if ((SeedV[xc][zc] == biOcean) && (SeedV[xc - 1][zc] == biOcean) && (SeedV[xc + 1][zc] == biOcean) && + (SeedV[xc][zc - 1] == biOcean) && (SeedV[xc][zc + 1] == biOcean) && + (SeedV[xc - 1][zc - 1] == biOcean) && (SeedV[xc + 1][zc - 1] == biOcean) && + (SeedV[xc - 1][zc + 1] == biOcean) && (SeedV[xc + 1][zc + 1] == biOcean)) + { + SeedV[xc][zc] = biMushroomIsland; + } } - } // For each column find the nearest distorted cell and use its value as the biome: int MushroomOceanThreshold = m_OceanCellSize * m_OceanCellSize * m_MushroomIslandSize / 1024; @@ -509,28 +525,30 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(cChunkCoords a_ChunkCoords, cC int MinDist = m_OceanCellSize * m_OceanCellSize * 16; // There has to be a cell closer than this EMCSBiome Biome = biPlains; // Find the nearest cell seed: - for (int xs = 1; xs < 2 * NEIGHBORHOOD_SIZE; xs++) for (int zs = 1; zs < 2 * NEIGHBORHOOD_SIZE; zs++) - { - int Dist = (SeedX[xs][zs] - AbsoluteX) * (SeedX[xs][zs] - AbsoluteX) + (SeedZ[xs][zs] - AbsoluteZ) * (SeedZ[xs][zs] - AbsoluteZ); - if (Dist >= MinDist) + for (int xs = 1; xs < 2 * NEIGHBORHOOD_SIZE; xs++) + for (int zs = 1; zs < 2 * NEIGHBORHOOD_SIZE; zs++) { - continue; - } - MinDist = Dist; - Biome = SeedV[xs][zs]; - // Shrink mushroom biome and add a shore: - if (Biome == biMushroomIsland) - { - if (Dist > MushroomOceanThreshold) + int Dist = (SeedX[xs][zs] - AbsoluteX) * (SeedX[xs][zs] - AbsoluteX) + + (SeedZ[xs][zs] - AbsoluteZ) * (SeedZ[xs][zs] - AbsoluteZ); + if (Dist >= MinDist) { - Biome = biOcean; + continue; } - else if (Dist > MushroomShoreThreshold) + MinDist = Dist; + Biome = SeedV[xs][zs]; + // Shrink mushroom biome and add a shore: + if (Biome == biMushroomIsland) { - Biome = biMushroomShore; + if (Dist > MushroomOceanThreshold) + { + Biome = biOcean; + } + else if (Dist > MushroomShoreThreshold) + { + Biome = biMushroomShore; + } } - } - } // for zs, xs + } // for zs, xs cChunkDef::SetBiome(a_BiomeMap, x, z, Biome); } // for x @@ -556,7 +574,7 @@ void cBioGenMultiStepMap::AddRivers(cChunkCoords a_ChunkCoords, cChunkDef::Biome float NoiseCoordX = static_cast<float>(a_ChunkCoords.m_ChunkX * cChunkDef::Width + x) / m_RiverCellSize; - double Noise = m_Noise1.CubicNoise2D( NoiseCoordX, NoiseCoordZ); + double Noise = m_Noise1.CubicNoise2D(NoiseCoordX, NoiseCoordZ); Noise += 0.5 * m_Noise3.CubicNoise2D(2 * NoiseCoordX, 2 * NoiseCoordZ); Noise += 0.1 * m_Noise5.CubicNoise2D(8 * NoiseCoordX, 8 * NoiseCoordZ); @@ -588,12 +606,30 @@ void cBioGenMultiStepMap::ApplyTemperatureHumidity(cChunkCoords a_ChunkCoords, c void cBioGenMultiStepMap::Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ, int a_CellSize) { - double NoiseX = m_Noise3.CubicNoise2D( static_cast<float>(a_BlockX / a_CellSize), static_cast<float>(a_BlockZ / a_CellSize)); - NoiseX += 0.5 * m_Noise2.CubicNoise2D(2 * static_cast<float>(a_BlockX / a_CellSize), 2 * static_cast<float>(a_BlockZ / a_CellSize)); - NoiseX += 0.1 * m_Noise1.CubicNoise2D(16 * static_cast<float>(a_BlockX / a_CellSize), 16 * static_cast<float>(a_BlockZ / a_CellSize)); - double NoiseZ = m_Noise6.CubicNoise2D( static_cast<float>(a_BlockX / a_CellSize), static_cast<float>(a_BlockZ / a_CellSize)); - NoiseZ += 0.5 * m_Noise5.CubicNoise2D(2 * static_cast<float>(a_BlockX / a_CellSize), 2 * static_cast<float>(a_BlockZ / a_CellSize)); - NoiseZ += 0.1 * m_Noise4.CubicNoise2D(16 * static_cast<float>(a_BlockX / a_CellSize), 16 * static_cast<float>(a_BlockZ / a_CellSize)); + double NoiseX = + m_Noise3.CubicNoise2D(static_cast<float>(a_BlockX / a_CellSize), static_cast<float>(a_BlockZ / a_CellSize)); + NoiseX += 0.5 * + m_Noise2.CubicNoise2D( + 2 * static_cast<float>(a_BlockX / a_CellSize), + 2 * static_cast<float>(a_BlockZ / a_CellSize) + ); + NoiseX += 0.1 * + m_Noise1.CubicNoise2D( + 16 * static_cast<float>(a_BlockX / a_CellSize), + 16 * static_cast<float>(a_BlockZ / a_CellSize) + ); + double NoiseZ = + m_Noise6.CubicNoise2D(static_cast<float>(a_BlockX / a_CellSize), static_cast<float>(a_BlockZ / a_CellSize)); + NoiseZ += 0.5 * + m_Noise5.CubicNoise2D( + 2 * static_cast<float>(a_BlockX / a_CellSize), + 2 * static_cast<float>(a_BlockZ / a_CellSize) + ); + NoiseZ += 0.1 * + m_Noise4.CubicNoise2D( + 16 * static_cast<float>(a_BlockX / a_CellSize), + 16 * static_cast<float>(a_BlockZ / a_CellSize) + ); a_DistortedX = a_BlockX + static_cast<int>(a_CellSize * 0.5 * NoiseX); a_DistortedZ = a_BlockZ + static_cast<int>(a_CellSize * 0.5 * NoiseZ); @@ -603,7 +639,11 @@ void cBioGenMultiStepMap::Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX -void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(cChunkCoords a_ChunkCoords, IntMap & a_TemperatureMap, IntMap & a_HumidityMap) +void cBioGenMultiStepMap::BuildTemperatureHumidityMaps( + cChunkCoords a_ChunkCoords, + IntMap & a_TemperatureMap, + IntMap & a_HumidityMap +) { // Linear interpolation over 8x8 blocks; use double for better precision: DblMap TemperatureMap; @@ -615,12 +655,12 @@ void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(cChunkCoords a_ChunkCoord { float NoiseCoordX = static_cast<float>(a_ChunkCoords.m_ChunkX * cChunkDef::Width + x) / m_LandBiomesSize; - double NoiseT = m_Noise1.CubicNoise2D( NoiseCoordX, NoiseCoordZ); + double NoiseT = m_Noise1.CubicNoise2D(NoiseCoordX, NoiseCoordZ); NoiseT += 0.5 * m_Noise2.CubicNoise2D(2 * NoiseCoordX, 2 * NoiseCoordZ); NoiseT += 0.1 * m_Noise3.CubicNoise2D(8 * NoiseCoordX, 8 * NoiseCoordZ); TemperatureMap[x + 17 * z] = NoiseT; - double NoiseH = m_Noise4.CubicNoise2D( NoiseCoordX, NoiseCoordZ); + double NoiseH = m_Noise4.CubicNoise2D(NoiseCoordX, NoiseCoordZ); NoiseH += 0.5 * m_Noise5.CubicNoise2D(2 * NoiseCoordX, 2 * NoiseCoordZ); NoiseH += 0.1 * m_Noise6.CubicNoise2D(8 * NoiseCoordX, 8 * NoiseCoordZ); HumidityMap[x + 17 * z] = NoiseH; @@ -633,7 +673,7 @@ void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(cChunkCoords a_ChunkCoord for (size_t idx = 0; idx < ARRAYCOUNT(a_TemperatureMap); idx++) { a_TemperatureMap[idx] = Clamp(static_cast<int>(128 + TemperatureMap[idx] * 128), 0, 255); - a_HumidityMap[idx] = Clamp(static_cast<int>(128 + HumidityMap[idx] * 128), 0, 255); + a_HumidityMap[idx] = Clamp(static_cast<int>(128 + HumidityMap[idx] * 128), 0, 255); } } @@ -641,28 +681,64 @@ void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(cChunkCoords a_ChunkCoord -void cBioGenMultiStepMap::DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap, const IntMap & a_HumidityMap) +void cBioGenMultiStepMap::DecideLandBiomes( + cChunkDef::BiomeMap & a_BiomeMap, + const IntMap & a_TemperatureMap, + const IntMap & a_HumidityMap +) { - static const EMCSBiome BiomeMap[] = - { - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - /* 0 */ biTundra, biTundra, biTundra, biTundra, biPlains, biPlains, biPlains, biPlains, biPlains, biPlains, biDesert, biDesert, biDesert, biDesert, biDesert, biDesert, - /* 1 */ biTundra, biTundra, biTundra, biTundra, biPlains, biPlains, biPlains, biPlains, biPlains, biPlains, biDesert, biDesert, biDesert, biDesert, biDesert, biDesert, - /* 2 */ biTundra, biTundra, biTundra, biTundra, biPlains, biExtremeHills, biPlains, biPlains, biPlains, biPlains, biDesert, biDesert, biDesertHills, biDesertHills, biDesert, biDesert, - /* 3 */ biTundra, biTundra, biTundra, biTundra, biExtremeHills, biExtremeHills, biPlains, biPlains, biPlains, biPlains, biDesert, biDesert, biDesertHills, biDesertHills, biDesert, biDesert, - /* 4 */ biTundra, biTundra, biIceMountains, biIceMountains, biExtremeHills, biExtremeHills, biPlains, biPlains, biPlains, biPlains, biForestHills, biForestHills, biExtremeHills, biExtremeHills, biDesertHills, biDesert, - /* 5 */ biTundra, biTundra, biIceMountains, biIceMountains, biExtremeHills, biExtremeHills, biPlains, biPlains, biPlains, biPlains, biForestHills, biForestHills, biExtremeHills, biExtremeHills, biDesertHills, biDesert, - /* 6 */ biTundra, biTundra, biIceMountains, biIceMountains, biForestHills, biForestHills, biForest, biForest, biForest, biForest, biForest, biForestHills, biExtremeHills, biExtremeHills, biPlains, biPlains, - /* 7 */ biTundra, biTundra, biIceMountains, biIceMountains, biForestHills, biForestHills, biForest, biForest, biForest, biForest, biForest, biForestHills, biExtremeHills, biExtremeHills, biPlains, biPlains, - /* 8 */ biTundra, biTundra, biTaiga, biTaiga, biForest, biForest, biForest, biForest, biForest, biForest, biForest, biForestHills, biExtremeHills, biExtremeHills, biPlains, biPlains, - /* 9 */ biTundra, biTundra, biTaiga, biTaiga, biForest, biForest, biForest, biForest, biForest, biForest, biForest, biForestHills, biExtremeHills, biExtremeHills, biPlains, biPlains, - /* 10 */ biTaiga, biTaiga, biTaiga, biIceMountains, biForestHills, biForestHills, biForest, biForest, biForest, biForest, biJungle, biJungle, biSwampland, biSwampland, biSwampland, biSwampland, - /* 11 */ biTaiga, biTaiga, biIceMountains, biIceMountains, biExtremeHills, biForestHills, biForest, biForest, biForest, biForest, biJungle, biJungle, biSwampland, biSwampland, biSwampland, biSwampland, - /* 12 */ biTaiga, biTaiga, biIceMountains, biIceMountains, biExtremeHills, biJungleHills, biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, biSwampland, biSwampland, biSwampland, biSwampland, - /* 13 */ biTaiga, biTaiga, biTaiga, biIceMountains, biJungleHills, biJungleHills, biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, biSwampland, biSwampland, biSwampland, biSwampland, - /* 14 */ biTaiga, biTaiga, biTaiga, biTaiga, biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, biSwampland, biSwampland, biSwampland, biSwampland, - /* 15 */ biTaiga, biTaiga, biTaiga, biTaiga, biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, biSwampland, biSwampland, biSwampland, biSwampland, - } ; + static const EMCSBiome BiomeMap[] = { + // 0 1 2 3 4 5 6 7 8 9 + // 10 11 12 13 14 15 + /* 0 */ biTundra, biTundra, biTundra, biTundra, biPlains, biPlains, + biPlains, biPlains, biPlains, biPlains, biDesert, biDesert, + biDesert, biDesert, biDesert, biDesert, + /* 1 */ biTundra, biTundra, biTundra, biTundra, biPlains, biPlains, + biPlains, biPlains, biPlains, biPlains, biDesert, biDesert, + biDesert, biDesert, biDesert, biDesert, + /* 2 */ biTundra, biTundra, biTundra, biTundra, biPlains, biExtremeHills, + biPlains, biPlains, biPlains, biPlains, biDesert, biDesert, + biDesertHills, biDesertHills, biDesert, biDesert, + /* 3 */ biTundra, biTundra, biTundra, biTundra, biExtremeHills, biExtremeHills, + biPlains, biPlains, biPlains, biPlains, biDesert, biDesert, + biDesertHills, biDesertHills, biDesert, biDesert, + /* 4 */ biTundra, biTundra, biIceMountains, biIceMountains, biExtremeHills, biExtremeHills, + biPlains, biPlains, biPlains, biPlains, biForestHills, biForestHills, + biExtremeHills, biExtremeHills, biDesertHills, biDesert, + /* 5 */ biTundra, biTundra, biIceMountains, biIceMountains, biExtremeHills, biExtremeHills, + biPlains, biPlains, biPlains, biPlains, biForestHills, biForestHills, + biExtremeHills, biExtremeHills, biDesertHills, biDesert, + /* 6 */ biTundra, biTundra, biIceMountains, biIceMountains, biForestHills, biForestHills, + biForest, biForest, biForest, biForest, biForest, biForestHills, + biExtremeHills, biExtremeHills, biPlains, biPlains, + /* 7 */ biTundra, biTundra, biIceMountains, biIceMountains, biForestHills, biForestHills, + biForest, biForest, biForest, biForest, biForest, biForestHills, + biExtremeHills, biExtremeHills, biPlains, biPlains, + /* 8 */ biTundra, biTundra, biTaiga, biTaiga, biForest, biForest, + biForest, biForest, biForest, biForest, biForest, biForestHills, + biExtremeHills, biExtremeHills, biPlains, biPlains, + /* 9 */ biTundra, biTundra, biTaiga, biTaiga, biForest, biForest, + biForest, biForest, biForest, biForest, biForest, biForestHills, + biExtremeHills, biExtremeHills, biPlains, biPlains, + /* 10 */ biTaiga, biTaiga, biTaiga, biIceMountains, biForestHills, biForestHills, + biForest, biForest, biForest, biForest, biJungle, biJungle, + biSwampland, biSwampland, biSwampland, biSwampland, + /* 11 */ biTaiga, biTaiga, biIceMountains, biIceMountains, biExtremeHills, biForestHills, + biForest, biForest, biForest, biForest, biJungle, biJungle, + biSwampland, biSwampland, biSwampland, biSwampland, + /* 12 */ biTaiga, biTaiga, biIceMountains, biIceMountains, biExtremeHills, biJungleHills, + biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, + biSwampland, biSwampland, biSwampland, biSwampland, + /* 13 */ biTaiga, biTaiga, biTaiga, biIceMountains, biJungleHills, biJungleHills, + biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, + biSwampland, biSwampland, biSwampland, biSwampland, + /* 14 */ biTaiga, biTaiga, biTaiga, biTaiga, biJungle, biJungle, + biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, + biSwampland, biSwampland, biSwampland, biSwampland, + /* 15 */ biTaiga, biTaiga, biTaiga, biTaiga, biJungle, biJungle, + biJungle, biJungle, biJungle, biJungle, biJungle, biJungle, + biSwampland, biSwampland, biSwampland, biSwampland, + }; for (int z = 0; z < cChunkDef::Width; z++) { int idxZ = 17 * z; @@ -675,7 +751,7 @@ void cBioGenMultiStepMap::DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, con } int idx = idxZ + x; int Temperature = a_TemperatureMap[idx] / 16; // -> [0..15] range - int Humidity = a_HumidityMap[idx] / 16; // -> [0..15] range + int Humidity = a_HumidityMap[idx] / 16; // -> [0..15] range cChunkDef::SetBiome(a_BiomeMap, x, z, BiomeMap[Temperature + 16 * Humidity]); } // for x } // for z @@ -701,7 +777,7 @@ void cBioGenMultiStepMap::FreezeWaterBiomes(cChunkDef::BiomeMap & a_BiomeMap, co { case biRiver: cChunkDef::SetBiome(a_BiomeMap, x, z, biFrozenRiver); break; case biOcean: cChunkDef::SetBiome(a_BiomeMap, x, z, biFrozenOcean); break; - default: break; + default: break; } } // for x idx += 1; @@ -751,33 +827,38 @@ void cBioGenTwoLevel::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap // Distortions for linear interpolation: int DistortX[cChunkDef::Width + 1][cChunkDef::Width + 1]; int DistortZ[cChunkDef::Width + 1][cChunkDef::Width + 1]; - for (int x = 0; x <= 4; x++) for (int z = 0; z <= 4; z++) - { - float BlockX = static_cast<float>(BaseX + x * 4); - float BlockZ = static_cast<float>(BaseZ + z * 4); - double NoiseX = m_AmpX1 * m_Noise1.CubicNoise2D(BlockX * m_FreqX1, BlockZ * m_FreqX1); - NoiseX += m_AmpX2 * m_Noise2.CubicNoise2D(BlockX * m_FreqX2, BlockZ * m_FreqX2); - NoiseX += m_AmpX3 * m_Noise3.CubicNoise2D(BlockX * m_FreqX3, BlockZ * m_FreqX3); - double NoiseZ = m_AmpZ1 * m_Noise4.CubicNoise2D(BlockX * m_FreqZ1, BlockZ * m_FreqZ1); - NoiseZ += m_AmpZ2 * m_Noise5.CubicNoise2D(BlockX * m_FreqZ2, BlockZ * m_FreqZ2); - NoiseZ += m_AmpZ3 * m_Noise6.CubicNoise2D(BlockX * m_FreqZ3, BlockZ * m_FreqZ3); - - DistortX[4 * x][4 * z] = static_cast<int>(BlockX + NoiseX); - DistortZ[4 * x][4 * z] = static_cast<int>(BlockZ + NoiseZ); - } + for (int x = 0; x <= 4; x++) + for (int z = 0; z <= 4; z++) + { + float BlockX = static_cast<float>(BaseX + x * 4); + float BlockZ = static_cast<float>(BaseZ + z * 4); + double NoiseX = m_AmpX1 * m_Noise1.CubicNoise2D(BlockX * m_FreqX1, BlockZ * m_FreqX1); + NoiseX += m_AmpX2 * m_Noise2.CubicNoise2D(BlockX * m_FreqX2, BlockZ * m_FreqX2); + NoiseX += m_AmpX3 * m_Noise3.CubicNoise2D(BlockX * m_FreqX3, BlockZ * m_FreqX3); + double NoiseZ = m_AmpZ1 * m_Noise4.CubicNoise2D(BlockX * m_FreqZ1, BlockZ * m_FreqZ1); + NoiseZ += m_AmpZ2 * m_Noise5.CubicNoise2D(BlockX * m_FreqZ2, BlockZ * m_FreqZ2); + NoiseZ += m_AmpZ3 * m_Noise6.CubicNoise2D(BlockX * m_FreqZ3, BlockZ * m_FreqZ3); + + DistortX[4 * x][4 * z] = static_cast<int>(BlockX + NoiseX); + DistortZ[4 * x][4 * z] = static_cast<int>(BlockZ + NoiseZ); + } LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortX[0][0]); LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortZ[0][0]); - // Apply distortion to each block coord, then query the voronoi maps for biome group and biome index and choose biome based on that: + // Apply distortion to each block coord, then query the voronoi maps for biome group and biome index and choose + // biome based on that: for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) { int SeedX, SeedZ, MinDist2; int BiomeGroup = m_VoronoiLarge.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 7; - size_t BiomeIdx = static_cast<size_t>(m_VoronoiSmall.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 11); - int MinDist1 = (DistortX[x][z] - SeedX) * (DistortX[x][z] - SeedX) + (DistortZ[x][z] - SeedZ) * (DistortZ[x][z] - SeedZ); + size_t BiomeIdx = static_cast<size_t>( + m_VoronoiSmall.GetValueAt(DistortX[x][z], DistortZ[x][z], SeedX, SeedZ, MinDist2) / 11 + ); + int MinDist1 = (DistortX[x][z] - SeedX) * (DistortX[x][z] - SeedX) + + (DistortZ[x][z] - SeedZ) * (DistortZ[x][z] - SeedZ); cChunkDef::SetBiome(a_BiomeMap, x, z, SelectBiome(BiomeGroup, BiomeIdx, (MinDist1 < MinDist2 / 4) ? 1 : 0)); } } @@ -794,106 +875,300 @@ EMCSBiome cBioGenTwoLevel::SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int { EMCSBiome InnerBiome; EMCSBiome OuterBiome; - } ; + }; - static BiomeLevels bgOceanBlocks[] = - { - { biOcean, biOcean, }, - { biOcean, biOcean, }, - { biOcean, biOcean, }, - { biOcean, biOcean, }, - { biOcean, biDeepOcean, }, - { biOcean, biDeepOcean, }, - { biDeepOcean, biDeepOcean, }, - { biDeepOcean, biDeepOcean, }, - { biDeepOcean, biDeepOcean, }, - { biDeepOcean, biDeepOcean, }, - { biMushroomIsland, biMushroomShore, } - } ; - static BiomeLevels bgFrozenBlocks[] = - { - { biIcePlains, biIcePlains, }, - { biIceMountains, biIceMountains, }, - { biFrozenOcean, biFrozenRiver, }, - { biColdTaiga, biColdTaiga, }, - { biColdTaigaHills, biColdTaigaHills, }, - { biColdTaigaM, biColdTaigaM, }, - { biIcePlainsSpikes, biIcePlainsSpikes, }, - { biExtremeHills, biExtremeHillsEdge, }, - { biExtremeHillsPlus, biExtremeHillsEdge, }, - { biExtremeHillsPlusM, biExtremeHillsPlusM, }, - } ; - static BiomeLevels bgTemperateBlocks[] = - { - { biBirchForestHills, biBirchForest, }, - { biBirchForest, biBirchForest, }, - { biBirchForestHillsM, biBirchForestM, }, - { biBirchForestM, biBirchForestM, }, - { biForest, biForestHills, }, - { biFlowerForest, biFlowerForest, }, - { biRoofedForest, biForest, }, - { biRoofedForest, biRoofedForest, }, - { biRoofedForestM, biForest, }, - { biPlains, biPlains, }, - { biSunflowerPlains, biSunflowerPlains, }, - { biSwampland, biSwampland, }, - { biSwamplandM, biSwamplandM, }, - } ; - static BiomeLevels bgWarmBlocks[] = - { - { biDesertHills, biDesert, }, - { biDesert, biDesert, }, - { biDesertM, biDesertM, }, - { biSavannaPlateau, biSavanna, }, - { biSavanna, biSavanna, }, - { biSavannaM, biSavannaM, }, - } ; - static BiomeLevels bgMesaBlocks[] = - { - { biMesaPlateau, biMesa, }, - { biMesaPlateauF, biMesa, }, - { biMesaPlateauFM, biMesa, }, - { biMesaPlateauM, biMesa, }, - { biMesaBryce, biMesaBryce, }, - { biSavanna, biSavanna, }, - { biSavannaPlateau, biSavanna, }, - } ; - static BiomeLevels bgConifersBlocks[] = - { - { biTaiga, biTaiga, }, - { biTaigaM, biTaigaM, }, - { biMegaTaiga, biMegaTaiga, }, - { biMegaSpruceTaiga, biMegaSpruceTaiga, }, - { biMegaSpruceTaigaHills, biMegaSpruceTaiga, } - } ; - static BiomeLevels bgDenseTreesBlocks[] = - { - { biJungleHills, biJungle, }, - { biJungle, biJungleEdge, }, - { biJungleM, biJungleEdgeM, }, - } ; + static BiomeLevels bgOceanBlocks[] = { + { + biOcean, + biOcean, + }, + { + biOcean, + biOcean, + }, + { + biOcean, + biOcean, + }, + { + biOcean, + biOcean, + }, + { + biOcean, + biDeepOcean, + }, + { + biOcean, + biDeepOcean, + }, + { + biDeepOcean, + biDeepOcean, + }, + { + biDeepOcean, + biDeepOcean, + }, + { + biDeepOcean, + biDeepOcean, + }, + { + biDeepOcean, + biDeepOcean, + }, + { + biMushroomIsland, + biMushroomShore, + } + }; + static BiomeLevels bgFrozenBlocks[] = { + { + biIcePlains, + biIcePlains, + }, + { + biIceMountains, + biIceMountains, + }, + { + biFrozenOcean, + biFrozenRiver, + }, + { + biColdTaiga, + biColdTaiga, + }, + { + biColdTaigaHills, + biColdTaigaHills, + }, + { + biColdTaigaM, + biColdTaigaM, + }, + { + biIcePlainsSpikes, + biIcePlainsSpikes, + }, + { + biExtremeHills, + biExtremeHillsEdge, + }, + { + biExtremeHillsPlus, + biExtremeHillsEdge, + }, + { + biExtremeHillsPlusM, + biExtremeHillsPlusM, + }, + }; + static BiomeLevels bgTemperateBlocks[] = { + { + biBirchForestHills, + biBirchForest, + }, + { + biBirchForest, + biBirchForest, + }, + { + biBirchForestHillsM, + biBirchForestM, + }, + { + biBirchForestM, + biBirchForestM, + }, + { + biForest, + biForestHills, + }, + { + biFlowerForest, + biFlowerForest, + }, + { + biRoofedForest, + biForest, + }, + { + biRoofedForest, + biRoofedForest, + }, + { + biRoofedForestM, + biForest, + }, + { + biPlains, + biPlains, + }, + { + biSunflowerPlains, + biSunflowerPlains, + }, + { + biSwampland, + biSwampland, + }, + { + biSwamplandM, + biSwamplandM, + }, + }; + static BiomeLevels bgWarmBlocks[] = { + { + biDesertHills, + biDesert, + }, + { + biDesert, + biDesert, + }, + { + biDesertM, + biDesertM, + }, + { + biSavannaPlateau, + biSavanna, + }, + { + biSavanna, + biSavanna, + }, + { + biSavannaM, + biSavannaM, + }, + }; + static BiomeLevels bgMesaBlocks[] = { + { + biMesaPlateau, + biMesa, + }, + { + biMesaPlateauF, + biMesa, + }, + { + biMesaPlateauFM, + biMesa, + }, + { + biMesaPlateauM, + biMesa, + }, + { + biMesaBryce, + biMesaBryce, + }, + { + biSavanna, + biSavanna, + }, + { + biSavannaPlateau, + biSavanna, + }, + }; + static BiomeLevels bgConifersBlocks[] = { + { + biTaiga, + biTaiga, + }, + { + biTaigaM, + biTaigaM, + }, + { + biMegaTaiga, + biMegaTaiga, + }, + { + biMegaSpruceTaiga, + biMegaSpruceTaiga, + }, + { + biMegaSpruceTaigaHills, + biMegaSpruceTaiga, + } + }; + static BiomeLevels bgDenseTreesBlocks[] = { + { + biJungleHills, + biJungle, + }, + { + biJungle, + biJungleEdge, + }, + { + biJungleM, + biJungleEdgeM, + }, + }; static struct { BiomeLevels * Biomes; - size_t Count; - } BiomeGroups[] = - { - { bgOceanBlocks, ARRAYCOUNT(bgOceanBlocks), }, - { bgOceanBlocks, ARRAYCOUNT(bgOceanBlocks), }, - { bgFrozenBlocks, ARRAYCOUNT(bgFrozenBlocks), }, - { bgFrozenBlocks, ARRAYCOUNT(bgFrozenBlocks), }, - { bgTemperateBlocks, ARRAYCOUNT(bgTemperateBlocks), }, - { bgTemperateBlocks, ARRAYCOUNT(bgTemperateBlocks), }, - { bgConifersBlocks, ARRAYCOUNT(bgConifersBlocks), }, - { bgConifersBlocks, ARRAYCOUNT(bgConifersBlocks), }, - { bgWarmBlocks, ARRAYCOUNT(bgWarmBlocks), }, - { bgWarmBlocks, ARRAYCOUNT(bgWarmBlocks), }, - { bgMesaBlocks, ARRAYCOUNT(bgMesaBlocks), }, - { bgDenseTreesBlocks, ARRAYCOUNT(bgDenseTreesBlocks), }, - } ; + size_t Count; + } BiomeGroups[] = { + { + bgOceanBlocks, + ARRAYCOUNT(bgOceanBlocks), + }, + { + bgOceanBlocks, + ARRAYCOUNT(bgOceanBlocks), + }, + { + bgFrozenBlocks, + ARRAYCOUNT(bgFrozenBlocks), + }, + { + bgFrozenBlocks, + ARRAYCOUNT(bgFrozenBlocks), + }, + { + bgTemperateBlocks, + ARRAYCOUNT(bgTemperateBlocks), + }, + { + bgTemperateBlocks, + ARRAYCOUNT(bgTemperateBlocks), + }, + { + bgConifersBlocks, + ARRAYCOUNT(bgConifersBlocks), + }, + { + bgConifersBlocks, + ARRAYCOUNT(bgConifersBlocks), + }, + { + bgWarmBlocks, + ARRAYCOUNT(bgWarmBlocks), + }, + { + bgWarmBlocks, + ARRAYCOUNT(bgWarmBlocks), + }, + { + bgMesaBlocks, + ARRAYCOUNT(bgMesaBlocks), + }, + { + bgDenseTreesBlocks, + ARRAYCOUNT(bgDenseTreesBlocks), + }, + }; size_t Group = static_cast<size_t>(a_BiomeGroup) % ARRAYCOUNT(BiomeGroups); size_t Index = a_BiomeIdx % BiomeGroups[Group].Count; - return (a_DistLevel > 0) ? BiomeGroups[Group].Biomes[Index].InnerBiome : BiomeGroups[Group].Biomes[Index].OuterBiome; + return (a_DistLevel > 0) ? BiomeGroups[Group].Biomes[Index].InnerBiome + : BiomeGroups[Group].Biomes[Index].OuterBiome; } @@ -905,17 +1180,17 @@ void cBioGenTwoLevel::InitializeBiomeGen(cIniFile & a_IniFile) m_VoronoiLarge.SetCellSize(a_IniFile.GetValueSetI("Generator", "TwoLevelLargeCellSize", 1024)); m_VoronoiSmall.SetCellSize(a_IniFile.GetValueSetI("Generator", "TwoLevelSmallCellSize", 128)); m_FreqX1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave1Freq", 0.01)); - m_AmpX1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave1Amp", 80)); + m_AmpX1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave1Amp", 80)); m_FreqX2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave2Freq", 0.05)); - m_AmpX2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave2Amp", 20)); + m_AmpX2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave2Amp", 20)); m_FreqX3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave3Freq", 0.1)); - m_AmpX3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave3Amp", 8)); + m_AmpX3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave3Amp", 8)); m_FreqZ1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave1Freq", 0.01)); - m_AmpZ1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave1Amp", 80)); + m_AmpZ1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave1Amp", 80)); m_FreqZ2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave2Freq", 0.05)); - m_AmpZ2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave2Amp", 20)); + m_AmpZ2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave2Amp", 20)); m_FreqZ3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave3Freq", 0.1)); - m_AmpZ3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave3Amp", 8)); + m_AmpZ3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave3Amp", 8)); } @@ -925,84 +1200,179 @@ void cBioGenTwoLevel::InitializeBiomeGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cBioGenGrown: -class cBioGenGrown: - public cBiomeGen +class cBioGenGrown : public cBiomeGen { -public: + public: cBioGenGrown(int a_Seed) { auto FinalRivers = - std::make_shared<cIntGenChoice<2, 7>>(a_Seed + 12) - | MakeIntGen<cIntGenZoom <10>>(a_Seed + 11) - | MakeIntGen<cIntGenSmooth<8>>(a_Seed + 6) - | MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5) - | MakeIntGen<cIntGenZoom <8>>(a_Seed + 10) - | MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5) - | MakeIntGen<cIntGenZoom <8>>(a_Seed + 9) - | MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5) - | MakeIntGen<cIntGenZoom <8>>(a_Seed + 8) - | MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5) - | MakeIntGen<cIntGenZoom <9>>(a_Seed + 4) - | MakeIntGen<cIntGenRiver <7>>(a_Seed + 3) - | MakeIntGen<cIntGenZoom <10>>(a_Seed + 2) - | MakeIntGen<cIntGenSmooth<8>>(a_Seed + 1); - - auto alteration = - std::make_shared<cIntGenZoom <8>>(a_Seed, - std::make_shared<cIntGenLandOcean<6>>(a_Seed, 20 - )); - - auto alteration2 = - std::make_shared<cIntGenZoom <8>>(a_Seed + 1, - std::make_shared<cIntGenZoom <6>>(a_Seed + 2, - std::make_shared<cIntGenZoom <5>>(a_Seed + 1, - std::make_shared<cIntGenZoom <4>>(a_Seed + 2, - std::make_shared<cIntGenLandOcean<4>>(a_Seed + 1, 10 - ))))); - - auto FinalBiomes = - std::make_shared<cIntGenSmooth <8>> (a_Seed + 1, - std::make_shared<cIntGenZoom <10>>(a_Seed + 15, - std::make_shared<cIntGenSmooth <7>> (a_Seed + 1, - std::make_shared<cIntGenZoom <9>> (a_Seed + 16, - std::make_shared<cIntGenBeaches <6>> ( - std::make_shared<cIntGenZoom <8>> (a_Seed + 1, - std::make_shared<cIntGenAddIslands <6>> (a_Seed + 2004, 10, - std::make_shared<cIntGenAddToOcean <6>> (a_Seed + 10, 500, biDeepOcean, - std::make_shared<cIntGenReplaceRandomly<8>> (a_Seed + 1, biPlains, biSunflowerPlains, 20, - std::make_shared<cIntGenMBiomes <8>> (a_Seed + 5, alteration2, - std::make_shared<cIntGenAlternateBiomes<8>> (a_Seed + 1, alteration, - std::make_shared<cIntGenBiomeEdges <8>> (a_Seed + 3, - std::make_shared<cIntGenZoom <10>>(a_Seed + 2, - std::make_shared<cIntGenZoom <7>> (a_Seed + 4, - std::make_shared<cIntGenReplaceRandomly<5>> (a_Seed + 99, biIcePlains, biIcePlainsSpikes, 50, - std::make_shared<cIntGenZoom <5>> (a_Seed + 8, - std::make_shared<cIntGenAddToOcean <4>> (a_Seed + 10, 300, biDeepOcean, - std::make_shared<cIntGenAddToOcean <6>> (a_Seed + 9, 8, biMushroomIsland, - std::make_shared<cIntGenBiomes <8>> (a_Seed + 3000, - std::make_shared<cIntGenAddIslands <8>> (a_Seed + 2000, 200, - std::make_shared<cIntGenZoom <8>> (a_Seed + 5, - std::make_shared<cIntGenRareBiomeGroups<6>> (a_Seed + 5, 50, - std::make_shared<cIntGenBiomeGroupEdges<6>> ( - std::make_shared<cIntGenAddIslands <8>> (a_Seed + 2000, 200, - std::make_shared<cIntGenZoom <8>> (a_Seed + 7, - std::make_shared<cIntGenSetRandomly <6>> (a_Seed + 8, 50, bgOcean, - std::make_shared<cIntGenReplaceRandomly<6>> (a_Seed + 101, bgIce, bgTemperate, 150, - std::make_shared<cIntGenAddIslands <6>> (a_Seed + 2000, 200, - std::make_shared<cIntGenSetRandomly <6>> (a_Seed + 9, 50, bgOcean, - std::make_shared<cIntGenLandOcean <5>> (a_Seed + 100, 30) - | MakeIntGen<cIntGenZoom <6>> (a_Seed + 10) - ))))))))))))))))))))))))))))); - - m_Gen = - std::make_shared<cIntGenSmooth <16>>(a_Seed, - std::make_shared<cIntGenZoom <18>>(a_Seed, - std::make_shared<cIntGenSmooth <11>>(a_Seed, - std::make_shared<cIntGenZoom <13>>(a_Seed, - std::make_shared<cIntGenMixRivers<8>> ( - FinalBiomes, FinalRivers - ))))); + std::make_shared<cIntGenChoice<2, 7>>(a_Seed + 12) | MakeIntGen<cIntGenZoom<10>>(a_Seed + 11) | + MakeIntGen<cIntGenSmooth<8>>(a_Seed + 6) | MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5) | + MakeIntGen<cIntGenZoom<8>>(a_Seed + 10) | MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5) | + MakeIntGen<cIntGenZoom<8>>(a_Seed + 9) | MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5) | + MakeIntGen<cIntGenZoom<8>>(a_Seed + 8) | MakeIntGen<cIntGenSmooth<6>>(a_Seed + 5) | + MakeIntGen<cIntGenZoom<9>>(a_Seed + 4) | MakeIntGen<cIntGenRiver<7>>(a_Seed + 3) | + MakeIntGen<cIntGenZoom<10>>(a_Seed + 2) | MakeIntGen<cIntGenSmooth<8>>(a_Seed + 1); + + auto alteration = std::make_shared<cIntGenZoom<8>>(a_Seed, std::make_shared<cIntGenLandOcean<6>>(a_Seed, 20)); + + auto alteration2 = std::make_shared<cIntGenZoom<8>>( + a_Seed + 1, + std::make_shared<cIntGenZoom<6>>( + a_Seed + 2, + std::make_shared<cIntGenZoom<5>>( + a_Seed + 1, + std::make_shared<cIntGenZoom<4>>(a_Seed + 2, std::make_shared<cIntGenLandOcean<4>>(a_Seed + 1, 10)) + ) + ) + ); + + auto FinalBiomes = std::make_shared<cIntGenSmooth<8>>( + a_Seed + 1, + std::make_shared<cIntGenZoom<10>>( + a_Seed + 15, + std::make_shared<cIntGenSmooth<7>>( + a_Seed + 1, + std::make_shared<cIntGenZoom<9>>( + a_Seed + 16, + std::make_shared<cIntGenBeaches<6>>(std::make_shared<cIntGenZoom<8>>( + a_Seed + 1, + std::make_shared<cIntGenAddIslands<6>>( + a_Seed + 2004, + 10, + std::make_shared<cIntGenAddToOcean<6>>( + a_Seed + 10, + 500, + biDeepOcean, + std::make_shared<cIntGenReplaceRandomly<8>>( + a_Seed + 1, + biPlains, + biSunflowerPlains, + 20, + std::make_shared<cIntGenMBiomes<8>>( + a_Seed + 5, + alteration2, + std::make_shared<cIntGenAlternateBiomes<8>>( + a_Seed + 1, + alteration, + std::make_shared<cIntGenBiomeEdges<8>>( + a_Seed + 3, + std::make_shared<cIntGenZoom<10>>( + a_Seed + 2, + std::make_shared<cIntGenZoom<7>>( + a_Seed + 4, + std::make_shared<cIntGenReplaceRandomly<5>>( + a_Seed + 99, + biIcePlains, + biIcePlainsSpikes, + 50, + std::make_shared<cIntGenZoom<5>>( + a_Seed + 8, + std::make_shared<cIntGenAddToOcean<4>>( + a_Seed + 10, + 300, + biDeepOcean, + std::make_shared<cIntGenAddToOcean<6>>( + a_Seed + 9, + 8, + biMushroomIsland, + std::make_shared<cIntGenBiomes<8>>( + a_Seed + 3000, + std::make_shared<cIntGenAddIslands<8>>( + a_Seed + 2000, + 200, + std::make_shared<cIntGenZoom<8>>( + a_Seed + 5, + std::make_shared< + cIntGenRareBiomeGroups<6>>( + a_Seed + 5, + 50, + std::make_shared< + cIntGenBiomeGroupEdges<6>>(std::make_shared< + cIntGenAddIslands< + 8>>( + a_Seed + 2000, + 200, + std::make_shared< + cIntGenZoom<8>>( + a_Seed + 7, + std::make_shared< + cIntGenSetRandomly<6>>( + a_Seed + 8, + 50, + bgOcean, + std::make_shared<cIntGenReplaceRandomly< + 6>>( + a_Seed + + 101, + bgIce, + bgTemperate, + 150, + std::make_shared<cIntGenAddIslands< + 6>>( + a_Seed + + 2000, + 200, + std::make_shared<cIntGenSetRandomly< + 6>>( + a_Seed + + 9, + 50, + bgOcean, + std::make_shared< + cIntGenLandOcean< + 5>>( + a_Seed + + 100, + 30 + ) | + MakeIntGen<cIntGenZoom< + 6>>( + a_Seed + + 10 + ) + ) + ) + ) + ) + ) + )) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + )) + ) + ) + ) + ); + + m_Gen = std::make_shared<cIntGenSmooth<16>>( + a_Seed, + std::make_shared<cIntGenZoom<18>>( + a_Seed, + std::make_shared<cIntGenSmooth<11>>( + a_Seed, + std::make_shared<cIntGenZoom<13>>( + a_Seed, + std::make_shared<cIntGenMixRivers<8>>(FinalBiomes, FinalRivers) + ) + ) + ) + ); } virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_Biomes) override @@ -1018,7 +1388,7 @@ public: } } -protected: + protected: std::shared_ptr<cIntGen<16, 16>> m_Gen; }; @@ -1029,90 +1399,223 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cBioGenProtGrown: -class cBioGenProtGrown: - public cBiomeGen +class cBioGenProtGrown : public cBiomeGen { -public: + public: cBioGenProtGrown(int a_Seed) { - auto FinalRivers = - std::make_shared<cProtIntGenSmooth>(a_Seed + 1, - std::make_shared<cProtIntGenZoom >(a_Seed + 2, - std::make_shared<cProtIntGenRiver >(a_Seed + 3, - std::make_shared<cProtIntGenZoom >(a_Seed + 4, - std::make_shared<cProtIntGenSmooth>(a_Seed + 5, - std::make_shared<cProtIntGenZoom >(a_Seed + 8, - std::make_shared<cProtIntGenSmooth>(a_Seed + 5, - std::make_shared<cProtIntGenZoom >(a_Seed + 9, - std::make_shared<cProtIntGenSmooth>(a_Seed + 5, - std::make_shared<cProtIntGenZoom >(a_Seed + 10, - std::make_shared<cProtIntGenSmooth>(a_Seed + 5, - std::make_shared<cProtIntGenSmooth>(a_Seed + 6, - std::make_shared<cProtIntGenZoom >(a_Seed + 11, - std::make_shared<cProtIntGenChoice>(a_Seed + 12, 2 - )))))))))))))); - - auto alteration = - std::make_shared<cProtIntGenZoom >(a_Seed, - std::make_shared<cProtIntGenLandOcean>(a_Seed, 20 - )); - - auto alteration2 = - std::make_shared<cProtIntGenZoom >(a_Seed + 1, - std::make_shared<cProtIntGenZoom >(a_Seed + 2, - std::make_shared<cProtIntGenZoom >(a_Seed + 1, - std::make_shared<cProtIntGenZoom >(a_Seed + 2, - std::make_shared<cProtIntGenLandOcean>(a_Seed + 1, 10 - ))))); - - auto FinalBiomes = - std::make_shared<cProtIntGenSmooth >(a_Seed + 1, - std::make_shared<cProtIntGenZoom >(a_Seed + 15, - std::make_shared<cProtIntGenSmooth >(a_Seed + 1, - std::make_shared<cProtIntGenZoom >(a_Seed + 16, - std::make_shared<cProtIntGenBeaches >( - std::make_shared<cProtIntGenZoom >(a_Seed + 1, - std::make_shared<cProtIntGenAddIslands >(a_Seed + 2004, 10, - std::make_shared<cProtIntGenAddToOcean >(a_Seed + 10, 500, biDeepOcean, - std::make_shared<cProtIntGenReplaceRandomly>(a_Seed + 1, biPlains, biSunflowerPlains, 20, - std::make_shared<cProtIntGenMBiomes >(a_Seed + 5, alteration2, - std::make_shared<cProtIntGenAlternateBiomes>(a_Seed + 1, alteration, - std::make_shared<cProtIntGenBiomeEdges >(a_Seed + 3, - std::make_shared<cProtIntGenZoom >(a_Seed + 2, - std::make_shared<cProtIntGenZoom >(a_Seed + 4, - std::make_shared<cProtIntGenReplaceRandomly>(a_Seed + 99, biIcePlains, biIcePlainsSpikes, 50, - std::make_shared<cProtIntGenZoom >(a_Seed + 8, - std::make_shared<cProtIntGenAddToOcean >(a_Seed + 10, 300, biDeepOcean, - std::make_shared<cProtIntGenAddToOcean >(a_Seed + 9, 8, biMushroomIsland, - std::make_shared<cProtIntGenBiomes >(a_Seed + 3000, - std::make_shared<cProtIntGenAddIslands >(a_Seed + 2000, 200, - std::make_shared<cProtIntGenZoom >(a_Seed + 5, - std::make_shared<cProtIntGenRareBiomeGroups>(a_Seed + 5, 50, - std::make_shared<cProtIntGenBiomeGroupEdges>( - std::make_shared<cProtIntGenAddIslands >(a_Seed + 2000, 200, - std::make_shared<cProtIntGenZoom >(a_Seed + 7, - std::make_shared<cProtIntGenSetRandomly >(a_Seed + 8, 50, bgOcean, - std::make_shared<cProtIntGenReplaceRandomly>(a_Seed + 101, bgIce, bgTemperate, 150, - std::make_shared<cProtIntGenAddIslands >(a_Seed + 2000, 200, - std::make_shared<cProtIntGenSetRandomly >(a_Seed + 9, 50, bgOcean, - std::make_shared<cProtIntGenZoom >(a_Seed + 10, - std::make_shared<cProtIntGenLandOcean >(a_Seed + 100, 30 - ))))))))))))))))))))))))))))))); - - m_Gen = - std::make_shared<cProtIntGenSmooth >(a_Seed, - std::make_shared<cProtIntGenZoom >(a_Seed, - std::make_shared<cProtIntGenSmooth >(a_Seed, - std::make_shared<cProtIntGenZoom >(a_Seed, - std::make_shared<cProtIntGenMixRivers>( - FinalBiomes, FinalRivers - ))))); + auto FinalRivers = std::make_shared<cProtIntGenSmooth>( + a_Seed + 1, + std::make_shared<cProtIntGenZoom>( + a_Seed + 2, + std::make_shared<cProtIntGenRiver>( + a_Seed + 3, + std::make_shared<cProtIntGenZoom>( + a_Seed + 4, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 5, + std::make_shared<cProtIntGenZoom>( + a_Seed + 8, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 5, + std::make_shared<cProtIntGenZoom>( + a_Seed + 9, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 5, + std::make_shared<cProtIntGenZoom>( + a_Seed + 10, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 5, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 6, + std::make_shared<cProtIntGenZoom>( + a_Seed + 11, + std::make_shared<cProtIntGenChoice>(a_Seed + 12, 2) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ); + + auto alteration = std::make_shared<cProtIntGenZoom>(a_Seed, std::make_shared<cProtIntGenLandOcean>(a_Seed, 20)); + + auto alteration2 = std::make_shared<cProtIntGenZoom>( + a_Seed + 1, + std::make_shared<cProtIntGenZoom>( + a_Seed + 2, + std::make_shared<cProtIntGenZoom>( + a_Seed + 1, + std::make_shared<cProtIntGenZoom>( + a_Seed + 2, + std::make_shared<cProtIntGenLandOcean>(a_Seed + 1, 10) + ) + ) + ) + ); + + auto FinalBiomes = std::make_shared<cProtIntGenSmooth>( + a_Seed + 1, + std::make_shared<cProtIntGenZoom>( + a_Seed + 15, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 1, + std::make_shared<cProtIntGenZoom>( + a_Seed + 16, + std::make_shared<cProtIntGenBeaches>(std::make_shared<cProtIntGenZoom>( + a_Seed + 1, + std::make_shared<cProtIntGenAddIslands>( + a_Seed + 2004, + 10, + std::make_shared<cProtIntGenAddToOcean>( + a_Seed + 10, + 500, + biDeepOcean, + std::make_shared<cProtIntGenReplaceRandomly>( + a_Seed + 1, + biPlains, + biSunflowerPlains, + 20, + std::make_shared<cProtIntGenMBiomes>( + a_Seed + 5, + alteration2, + std::make_shared<cProtIntGenAlternateBiomes>( + a_Seed + 1, + alteration, + std::make_shared<cProtIntGenBiomeEdges>( + a_Seed + 3, + std::make_shared<cProtIntGenZoom>( + a_Seed + 2, + std::make_shared<cProtIntGenZoom>( + a_Seed + 4, + std::make_shared<cProtIntGenReplaceRandomly>( + a_Seed + 99, + biIcePlains, + biIcePlainsSpikes, + 50, + std::make_shared<cProtIntGenZoom>( + a_Seed + 8, + std::make_shared<cProtIntGenAddToOcean>( + a_Seed + 10, + 300, + biDeepOcean, + std::make_shared<cProtIntGenAddToOcean>( + a_Seed + 9, + 8, + biMushroomIsland, + std::make_shared<cProtIntGenBiomes>( + a_Seed + 3000, + std::make_shared<cProtIntGenAddIslands>( + a_Seed + 2000, + 200, + std::make_shared<cProtIntGenZoom>( + a_Seed + 5, + std::make_shared< + cProtIntGenRareBiomeGroups>( + a_Seed + 5, + 50, + std::make_shared< + cProtIntGenBiomeGroupEdges>(std::make_shared< + cProtIntGenAddIslands>( + a_Seed + 2000, + 200, + std::make_shared< + cProtIntGenZoom>( + a_Seed + 7, + std::make_shared< + cProtIntGenSetRandomly>( + a_Seed + 8, + 50, + bgOcean, + std::make_shared< + cProtIntGenReplaceRandomly>( + a_Seed + + 101, + bgIce, + bgTemperate, + 150, + std::make_shared< + cProtIntGenAddIslands>( + a_Seed + + 2000, + 200, + std::make_shared< + cProtIntGenSetRandomly>( + a_Seed + + 9, + 50, + bgOcean, + std::make_shared< + cProtIntGenZoom>( + a_Seed + + 10, + std::make_shared< + cProtIntGenLandOcean>( + a_Seed + + 100, + 30 + ) + ) + ) + ) + ) + ) + ) + )) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + )) + ) + ) + ) + ); + + m_Gen = std::make_shared<cProtIntGenSmooth>( + a_Seed, + std::make_shared<cProtIntGenZoom>( + a_Seed, + std::make_shared<cProtIntGenSmooth>( + a_Seed, + std::make_shared<cProtIntGenZoom>( + a_Seed, + std::make_shared<cProtIntGenMixRivers>(FinalBiomes, FinalRivers) + ) + ) + ) + ); } virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_Biomes) override { int vals[16 * 16]; - m_Gen->GetInts(a_ChunkCoords.m_ChunkX * cChunkDef::Width, a_ChunkCoords.m_ChunkZ * cChunkDef::Width, 16, 16, vals); + m_Gen->GetInts( + a_ChunkCoords.m_ChunkX * cChunkDef::Width, + a_ChunkCoords.m_ChunkZ * cChunkDef::Width, + 16, + 16, + vals + ); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) @@ -1122,7 +1625,7 @@ public: } } -protected: + protected: std::shared_ptr<cProtIntGen> m_Gen; }; diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index 3c630e396..5ee2cf950 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -22,37 +22,35 @@ Interfaces to the various biome generators: -class cBioGenConstant : - public cBiomeGen +class cBioGenConstant : public cBiomeGen { -public: - cBioGenConstant(void) : m_Biome(biPlains) {} - -protected: + public: + cBioGenConstant(void) : + m_Biome(biPlains) + { + } + protected: EMCSBiome m_Biome; // cBiomeGen overrides: virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void InitializeBiomeGen(cIniFile & a_IniFile) override; -} ; +}; /** A simple cache that stores N most recently generated chunks' biomes; N being settable upon creation */ -class cBioGenCache: - public cBiomeGen +class cBioGenCache : public cBiomeGen { using Super = cBiomeGen; -public: - + public: cBioGenCache(cBiomeGen & a_BioGenToCache, size_t a_CacheSize); -protected: - + protected: friend class cBioGenMulticache; cBiomeGen & m_BioGenToCache; @@ -62,17 +60,18 @@ protected: cChunkCoords m_Coords; cChunkDef::BiomeMap m_BiomeMap; - /** Default constructor: Fill in bogus coords so that the item is not used in the cache until properly calculated. */ - sCacheData(): + /** Default constructor: Fill in bogus coords so that the item is not used in the cache until properly + * calculated. */ + sCacheData() : m_Coords(0x7fffffff, 0x7fffffff) { } - } ; + }; // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data - size_t m_CacheSize; - std::vector<size_t> m_CacheOrder; // MRU-ized order, indices into m_CacheData array - std::vector<sCacheData> m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used + size_t m_CacheSize; + std::vector<size_t> m_CacheOrder; // MRU-ized order, indices into m_CacheData array + std::vector<sCacheData> m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used // Cache statistics size_t m_NumHits; @@ -81,26 +80,24 @@ protected: virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void InitializeBiomeGen(cIniFile & a_IniFile) override; -} ; +}; -class cBioGenMulticache: - public cBiomeGen +class cBioGenMulticache : public cBiomeGen { using Super = cBiomeGen; -public: + public: /* Creates a new multicache - a cache that divides the caching into several sub-caches based on the chunk coords. This allows us to use shorter cache depths with faster lookups for more covered area. (#381) a_SubCacheSize defines the size of each sub-cache a_NumSubCaches defines how many sub-caches are used for the multicache. */ cBioGenMulticache(std::unique_ptr<cBiomeGen> a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches); -protected: - + protected: /** Number of sub-caches. Pulled out of m_Caches.size() for faster access. */ size_t m_NumSubCaches; @@ -120,58 +117,51 @@ protected: /** Base class for generators that use a list of available biomes. This class takes care of the list. */ -class cBiomeGenList: - public cBiomeGen +class cBiomeGenList : public cBiomeGen { using Super = cBiomeGen; -protected: - + protected: // List of biomes that the generator is allowed to generate: typedef std::vector<EMCSBiome> EMCSBiomes; EMCSBiomes m_Biomes; - int m_BiomesCount; // Pulled out of m_Biomes for faster access + int m_BiomesCount; // Pulled out of m_Biomes for faster access /** Parses the INI file setting string into m_Biomes. */ void InitializeBiomes(const AString & a_Biomes); -} ; +}; -class cBioGenCheckerboard: - public cBiomeGenList +class cBioGenCheckerboard : public cBiomeGenList { using Super = cBiomeGenList; -protected: - + protected: int m_BiomeSize; // cBiomeGen overrides: virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void InitializeBiomeGen(cIniFile & a_IniFile) override; -} ; +}; -class cBioGenVoronoi: - public cBiomeGenList +class cBioGenVoronoi : public cBiomeGenList { using Super = cBiomeGenList; -public: - + public: cBioGenVoronoi(int a_Seed) : m_Voronoi(a_Seed) { } -protected: - + protected: cVoronoiMap m_Voronoi; // cBiomeGen overrides: @@ -179,27 +169,23 @@ protected: virtual void InitializeBiomeGen(cIniFile & a_IniFile) override; EMCSBiome VoronoiBiome(int a_BlockX, int a_BlockZ); -} ; +}; -class cBioGenDistortedVoronoi: - public cBiomeGenList +class cBioGenDistortedVoronoi : public cBiomeGenList { using Super = cBiomeGenList; -public: - - cBioGenDistortedVoronoi(int a_Seed): - m_Noise(a_Seed), - m_Voronoi(a_Seed), - m_CellSize(0) + public: + cBioGenDistortedVoronoi(int a_Seed) : + m_Noise(a_Seed), m_Voronoi(a_Seed), m_CellSize(0) { } -protected: + protected: /** Noise used for the distortion */ cNoise m_Noise; @@ -215,22 +201,20 @@ protected: /** Distorts the coords using a Perlin-like noise */ void Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ); -} ; +}; -class cBioGenMultiStepMap: - public cBiomeGen +class cBioGenMultiStepMap : public cBiomeGen { using Super = cBiomeGen; -public: - + public: cBioGenMultiStepMap(int a_Seed); -protected: + protected: // Noises used for composing the perlin-noise: cNoise m_Noise1; cNoise m_Noise2; @@ -239,22 +223,22 @@ protected: cNoise m_Noise5; cNoise m_Noise6; - int m_Seed; - int m_OceanCellSize; - int m_MushroomIslandSize; - int m_RiverCellSize; + int m_Seed; + int m_OceanCellSize; + int m_MushroomIslandSize; + int m_RiverCellSize; double m_RiverWidthThreshold; - float m_LandBiomesSize; + float m_LandBiomesSize; - typedef int IntMap[17 * 17]; // x + 17 * z, expected trimmed into [0..255] range + typedef int IntMap[17 * 17]; // x + 17 * z, expected trimmed into [0..255] range typedef double DblMap[17 * 17]; // x + 17 * z, expected trimmed into [0..1] range // cBiomeGen overrides: virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void InitializeBiomeGen(cIniFile & a_IniFile) override; - /** Step 1: Decides between ocean, land and mushroom, using a DistVoronoi with special conditions and post-processing for mushroom islands - Sets biomes to biOcean, -1 (i.e. land), biMushroomIsland or biMushroomShore. */ + /** Step 1: Decides between ocean, land and mushroom, using a DistVoronoi with special conditions and + post-processing for mushroom islands Sets biomes to biOcean, -1 (i.e. land), biMushroomIsland or biMushroomShore. */ void DecideOceanLandMushroom(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap); /** Step 2: Add rivers to the land @@ -262,7 +246,8 @@ protected: void AddRivers(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap); /** Step 3: Decide land biomes using a temperature / humidity map; freeze ocean / river in low temperatures. - Flips all remaining "-1" biomes into land biomes. Also flips some biOcean and biRiver into biFrozenOcean, biFrozenRiver, based on temp map. */ + Flips all remaining "-1" biomes into land biomes. Also flips some biOcean and biRiver into biFrozenOcean, + biFrozenRiver, based on temp map. */ void ApplyTemperatureHumidity(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap); /** Distorts the coords using a Perlin-like noise, with a specified cell-size */ @@ -272,26 +257,28 @@ protected: void BuildTemperatureHumidityMaps(cChunkCoords a_ChunkCoords, IntMap & a_TemperatureMap, IntMap & a_HumidityMap); /** Flips all remaining "-1" biomes into land biomes using the two maps */ - void DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap, const IntMap & a_HumidityMap); + void DecideLandBiomes( + cChunkDef::BiomeMap & a_BiomeMap, + const IntMap & a_TemperatureMap, + const IntMap & a_HumidityMap + ); /** Flips biOcean and biRiver into biFrozenOcean and biFrozenRiver if the temperature is too low */ void FreezeWaterBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap); -} ; +}; -class cBioGenTwoLevel: - public cBiomeGen +class cBioGenTwoLevel : public cBiomeGen { using Super = cBiomeGen; -public: - + public: cBioGenTwoLevel(int a_Seed); -protected: + protected: /** The Voronoi map that decides the groups of biomes */ cVoronoiMap m_VoronoiLarge; @@ -323,4 +310,4 @@ protected: Note that both params may overflow a_DistLevel is either 0 or 1; zero when it is at the edge of the small Voronoi cell, 1 near the center */ EMCSBiome SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel); -} ; +}; diff --git a/src/Generating/Caves.cpp b/src/Generating/Caves.cpp index 27978dd75..f41a9f389 100644 --- a/src/Generating/Caves.cpp +++ b/src/Generating/Caves.cpp @@ -13,14 +13,14 @@ Caves are generated in "nests" - groups of tunnels generated from a single point For each chunk, all the nests that could intersect it are generated. For each nest, first the schematic structure is generated (tunnel from ... to ..., branch, tunnel2 from ... to ...) Then each tunnel is randomized by inserting points in between its ends. -Finally each tunnel is smoothed and Bresenham-3D-ed so that it is a collection of spheres with their centers next to each other. -When the tunnels are ready, they are simply carved into the chunk, one by one. -To optimize, each tunnel keeps track of its bounding box, so that it can be skipped for chunks that don't intersect it. +Finally each tunnel is smoothed and Bresenham-3D-ed so that it is a collection of spheres with their centers next to +each other. When the tunnels are ready, they are simply carved into the chunk, one by one. To optimize, each tunnel +keeps track of its bounding box, so that it can be skipped for chunks that don't intersect it. MarbleCaves generator: -For each voxel a 3D noise function is evaluated, if the value crosses a boundary, the voxel is dug out, otherwise it is kept. -Problem with this is the amount of CPU work needed for each chunk. -Also the overall shape of the generated holes is unsatisfactory - there are whole "sheets" of holes in the ground. +For each voxel a 3D noise function is evaluated, if the value crosses a boundary, the voxel is dug out, otherwise it is +kept. Problem with this is the amount of CPU work needed for each chunk. Also the overall shape of the generated holes +is unsatisfactory - there are whole "sheets" of holes in the ground. DualRidgeCaves generator: Instead of evaluating a single noise function, two different noise functions are multiplied. This produces @@ -51,13 +51,10 @@ struct cCaveDefPoint int m_Radius; cCaveDefPoint(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Radius) : - m_BlockX(a_BlockX), - m_BlockY(a_BlockY), - m_BlockZ(a_BlockZ), - m_Radius(a_Radius) + m_BlockX(a_BlockX), m_BlockY(a_BlockY), m_BlockZ(a_BlockZ), m_Radius(a_Radius) { } -} ; +}; typedef std::vector<cCaveDefPoint> cCaveDefPoints; @@ -76,7 +73,8 @@ class cCaveTunnel /** Generates the shaping defpoints for the cave, based on the cave block coords and noise */ void Randomize(cNoise & a_Noise); - /** Refines (adds and smooths) defpoints from a_Src into a_Dst; returns false if no refinement possible (segments too short) */ + /** Refines (adds and smooths) defpoints from a_Src into a_Dst; returns false if no refinement possible (segments + * too short) */ bool RefineDefPoints(const cCaveDefPoints & a_Src, cCaveDefPoints & a_Dst); /** Does rounds of smoothing, two passes of RefineDefPoints(), as long as they return true */ @@ -88,27 +86,34 @@ class cCaveTunnel /** Calculates the bounding box of the points present */ void CalcBoundingBox(void); -public: + public: cCaveDefPoints m_Points; cCaveTunnel( - int a_BlockStartX, int a_BlockStartY, int a_BlockStartZ, int a_StartRadius, - int a_BlockEndX, int a_BlockEndY, int a_BlockEndZ, int a_EndRadius, + int a_BlockStartX, + int a_BlockStartY, + int a_BlockStartZ, + int a_StartRadius, + int a_BlockEndX, + int a_BlockEndY, + int a_BlockEndZ, + int a_EndRadius, cNoise & a_Noise ); /** Carves the tunnel into the chunk specified */ void ProcessChunk( - int a_ChunkX, int a_ChunkZ, + int a_ChunkX, + int a_ChunkZ, cChunkDef::BlockTypes & a_BlockTypes, cChunkDesc::BlockNibbleBytes & a_BlockMetas, cChunkDef::HeightMap & a_HeightMap ); - #ifndef NDEBUG +#ifndef NDEBUG AString ExportAsSVG(int a_Color, int a_OffsetX, int a_OffsetZ) const; - #endif // !NDEBUG -} ; +#endif // !NDEBUG +}; typedef std::vector<cCaveTunnel *> cCaveTunnels; @@ -117,13 +122,11 @@ typedef std::vector<cCaveTunnel *> cCaveTunnels; /** A collection of connected tunnels, possibly branching. */ -class cStructGenWormNestCaves::cCaveSystem: - public cGridStructGen::cStructure +class cStructGenWormNestCaves::cCaveSystem : public cGridStructGen::cStructure { using Super = cGridStructGen::cStructure; -public: - + public: // The generating block position; is read directly in cStructGenWormNestCaves::GetCavesForChunk() int m_BlockX; int m_BlockZ; @@ -131,24 +134,22 @@ public: cCaveSystem(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_MaxOffset, int a_Size, cNoise & a_Noise); virtual ~cCaveSystem() override; -protected: + protected: int m_Size; cCaveTunnels m_Tunnels; void Clear(void); - /** Generates a_Segment successive tunnels, with possible branches. Generates the same output for the same [x, y, z, a_Segments] */ - void GenerateTunnelsFromPoint( - int a_OriginX, int a_OriginY, int a_OriginZ, - cNoise & a_Noise, int a_Segments - ); + /** Generates a_Segment successive tunnels, with possible branches. Generates the same output for the same [x, y, z, + * a_Segments] */ + void GenerateTunnelsFromPoint(int a_OriginX, int a_OriginY, int a_OriginZ, cNoise & a_Noise, int a_Segments); /** Returns a radius based on the location provided. */ int GetRadius(cNoise & a_Noise, int a_OriginX, int a_OriginY, int a_OriginZ); // cGridStructGen::cStructure overrides: virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override; -} ; +}; @@ -158,13 +159,19 @@ protected: // cCaveTunnel: cCaveTunnel::cCaveTunnel( - int a_BlockStartX, int a_BlockStartY, int a_BlockStartZ, int a_StartRadius, - int a_BlockEndX, int a_BlockEndY, int a_BlockEndZ, int a_EndRadius, + int a_BlockStartX, + int a_BlockStartY, + int a_BlockStartZ, + int a_StartRadius, + int a_BlockEndX, + int a_BlockEndY, + int a_BlockEndZ, + int a_EndRadius, cNoise & a_Noise ) { m_Points.emplace_back(a_BlockStartX, a_BlockStartY, a_BlockStartZ, a_StartRadius); - m_Points.emplace_back(a_BlockEndX, a_BlockEndY, a_BlockEndZ, a_EndRadius); + m_Points.emplace_back(a_BlockEndX, a_BlockEndY, a_BlockEndZ, a_EndRadius); if ((a_BlockStartY <= 0) && (a_BlockEndY <= 0)) { @@ -356,7 +363,7 @@ void cCaveTunnel::FinishLinear(void) } // move along x - PrevX += sx; + PrevX += sx; yd += dy; zd += dz; } @@ -456,7 +463,8 @@ void cCaveTunnel::CalcBoundingBox(void) void cCaveTunnel::ProcessChunk( - int a_ChunkX, int a_ChunkZ, + int a_ChunkX, + int a_ChunkZ, cChunkDef::BlockTypes & a_BlockTypes, cChunkDesc::BlockNibbleBytes & a_BlockMetas, cChunkDef::HeightMap & a_HeightMap @@ -464,10 +472,8 @@ void cCaveTunnel::ProcessChunk( { int BaseX = a_ChunkX * cChunkDef::Width; int BaseZ = a_ChunkZ * cChunkDef::Width; - if ( - (BaseX > m_MaxBlockX) || (BaseX + cChunkDef::Width < m_MinBlockX) || - (BaseZ > m_MaxBlockZ) || (BaseZ + cChunkDef::Width < m_MinBlockZ) - ) + if ((BaseX > m_MaxBlockX) || (BaseX + cChunkDef::Width < m_MinBlockX) || (BaseZ > m_MaxBlockZ) || + (BaseZ + cChunkDef::Width < m_MinBlockZ)) { // Tunnel does not intersect the chunk at all, bail out return; @@ -479,12 +485,8 @@ void cCaveTunnel::ProcessChunk( int BlockEndZ = BlockStartZ + cChunkDef::Width; for (cCaveDefPoints::const_iterator itr = m_Points.begin(), end = m_Points.end(); itr != end; ++itr) { - if ( - (itr->m_BlockX + itr->m_Radius < BlockStartX) || - (itr->m_BlockX - itr->m_Radius > BlockEndX) || - (itr->m_BlockZ + itr->m_Radius < BlockStartZ) || - (itr->m_BlockZ - itr->m_Radius > BlockEndZ) - ) + if ((itr->m_BlockX + itr->m_Radius < BlockStartX) || (itr->m_BlockX - itr->m_Radius > BlockEndX) || + (itr->m_BlockZ + itr->m_Radius < BlockStartZ) || (itr->m_BlockZ - itr->m_Radius > BlockEndZ)) { // Cannot intersect, bail out early continue; @@ -495,38 +497,39 @@ void cCaveTunnel::ProcessChunk( int DifY = itr->m_BlockY; int DifZ = itr->m_BlockZ - BlockStartZ; // substitution for faster calc int Bottom = std::max(itr->m_BlockY - 3 * itr->m_Radius / 7, 1); - int Top = std::min(itr->m_BlockY + 3 * itr->m_Radius / 7, static_cast<int>(cChunkDef::Height)); - int SqRad = itr->m_Radius * itr->m_Radius; - for (int z = 0; z < cChunkDef::Width; z++) for (int x = 0; x < cChunkDef::Width; x++) - { - for (int y = Bottom; y <= Top; y++) + int Top = std::min(itr->m_BlockY + 3 * itr->m_Radius / 7, static_cast<int>(cChunkDef::Height)); + int SqRad = itr->m_Radius * itr->m_Radius; + for (int z = 0; z < cChunkDef::Width; z++) + for (int x = 0; x < cChunkDef::Width; x++) { - int SqDist = (DifX - x) * (DifX - x) + (DifY - y) * (DifY - y) + (DifZ - z) * (DifZ - z); - if (4 * SqDist <= SqRad) + for (int y = Bottom; y <= Top; y++) { - if (cBlockInfo::CanBeTerraformed(cChunkDef::GetBlock(a_BlockTypes, x, y, z))) + int SqDist = (DifX - x) * (DifX - x) + (DifY - y) * (DifY - y) + (DifZ - z) * (DifZ - z); + if (4 * SqDist <= SqRad) { - cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_AIR); - } - } - else if (SqDist <= SqRad * 2) - { - if (cChunkDef::GetBlock(a_BlockTypes, x, y, z) == E_BLOCK_SAND) - { - const auto Index = cChunkDef::MakeIndex(x, y, z); - if (a_BlockMetas[Index] == 1) + if (cBlockInfo::CanBeTerraformed(cChunkDef::GetBlock(a_BlockTypes, x, y, z))) { - a_BlockMetas[Index] = 0; - cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_RED_SANDSTONE); + cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_AIR); } - else + } + else if (SqDist <= SqRad * 2) + { + if (cChunkDef::GetBlock(a_BlockTypes, x, y, z) == E_BLOCK_SAND) { - cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_SANDSTONE); + const auto Index = cChunkDef::MakeIndex(x, y, z); + if (a_BlockMetas[Index] == 1) + { + a_BlockMetas[Index] = 0; + cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_RED_SANDSTONE); + } + else + { + cChunkDef::SetBlock(a_BlockTypes, x, y, z, E_BLOCK_SANDSTONE); + } } } - } - } // for y - } // for x, z + } // for y + } // for x, z } // for itr - m_Points[] /* @@ -577,23 +580,30 @@ AString cCaveTunnel::ExportAsSVG(int a_Color, int a_OffsetX, int a_OffsetZ) cons //////////////////////////////////////////////////////////////////////////////// // cStructGenWormNestCaves::cCaveSystem: -cStructGenWormNestCaves::cCaveSystem::cCaveSystem(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_MaxOffset, int a_Size, cNoise & a_Noise) : - Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), - m_Size(a_Size) +cStructGenWormNestCaves::cCaveSystem::cCaveSystem( + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ, + int a_MaxOffset, + int a_Size, + cNoise & a_Noise +) : + Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Size(a_Size) { int Num = 1 + a_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) % 3; for (int i = 0; i < Num; i++) { int OriginX = a_OriginX + (a_Noise.IntNoise3DInt(13 * a_OriginX, 17 * a_OriginZ, 11 * i) / 19) % a_MaxOffset; int OriginZ = a_OriginZ + (a_Noise.IntNoise3DInt(17 * a_OriginX, 13 * a_OriginZ, 11 * i) / 23) % a_MaxOffset; - int OriginY = 20 + (a_Noise.IntNoise3DInt(19 * a_OriginX, 13 * a_OriginZ, 11 * i) / 17) % 20; + int OriginY = 20 + (a_Noise.IntNoise3DInt(19 * a_OriginX, 13 * a_OriginZ, 11 * i) / 17) % 20; // Generate three branches from the origin point: // The tunnels generated depend on X, Y, Z and Branches, // for the same set of numbers it generates the same offsets! // That's why we add a +1 to X in the third line - GenerateTunnelsFromPoint(OriginX, OriginY, OriginZ, a_Noise, 3); - GenerateTunnelsFromPoint(OriginX, OriginY, OriginZ, a_Noise, 2); + GenerateTunnelsFromPoint(OriginX, OriginY, OriginZ, a_Noise, 3); + GenerateTunnelsFromPoint(OriginX, OriginY, OriginZ, a_Noise, 2); GenerateTunnelsFromPoint(OriginX + 1, OriginY, OriginZ, a_Noise, 3); } } @@ -615,8 +625,8 @@ void cStructGenWormNestCaves::cCaveSystem::DrawIntoChunk(cChunkDesc & a_ChunkDes { int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); - cChunkDef::BlockTypes & BlockTypes = a_ChunkDesc.GetBlockTypes(); - cChunkDef::HeightMap & HeightMap = a_ChunkDesc.GetHeightMap(); + cChunkDef::BlockTypes & BlockTypes = a_ChunkDesc.GetBlockTypes(); + cChunkDef::HeightMap & HeightMap = a_ChunkDesc.GetHeightMap(); cChunkDesc::BlockNibbleBytes & BlockMetas = a_ChunkDesc.GetBlockMetasUncompressed(); for (cCaveTunnels::const_iterator itr = m_Tunnels.begin(), end = m_Tunnels.end(); itr != end; ++itr) { @@ -642,17 +652,26 @@ void cStructGenWormNestCaves::cCaveSystem::Clear(void) void cStructGenWormNestCaves::cCaveSystem::GenerateTunnelsFromPoint( - int a_OriginX, int a_OriginY, int a_OriginZ, - cNoise & a_Noise, int a_NumSegments + int a_OriginX, + int a_OriginY, + int a_OriginZ, + cNoise & a_Noise, + int a_NumSegments ) { int DoubleSize = m_Size * 2; int Radius = GetRadius(a_Noise, a_OriginX + a_OriginY, a_OriginY + a_OriginZ, a_OriginZ + a_OriginX); for (int i = a_NumSegments - 1; i >= 0; --i) { - int EndX = a_OriginX + (((a_Noise.IntNoise3DInt(a_OriginX, a_OriginY, a_OriginZ + 11 * a_NumSegments) / 7) % DoubleSize) - m_Size) / 2; - int EndY = a_OriginY + (((a_Noise.IntNoise3DInt(a_OriginY, 13 * a_NumSegments, a_OriginZ + a_OriginX) / 7) % DoubleSize) - m_Size) / 4; - int EndZ = a_OriginZ + (((a_Noise.IntNoise3DInt(a_OriginZ + 17 * a_NumSegments, a_OriginX, a_OriginY) / 7) % DoubleSize) - m_Size) / 2; + int EndX = a_OriginX + + (((a_Noise.IntNoise3DInt(a_OriginX, a_OriginY, a_OriginZ + 11 * a_NumSegments) / 7) % DoubleSize) - m_Size + ) / 2; + int EndY = a_OriginY + + (((a_Noise.IntNoise3DInt(a_OriginY, 13 * a_NumSegments, a_OriginZ + a_OriginX) / 7) % DoubleSize) - m_Size + ) / 4; + int EndZ = a_OriginZ + + (((a_Noise.IntNoise3DInt(a_OriginZ + 17 * a_NumSegments, a_OriginX, a_OriginY) / 7) % DoubleSize) - m_Size + ) / 2; int EndR = GetRadius(a_Noise, a_OriginX + 7 * i, a_OriginY + 11 * i, a_OriginZ + a_OriginX); m_Tunnels.push_back(new cCaveTunnel(a_OriginX, a_OriginY, a_OriginZ, Radius, EndX, EndY, EndZ, EndR, a_Noise)); GenerateTunnelsFromPoint(EndX, EndY, EndZ, a_Noise, i); @@ -669,16 +688,18 @@ void cStructGenWormNestCaves::cCaveSystem::GenerateTunnelsFromPoint( int cStructGenWormNestCaves::cCaveSystem::GetRadius(cNoise & a_Noise, int a_OriginX, int a_OriginY, int a_OriginZ) { - // Instead of a flat distribution noise function, we need to shape it, so that most caves are smallish and only a few select are large + // Instead of a flat distribution noise function, we need to shape it, so that most caves are smallish and only a + // few select are large int rnd = a_Noise.IntNoise3DInt(a_OriginX, a_OriginY, a_OriginZ) / 11; /* // Not good enough: - // The algorithm of choice: emulate gauss-distribution noise by adding 3 flat noises, then fold it in half using absolute value. + // The algorithm of choice: emulate gauss-distribution noise by adding 3 flat noises, then fold it in half using + absolute value. // To save on processing, use one random value and extract 3 bytes to be separately added as the gaussian noise int sum = (rnd & 0xff) + ((rnd >> 8) & 0xff) + ((rnd >> 16) & 0xff); // sum is now a gaussian-distribution noise within [0 .. 767], with center at 384. - // We want mapping 384 -> 3, 0 -> 19, 768 -> 19, so divide by 24 to get [0 .. 31] with center at 16, then use abs() to fold around the center - int res = 3 + abs((sum / 24) - 16); + // We want mapping 384 -> 3, 0 -> 19, 768 -> 19, so divide by 24 to get [0 .. 31] with center at 16, then use abs() + to fold around the center int res = 3 + abs((sum / 24) - 16); */ // Algorithm of choice: random value in the range of zero to random value - heavily towards zero @@ -693,7 +714,12 @@ int cStructGenWormNestCaves::cCaveSystem::GetRadius(cNoise & a_Noise, int a_Orig //////////////////////////////////////////////////////////////////////////////// // cStructGenWormNestCaves: -cGridStructGen::cStructurePtr cStructGenWormNestCaves::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) +cGridStructGen::cStructurePtr cStructGenWormNestCaves::CreateStructure( + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ +) { return cStructurePtr(new cCaveSystem(a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxOffset, m_Size, m_Noise)); } @@ -705,7 +731,7 @@ cGridStructGen::cStructurePtr cStructGenWormNestCaves::CreateStructure(int a_Gri //////////////////////////////////////////////////////////////////////////////// // cStructGenMarbleCaves: -static float GetMarbleNoise( float x, float y, float z, cNoise & a_Noise) +static float GetMarbleNoise(float x, float y, float z, cNoise & a_Noise) { static const float PI_2 = 1.57079633f; float oct1 = (a_Noise.CubicNoise3D(x * 0.1f, y * 0.1f, z * 0.1f)) * 4; @@ -747,7 +773,9 @@ void cStructGenMarbleCaves::GenFinish(cChunkDesc & a_ChunkDesc) const float yy = static_cast<float>(y); const float WaveNoise = 1; - if (cosf(GetMarbleNoise(xx, yy * 0.5f, zz, Noise)) * fabs(cosf(yy * 0.2f + WaveNoise * 2) * 0.75f + WaveNoise) > 0.0005f) + if (cosf(GetMarbleNoise(xx, yy * 0.5f, zz, Noise)) * + fabs(cosf(yy * 0.2f + WaveNoise * 2) * 0.75f + WaveNoise) > + 0.0005f) { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR); } @@ -788,7 +816,3 @@ void cStructGenDualRidgeCaves::GenFinish(cChunkDesc & a_ChunkDesc) } // for x } // for z } - - - - diff --git a/src/Generating/Caves.h b/src/Generating/Caves.h index 82545b4e0..c057b4b4f 100644 --- a/src/Generating/Caves.h +++ b/src/Generating/Caves.h @@ -18,57 +18,52 @@ -class cStructGenMarbleCaves : - public cFinishGen +class cStructGenMarbleCaves : public cFinishGen { -public: - cStructGenMarbleCaves(int a_Seed) : m_Seed(a_Seed) {} - -protected: + public: + cStructGenMarbleCaves(int a_Seed) : + m_Seed(a_Seed) + { + } + protected: int m_Seed; // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cStructGenDualRidgeCaves : - public cFinishGen +class cStructGenDualRidgeCaves : public cFinishGen { -public: + public: cStructGenDualRidgeCaves(int a_Seed, float a_Threshold) : - m_Noise1(a_Seed), - m_Noise2(2 * a_Seed + 19999), - m_Seed(a_Seed), - m_Threshold(a_Threshold) + m_Noise1(a_Seed), m_Noise2(2 * a_Seed + 19999), m_Seed(a_Seed), m_Threshold(a_Threshold) { } -protected: + protected: cNoise m_Noise1; cNoise m_Noise2; - int m_Seed; - float m_Threshold; + int m_Seed; + float m_Threshold; // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cStructGenWormNestCaves: - public cGridStructGen +class cStructGenWormNestCaves : public cGridStructGen { using Super = cGridStructGen; -public: - + public: cStructGenWormNestCaves(int a_Seed, int a_Size = 64, int a_Grid = 96, int a_MaxOffset = 128) : Super(a_Seed, a_Grid, a_Grid, a_MaxOffset, a_MaxOffset, a_Size, a_Size, 100), m_Size(a_Size), @@ -77,18 +72,13 @@ public: { } -protected: - + protected: class cCaveSystem; // fwd: Caves.cpp - int m_Size; // relative size of the cave systems' caves. Average number of blocks of each initial tunnel - int m_MaxOffset; // maximum offset of the cave nest origin from the grid cell the nest belongs to - int m_Grid; // average spacing of the nests + int m_Size; // relative size of the cave systems' caves. Average number of blocks of each initial tunnel + int m_MaxOffset; // maximum offset of the cave nest origin from the grid cell the nest belongs to + int m_Grid; // average spacing of the nests // cGridStructGen override: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; -} ; - - - - +}; diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index b2a332489..847dfc2cf 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -1,7 +1,8 @@ // ChunkDesc.cpp -// Implements the cChunkDesc class representing the chunk description used while generating a chunk. This class is also exported to Lua for HOOK_CHUNK_GENERATING. +// Implements the cChunkDesc class representing the chunk description used while generating a chunk. This class is also +// exported to Lua for HOOK_CHUNK_GENERATING. #include "Globals.h" #include "ChunkDesc.h" @@ -25,8 +26,8 @@ cChunkDesc::cChunkDesc(cChunkCoords a_Coords) : memset(m_BlockTypes, 0, sizeof(cChunkDef::BlockTypes)); memset(m_BlockMeta, 0, sizeof(cChunkDef::BlockNibbles)); */ - memset(m_BiomeMap, 0, sizeof(cChunkDef::BiomeMap)); - memset(m_HeightMap, 0, sizeof(cChunkDef::HeightMap)); + memset(m_BiomeMap, 0, sizeof(cChunkDef::BiomeMap)); + memset(m_HeightMap, 0, sizeof(cChunkDef::HeightMap)); } @@ -69,7 +70,8 @@ void cChunkDesc::SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE -void cChunkDesc::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const +void cChunkDesc::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) + const { m_BlockArea.GetRelBlockTypeMeta(a_RelX, a_RelY, a_RelZ, a_BlockType, a_BlockMeta); } @@ -268,7 +270,13 @@ bool cChunkDesc::IsUsingDefaultFinish(void) const -void cChunkDesc::WriteBlockArea(const cBlockArea & a_BlockArea, int a_RelX, int a_RelY, int a_RelZ, cBlockArea::eMergeStrategy a_MergeStrategy) +void cChunkDesc::WriteBlockArea( + const cBlockArea & a_BlockArea, + int a_RelX, + int a_RelY, + int a_RelZ, + cBlockArea::eMergeStrategy a_MergeStrategy +) { m_BlockArea.Merge(a_BlockArea, a_RelX, a_RelY, a_RelZ, a_MergeStrategy); } @@ -277,7 +285,15 @@ void cChunkDesc::WriteBlockArea(const cBlockArea & a_BlockArea, int a_RelX, int -void cChunkDesc::ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ) +void cChunkDesc::ReadBlockArea( + cBlockArea & a_Dest, + int a_MinRelX, + int a_MaxRelX, + int a_MinRelY, + int a_MaxRelY, + int a_MinRelZ, + int a_MaxRelZ +) { // Normalize the coords: if (a_MinRelX > a_MaxRelX) @@ -429,10 +445,14 @@ HEIGHTTYPE cChunkDesc::GetMinHeight(void) const void cChunkDesc::FillRelCuboid( - int a_MinX, int a_MaxX, - int a_MinY, int a_MaxY, - int a_MinZ, int a_MaxZ, - BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_BlockMeta ) { int MinX = std::max(a_MinX, 0); @@ -459,11 +479,16 @@ void cChunkDesc::FillRelCuboid( void cChunkDesc::ReplaceRelCuboid( - int a_MinX, int a_MaxX, - int a_MinY, int a_MaxY, - int a_MinZ, int a_MaxZ, - BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta, - BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + BLOCKTYPE a_SrcType, + NIBBLETYPE a_SrcMeta, + BLOCKTYPE a_DstType, + NIBBLETYPE a_DstMeta ) { int MinX = std::max(a_MinX, 0); @@ -496,10 +521,14 @@ void cChunkDesc::ReplaceRelCuboid( void cChunkDesc::FloorRelCuboid( - int a_MinX, int a_MaxX, - int a_MinY, int a_MaxY, - int a_MinZ, int a_MaxZ, - BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + BLOCKTYPE a_DstType, + NIBBLETYPE a_DstMeta ) { int MinX = std::max(a_MinX, 0); @@ -535,11 +564,16 @@ void cChunkDesc::FloorRelCuboid( void cChunkDesc::RandomFillRelCuboid( - int a_MinX, int a_MaxX, - int a_MinY, int a_MaxY, - int a_MinZ, int a_MaxZ, - BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, - int a_RandomSeed, int a_ChanceOutOf10k + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_BlockMeta, + int a_RandomSeed, + int a_ChanceOutOf10k ) { cNoise Noise(a_RandomSeed); @@ -595,7 +629,11 @@ cBlockEntity * cChunkDesc::GetBlockEntity(int a_RelX, int a_RelY, int a_RelZ) int AbsZ = a_RelZ + m_Coords.m_ChunkZ * cChunkDef::Width; // The block entity is not created yet, try to create it and add to list: - auto be = cBlockEntity::CreateByBlockType(GetBlockType(a_RelX, a_RelY, a_RelZ), GetBlockMeta(a_RelX, a_RelY, a_RelZ), {AbsX, a_RelY, AbsZ}); + auto be = cBlockEntity::CreateByBlockType( + GetBlockType(a_RelX, a_RelY, a_RelZ), + GetBlockMeta(a_RelX, a_RelY, a_RelZ), + {AbsX, a_RelY, AbsZ} + ); if (be == nullptr) { // No block entity for this block type @@ -670,8 +708,3 @@ void cChunkDesc::VerifyHeightmap(void) } #endif // !NDEBUG - - - - - diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h index d066660f1..1c5f9e256 100644 --- a/src/Generating/ChunkDesc.h +++ b/src/Generating/ChunkDesc.h @@ -1,7 +1,8 @@ // ChunkDesc.h -// Declares the cChunkDesc class representing the chunk description used while generating a chunk. This class is also exported to Lua for HOOK_CHUNK_GENERATING. +// Declares the cChunkDesc class representing the chunk description used while generating a chunk. This class is also +// exported to Lua for HOOK_CHUNK_GENERATING. @@ -26,7 +27,7 @@ class cBlockArea; // tolua_begin class cChunkDesc { -public: + public: // tolua_end /** The datatype used to represent the entire chunk worth of shape. @@ -55,8 +56,8 @@ public: // tolua_begin - void FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + void FillBlocks(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + void SetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); // tolua_end /** Returns the BlockType and BlockMeta at the specified coords. @@ -64,18 +65,18 @@ public: void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; // tolua_begin - void SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType); - BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const; + void SetBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType); + BLOCKTYPE GetBlockType(int a_RelX, int a_RelY, int a_RelZ) const; - void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta); + void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta); NIBBLETYPE GetBlockMeta(int a_RelX, int a_RelY, int a_RelZ) const; - void SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID); - EMCSBiome GetBiome(int a_RelX, int a_RelZ) const; + void SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID); + EMCSBiome GetBiome(int a_RelX, int a_RelZ) const; // These operate on the heightmap, so they could get out of sync with the data // Use UpdateHeightmap() to re-calculate heightmap from the block data - void SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height); + void SetHeight(int a_RelX, int a_RelZ, HEIGHTTYPE a_Height); HEIGHTTYPE GetHeight(int a_RelX, int a_RelZ) const; // tolua_end @@ -117,11 +118,26 @@ public: void SetUseDefaultFinish(bool a_bUseDefaultFinish); bool IsUsingDefaultFinish(void) const; - /** Writes the block area into the chunk, with its origin set at the specified relative coords. Area's data overwrite everything in the chunk. */ - void WriteBlockArea(const cBlockArea & a_BlockArea, int a_RelX, int a_RelY, int a_RelZ, cBlockArea::eMergeStrategy a_MergeStrategy = cBlockArea::msOverwrite); + /** Writes the block area into the chunk, with its origin set at the specified relative coords. Area's data + * overwrite everything in the chunk. */ + void WriteBlockArea( + const cBlockArea & a_BlockArea, + int a_RelX, + int a_RelY, + int a_RelZ, + cBlockArea::eMergeStrategy a_MergeStrategy = cBlockArea::msOverwrite + ); /** Reads an area from the chunk into a cBlockArea, blocktypes and blockmetas */ - void ReadBlockArea(cBlockArea & a_Dest, int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ); + void ReadBlockArea( + cBlockArea & a_Dest, + int a_MinRelX, + int a_MaxRelX, + int a_MinRelY, + int a_MaxRelY, + int a_MinRelZ, + int a_MaxRelZ + ); /** Returns the maximum height value in the heightmap. */ HEIGHTTYPE GetMaxHeight(void) const; @@ -131,91 +147,131 @@ public: /** Fills the relative cuboid with specified block; allows cuboid out of range of this chunk */ void FillRelCuboid( - int a_MinX, int a_MaxX, - int a_MinY, int a_MaxY, - int a_MinZ, int a_MaxZ, - BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_BlockMeta ); /** Fills the relative cuboid with specified block; allows cuboid out of range of this chunk */ void FillRelCuboid(const cCuboid & a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { FillRelCuboid( - a_RelCuboid.p1.x, a_RelCuboid.p2.x, - a_RelCuboid.p1.y, a_RelCuboid.p2.y, - a_RelCuboid.p1.z, a_RelCuboid.p2.z, - a_BlockType, a_BlockMeta + a_RelCuboid.p1.x, + a_RelCuboid.p2.x, + a_RelCuboid.p1.y, + a_RelCuboid.p2.y, + a_RelCuboid.p1.z, + a_RelCuboid.p2.z, + a_BlockType, + a_BlockMeta ); } /** Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk */ void ReplaceRelCuboid( - int a_MinX, int a_MaxX, - int a_MinY, int a_MaxY, - int a_MinZ, int a_MaxZ, - BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta, - BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + BLOCKTYPE a_SrcType, + NIBBLETYPE a_SrcMeta, + BLOCKTYPE a_DstType, + NIBBLETYPE a_DstMeta ); /** Replaces the specified src blocks in the cuboid by the dst blocks; allows cuboid out of range of this chunk */ void ReplaceRelCuboid( const cCuboid & a_RelCuboid, - BLOCKTYPE a_SrcType, NIBBLETYPE a_SrcMeta, - BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta + BLOCKTYPE a_SrcType, + NIBBLETYPE a_SrcMeta, + BLOCKTYPE a_DstType, + NIBBLETYPE a_DstMeta ) { ReplaceRelCuboid( - a_RelCuboid.p1.x, a_RelCuboid.p2.x, - a_RelCuboid.p1.y, a_RelCuboid.p2.y, - a_RelCuboid.p1.z, a_RelCuboid.p2.z, - a_SrcType, a_SrcMeta, - a_DstType, a_DstMeta + a_RelCuboid.p1.x, + a_RelCuboid.p2.x, + a_RelCuboid.p1.y, + a_RelCuboid.p2.y, + a_RelCuboid.p1.z, + a_RelCuboid.p2.z, + a_SrcType, + a_SrcMeta, + a_DstType, + a_DstMeta ); } - /** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk */ + /** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid + * out of range of this chunk */ void FloorRelCuboid( - int a_MinX, int a_MaxX, - int a_MinY, int a_MaxY, - int a_MinZ, int a_MaxZ, - BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + BLOCKTYPE a_DstType, + NIBBLETYPE a_DstMeta ); - /** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid out of range of this chunk */ - void FloorRelCuboid( - const cCuboid & a_RelCuboid, - BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta - ) + /** Replaces the blocks in the cuboid by the dst blocks if they are considered non-floor (air, water); allows cuboid + * out of range of this chunk */ + void FloorRelCuboid(const cCuboid & a_RelCuboid, BLOCKTYPE a_DstType, NIBBLETYPE a_DstMeta) { FloorRelCuboid( - a_RelCuboid.p1.x, a_RelCuboid.p2.x, - a_RelCuboid.p1.y, a_RelCuboid.p2.y, - a_RelCuboid.p1.z, a_RelCuboid.p2.z, - a_DstType, a_DstMeta + a_RelCuboid.p1.x, + a_RelCuboid.p2.x, + a_RelCuboid.p1.y, + a_RelCuboid.p2.y, + a_RelCuboid.p1.z, + a_RelCuboid.p2.z, + a_DstType, + a_DstMeta ); } /** Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk */ void RandomFillRelCuboid( - int a_MinX, int a_MaxX, - int a_MinY, int a_MaxY, - int a_MinZ, int a_MaxZ, - BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, - int a_RandomSeed, int a_ChanceOutOf10k + int a_MinX, + int a_MaxX, + int a_MinY, + int a_MaxY, + int a_MinZ, + int a_MaxZ, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_BlockMeta, + int a_RandomSeed, + int a_ChanceOutOf10k ); /** Fills the relative cuboid with specified block with a random chance; allows cuboid out of range of this chunk */ void RandomFillRelCuboid( - const cCuboid & a_RelCuboid, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, - int a_RandomSeed, int a_ChanceOutOf10k + const cCuboid & a_RelCuboid, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_BlockMeta, + int a_RandomSeed, + int a_ChanceOutOf10k ) { RandomFillRelCuboid( - a_RelCuboid.p1.x, a_RelCuboid.p2.x, - a_RelCuboid.p1.y, a_RelCuboid.p2.y, - a_RelCuboid.p1.z, a_RelCuboid.p2.z, - a_BlockType, a_BlockMeta, - a_RandomSeed, a_ChanceOutOf10k + a_RelCuboid.p1.x, + a_RelCuboid.p2.x, + a_RelCuboid.p1.y, + a_RelCuboid.p2.y, + a_RelCuboid.p1.z, + a_RelCuboid.p2.z, + a_BlockType, + a_BlockMeta, + a_RandomSeed, + a_ChanceOutOf10k ); } @@ -231,42 +287,48 @@ public: // tolua_end // Accessors used by cChunkGenerator::Generator descendants: - inline cChunkDef::BiomeMap & GetBiomeMap (void) { return m_BiomeMap; } - inline cChunkDef::BlockTypes & GetBlockTypes (void) { return *(reinterpret_cast<cChunkDef::BlockTypes *>(m_BlockArea.GetBlockTypes())); } + inline cChunkDef::BiomeMap & GetBiomeMap(void) { return m_BiomeMap; } + inline cChunkDef::BlockTypes & GetBlockTypes(void) + { + return *(reinterpret_cast<cChunkDef::BlockTypes *>(m_BlockArea.GetBlockTypes())); + } // CANNOT, different compression! - // inline cChunkDef::BlockNibbles & GetBlockMetas (void) { return *((cChunkDef::BlockNibbles *)m_BlockArea.GetBlockMetas()); } - inline BlockNibbleBytes & GetBlockMetasUncompressed(void) { return *(reinterpret_cast<BlockNibbleBytes *>(m_BlockArea.GetBlockMetas())); } - inline cChunkDef::HeightMap & GetHeightMap (void) { return m_HeightMap; } - inline cEntityList & GetEntities (void) { return m_Entities; } - inline cBlockEntities & GetBlockEntities (void) { return m_BlockEntities; } + // inline cChunkDef::BlockNibbles & GetBlockMetas (void) { return *((cChunkDef::BlockNibbles + // *)m_BlockArea.GetBlockMetas()); } + inline BlockNibbleBytes & GetBlockMetasUncompressed(void) + { + return *(reinterpret_cast<BlockNibbleBytes *>(m_BlockArea.GetBlockMetas())); + } + inline cChunkDef::HeightMap & GetHeightMap(void) { return m_HeightMap; } + inline cEntityList & GetEntities(void) { return m_Entities; } + inline cBlockEntities & GetBlockEntities(void) { return m_BlockEntities; } - inline const cChunkDef::BiomeMap & GetBiomeMap() const { return m_BiomeMap; } - inline const cChunkDef::BlockTypes & GetBlockTypes() const { return *(reinterpret_cast<cChunkDef::BlockTypes *>(m_BlockArea.GetBlockTypes())); } - inline const cChunkDef::HeightMap & GetHeightMap() const { return m_HeightMap; } + inline const cChunkDef::BiomeMap & GetBiomeMap() const { return m_BiomeMap; } + inline const cChunkDef::BlockTypes & GetBlockTypes() const + { + return *(reinterpret_cast<cChunkDef::BlockTypes *>(m_BlockArea.GetBlockTypes())); + } + inline const cChunkDef::HeightMap & GetHeightMap() const { return m_HeightMap; } /** Compresses the metas from the BlockArea format (1 meta per byte) into regular format (2 metas per byte) */ void CompressBlockMetas(cChunkDef::BlockNibbles & a_DestMetas); - #ifndef NDEBUG +#ifndef NDEBUG /** Verifies that the heightmap corresponds to blocktype contents; if not, asserts on that column */ void VerifyHeightmap(void); - #endif // !NDEBUG +#endif // !NDEBUG -private: + private: cChunkCoords m_Coords; - cChunkDef::BiomeMap m_BiomeMap; - cBlockArea m_BlockArea; - cChunkDef::HeightMap m_HeightMap; - cEntityList m_Entities; - cBlockEntities m_BlockEntities; // Individual block entities are NOT owned by this object! + cChunkDef::BiomeMap m_BiomeMap; + cBlockArea m_BlockArea; + cChunkDef::HeightMap m_HeightMap; + cEntityList m_Entities; + cBlockEntities m_BlockEntities; // Individual block entities are NOT owned by this object! bool m_bUseDefaultBiomes; bool m_bUseDefaultHeight; bool m_bUseDefaultComposition; bool m_bUseDefaultFinish; -} ; // tolua_export - - - - +}; // tolua_export diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index b8486e3d6..f5318be78 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -74,7 +74,3 @@ EMCSBiome cChunkGenerator::GetBiomeAt(int a_BlockX, int a_BlockZ) GenerateBiomes({ChunkX, ChunkZ}, Biomes); return cChunkDef::GetBiome(Biomes, a_BlockX, a_BlockZ); } - - - - diff --git a/src/Generating/ChunkGenerator.h b/src/Generating/ChunkGenerator.h index 5b9f2c0ac..db53c5a0c 100644 --- a/src/Generating/ChunkGenerator.h +++ b/src/Generating/ChunkGenerator.h @@ -19,7 +19,7 @@ The cChunkGeneratorThread uses this interface to generate chunks for a single wo Ths calls to generate chunks are synchronous - they don't return until the chunk is fully generated. */ class cChunkGenerator { -public: + public: virtual ~cChunkGenerator() {} // Force a virtual destructor /** Called to initialize the generator on server startup. @@ -47,15 +47,10 @@ public: static std::unique_ptr<cChunkGenerator> CreateFromIniFile(cIniFile & a_IniFile); -protected: - + protected: /** The main seed, read from the INI file, used for the entire generator. */ int m_Seed; /** The dimension, read from the INI file. */ eDimension m_Dimension; }; - - - - diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp index 02786ede9..77354ef6b 100644 --- a/src/Generating/CompoGen.cpp +++ b/src/Generating/CompoGen.cpp @@ -65,32 +65,16 @@ void cCompoGenSameBlock::InitializeCompoGen(cIniFile & a_IniFile) void cCompoGenDebugBiomes::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) { - static BLOCKTYPE Blocks[] = - { - E_BLOCK_STONE, - E_BLOCK_COBBLESTONE, - E_BLOCK_LOG, - E_BLOCK_PLANKS, - E_BLOCK_SANDSTONE, - E_BLOCK_WOOL, - E_BLOCK_COAL_ORE, - E_BLOCK_IRON_ORE, - E_BLOCK_GOLD_ORE, - E_BLOCK_DIAMOND_ORE, - E_BLOCK_LAPIS_ORE, - E_BLOCK_REDSTONE_ORE, - E_BLOCK_IRON_BLOCK, - E_BLOCK_GOLD_BLOCK, - E_BLOCK_DIAMOND_BLOCK, - E_BLOCK_LAPIS_BLOCK, - E_BLOCK_BRICK, - E_BLOCK_MOSSY_COBBLESTONE, - E_BLOCK_OBSIDIAN, - E_BLOCK_NETHERRACK, - E_BLOCK_SOULSAND, - E_BLOCK_NETHER_BRICK, - E_BLOCK_BEDROCK, - } ; + static BLOCKTYPE Blocks[] = { + E_BLOCK_STONE, E_BLOCK_COBBLESTONE, E_BLOCK_LOG, + E_BLOCK_PLANKS, E_BLOCK_SANDSTONE, E_BLOCK_WOOL, + E_BLOCK_COAL_ORE, E_BLOCK_IRON_ORE, E_BLOCK_GOLD_ORE, + E_BLOCK_DIAMOND_ORE, E_BLOCK_LAPIS_ORE, E_BLOCK_REDSTONE_ORE, + E_BLOCK_IRON_BLOCK, E_BLOCK_GOLD_BLOCK, E_BLOCK_DIAMOND_BLOCK, + E_BLOCK_LAPIS_BLOCK, E_BLOCK_BRICK, E_BLOCK_MOSSY_COBBLESTONE, + E_BLOCK_OBSIDIAN, E_BLOCK_NETHERRACK, E_BLOCK_SOULSAND, + E_BLOCK_NETHER_BRICK, E_BLOCK_BEDROCK, + }; a_ChunkDesc.SetHeightFromShape(a_Shape); a_ChunkDesc.FillBlocks(E_BLOCK_AIR, 0); @@ -146,9 +130,9 @@ void cCompoGenClassic::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc a_ChunkDesc.SetHeightFromShape(a_Shape); // The patterns to use for different situations, must be same length! - const BLOCKTYPE PatternGround[] = {m_BlockTop, m_BlockMiddle, m_BlockMiddle, m_BlockMiddle} ; - const BLOCKTYPE PatternBeach[] = {m_BlockBeach, m_BlockBeach, m_BlockBeach, m_BlockBeachBottom} ; - const BLOCKTYPE PatternOcean[] = {m_BlockMiddle, m_BlockMiddle, m_BlockMiddle, m_BlockBottom} ; + const BLOCKTYPE PatternGround[] = {m_BlockTop, m_BlockMiddle, m_BlockMiddle, m_BlockMiddle}; + const BLOCKTYPE PatternBeach[] = {m_BlockBeach, m_BlockBeach, m_BlockBeach, m_BlockBeachBottom}; + const BLOCKTYPE PatternOcean[] = {m_BlockMiddle, m_BlockMiddle, m_BlockMiddle, m_BlockBottom}; static int PatternLength = ARRAYCOUNT(PatternGround); ASSERT(ARRAYCOUNT(PatternGround) == ARRAYCOUNT(PatternBeach)); ASSERT(ARRAYCOUNT(PatternGround) == ARRAYCOUNT(PatternOcean)); @@ -196,15 +180,21 @@ void cCompoGenClassic::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc void cCompoGenClassic::InitializeCompoGen(cIniFile & a_IniFile) { - m_SeaLevel = a_IniFile.GetValueSetI("Generator", "SeaLevel", m_SeaLevel); - m_BeachHeight = a_IniFile.GetValueSetI("Generator", "ClassicBeachHeight", m_BeachHeight); - m_BeachDepth = a_IniFile.GetValueSetI("Generator", "ClassicBeachDepth", m_BeachDepth); - m_BlockTop = static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockTop", "grass").m_ItemType); - m_BlockMiddle = static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockMiddle", "dirt").m_ItemType); - m_BlockBottom = static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockBottom", "stone").m_ItemType); - m_BlockBeach = static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockBeach", "sand").m_ItemType); - m_BlockBeachBottom = static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockBeachBottom", "sandstone").m_ItemType); - m_BlockSea = static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockSea", "stationarywater").m_ItemType); + m_SeaLevel = a_IniFile.GetValueSetI("Generator", "SeaLevel", m_SeaLevel); + m_BeachHeight = a_IniFile.GetValueSetI("Generator", "ClassicBeachHeight", m_BeachHeight); + m_BeachDepth = a_IniFile.GetValueSetI("Generator", "ClassicBeachDepth", m_BeachDepth); + m_BlockTop = static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockTop", "grass").m_ItemType); + m_BlockMiddle = + static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockMiddle", "dirt").m_ItemType); + m_BlockBottom = + static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockBottom", "stone").m_ItemType); + m_BlockBeach = + static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockBeach", "sand").m_ItemType); + m_BlockBeachBottom = + static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockBeachBottom", "sandstone").m_ItemType + ); + m_BlockSea = + static_cast<BLOCKTYPE>(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockSea", "stationarywater").m_ItemType); } @@ -215,9 +205,7 @@ void cCompoGenClassic::InitializeCompoGen(cIniFile & a_IniFile) // cCompoGenNether: cCompoGenNether::cCompoGenNether(int a_Seed) : - m_Noise1(a_Seed + 10), - m_Noise2(a_Seed * a_Seed * 10 + a_Seed * 1000 + 6000), - m_MaxThreshold(25000) + m_Noise1(a_Seed + 10), m_Noise2(a_Seed * a_Seed * 10 + a_Seed * 1000 + 6000), m_MaxThreshold(25000) { } @@ -232,9 +220,10 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc: const int SEGMENT_HEIGHT = 8; const int INTERPOL_X = 16; // Must be a divisor of 16 const int INTERPOL_Z = 16; // Must be a divisor of 16 - // Interpolate the chunk in 16 * SEGMENT_HEIGHT * 16 "segments", each SEGMENT_HEIGHT blocks high and each linearly interpolated separately. - // Have two buffers, one for the lowest floor and one for the highest floor, so that Y-interpolation can be done between them - // Then swap the buffers and use the previously-top one as the current-bottom, without recalculating it. + // Interpolate the chunk in 16 * SEGMENT_HEIGHT * 16 "segments", each SEGMENT_HEIGHT blocks high and each linearly + // interpolated separately. Have two buffers, one for the lowest floor and one for the highest floor, so that + // Y-interpolation can be done between them Then swap the buffers and use the previously-top one as the + // current-bottom, without recalculating it. int FloorBuf1[17 * 17]; int FloorBuf2[17 * 17]; @@ -244,73 +233,84 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc: int BaseZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; // Interpolate the lowest floor: - for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++) - { - // We need to store the intermediate result in a volatile variable, otherwise gcc -O2 optimizes - // through the undefined behavior in cNoise and produces different data than the other platforms / build types (#4384) - volatile int intermediate = - m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, 0, BaseZ + INTERPOL_Z * z) * - m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, 0, BaseZ + INTERPOL_Z * z); - FloorLo[INTERPOL_X * x + 17 * INTERPOL_Z * z] = intermediate / 256; - } // for x, z - FloorLo[] + for (int z = 0; z <= 16 / INTERPOL_Z; z++) + for (int x = 0; x <= 16 / INTERPOL_X; x++) + { + // We need to store the intermediate result in a volatile variable, otherwise gcc -O2 optimizes + // through the undefined behavior in cNoise and produces different data than the other platforms / build + // types (#4384) + volatile int intermediate = m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, 0, BaseZ + INTERPOL_Z * z) * + m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, 0, BaseZ + INTERPOL_Z * z); + FloorLo[INTERPOL_X * x + 17 * INTERPOL_Z * z] = intermediate / 256; + } // for x, z - FloorLo[] LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorLo); // Interpolate segments: for (int Segment = 0; Segment < MaxHeight; Segment += SEGMENT_HEIGHT) { // First update the high floor: - for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++) - { - // We need to store the intermediate result in a volatile variable, otherwise gcc -O2 optimizes - // through the undefined behavior in cNoise and produces different data than the other platforms / build types (#4384) - volatile int intermediate = - m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) * - m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z); - FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] = intermediate / 256; - } // for x, z - FloorLo[] + for (int z = 0; z <= 16 / INTERPOL_Z; z++) + for (int x = 0; x <= 16 / INTERPOL_X; x++) + { + // We need to store the intermediate result in a volatile variable, otherwise gcc -O2 optimizes + // through the undefined behavior in cNoise and produces different data than the other platforms / build + // types (#4384) + volatile int intermediate = + m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) * + m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z); + FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] = intermediate / 256; + } // for x, z - FloorLo[] LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi); // Interpolate between FloorLo and FloorHi: - for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) - { - int Threshold = static_cast<int>(m_Noise1.CubicNoise2D(static_cast<float>(BaseX + x) / 75, static_cast<float>(BaseZ + z) / 75) * m_MaxThreshold); - int Lo = FloorLo[x + 17 * z] / 256; - int Hi = FloorHi[x + 17 * z] / 256; - for (int y = 0; y < SEGMENT_HEIGHT; y++) + for (int z = 0; z < 16; z++) + for (int x = 0; x < 16; x++) { - int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; - if (Val < Threshold) + int Threshold = static_cast<int>( + m_Noise1.CubicNoise2D(static_cast<float>(BaseX + x) / 75, static_cast<float>(BaseZ + z) / 75) * + m_MaxThreshold + ); + int Lo = FloorLo[x + 17 * z] / 256; + int Hi = FloorHi[x + 17 * z] / 256; + for (int y = 0; y < SEGMENT_HEIGHT; y++) { - a_ChunkDesc.SetBlockType(x, y + Segment, z, E_BLOCK_NETHERRACK); + int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; + if (Val < Threshold) + { + a_ChunkDesc.SetBlockType(x, y + Segment, z, E_BLOCK_NETHERRACK); + } } } - } // Swap the floors: std::swap(FloorLo, FloorHi); } // Bedrock at the bottom and at the top, cover ceiling with netherrack: - for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) - { - a_ChunkDesc.SetBlockType(x, 0, z, E_BLOCK_BEDROCK); + for (int z = 0; z < 16; z++) + for (int x = 0; x < 16; x++) + { + a_ChunkDesc.SetBlockType(x, 0, z, E_BLOCK_BEDROCK); - int Height = a_ChunkDesc.GetHeight(x, z); - a_ChunkDesc.SetBlockType(x, Height, z, E_BLOCK_BEDROCK); + int Height = a_ChunkDesc.GetHeight(x, z); + a_ChunkDesc.SetBlockType(x, Height, z, E_BLOCK_BEDROCK); - NOISE_DATATYPE CeilingDisguise = (m_Noise1.CubicNoise2D(static_cast<float>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + x) / 10, static_cast<float>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z) / 10)); - if (CeilingDisguise < 0) - { - CeilingDisguise = -CeilingDisguise; - } + NOISE_DATATYPE CeilingDisguise = (m_Noise1.CubicNoise2D( + static_cast<float>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + x) / 10, + static_cast<float>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z) / 10 + )); + if (CeilingDisguise < 0) + { + CeilingDisguise = -CeilingDisguise; + } - int CeilingDisguiseHeight = Height - 2 - FloorC(CeilingDisguise * 3); + int CeilingDisguiseHeight = Height - 2 - FloorC(CeilingDisguise * 3); - for (int y = Height - 1; y > CeilingDisguiseHeight; y--) - { - a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_NETHERRACK); + for (int y = Height - 1; y > CeilingDisguiseHeight; y--) + { + a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_NETHERRACK); + } } - } } @@ -364,23 +364,21 @@ cCompoGenCache::~cCompoGenCache() void cCompoGenCache::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) { - #ifndef NDEBUG +#ifndef NDEBUG if (((m_NumHits + m_NumMisses) % 1024) == 10) { - // LOGD("CompoGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / (m_NumHits + m_NumMisses)); - // LOGD("CompoGenCache: Avg cache chain length: %.2f", static_cast<float>(m_TotalChain) / m_NumHits); + // LOGD("CompoGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / + // (m_NumHits + m_NumMisses)); LOGD("CompoGenCache: Avg cache chain length: %.2f", + // static_cast<float>(m_TotalChain) / m_NumHits); } - #endif // !NDEBUG +#endif // !NDEBUG int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); for (int i = 0; i < m_CacheSize; i++) { - if ( - (m_CacheData[m_CacheOrder[i]].m_ChunkX != ChunkX) || - (m_CacheData[m_CacheOrder[i]].m_ChunkZ != ChunkZ) - ) + if ((m_CacheData[m_CacheOrder[i]].m_ChunkX != ChunkX) || (m_CacheData[m_CacheOrder[i]].m_ChunkZ != ChunkZ)) { continue; } @@ -395,9 +393,13 @@ void cCompoGenCache::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc:: m_CacheOrder[0] = Idx; // Use the cached data: - memcpy(a_ChunkDesc.GetBlockTypes(), m_CacheData[Idx].m_BlockTypes, sizeof(a_ChunkDesc.GetBlockTypes())); - memcpy(a_ChunkDesc.GetBlockMetasUncompressed(), m_CacheData[Idx].m_BlockMetas, sizeof(a_ChunkDesc.GetBlockMetasUncompressed())); - memcpy(a_ChunkDesc.GetHeightMap(), m_CacheData[Idx].m_HeightMap, sizeof(a_ChunkDesc.GetHeightMap())); + memcpy(a_ChunkDesc.GetBlockTypes(), m_CacheData[Idx].m_BlockTypes, sizeof(a_ChunkDesc.GetBlockTypes())); + memcpy( + a_ChunkDesc.GetBlockMetasUncompressed(), + m_CacheData[Idx].m_BlockMetas, + sizeof(a_ChunkDesc.GetBlockMetasUncompressed()) + ); + memcpy(a_ChunkDesc.GetHeightMap(), m_CacheData[Idx].m_HeightMap, sizeof(a_ChunkDesc.GetHeightMap())); m_NumHits++; m_TotalChain += i; @@ -415,9 +417,13 @@ void cCompoGenCache::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc:: m_CacheOrder[i] = m_CacheOrder[i - 1]; } // for i - m_CacheOrder[] m_CacheOrder[0] = Idx; - memcpy(m_CacheData[Idx].m_BlockTypes, a_ChunkDesc.GetBlockTypes(), sizeof(a_ChunkDesc.GetBlockTypes())); - memcpy(m_CacheData[Idx].m_BlockMetas, a_ChunkDesc.GetBlockMetasUncompressed(), sizeof(a_ChunkDesc.GetBlockMetasUncompressed())); - memcpy(m_CacheData[Idx].m_HeightMap, a_ChunkDesc.GetHeightMap(), sizeof(a_ChunkDesc.GetHeightMap())); + memcpy(m_CacheData[Idx].m_BlockTypes, a_ChunkDesc.GetBlockTypes(), sizeof(a_ChunkDesc.GetBlockTypes())); + memcpy( + m_CacheData[Idx].m_BlockMetas, + a_ChunkDesc.GetBlockMetasUncompressed(), + sizeof(a_ChunkDesc.GetBlockMetasUncompressed()) + ); + memcpy(m_CacheData[Idx].m_HeightMap, a_ChunkDesc.GetHeightMap(), sizeof(a_ChunkDesc.GetHeightMap())); m_CacheData[Idx].m_ChunkX = ChunkX; m_CacheData[Idx].m_ChunkZ = ChunkZ; } diff --git a/src/Generating/CompoGen.h b/src/Generating/CompoGen.h index 53154ec07..bc5eb104e 100644 --- a/src/Generating/CompoGen.h +++ b/src/Generating/CompoGen.h @@ -23,53 +23,47 @@ -class cCompoGenSameBlock : - public cTerrainCompositionGen +class cCompoGenSameBlock : public cTerrainCompositionGen { -public: + public: cCompoGenSameBlock(void) : - m_BlockType(E_BLOCK_STONE), - m_IsBedrocked(true) - {} - -protected: + m_BlockType(E_BLOCK_STONE), m_IsBedrocked(true) + { + } + protected: BLOCKTYPE m_BlockType; - bool m_IsBedrocked; + bool m_IsBedrocked; // cTerrainCompositionGen overrides: virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) override; virtual void InitializeCompoGen(cIniFile & a_IniFile) override; -} ; +}; -class cCompoGenDebugBiomes : - public cTerrainCompositionGen +class cCompoGenDebugBiomes : public cTerrainCompositionGen { -public: + public: cCompoGenDebugBiomes(void) {} -protected: - + protected: // cTerrainCompositionGen overrides: virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) override; -} ; +}; -class cCompoGenClassic : - public cTerrainCompositionGen +class cCompoGenClassic : public cTerrainCompositionGen { -public: + public: cCompoGenClassic(void); -protected: - + protected: int m_SeaLevel; int m_BeachHeight; int m_BeachDepth; @@ -83,19 +77,18 @@ protected: // cTerrainCompositionGen overrides: virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) override; virtual void InitializeCompoGen(cIniFile & a_IniFile) override; -} ; +}; -class cCompoGenNether : - public cTerrainCompositionGen +class cCompoGenNether : public cTerrainCompositionGen { -public: + public: cCompoGenNether(int a_Seed); -protected: + protected: cNoise m_Noise1; cNoise m_Noise2; @@ -104,17 +97,16 @@ protected: // cTerrainCompositionGen overrides: virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) override; virtual void InitializeCompoGen(cIniFile & a_IniFile) override; -} ; +}; /** Caches most-recently-used chunk composition of another composition generator. Caches only the types and metas */ -class cCompoGenCache : - public cTerrainCompositionGen +class cCompoGenCache : public cTerrainCompositionGen { -public: + public: cCompoGenCache(std::unique_ptr<cTerrainCompositionGen> a_Underlying, int a_CacheSize); virtual ~cCompoGenCache() override; @@ -122,26 +114,25 @@ public: virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) override; virtual void InitializeCompoGen(cIniFile & a_IniFile) override; -protected: - + protected: std::unique_ptr<cTerrainCompositionGen> m_Underlying; struct sCacheData { int m_ChunkX; int m_ChunkZ; - cChunkDef::BlockTypes m_BlockTypes; + cChunkDef::BlockTypes m_BlockTypes; cChunkDesc::BlockNibbleBytes m_BlockMetas; // The metas are uncompressed, 1 meta per byte - cChunkDef::HeightMap m_HeightMap; - } ; + cChunkDef::HeightMap m_HeightMap; + }; // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data - int m_CacheSize; - int * m_CacheOrder; // MRU-ized order, indices into m_CacheData array - sCacheData * m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used + int m_CacheSize; + int * m_CacheOrder; // MRU-ized order, indices into m_CacheData array + sCacheData * m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used // Cache statistics int m_NumHits; int m_NumMisses; int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits) -} ; +}; diff --git a/src/Generating/CompoGenBiomal.cpp b/src/Generating/CompoGenBiomal.cpp index 967a4a89c..eea38be8a 100644 --- a/src/Generating/CompoGenBiomal.cpp +++ b/src/Generating/CompoGenBiomal.cpp @@ -24,10 +24,10 @@ Each pattern has 256 blocks so that there's no need to check pattern bounds when pattern - there will always be enough pattern left, even for the whole-chunk-height columns. */ class cPattern { -public: + public: struct BlockInfo { - BLOCKTYPE m_BlockType = E_BLOCK_STONE; + BLOCKTYPE m_BlockType = E_BLOCK_STONE; NIBBLETYPE m_BlockMeta = 0; }; @@ -47,9 +47,9 @@ public: const BlockInfo * Get(void) const { return m_Pattern; } -protected: + protected: BlockInfo m_Pattern[cChunkDef::Height] = {}; -} ; +}; @@ -58,97 +58,81 @@ protected: //////////////////////////////////////////////////////////////////////////////// // Land top block patterns: -static constexpr cPattern patGrass = -{ +static constexpr cPattern patGrass = { {E_BLOCK_GRASS, 0}, - {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, - {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, - {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, -} ; + {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, + {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, + {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, +}; -static constexpr cPattern patSand = -{ - { E_BLOCK_SAND, 0}, - { E_BLOCK_SAND, 0}, - { E_BLOCK_SAND, 0}, - { E_BLOCK_SANDSTONE, 0}, -} ; +static constexpr cPattern patSand = { + {E_BLOCK_SAND, 0}, + {E_BLOCK_SAND, 0}, + {E_BLOCK_SAND, 0}, + {E_BLOCK_SANDSTONE, 0}, +}; -static constexpr cPattern patDirt = -{ +static constexpr cPattern patDirt = { {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, -} ; +}; -static constexpr cPattern patPodzol = -{ +static constexpr cPattern patPodzol = { {E_BLOCK_DIRT, E_META_DIRT_PODZOL}, {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, -} ; +}; -static constexpr cPattern patGrassLess = -{ +static constexpr cPattern patGrassLess = { {E_BLOCK_DIRT, E_META_DIRT_GRASSLESS}, {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, {E_BLOCK_DIRT, E_META_DIRT_NORMAL}, -} ; +}; -static constexpr cPattern patMycelium = -{ +static constexpr cPattern patMycelium = { {E_BLOCK_MYCELIUM, 0}, - {E_BLOCK_DIRT, 0}, - {E_BLOCK_DIRT, 0}, - {E_BLOCK_DIRT, 0}, -} ; + {E_BLOCK_DIRT, 0}, + {E_BLOCK_DIRT, 0}, + {E_BLOCK_DIRT, 0}, +}; -static constexpr cPattern patGravel = -{ +static constexpr cPattern patGravel = { {E_BLOCK_GRAVEL, 0}, {E_BLOCK_GRAVEL, 0}, {E_BLOCK_GRAVEL, 0}, - {E_BLOCK_STONE, 0}, -} ; + {E_BLOCK_STONE, 0}, +}; -static constexpr cPattern patStone = -{ - {E_BLOCK_STONE, 0}, - {E_BLOCK_STONE, 0}, - {E_BLOCK_STONE, 0}, - {E_BLOCK_STONE, 0}, -} ; +static constexpr cPattern patStone = { + {E_BLOCK_STONE, 0}, + {E_BLOCK_STONE, 0}, + {E_BLOCK_STONE, 0}, + {E_BLOCK_STONE, 0}, +}; //////////////////////////////////////////////////////////////////////////////// // Ocean floor patterns: -static constexpr cPattern patOFSand = -{ - {E_BLOCK_SAND, 0}, +static constexpr cPattern patOFSand = {{E_BLOCK_SAND, 0}, {E_BLOCK_SAND, 0}, {E_BLOCK_SAND, 0}, {E_BLOCK_SANDSTONE, 0}}; + +static constexpr cPattern patOFClay = { + {E_BLOCK_CLAY, 0}, + {E_BLOCK_CLAY, 0}, {E_BLOCK_SAND, 0}, {E_BLOCK_SAND, 0}, - {E_BLOCK_SANDSTONE, 0} -} ; +}; -static constexpr cPattern patOFClay = -{ - { E_BLOCK_CLAY, 0}, - { E_BLOCK_CLAY, 0}, - { E_BLOCK_SAND, 0}, - { E_BLOCK_SAND, 0}, -} ; - -static constexpr cPattern patOFOrangeClay = -{ - { E_BLOCK_STAINED_CLAY, E_META_STAINED_GLASS_ORANGE}, - { E_BLOCK_STAINED_CLAY, E_META_STAINED_GLASS_ORANGE}, - { E_BLOCK_STAINED_CLAY, E_META_STAINED_GLASS_ORANGE}, -} ; +static constexpr cPattern patOFOrangeClay = { + {E_BLOCK_STAINED_CLAY, E_META_STAINED_GLASS_ORANGE}, + {E_BLOCK_STAINED_CLAY, E_META_STAINED_GLASS_ORANGE}, + {E_BLOCK_STAINED_CLAY, E_META_STAINED_GLASS_ORANGE}, +}; @@ -157,19 +141,16 @@ static constexpr cPattern patOFOrangeClay = //////////////////////////////////////////////////////////////////////////////// // cCompoGenBiomal: -class cCompoGenBiomal : - public cTerrainCompositionGen +class cCompoGenBiomal : public cTerrainCompositionGen { -public: + public: cCompoGenBiomal(int a_Seed) : - m_SeaLevel(62), - m_OceanFloorSelect(a_Seed + 1), - m_MesaFloor(a_Seed + 2) + m_SeaLevel(62), m_OceanFloorSelect(a_Seed + 1), m_MesaFloor(a_Seed + 2) { initMesaPattern(a_Seed); } -protected: + protected: /** The block height at which water is generated instead of air. */ HEIGHTTYPE m_SeaLevel; @@ -208,11 +189,10 @@ protected: /** Initializes the m_MesaPattern with a pattern based on the generator's seed. */ void initMesaPattern(int a_Seed) { - // In a loop, choose whether to use one, two or three layers of stained clay, then choose a color and width for each layer - // Separate each group with another layer of hardened clay + // In a loop, choose whether to use one, two or three layers of stained clay, then choose a color and width for + // each layer Separate each group with another layer of hardened clay cNoise patternNoise(a_Seed); - static NIBBLETYPE allowedColors[] = - { + static NIBBLETYPE allowedColors[] = { E_META_STAINED_CLAY_YELLOW, E_META_STAINED_CLAY_YELLOW, E_META_STAINED_CLAY_RED, @@ -228,13 +208,22 @@ protected: E_META_STAINED_CLAY_ORANGE, E_META_STAINED_CLAY_ORANGE, E_META_STAINED_CLAY_LIGHTGRAY, - } ; + }; static int layerSizes[] = // Adjust the chance so that thinner layers occur more commonly - { - 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, - 3, 3, - } ; + { + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 2, + 2, + 2, + 3, + 3, + }; int idx = ARRAYCOUNT(m_MesaPattern) - 1; while (idx >= 0) { @@ -246,13 +235,13 @@ protected: { int numBlocks = layerSizes[(static_cast<size_t>(rnd) % ARRAYCOUNT(layerSizes))]; NIBBLETYPE Color = allowedColors[static_cast<size_t>(rnd / 4) % ARRAYCOUNT(allowedColors)]; - if ( - ((numBlocks == 3) && (numLayers == 2)) || // In two-layer mode disallow the 3-high layers: - (Color == E_META_STAINED_CLAY_WHITE)) // White stained clay can ever be only 1 block high + if (((numBlocks == 3) && (numLayers == 2)) || // In two-layer mode disallow the 3-high layers: + (Color == E_META_STAINED_CLAY_WHITE)) // White stained clay can ever be only 1 block high { numBlocks = 1; } - numBlocks = std::min(idx + 1, numBlocks); // Limit by idx so that we don't have to check inside the loop + numBlocks = + std::min(idx + 1, numBlocks); // Limit by idx so that we don't have to check inside the loop rnd /= 32; for (int block = 0; block < numBlocks; block++, idx--) { @@ -341,10 +330,13 @@ protected: case biMegaSpruceTaigaHills: { // Select the pattern to use - podzol, grass or grassless dirt: - NOISE_DATATYPE NoiseX = (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + a_RelX)) / FrequencyX; - NOISE_DATATYPE NoiseY = (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + a_RelZ)) / FrequencyZ; + NOISE_DATATYPE NoiseX = + (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + a_RelX)) / FrequencyX; + NOISE_DATATYPE NoiseY = + (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + a_RelZ)) / FrequencyZ; NOISE_DATATYPE Val = m_OceanFloorSelect.CubicNoise2D(NoiseX, NoiseY); - const cPattern::BlockInfo * Pattern = (Val < -0.9) ? patGrassLess.Get() : ((Val > 0) ? patPodzol.Get() : patGrass.Get()); + const cPattern::BlockInfo * Pattern = + (Val < -0.9) ? patGrassLess.Get() : ((Val > 0) ? patPodzol.Get() : patGrass.Get()); FillColumnPattern(a_ChunkDesc, a_RelX, a_RelZ, Pattern, a_ShapeColumn); return; } @@ -383,8 +375,10 @@ protected: case biExtremeHillsM: { // Select the pattern to use - gravel, stone or grass: - NOISE_DATATYPE NoiseX = (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + a_RelX)) / FrequencyX; - NOISE_DATATYPE NoiseY = (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + a_RelZ)) / FrequencyZ; + NOISE_DATATYPE NoiseX = + (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + a_RelX)) / FrequencyX; + NOISE_DATATYPE NoiseY = + (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + a_RelZ)) / FrequencyZ; NOISE_DATATYPE Val = m_OceanFloorSelect.CubicNoise2D(NoiseX, NoiseY); const cPattern::BlockInfo * Pattern = (Val < 0.0) ? patStone.Get() : patGrass.Get(); FillColumnPattern(a_ChunkDesc, a_RelX, a_RelZ, Pattern, a_ShapeColumn); @@ -409,7 +403,13 @@ protected: /** Fills the specified column with the specified pattern; restarts the pattern when air is reached, switches to ocean floor pattern if ocean is reached. Always adds bedrock at the very bottom. */ - void FillColumnPattern(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelZ, const cPattern::BlockInfo * a_Pattern, const Byte * a_ShapeColumn) + void FillColumnPattern( + cChunkDesc & a_ChunkDesc, + int a_RelX, + int a_RelZ, + const cPattern::BlockInfo * a_Pattern, + const Byte * a_ShapeColumn + ) { bool HasHadWater = false; int PatternIdx = 0; @@ -424,7 +424,13 @@ protected: if (a_ShapeColumn[y] > 0) { // "ground" part, use the pattern: - a_ChunkDesc.SetBlockTypeMeta(a_RelX, y, a_RelZ, a_Pattern[PatternIdx].m_BlockType, a_Pattern[PatternIdx].m_BlockMeta); + a_ChunkDesc.SetBlockTypeMeta( + a_RelX, + y, + a_RelZ, + a_Pattern[PatternIdx].m_BlockType, + a_Pattern[PatternIdx].m_BlockMeta + ); PatternIdx++; continue; } @@ -476,8 +482,10 @@ protected: return; } - NOISE_DATATYPE NoiseX = (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + a_RelX)) / FrequencyX; - NOISE_DATATYPE NoiseY = (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + a_RelZ)) / FrequencyZ; + NOISE_DATATYPE NoiseX = + (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + a_RelX)) / FrequencyX; + NOISE_DATATYPE NoiseY = + (static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + a_RelZ)) / FrequencyZ; int ClayFloor = m_SeaLevel - 6 + static_cast<int>(4.f * m_MesaFloor.CubicNoise2D(NoiseX, NoiseY)); if (ClayFloor >= Top) { @@ -501,7 +509,8 @@ protected: } // Difficult case: use the mesa pattern and watch for overhangs: - int PatternIdx = cChunkDef::Height - (Top - ClayFloor); // We want the block at index ClayFloor to be pattern's 256th block (first stone) + int PatternIdx = cChunkDef::Height - + (Top - ClayFloor); // We want the block at index ClayFloor to be pattern's 256th block (first stone) const cPattern::BlockInfo * Pattern = m_MesaPattern; bool HasHadWater = false; for (int y = Top; y > 0; y--) @@ -509,7 +518,13 @@ protected: if (a_ShapeColumn[y] > 0) { // "ground" part, use the pattern: - a_ChunkDesc.SetBlockTypeMeta(a_RelX, y, a_RelZ, Pattern[PatternIdx].m_BlockType, Pattern[PatternIdx].m_BlockMeta); + a_ChunkDesc.SetBlockTypeMeta( + a_RelX, + y, + a_RelZ, + Pattern[PatternIdx].m_BlockType, + Pattern[PatternIdx].m_BlockMeta + ); PatternIdx++; continue; } @@ -576,7 +591,7 @@ protected: return patDirt.Get(); } } -} ; +}; diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 14236a2e1..3c7f44f0a 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -1,7 +1,8 @@ // ComposableGenerator.cpp -// Implements the cComposableGenerator class representing the chunk generator that takes the composition approach to generating chunks +// Implements the cComposableGenerator class representing the chunk generator that takes the composition approach to +// generating chunks #include "Globals.h" @@ -115,10 +116,8 @@ std::unique_ptr<cTerrainCompositionGen> cTerrainCompositionGen::CreateCompositio //////////////////////////////////////////////////////////////////////////////// // cComposableGenerator: -cComposableGenerator::cComposableGenerator(): - m_BiomeGen(), - m_ShapeGen(), - m_CompositionGen() +cComposableGenerator::cComposableGenerator() : + m_BiomeGen(), m_ShapeGen(), m_CompositionGen() { } @@ -205,10 +204,12 @@ void cComposableGenerator::InitializeGeneratorDefaults(cIniFile & a_IniFile, eDi { case dimOverworld: { - a_IniFile.GetValueSet("Generator", "BiomeGen", "Grown"); - a_IniFile.GetValueSet("Generator", "ShapeGen", "BiomalNoise3D"); + a_IniFile.GetValueSet("Generator", "BiomeGen", "Grown"); + a_IniFile.GetValueSet("Generator", "ShapeGen", "BiomalNoise3D"); a_IniFile.GetValueSet("Generator", "CompositionGen", "Biomal"); - a_IniFile.GetValueSet("Generator", "Finishers", + a_IniFile.GetValueSet( + "Generator", + "Finishers", "RoughRavines, " "WormNestCaves, " "WaterLakes, " @@ -238,14 +239,16 @@ void cComposableGenerator::InitializeGeneratorDefaults(cIniFile & a_IniFile, eDi case dimNether: { - a_IniFile.GetValueSet("Generator", "Generator", "Composable"); - a_IniFile.GetValueSet("Generator", "BiomeGen", "Constant"); - a_IniFile.GetValueSet("Generator", "ConstantBiome", "Nether"); - a_IniFile.GetValueSet("Generator", "ShapeGen", "HeightMap"); - a_IniFile.GetValueSet("Generator", "HeightGen", "Flat"); - a_IniFile.GetValueSet("Generator", "FlatHeight", "128"); - a_IniFile.GetValueSet("Generator", "CompositionGen", "Nether"); - a_IniFile.GetValueSet("Generator", "Finishers", + a_IniFile.GetValueSet("Generator", "Generator", "Composable"); + a_IniFile.GetValueSet("Generator", "BiomeGen", "Constant"); + a_IniFile.GetValueSet("Generator", "ConstantBiome", "Nether"); + a_IniFile.GetValueSet("Generator", "ShapeGen", "HeightMap"); + a_IniFile.GetValueSet("Generator", "HeightGen", "Flat"); + a_IniFile.GetValueSet("Generator", "FlatHeight", "128"); + a_IniFile.GetValueSet("Generator", "CompositionGen", "Nether"); + a_IniFile.GetValueSet( + "Generator", + "Finishers", "SoulsandRims, " "WormNestCaves, " "BottomLava, " @@ -254,17 +257,18 @@ void cComposableGenerator::InitializeGeneratorDefaults(cIniFile & a_IniFile, eDi "NetherOreNests, " "PieceStructures: NetherFort, " "GlowStone, " - "PreSimulator"); + "PreSimulator" + ); break; } // dimNether case dimEnd: { - a_IniFile.GetValueSet("Generator", "BiomeGen", "Constant"); - a_IniFile.GetValueSet("Generator", "ConstantBiome", "End"); - a_IniFile.GetValueSet("Generator", "ShapeGen", "End"); + a_IniFile.GetValueSet("Generator", "BiomeGen", "Constant"); + a_IniFile.GetValueSet("Generator", "ConstantBiome", "End"); + a_IniFile.GetValueSet("Generator", "ShapeGen", "End"); a_IniFile.GetValueSet("Generator", "CompositionGen", "End"); - a_IniFile.GetValueSet("Generator", "Finishers", "EnderDragonFightStructures"); + a_IniFile.GetValueSet("Generator", "Finishers", "EnderDragonFightStructures"); break; } // dimEnd @@ -295,8 +299,10 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) int MultiCacheLength = a_IniFile.GetValueSetI("Generator", "BiomeGenMultiCacheLength", 128); if (CacheSize < 4) { - LOGWARNING("Biomegen cache size set too low, would hurt performance instead of helping. Increasing from %d to %d", - CacheSize, 4 + LOGWARNING( + "Biomegen cache size set too low, would hurt performance instead of helping. Increasing from %d to %d", + CacheSize, + 4 ); CacheSize = 4; } @@ -304,7 +310,11 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) if (MultiCacheLength > 0) { LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength); - m_BiomeGen = std::make_unique<cBioGenMulticache>(std::move(m_BiomeGen), static_cast<size_t>(CacheSize), static_cast<size_t>(MultiCacheLength)); + m_BiomeGen = std::make_unique<cBioGenMulticache>( + std::move(m_BiomeGen), + static_cast<size_t>(CacheSize), + static_cast<size_t>(MultiCacheLength) + ); } else { @@ -319,12 +329,7 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) void cComposableGenerator::InitShapeGen(cIniFile & a_IniFile) { bool CacheOffByDefault = false; - m_ShapeGen = cTerrainShapeGen::CreateShapeGen( - a_IniFile, - *m_BiomeGen, - m_Seed, - CacheOffByDefault - ); + m_ShapeGen = cTerrainShapeGen::CreateShapeGen(a_IniFile, *m_BiomeGen, m_Seed, CacheOffByDefault); /* // TODO @@ -334,8 +339,8 @@ void cComposableGenerator::InitShapeGen(cIniFile & a_IniFile) { if (CacheSize < 4) { - LOGWARNING("Heightgen cache size set too low, would hurt performance instead of helping. Increasing from %d to %d", - CacheSize, 4 + LOGWARNING("Heightgen cache size set too low, would hurt performance instead of helping. Increasing from %d + to %d", CacheSize, 4 ); CacheSize = 4; } @@ -351,12 +356,7 @@ void cComposableGenerator::InitShapeGen(cIniFile & a_IniFile) void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile) { - m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen( - a_IniFile, - *m_BiomeGen, - *m_ShapeGen, - m_Seed - ); + m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen(a_IniFile, *m_BiomeGen, *m_ShapeGen, m_Seed); // Add a cache over the composition generator: // Even a cache of size 1 is useful due to the CompositedHeiGen cache after us doing re-composition on its misses @@ -367,7 +367,11 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile) } // Create a cache of the composited heightmaps, so that finishers may use it: - m_CompositedHeightCache = std::make_unique<cHeiGenMultiCache>(std::make_unique<cCompositedHeiGen>(*m_BiomeGen, *m_ShapeGen, *m_CompositionGen), 16, 128); + m_CompositedHeightCache = std::make_unique<cHeiGenMultiCache>( + std::make_unique<cCompositedHeiGen>(*m_BiomeGen, *m_ShapeGen, *m_CompositionGen), + 16, + 128 + ); // 128 subcaches of depth 16 each = 0.5 MiB of RAM. Acceptable, for the amount of work this saves. } @@ -423,7 +427,9 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) AllowedBlocks.push_back(E_BLOCK_HARDENED_CLAY); AllowedBlocks.push_back(E_BLOCK_STAINED_CLAY); - m_FinishGens.push_back(std::make_unique<cFinishGenSingleTopBlock>(m_Seed, E_BLOCK_DEAD_BUSH, AllowedBiomes, 2, AllowedBlocks)); + m_FinishGens.push_back( + std::make_unique<cFinishGenSingleTopBlock>(m_Seed, E_BLOCK_DEAD_BUSH, AllowedBiomes, 2, AllowedBlocks) + ); } else if (NoCaseCompare(finisher, "DirectOverhangs") == 0) { @@ -431,7 +437,8 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(finisher, "DirtPockets") == 0) { - auto Gen = std::make_unique<cFinishGenOrePockets>(m_Seed + 1, cFinishGenOrePockets::DefaultNaturalPatches()); + auto Gen = + std::make_unique<cFinishGenOrePockets>(m_Seed + 1, cFinishGenOrePockets::DefaultNaturalPatches()); Gen->Initialize(a_IniFile, "DirtPockets"); m_FinishGens.push_back(std::move(Gen)); } @@ -446,19 +453,28 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(finisher, "DungeonRooms") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsGridSize", 48); - int MaxSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMaxSize", 7); - int MinSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMinSize", 5); - AString HeightDistrib = a_IniFile.GetValueSet ("Generator", "DungeonRoomsHeightDistrib", "0, 0; 10, 10; 11, 500; 40, 500; 60, 40; 90, 1"); - m_FinishGens.push_back(std::make_unique<cDungeonRoomsFinisher>(*m_ShapeGen, m_Seed, GridSize, MaxSize, MinSize, HeightDistrib)); + int GridSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsGridSize", 48); + int MaxSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMaxSize", 7); + int MinSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMinSize", 5); + AString HeightDistrib = a_IniFile.GetValueSet( + "Generator", + "DungeonRoomsHeightDistrib", + "0, 0; 10, 10; 11, 500; 40, 500; 60, 40; 90, 1" + ); + m_FinishGens.push_back( + std::make_unique<cDungeonRoomsFinisher>(*m_ShapeGen, m_Seed, GridSize, MaxSize, MinSize, HeightDistrib) + ); } else if (NoCaseCompare(finisher, "EnderDragonFightStructures") == 0) { - AString Pillars = a_IniFile.GetValueSet("Generator", "ObsidianPillars", + AString Pillars = a_IniFile.GetValueSet( + "Generator", + "ObsidianPillars", "76|3|false; 79|3|true; 82|3|true; " "85|4|false; 88|4|false; 91|4|false; " "94|5|false; 97|5|false; 100|5|false; " - "103|6|false"); + "103|6|false" + ); int Radius = a_IniFile.GetValueSetI("Generator", "ObsidianPillarsRadius", 43); auto Gen = std::make_unique<cEnderDragonFightStructuresGen>(m_Seed); Gen->Init(Pillars, Radius); @@ -479,11 +495,15 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) else if (NoCaseCompare(finisher, "LavaLakes") == 0) { int Probability = a_IniFile.GetValueSetI("Generator", "LavaLakesProbability", 10); - m_FinishGens.push_back(std::make_unique<cStructGenLakes>(m_Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, *m_ShapeGen, Probability)); + m_FinishGens.push_back( + std::make_unique<cStructGenLakes>(m_Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, *m_ShapeGen, Probability) + ); } else if (NoCaseCompare(finisher, "LavaSprings") == 0) { - m_FinishGens.push_back(std::make_unique<cFinishGenFluidSprings>(m_Seed, E_BLOCK_LAVA, a_IniFile, m_Dimension)); + m_FinishGens.push_back( + std::make_unique<cFinishGenFluidSprings>(m_Seed, E_BLOCK_LAVA, a_IniFile, m_Dimension) + ); } else if (NoCaseCompare(finisher, "Lilypads") == 0) { @@ -497,7 +517,9 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) AllowedBlocks.push_back(E_BLOCK_WATER); AllowedBlocks.push_back(E_BLOCK_STATIONARY_WATER); - m_FinishGens.push_back(std::make_unique<cFinishGenSingleTopBlock>(m_Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks)); + m_FinishGens.push_back( + std::make_unique<cFinishGenSingleTopBlock>(m_Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks) + ); } else if (NoCaseCompare(finisher, "MarbleCaves") == 0) { @@ -505,20 +527,27 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(finisher, "MineShafts") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "MineShaftsGridSize", 512); - int MaxOffset = a_IniFile.GetValueSetI("Generator", "MineShaftsMaxOffset", 256); - int MaxSystemSize = a_IniFile.GetValueSetI("Generator", "MineShaftsMaxSystemSize", 160); - int ChanceCorridor = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCorridor", 600); - int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200); + int GridSize = a_IniFile.GetValueSetI("Generator", "MineShaftsGridSize", 512); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "MineShaftsMaxOffset", 256); + int MaxSystemSize = a_IniFile.GetValueSetI("Generator", "MineShaftsMaxSystemSize", 160); + int ChanceCorridor = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCorridor", 600); + int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200); int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200); m_FinishGens.push_back(std::make_unique<cStructGenMineShafts>( - m_Seed, GridSize, MaxOffset, MaxSystemSize, - ChanceCorridor, ChanceCrossing, ChanceStaircase + m_Seed, + GridSize, + MaxOffset, + MaxSystemSize, + ChanceCorridor, + ChanceCrossing, + ChanceStaircase )); } else if (NoCaseCompare(finisher, "NaturalPatches") == 0) { - m_FinishGens.push_back(std::make_unique<cFinishGenOreNests>(m_Seed + 1, cFinishGenOreNests::DefaultNaturalPatches())); + m_FinishGens.push_back( + std::make_unique<cFinishGenOreNests>(m_Seed + 1, cFinishGenOreNests::DefaultNaturalPatches()) + ); } else if (NoCaseCompare(finisher, "NetherClumpFoliage") == 0) { @@ -526,11 +555,15 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(finisher, "NetherOreNests") == 0) { - m_FinishGens.push_back(std::make_unique<cFinishGenOreNests>(m_Seed + 2, cFinishGenOreNests::DefaultNetherOres())); + m_FinishGens.push_back( + std::make_unique<cFinishGenOreNests>(m_Seed + 2, cFinishGenOreNests::DefaultNetherOres()) + ); } else if (NoCaseCompare(finisher, "OreNests") == 0) { - m_FinishGens.push_back(std::make_unique<cFinishGenOreNests>(m_Seed + 3, cFinishGenOreNests::DefaultOverworldOres())); + m_FinishGens.push_back( + std::make_unique<cFinishGenOreNests>(m_Seed + 3, cFinishGenOreNests::DefaultOverworldOres()) + ); } else if (NoCaseCompare(finisher, "OrePockets") == 0) { @@ -547,7 +580,8 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) { if (split.size() < 2) { - LOGWARNING("The PieceStructures generator needs the structures to use. Example: \"PieceStructures: NetherFort\"."); + LOGWARNING("The PieceStructures generator needs the structures to use. Example: \"PieceStructures: " + "NetherFort\"."); continue; } @@ -561,10 +595,12 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) { // Load the settings bool PreSimulateFallingBlocks = a_IniFile.GetValueSetB("Generator", "PreSimulatorFallingBlocks", true); - bool PreSimulateWater = a_IniFile.GetValueSetB("Generator", "PreSimulatorWater", true); - bool PreSimulateLava = a_IniFile.GetValueSetB("Generator", "PreSimulatorLava", true); + bool PreSimulateWater = a_IniFile.GetValueSetB("Generator", "PreSimulatorWater", true); + bool PreSimulateLava = a_IniFile.GetValueSetB("Generator", "PreSimulatorLava", true); - m_FinishGens.push_back(std::make_unique<cFinishGenPreSimulator>(PreSimulateFallingBlocks, PreSimulateWater, PreSimulateLava)); + m_FinishGens.push_back( + std::make_unique<cFinishGenPreSimulator>(PreSimulateFallingBlocks, PreSimulateWater, PreSimulateLava) + ); } else if (NoCaseCompare(finisher, "Ravines") == 0) { @@ -572,24 +608,28 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(finisher, "RoughRavines") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesGridSize", 256); - int MaxOffset = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxOffset", 128); - int MaxSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxSize", 128); - int MinSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMinSize", 64); - double MaxCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCenterWidth", 8); - double MinCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCenterWidth", 2); - double MaxRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxRoughness", 0.2); - double MinRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinRoughness", 0.05); - double MaxFloorHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxFloorHeightEdge", 8); - double MinFloorHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinFloorHeightEdge", 30); - double MaxFloorHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxFloorHeightCenter", 20); - double MinFloorHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinFloorHeightCenter", 6); - double MaxCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightEdge", 56); - double MinCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightEdge", 38); - double MaxCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightCenter", 58); - double MinCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightCenter", 36); + int GridSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesGridSize", 256); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxOffset", 128); + int MaxSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMaxSize", 128); + int MinSize = a_IniFile.GetValueSetI("Generator", "RoughRavinesMinSize", 64); + double MaxCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCenterWidth", 8); + double MinCenterWidth = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCenterWidth", 2); + double MaxRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxRoughness", 0.2); + double MinRoughness = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinRoughness", 0.05); + double MaxFloorHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxFloorHeightEdge", 8); + double MinFloorHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinFloorHeightEdge", 30); + double MaxFloorHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxFloorHeightCenter", 20); + double MinFloorHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinFloorHeightCenter", 6); + double MaxCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightEdge", 56); + double MinCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightEdge", 38); + double MaxCeilingHeightCenter = + a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightCenter", 58); + double MinCeilingHeightCenter = + a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightCenter", 36); m_FinishGens.push_back(std::make_unique<cRoughRavines>( - m_Seed, MaxSize, MinSize, + m_Seed, + MaxSize, + MinSize, static_cast<float>(MaxCenterWidth), static_cast<float>(MinCenterWidth), static_cast<float>(MaxRoughness), @@ -602,14 +642,16 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) static_cast<float>(MinCeilingHeightEdge), static_cast<float>(MaxCeilingHeightCenter), static_cast<float>(MinCeilingHeightCenter), - GridSize, MaxOffset + GridSize, + MaxOffset )); } else if (NoCaseCompare(finisher, "SinglePieceStructures") == 0) { if (split.size() < 2) { - LOGWARNING("The SinglePieceStructures generator needs the structures to use. Example: \"SinglePieceStructures: DesertPyramid\"."); + LOGWARNING("The SinglePieceStructures generator needs the structures to use. Example: " + "\"SinglePieceStructures: DesertPyramid\"."); continue; } @@ -629,9 +671,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(finisher, "SprinkleFoliage") == 0) { - int MaxCactusHeight = a_IniFile.GetValueI("Plants", "MaxCactusHeight", 3); - int MaxSugarcaneHeight = a_IniFile.GetValueI("Plants", "MaxSugarcaneHeight", 3); - m_FinishGens.push_back(std::make_unique<cFinishGenSprinkleFoliage>(m_Seed, MaxCactusHeight, MaxSugarcaneHeight)); + int MaxCactusHeight = a_IniFile.GetValueI("Plants", "MaxCactusHeight", 3); + int MaxSugarcaneHeight = a_IniFile.GetValueI("Plants", "MaxSugarcaneHeight", 3); + m_FinishGens.push_back( + std::make_unique<cFinishGenSprinkleFoliage>(m_Seed, MaxCactusHeight, MaxSugarcaneHeight) + ); } else if (NoCaseCompare(finisher, "TallGrass") == 0) { @@ -639,19 +683,33 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } else if (NoCaseCompare(finisher, "Trees") == 0) { - m_FinishGens.push_back(std::make_unique<cStructGenTrees>(m_Seed, *m_BiomeGen, *m_ShapeGen, *m_CompositionGen)); + m_FinishGens.push_back( + std::make_unique<cStructGenTrees>(m_Seed, *m_BiomeGen, *m_ShapeGen, *m_CompositionGen) + ); } else if (NoCaseCompare(finisher, "Villages") == 0) { - int GridSize = a_IniFile.GetValueSetI("Generator", "VillageGridSize", 384); - int MaxOffset = a_IniFile.GetValueSetI("Generator", "VillageMaxOffset", 128); - int MaxDepth = a_IniFile.GetValueSetI("Generator", "VillageMaxDepth", 2); - int MaxSize = a_IniFile.GetValueSetI("Generator", "VillageMaxSize", 128); + int GridSize = a_IniFile.GetValueSetI("Generator", "VillageGridSize", 384); + int MaxOffset = a_IniFile.GetValueSetI("Generator", "VillageMaxOffset", 128); + int MaxDepth = a_IniFile.GetValueSetI("Generator", "VillageMaxDepth", 2); + int MaxSize = a_IniFile.GetValueSetI("Generator", "VillageMaxSize", 128); int MinDensity = a_IniFile.GetValueSetI("Generator", "VillageMinDensity", 50); int MaxDensity = a_IniFile.GetValueSetI("Generator", "VillageMaxDensity", 80); AString PrefabList = a_IniFile.GetValueSet("Generator", "VillagePrefabs", "PlainsVillage, SandVillage"); auto Prefabs = StringSplitAndTrim(PrefabList, ","); - m_FinishGens.push_back(std::make_unique<cVillageGen>(m_Seed, GridSize, MaxOffset, MaxDepth, MaxSize, MinDensity, MaxDensity, *m_BiomeGen, *m_CompositedHeightCache, seaLevel, Prefabs)); + m_FinishGens.push_back(std::make_unique<cVillageGen>( + m_Seed, + GridSize, + MaxOffset, + MaxDepth, + MaxSize, + MinDensity, + MaxDensity, + *m_BiomeGen, + *m_CompositedHeightCache, + seaLevel, + Prefabs + )); } else if (NoCaseCompare(finisher, "Vines") == 0) { @@ -661,16 +719,20 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) else if (NoCaseCompare(finisher, "WaterLakes") == 0) { int Probability = a_IniFile.GetValueSetI("Generator", "WaterLakesProbability", 25); - m_FinishGens.push_back(std::make_unique<cStructGenLakes>(m_Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, *m_ShapeGen, Probability)); + m_FinishGens.push_back( + std::make_unique<cStructGenLakes>(m_Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, *m_ShapeGen, Probability) + ); } else if (NoCaseCompare(finisher, "WaterSprings") == 0) { - m_FinishGens.push_back(std::make_unique<cFinishGenFluidSprings>(m_Seed, E_BLOCK_WATER, a_IniFile, m_Dimension)); + m_FinishGens.push_back( + std::make_unique<cFinishGenFluidSprings>(m_Seed, E_BLOCK_WATER, a_IniFile, m_Dimension) + ); } else if (NoCaseCompare(finisher, "WormNestCaves") == 0) { - int Size = a_IniFile.GetValueSetI("Generator", "WormNestCavesSize", 64); - int Grid = a_IniFile.GetValueSetI("Generator", "WormNestCavesGrid", 96); + int Size = a_IniFile.GetValueSetI("Generator", "WormNestCavesSize", 64); + int Grid = a_IniFile.GetValueSetI("Generator", "WormNestCavesGrid", 96); int MaxOffset = a_IniFile.GetValueSetI("Generator", "WormNestMaxOffset", 32); m_FinishGens.push_back(std::make_unique<cStructGenWormNestCaves>(m_Seed, Size, Grid, MaxOffset)); } diff --git a/src/Generating/ComposableGenerator.h b/src/Generating/ComposableGenerator.h index 4105fbf83..0a7d99b7d 100644 --- a/src/Generating/ComposableGenerator.h +++ b/src/Generating/ComposableGenerator.h @@ -1,7 +1,8 @@ // ComposableGenerator.h -// Declares the cComposableGenerator class representing the chunk generator that takes the composition approach to generating chunks +// Declares the cComposableGenerator class representing the chunk generator that takes the composition approach to +// generating chunks /* Generating works by composing several algorithms: @@ -41,7 +42,7 @@ The output array is sequenced in the same way as the MapChunk packet's biome dat */ class cBiomeGen { -public: + public: virtual ~cBiomeGen() {} // Force a virtual destructor in descendants /** Generates biomes for the given chunk */ @@ -55,12 +56,8 @@ public: a_CacheOffByDefault gets set to whether the cache should be disabled by default. Used in BiomeVisualiser, too. Implemented in BioGen.cpp! */ - static std::unique_ptr<cBiomeGen> CreateBiomeGen( - cIniFile & a_IniFile, - int a_Seed, - bool & a_CacheOffByDefault - ); -} ; + static std::unique_ptr<cBiomeGen> CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault); +}; @@ -70,14 +67,14 @@ public: A terrain shape generator takes chunk coords on input and outputs a 3D array of "shape" for that chunk. The shape here represents the distinction between air and solid; there's no representation of Water since that is added by the composition geenrator. -The output array is indexed [y + 256 * z + 16 * 256 * x], so that it's fast to later compose a single column of the terrain, -which is the dominant operation following the shape generation. -The generator may request biome information from the underlying BiomeGen, it may even request information for -other chunks than the one it's currently generating (neighbors - for averaging) +The output array is indexed [y + 256 * z + 16 * 256 * x], so that it's fast to later compose a single column of the +terrain, which is the dominant operation following the shape generation. The generator may request biome information +from the underlying BiomeGen, it may even request information for other chunks than the one it's currently generating +(neighbors - for averaging) */ class cTerrainShapeGen { -public: + public: virtual ~cTerrainShapeGen() {} // Force a virtual destructor in descendants /** Generates the shape for the given chunk */ @@ -87,9 +84,9 @@ public: virtual void InitializeShapeGen(cIniFile & a_IniFile) {} /** Creates the correct TerrainShapeGen descendant based on the ini file settings and the seed provided. - a_BiomeGen is the underlying biome generator, some shape generators may depend on it providing additional biomes data around the chunk - a_CacheOffByDefault gets set to whether the cache should be disabled by default - Implemented in ShapeGen.cpp! + a_BiomeGen is the underlying biome generator, some shape generators may depend on it providing additional biomes + data around the chunk a_CacheOffByDefault gets set to whether the cache should be disabled by default Implemented in + ShapeGen.cpp! */ static std::unique_ptr<cTerrainShapeGen> CreateShapeGen( cIniFile & a_IniFile, @@ -97,7 +94,7 @@ public: int a_Seed, bool & a_CacheOffByDefault ); -} ; +}; @@ -109,7 +106,7 @@ consume the heightmap is wasteful, so this interface is used instead; it has a c that data is retained. */ class cTerrainHeightGen { -public: + public: virtual ~cTerrainHeightGen() {} // Force a virtual destructor in descendants /** Retrieves the heightmap for the specified chunk. */ @@ -126,7 +123,11 @@ public: auto chunkCoords = cChunkDef::BlockToChunk({a_BlockX, 0, a_BlockZ}); cChunkDef::HeightMap heightMap; GenHeightMap(chunkCoords, heightMap); - return cChunkDef::GetHeight(heightMap, a_BlockX - chunkCoords.m_ChunkX * cChunkDef::Width, a_BlockZ - chunkCoords.m_ChunkZ * cChunkDef::Width); + return cChunkDef::GetHeight( + heightMap, + a_BlockX - chunkCoords.m_ChunkX * cChunkDef::Width, + a_BlockZ - chunkCoords.m_ChunkZ * cChunkDef::Width + ); } /** Creates a cTerrainHeightGen descendant based on the INI file settings. */ @@ -136,7 +137,7 @@ public: int a_Seed, bool & a_CacheOffByDefault ); -} ; +}; @@ -149,7 +150,7 @@ but it may request information for other chunks than the one it's currently gene */ class cTerrainCompositionGen { -public: + public: virtual ~cTerrainCompositionGen() {} // Force a virtual destructor in descendants /** Generates the chunk's composition into a_ChunkDesc, using the terrain shape provided in a_Shape. @@ -160,15 +161,16 @@ public: virtual void InitializeCompoGen(cIniFile & a_IniFile) {} /** Creates the correct TerrainCompositionGen descendant based on the ini file settings and the seed provided. - a_BiomeGen is the underlying biome generator, some composition generators may depend on it providing additional biomes around the chunk - a_ShapeGen is the underlying shape generator, some composition generators may depend on it providing additional shape around the chunk. */ + a_BiomeGen is the underlying biome generator, some composition generators may depend on it providing additional + biomes around the chunk a_ShapeGen is the underlying shape generator, some composition generators may depend on it + providing additional shape around the chunk. */ static std::unique_ptr<cTerrainCompositionGen> CreateCompositionGen( cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, cTerrainShapeGen & a_ShapeGen, int a_Seed ); -} ; +}; @@ -183,23 +185,21 @@ no longer relevant, all structure generators are considered finishers now (#398) */ class cFinishGen { -public: + public: virtual ~cFinishGen() {} // Force a virtual destructor in descendants virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0; -} ; +}; -class cComposableGenerator: - public cChunkGenerator +class cComposableGenerator : public cChunkGenerator { using Super = cChunkGenerator; -public: - + public: cComposableGenerator(); // cChunkGenerator::cGenerator overrides: @@ -212,8 +212,7 @@ public: static void InitializeGeneratorDefaults(cIniFile & a_IniFile, eDimension a_Dimension); -protected: - + protected: // The generator's composition: /** The biome generator. */ std::unique_ptr<cBiomeGen> m_BiomeGen; @@ -242,4 +241,4 @@ protected: /** Reads the finishers from the ini and initializes m_FinishGens accordingly */ void InitFinishGens(cIniFile & a_IniFile); -} ; +}; diff --git a/src/Generating/CompositedHeiGen.h b/src/Generating/CompositedHeiGen.h index 6107d33ae..3153991b7 100644 --- a/src/Generating/CompositedHeiGen.h +++ b/src/Generating/CompositedHeiGen.h @@ -1,8 +1,9 @@ // CompositedHeiGen.h -// Declares the cCompositedHeiGen class representing a cTerrainHeightGen descendant that calculates heightmap of the composited terrain -// This is used to further cache heightmaps for chunks already generated for finishers that require only heightmap information +// Declares the cCompositedHeiGen class representing a cTerrainHeightGen descendant that calculates heightmap of the +// composited terrain This is used to further cache heightmaps for chunks already generated for finishers that require +// only heightmap information @@ -16,14 +17,15 @@ -class cCompositedHeiGen: - public cTerrainHeightGen +class cCompositedHeiGen : public cTerrainHeightGen { -public: - cCompositedHeiGen(cBiomeGen & a_BiomeGen, cTerrainShapeGen & a_ShapeGen, cTerrainCompositionGen & a_CompositionGen): - m_BiomeGen(a_BiomeGen), - m_ShapeGen(a_ShapeGen), - m_CompositionGen(a_CompositionGen) + public: + cCompositedHeiGen( + cBiomeGen & a_BiomeGen, + cTerrainShapeGen & a_ShapeGen, + cTerrainCompositionGen & a_CompositionGen + ) : + m_BiomeGen(a_BiomeGen), m_ShapeGen(a_ShapeGen), m_CompositionGen(a_CompositionGen) { } @@ -41,7 +43,7 @@ public: memcpy(a_HeightMap, desc.GetHeightMap(), sizeof(a_HeightMap)); } -protected: + protected: cBiomeGen & m_BiomeGen; cTerrainShapeGen & m_ShapeGen; cTerrainCompositionGen & m_CompositionGen; diff --git a/src/Generating/DistortedHeightmap.cpp b/src/Generating/DistortedHeightmap.cpp index 32b1a3a18..ce56148bf 100644 --- a/src/Generating/DistortedHeightmap.cpp +++ b/src/Generating/DistortedHeightmap.cpp @@ -23,96 +23,188 @@ Usually you'd want to keep both numbers the same. The numbers are "relative", not absolute maximum; overhangs of a slightly larger size are possible due to the way that noise is calculated. */ -const cDistortedHeightmap::sGenParam cDistortedHeightmap::m_GenParam[256] = -{ +const cDistortedHeightmap::sGenParam cDistortedHeightmap::m_GenParam[256] = { /* Biome | AmpX | AmpZ */ - /* biOcean */ { 1.5f, 1.5f}, - /* biPlains */ { 0.5f, 0.5f}, - /* biDesert */ { 0.5f, 0.5f}, + /* biOcean */ {1.5f, 1.5f}, + /* biPlains */ {0.5f, 0.5f}, + /* biDesert */ {0.5f, 0.5f}, /* biExtremeHills */ {16.0f, 16.0f}, - /* biForest */ { 3.0f, 3.0f}, - /* biTaiga */ { 1.5f, 1.5f}, - - /* biSwampland */ { 0.0f, 0.0f}, - /* biRiver */ { 0.0f, 0.0f}, - /* biNether */ { 0.0f, 0.0f}, // Unused, but must be here due to indexing - /* biSky */ { 0.0f, 0.0f}, // Unused, but must be here due to indexing - /* biFrozenOcean */ { 0.0f, 0.0f}, - /* biFrozenRiver */ { 0.0f, 0.0f}, - /* biIcePlains */ { 0.0f, 0.0f}, - /* biIceMountains */ { 8.0f, 8.0f}, - /* biMushroomIsland */ { 4.0f, 4.0f}, - /* biMushroomShore */ { 0.0f, 0.0f}, - /* biBeach */ { 0.0f, 0.0f}, - /* biDesertHills */ { 5.0f, 5.0f}, - /* biForestHills */ { 6.0f, 6.0f}, - /* biTaigaHills */ { 8.0f, 8.0f}, - /* biExtremeHillsEdge */ { 7.0f, 7.0f}, - /* biJungle */ { 4.0f, 4.0f}, - /* biJungleHills */ { 8.0f, 8.0f}, - /* biJungleEdge */ { 3.0f, 3.0f}, // 23 - /* biDeepOcean */ { 1.0f, 1.0f}, // 24 - /* biStoneBeach */ { 1.0f, 1.0f}, // 25 - /* biColdBeach */ { 1.0f, 1.0f}, // 26 - /* biBirchForest */ { 3.0f, 3.0f}, // 27 - /* biBirchForestHills */ { 6.0f, 6.0f}, // 28 - /* biRoofedForest */ { 3.0f, 3.0f}, // 29 - /* biColdTaiga */ { 0.5f, 0.5f}, // 30 - /* biColdTaigaHills */ { 4.0f, 4.0f}, // 31 - /* biMegaTaiga */ { 1.0f, 1.0f}, // 32 - /* biMegaTaigaHills */ { 4.0f, 4.0f}, // 33 + /* biForest */ {3.0f, 3.0f}, + /* biTaiga */ {1.5f, 1.5f}, + + /* biSwampland */ {0.0f, 0.0f}, + /* biRiver */ {0.0f, 0.0f}, + /* biNether */ {0.0f, 0.0f}, // Unused, but must be here due to indexing + /* biSky */ {0.0f, 0.0f}, // Unused, but must be here due to indexing + /* biFrozenOcean */ {0.0f, 0.0f}, + /* biFrozenRiver */ {0.0f, 0.0f}, + /* biIcePlains */ {0.0f, 0.0f}, + /* biIceMountains */ {8.0f, 8.0f}, + /* biMushroomIsland */ {4.0f, 4.0f}, + /* biMushroomShore */ {0.0f, 0.0f}, + /* biBeach */ {0.0f, 0.0f}, + /* biDesertHills */ {5.0f, 5.0f}, + /* biForestHills */ {6.0f, 6.0f}, + /* biTaigaHills */ {8.0f, 8.0f}, + /* biExtremeHillsEdge */ {7.0f, 7.0f}, + /* biJungle */ {4.0f, 4.0f}, + /* biJungleHills */ {8.0f, 8.0f}, + /* biJungleEdge */ {3.0f, 3.0f}, // 23 + /* biDeepOcean */ {1.0f, 1.0f}, // 24 + /* biStoneBeach */ {1.0f, 1.0f}, // 25 + /* biColdBeach */ {1.0f, 1.0f}, // 26 + /* biBirchForest */ {3.0f, 3.0f}, // 27 + /* biBirchForestHills */ {6.0f, 6.0f}, // 28 + /* biRoofedForest */ {3.0f, 3.0f}, // 29 + /* biColdTaiga */ {0.5f, 0.5f}, // 30 + /* biColdTaigaHills */ {4.0f, 4.0f}, // 31 + /* biMegaTaiga */ {1.0f, 1.0f}, // 32 + /* biMegaTaigaHills */ {4.0f, 4.0f}, // 33 /* biExtremeHillsPlus */ {32.0f, 32.0f}, // 34 - anyone say extreme plus? Make it extreme plus, then :) - /* biSavanna */ { 2.0f, 2.0f}, // 35 - /* biSavannaPlateau */ { 3.0f, 3.0f}, // 36 - /* biMesa */ { 2.0f, 2.0f}, // 37 - /* biMesaPlateauF */ { 2.0f, 2.0f}, // 38 - /* biMesaPlateau */ { 2.0f, 2.0f}, // 39 + /* biSavanna */ {2.0f, 2.0f}, // 35 + /* biSavannaPlateau */ {3.0f, 3.0f}, // 36 + /* biMesa */ {2.0f, 2.0f}, // 37 + /* biMesaPlateauF */ {2.0f, 2.0f}, // 38 + /* biMesaPlateau */ {2.0f, 2.0f}, // 39 // biomes 40 .. 128 are unused, 89 empty placeholders here: - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 40 .. 49 - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 50 .. 59 - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 60 .. 69 - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 70 .. 79 - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 80 .. 89 - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 90 .. 99 - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 100 .. 109 - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 110 .. 119 - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 120 .. 128 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 40 .. 49 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 50 .. 59 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 60 .. 69 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 70 .. 79 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 80 .. 89 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 90 .. 99 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 100 .. 109 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 110 .. 119 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 120 .. 128 // Release 1.7 biome variants: - /* biSunflowerPlains */ { 1.0f, 1.0f}, // 129 - /* biDesertM */ { 1.0f, 1.0f}, // 130 + /* biSunflowerPlains */ {1.0f, 1.0f}, // 129 + /* biDesertM */ {1.0f, 1.0f}, // 130 /* biExtremeHillsM */ {16.0f, 16.0f}, // 131 - /* biFlowerForest */ { 4.0f, 4.0f}, // 132 - /* biTaigaM */ { 3.0f, 3.0f}, // 133 - /* biSwamplandM */ { 0.0f, 0.0f}, // 134 + /* biFlowerForest */ {4.0f, 4.0f}, // 132 + /* biTaigaM */ {3.0f, 3.0f}, // 133 + /* biSwamplandM */ {0.0f, 0.0f}, // 134 // Biomes 135 .. 139 unused, 5 empty placeholders here: - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 135 .. 139 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 135 .. 139 - /* biIcePlainsSpikes */ { 1.0f, 1.0f}, // 140 + /* biIcePlainsSpikes */ {1.0f, 1.0f}, // 140 // Biomes 141 .. 148 unused, 8 empty placeholders here: - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 141 .. 148 - - /* biJungleM */ { 4.0f, 4.0f}, // 149 - {0.0f, 0.0f}, // 150 - /* biJungleEdgeM */ { 3.0f, 3.0f}, // 151 - {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, // 152 .. 154 - /* biBirchForestM */ { 3.0f, 3.0f}, // 155 - /* biBirchForestHillsM */ { 5.0f, 5.0f}, // 156 - /* biRoofedForestM */ { 2.0f, 2.0f}, // 157 - /* biColdTaigaM */ { 1.0f, 1.0f}, // 158 - {0.0f, 0.0f}, // 159 - /* biMegaSpruceTaiga */ { 3.0f, 3.0f}, // 160 - /* biMegaSpruceTaigaHills */ { 3.0f, 3.0f}, // 161 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 141 .. 148 + + /* biJungleM */ {4.0f, 4.0f}, // 149 + {0.0f, 0.0f}, // 150 + /* biJungleEdgeM */ {3.0f, 3.0f}, // 151 + {0.0f, 0.0f}, + {0.0f, 0.0f}, + {0.0f, 0.0f}, // 152 .. 154 + /* biBirchForestM */ {3.0f, 3.0f}, // 155 + /* biBirchForestHillsM */ {5.0f, 5.0f}, // 156 + /* biRoofedForestM */ {2.0f, 2.0f}, // 157 + /* biColdTaigaM */ {1.0f, 1.0f}, // 158 + {0.0f, 0.0f}, // 159 + /* biMegaSpruceTaiga */ {3.0f, 3.0f}, // 160 + /* biMegaSpruceTaigaHills */ {3.0f, 3.0f}, // 161 /* biExtremeHillsPlusM */ {32.0f, 32.0f}, // 162 - /* biSavannaM */ { 2.0f, 2.0f}, // 163 - /* biSavannaPlateauM */ { 3.0f, 3.0f}, // 164 - /* biMesaBryce */ { 0.5f, 0.5f}, // 165 - /* biMesaPlateauFM */ { 2.0f, 2.0f}, // 166 - /* biMesaPlateauM */ { 2.0f, 2.0f}, // 167 -} ; + /* biSavannaM */ {2.0f, 2.0f}, // 163 + /* biSavannaPlateauM */ {3.0f, 3.0f}, // 164 + /* biMesaBryce */ {0.5f, 0.5f}, // 165 + /* biMesaPlateauFM */ {2.0f, 2.0f}, // 166 + /* biMesaPlateauM */ {2.0f, 2.0f}, // 167 +}; @@ -121,18 +213,21 @@ const cDistortedHeightmap::sGenParam cDistortedHeightmap::m_GenParam[256] = cDistortedHeightmap::cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen) : m_NoiseDistortX(a_Seed + 1000), m_NoiseDistortZ(a_Seed + 2000), - m_CurChunkCoords(0x7fffffff, 0x7fffffff), // Set impossible coords for the chunk so that it's always considered stale + m_CurChunkCoords( + 0x7fffffff, + 0x7fffffff + ), // Set impossible coords for the chunk so that it's always considered stale m_BiomeGen(a_BiomeGen), m_UnderlyingHeiGen(a_Seed, a_BiomeGen), m_HeightGen(m_UnderlyingHeiGen, 64), m_IsInitialized(false) { - m_NoiseDistortX.AddOctave(static_cast<NOISE_DATATYPE>(1), static_cast<NOISE_DATATYPE>(0.5)); - m_NoiseDistortX.AddOctave(static_cast<NOISE_DATATYPE>(0.5), static_cast<NOISE_DATATYPE>(1)); + m_NoiseDistortX.AddOctave(static_cast<NOISE_DATATYPE>(1), static_cast<NOISE_DATATYPE>(0.5)); + m_NoiseDistortX.AddOctave(static_cast<NOISE_DATATYPE>(0.5), static_cast<NOISE_DATATYPE>(1)); m_NoiseDistortX.AddOctave(static_cast<NOISE_DATATYPE>(0.25), static_cast<NOISE_DATATYPE>(2)); - m_NoiseDistortZ.AddOctave(static_cast<NOISE_DATATYPE>(1), static_cast<NOISE_DATATYPE>(0.5)); - m_NoiseDistortZ.AddOctave(static_cast<NOISE_DATATYPE>(0.5), static_cast<NOISE_DATATYPE>(1)); + m_NoiseDistortZ.AddOctave(static_cast<NOISE_DATATYPE>(1), static_cast<NOISE_DATATYPE>(0.5)); + m_NoiseDistortZ.AddOctave(static_cast<NOISE_DATATYPE>(0.5), static_cast<NOISE_DATATYPE>(1)); m_NoiseDistortZ.AddOctave(static_cast<NOISE_DATATYPE>(0.25), static_cast<NOISE_DATATYPE>(2)); } @@ -148,7 +243,7 @@ void cDistortedHeightmap::Initialize(cIniFile & a_IniFile) } // Read the params from the INI file: - m_SeaLevel = a_IniFile.GetValueSetI("Generator", "SeaLevel", 62); + m_SeaLevel = a_IniFile.GetValueSetI("Generator", "SeaLevel", 62); m_FrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "DistortedHeightmapFrequencyX", 10)); m_FrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "DistortedHeightmapFrequencyY", 10)); m_FrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "DistortedHeightmapFrequencyZ", 10)); @@ -185,11 +280,13 @@ void cDistortedHeightmap::GenerateHeightArray(void) NOISE_DATATYPE DistortNoiseZ[DIM_X * DIM_Y * DIM_Z]; NOISE_DATATYPE Workspace[DIM_X * DIM_Y * DIM_Z]; NOISE_DATATYPE StartX = static_cast<NOISE_DATATYPE>(m_CurChunkCoords.m_ChunkX * cChunkDef::Width) / m_FrequencyX; - NOISE_DATATYPE EndX = static_cast<NOISE_DATATYPE>((m_CurChunkCoords.m_ChunkX + 1) * cChunkDef::Width - 1) / m_FrequencyX; + NOISE_DATATYPE EndX = + static_cast<NOISE_DATATYPE>((m_CurChunkCoords.m_ChunkX + 1) * cChunkDef::Width - 1) / m_FrequencyX; NOISE_DATATYPE StartY = 0; - NOISE_DATATYPE EndY = static_cast<NOISE_DATATYPE>(257) / m_FrequencyY; + NOISE_DATATYPE EndY = static_cast<NOISE_DATATYPE>(257) / m_FrequencyY; NOISE_DATATYPE StartZ = static_cast<NOISE_DATATYPE>(m_CurChunkCoords.m_ChunkZ * cChunkDef::Width) / m_FrequencyZ; - NOISE_DATATYPE EndZ = static_cast<NOISE_DATATYPE>((m_CurChunkCoords.m_ChunkZ + 1) * cChunkDef::Width - 1) / m_FrequencyZ; + NOISE_DATATYPE EndZ = + static_cast<NOISE_DATATYPE>((m_CurChunkCoords.m_ChunkZ + 1) * cChunkDef::Width - 1) / m_FrequencyZ; m_NoiseDistortX.Generate3D(DistortNoiseX, DIM_X, DIM_Y, DIM_Z, StartX, EndX, StartY, EndY, StartZ, EndZ, Workspace); m_NoiseDistortZ.Generate3D(DistortNoiseZ, DIM_X, DIM_Y, DIM_Z, StartX, EndX, StartY, EndY, StartZ, EndZ, Workspace); @@ -211,18 +308,17 @@ void cDistortedHeightmap::GenerateHeightArray(void) DistX += static_cast<NOISE_DATATYPE>(m_CurChunkCoords.m_ChunkX * cChunkDef::Width + x * INTERPOL_X); DistZ += static_cast<NOISE_DATATYPE>(m_CurChunkCoords.m_ChunkZ * cChunkDef::Width + z * INTERPOL_Z); // Adding 0.5 helps alleviate the interpolation artifacts - DistHei[NoiseArrayIdx + x] = static_cast<NOISE_DATATYPE>(GetHeightmapAt(DistX, DistZ)) + static_cast<NOISE_DATATYPE>(0.5); + DistHei[NoiseArrayIdx + x] = + static_cast<NOISE_DATATYPE>(GetHeightmapAt(DistX, DistZ)) + static_cast<NOISE_DATATYPE>(0.5); } } } // Upscale the distorted heightmap into full dimensions: - LinearUpscale3DArray( - DistHei, DIM_X, DIM_Y, DIM_Z, - m_DistortedHeightmap, INTERPOL_X, INTERPOL_Y, INTERPOL_Z - ); + LinearUpscale3DArray(DistHei, DIM_X, DIM_Y, DIM_Z, m_DistortedHeightmap, INTERPOL_X, INTERPOL_Y, INTERPOL_Z); - // DEBUG: Debug3DNoise(m_DistortedHeightmap, 17, 257, 17, fmt::format(FMT_STRING("DistortedHeightmap_{}_{}"), m_CurChunkX, m_CurChunkZ)); + // DEBUG: Debug3DNoise(m_DistortedHeightmap, 17, 257, 17, fmt::format(FMT_STRING("DistortedHeightmap_{}_{}"), + // m_CurChunkX, m_CurChunkZ)); } @@ -305,7 +401,13 @@ void cDistortedHeightmap::UpdateDistortAmps(void) { for (int x = 0; x < DIM_Z; x++) { - GetDistortAmpsAt(Biomes, x * INTERPOL_X, z * INTERPOL_Z, m_DistortAmpX[x + DIM_X * z], m_DistortAmpZ[x + DIM_X * z]); + GetDistortAmpsAt( + Biomes, + x * INTERPOL_X, + z * INTERPOL_Z, + m_DistortAmpX[x + DIM_X * z], + m_DistortAmpZ[x + DIM_X * z] + ); } } } @@ -314,7 +416,13 @@ void cDistortedHeightmap::UpdateDistortAmps(void) -void cDistortedHeightmap::GetDistortAmpsAt(BiomeNeighbors & a_Neighbors, int a_RelX, int a_RelZ, NOISE_DATATYPE & a_DistortAmpX, NOISE_DATATYPE & a_DistortAmpZ) +void cDistortedHeightmap::GetDistortAmpsAt( + BiomeNeighbors & a_Neighbors, + int a_RelX, + int a_RelZ, + NOISE_DATATYPE & a_DistortAmpX, + NOISE_DATATYPE & a_DistortAmpZ +) { // Sum up how many biomes of each type there are in the neighborhood: int BiomeCounts[256]; @@ -370,7 +478,3 @@ void cDistortedHeightmap::GetDistortAmpsAt(BiomeNeighbors & a_Neighbors, int a_R a_DistortAmpX = AmpX / Sum; a_DistortAmpZ = AmpZ / Sum; } - - - - diff --git a/src/Generating/DistortedHeightmap.h b/src/Generating/DistortedHeightmap.h index f523b8109..34d33438d 100644 --- a/src/Generating/DistortedHeightmap.h +++ b/src/Generating/DistortedHeightmap.h @@ -22,13 +22,12 @@ -class cDistortedHeightmap : - public cTerrainShapeGen +class cDistortedHeightmap : public cTerrainShapeGen { -public: + public: cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen); -protected: + protected: typedef cChunkDef::BiomeMap BiomeNeighbors[3][3]; // Linear upscaling step sizes, must be divisors of cChunkDef::Width and cChunkDef::Height, respectively: @@ -37,9 +36,9 @@ protected: static const int INTERPOL_Z = 8; // Linear upscaling buffer dimensions, calculated from the step sizes: - static const int DIM_X = 1 + (17 / INTERPOL_X); + static const int DIM_X = 1 + (17 / INTERPOL_X); static const int DIM_Y = 1 + (257 / INTERPOL_Y); - static const int DIM_Z = 1 + (17 / INTERPOL_Z); + static const int DIM_Z = 1 + (17 / INTERPOL_Z); cPerlinNoise m_NoiseDistortX; cPerlinNoise m_NoiseDistortZ; @@ -69,14 +68,15 @@ protected: { NOISE_DATATYPE m_DistortAmpX; NOISE_DATATYPE m_DistortAmpZ; - } ; + }; static const sGenParam m_GenParam[256]; // Distortion amplitudes for each direction, before linear upscaling NOISE_DATATYPE m_DistortAmpX[DIM_X * DIM_Z]; NOISE_DATATYPE m_DistortAmpZ[DIM_X * DIM_Z]; - /** True if Initialize() has been called. Used to initialize-once even with multiple init entrypoints (HeiGen / CompoGen). */ + /** True if Initialize() has been called. Used to initialize-once even with multiple init entrypoints (HeiGen / + * CompoGen). */ bool m_IsInitialized; @@ -93,7 +93,13 @@ protected: void UpdateDistortAmps(void); /** Calculates the X and Z distortion amplitudes based on the neighbors' biomes. */ - void GetDistortAmpsAt(BiomeNeighbors & a_Neighbors, int a_RelX, int a_RelZ, NOISE_DATATYPE & a_DistortAmpX, NOISE_DATATYPE & a_DistortAmpZ); + void GetDistortAmpsAt( + BiomeNeighbors & a_Neighbors, + int a_RelX, + int a_RelZ, + NOISE_DATATYPE & a_DistortAmpX, + NOISE_DATATYPE & a_DistortAmpZ + ); /** Reads the settings from the ini file. Skips reading if already initialized. */ void Initialize(cIniFile & a_IniFile); @@ -102,4 +108,4 @@ protected: // cTerrainShapeGen overrides: virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override; virtual void InitializeShapeGen(cIniFile & a_IniFile) override; -} ; +}; diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 96dd28333..c52d7257f 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -24,20 +24,21 @@ static const int ROOM_HEIGHT = 4; //////////////////////////////////////////////////////////////////////////////// // cDungeonRoom: -class cDungeonRoom: - public cGridStructGen::cStructure +class cDungeonRoom : public cGridStructGen::cStructure { using Super = cGridStructGen::cStructure; -public: - + public: cDungeonRoom( - int a_GridX, int a_GridZ, - int a_OriginX, int a_OriginZ, - int a_HalfSizeX, int a_HalfSizeZ, + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ, + int a_HalfSizeX, + int a_HalfSizeZ, int a_FloorHeight, cNoise & a_Noise - ): + ) : Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_StartX(a_OriginX - a_HalfSizeX), m_EndX(a_OriginX + a_HalfSizeX), @@ -57,7 +58,7 @@ public: int FirstChestPos = rnd % NumPositions; // The corner positions are a bit more likely, but we don't mind rnd = rnd / 512; int SecondChestPos = (FirstChestPos + 2 + (rnd % (NumPositions - 3))) % NumPositions; - m_Chest1 = DecodeChestCoords(FirstChestPos, SizeX, SizeZ); + m_Chest1 = DecodeChestCoords(FirstChestPos, SizeX, SizeZ); m_Chest2 = DecodeChestCoords(SecondChestPos, SizeX, SizeZ); // Choose what the mobspawner will spawn. @@ -77,8 +78,7 @@ public: } } -protected: - + protected: // The X range of the room, start inclusive, end exclusive: int m_StartX, m_EndX; @@ -126,16 +126,25 @@ protected: - /** Fills the specified area of blocks in the chunk with the specified blocktype if they are one of the overwritten block types. - The coords are absolute, start coords are inclusive, end coords are exclusive. */ - void ReplaceCuboid(cChunkDesc & a_ChunkDesc, int a_StartX, int a_StartY, int a_StartZ, int a_EndX, int a_EndY, int a_EndZ, BLOCKTYPE a_DstBlockType) + /** Fills the specified area of blocks in the chunk with the specified blocktype if they are one of the overwritten + block types. The coords are absolute, start coords are inclusive, end coords are exclusive. */ + void ReplaceCuboid( + cChunkDesc & a_ChunkDesc, + int a_StartX, + int a_StartY, + int a_StartZ, + int a_EndX, + int a_EndY, + int a_EndZ, + BLOCKTYPE a_DstBlockType + ) { int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; int RelStartX = Clamp(a_StartX - BlockX, 0, cChunkDef::Width); int RelStartZ = Clamp(a_StartZ - BlockZ, 0, cChunkDef::Width); - int RelEndX = Clamp(a_EndX - BlockX, 0, cChunkDef::Width); - int RelEndZ = Clamp(a_EndZ - BlockZ, 0, cChunkDef::Width); + int RelEndX = Clamp(a_EndX - BlockX, 0, cChunkDef::Width); + int RelEndZ = Clamp(a_EndZ - BlockZ, 0, cChunkDef::Width); for (int y = a_StartY; y < a_EndY; y++) { for (int z = RelStartZ; z < RelEndZ; z++) @@ -153,16 +162,27 @@ protected: - /** Fills the specified area of blocks in the chunk with a random pattern of the specified blocktypes, if they are one of the overwritten block types. - The coords are absolute, start coords are inclusive, end coords are exclusive. The first blocktype uses 75% chance, the second 25% chance. */ - void ReplaceCuboidRandom(cChunkDesc & a_ChunkDesc, int a_StartX, int a_StartY, int a_StartZ, int a_EndX, int a_EndY, int a_EndZ, BLOCKTYPE a_DstBlockType1, BLOCKTYPE a_DstBlockType2) + /** Fills the specified area of blocks in the chunk with a random pattern of the specified blocktypes, if they are + one of the overwritten block types. The coords are absolute, start coords are inclusive, end coords are exclusive. + The first blocktype uses 75% chance, the second 25% chance. */ + void ReplaceCuboidRandom( + cChunkDesc & a_ChunkDesc, + int a_StartX, + int a_StartY, + int a_StartZ, + int a_EndX, + int a_EndY, + int a_EndZ, + BLOCKTYPE a_DstBlockType1, + BLOCKTYPE a_DstBlockType2 + ) { int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; int RelStartX = Clamp(a_StartX - BlockX, 0, cChunkDef::Width - 1); int RelStartZ = Clamp(a_StartZ - BlockZ, 0, cChunkDef::Width - 1); - int RelEndX = Clamp(a_EndX - BlockX, 0, cChunkDef::Width); - int RelEndZ = Clamp(a_EndZ - BlockZ, 0, cChunkDef::Width); + int RelEndX = Clamp(a_EndX - BlockX, 0, cChunkDef::Width); + int RelEndZ = Clamp(a_EndZ - BlockZ, 0, cChunkDef::Width); auto & rnd = GetRandomProvider(); for (int y = a_StartY; y < a_EndY; y++) { @@ -188,9 +208,8 @@ protected: { int RelX = a_Chest.x - a_ChunkDesc.GetChunkX() * cChunkDef::Width; int RelZ = a_Chest.z - a_ChunkDesc.GetChunkZ() * cChunkDef::Width; - if ( - (RelX < 0) || (RelX >= cChunkDef::Width) || // The X coord is not in this chunk - (RelZ < 0) || (RelZ >= cChunkDef::Width) // The Z coord is not in this chunk + if ((RelX < 0) || (RelX >= cChunkDef::Width) || // The X coord is not in this chunk + (RelZ < 0) || (RelZ >= cChunkDef::Width) // The Z coord is not in this chunk ) { return; @@ -198,34 +217,34 @@ protected: a_ChunkDesc.SetBlockTypeMeta(RelX, m_FloorHeight + 1, RelZ, E_BLOCK_CHEST, static_cast<NIBBLETYPE>(a_Chest.y)); // Fill the chest with random loot - static const cLootProbab LootProbab[] = - { + static const cLootProbab LootProbab[] = { // Item, MinAmount, MaxAmount, Weight - { cItem(E_ITEM_GOLDEN_APPLE), 1, 1, 1 }, - { cItem(E_ITEM_DIAMOND_HORSE_ARMOR), 1, 1, 1 }, - { cItem(E_ITEM_GOLD_HORSE_ARMOR), 1, 1, 2 }, - { cItem(E_ITEM_GOLD), 1, 4, 2 }, - { cItem(E_ITEM_13_DISC), 1, 1, 4 }, - { cItem(E_ITEM_CAT_DISC), 1, 1, 4 }, - { cItem(E_ITEM_IRON_HORSE_ARMOR), 1, 1, 5 }, - { cItem(E_ITEM_IRON), 1, 4, 10 }, - { cItem(E_ITEM_WHEAT), 1, 4, 10 }, - { cItem(E_ITEM_GUNPOWDER), 1, 4, 10 }, - { cItem(E_ITEM_STRING), 1, 4, 10 }, - { cItem(E_ITEM_REDSTONE_DUST), 1, 4, 10 }, - { cItem(E_ITEM_COAL), 1, 4, 10 }, - { cItem(E_ITEM_BONE), 1, 4, 10 }, - { cItem(E_ITEM_ROTTEN_FLESH), 1, 4, 10 }, - { cItem(E_ITEM_SADDLE), 1, 1, 10 }, - { cItem(E_ITEM_BUCKET), 1, 1, 10 }, - { cItem(E_ITEM_BREAD), 1, 1, 10 }, - { cItem(E_ITEM_NAME_TAG), 1, 1, 10 }, - { cItem(E_ITEM_BEETROOT_SEEDS), 2, 4, 10 }, - { cItem(E_ITEM_MELON_SEEDS), 2, 4, 10 }, - { cItem(E_ITEM_PUMPKIN_SEEDS), 2, 4, 10 }, - } ; - - cChestEntity * ChestEntity = static_cast<cChestEntity *>(a_ChunkDesc.GetBlockEntity(RelX, m_FloorHeight + 1, RelZ)); + {cItem(E_ITEM_GOLDEN_APPLE), 1, 1, 1}, + {cItem(E_ITEM_DIAMOND_HORSE_ARMOR), 1, 1, 1}, + {cItem(E_ITEM_GOLD_HORSE_ARMOR), 1, 1, 2}, + {cItem(E_ITEM_GOLD), 1, 4, 2}, + {cItem(E_ITEM_13_DISC), 1, 1, 4}, + {cItem(E_ITEM_CAT_DISC), 1, 1, 4}, + {cItem(E_ITEM_IRON_HORSE_ARMOR), 1, 1, 5}, + {cItem(E_ITEM_IRON), 1, 4, 10}, + {cItem(E_ITEM_WHEAT), 1, 4, 10}, + {cItem(E_ITEM_GUNPOWDER), 1, 4, 10}, + {cItem(E_ITEM_STRING), 1, 4, 10}, + {cItem(E_ITEM_REDSTONE_DUST), 1, 4, 10}, + {cItem(E_ITEM_COAL), 1, 4, 10}, + {cItem(E_ITEM_BONE), 1, 4, 10}, + {cItem(E_ITEM_ROTTEN_FLESH), 1, 4, 10}, + {cItem(E_ITEM_SADDLE), 1, 1, 10}, + {cItem(E_ITEM_BUCKET), 1, 1, 10}, + {cItem(E_ITEM_BREAD), 1, 1, 10}, + {cItem(E_ITEM_NAME_TAG), 1, 1, 10}, + {cItem(E_ITEM_BEETROOT_SEEDS), 2, 4, 10}, + {cItem(E_ITEM_MELON_SEEDS), 2, 4, 10}, + {cItem(E_ITEM_PUMPKIN_SEEDS), 2, 4, 10}, + }; + + cChestEntity * ChestEntity = + static_cast<cChestEntity *>(a_ChunkDesc.GetBlockEntity(RelX, m_FloorHeight + 1, RelZ)); ASSERT((ChestEntity != nullptr) && (ChestEntity->GetBlockType() == E_BLOCK_CHEST)); cNoise Noise(a_ChunkDesc.GetChunkX() ^ a_ChunkDesc.GetChunkZ()); int NumSlots = 3 + ((Noise.IntNoise3DInt(a_Chest.x, a_Chest.y, a_Chest.z) / 11) % 4); @@ -238,12 +257,10 @@ protected: // cGridStructGen::cStructure override: virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override { - if ( - (m_EndX < a_ChunkDesc.GetChunkX() * cChunkDef::Width) || + if ((m_EndX < a_ChunkDesc.GetChunkX() * cChunkDef::Width) || (m_StartX >= a_ChunkDesc.GetChunkX() * cChunkDef::Width + cChunkDef::Width) || - (m_EndZ < a_ChunkDesc.GetChunkZ() * cChunkDef::Width) || - (m_StartZ >= a_ChunkDesc.GetChunkZ() * cChunkDef::Width + cChunkDef::Width) - ) + (m_EndZ < a_ChunkDesc.GetChunkZ() * cChunkDef::Width) || + (m_StartZ >= a_ChunkDesc.GetChunkZ() * cChunkDef::Width + cChunkDef::Width)) { // The chunk is not intersecting the room at all, bail out return; @@ -251,14 +268,24 @@ protected: int b = m_FloorHeight + 1; // Bottom int t = m_FloorHeight + 1 + ROOM_HEIGHT; // Top - ReplaceCuboidRandom(a_ChunkDesc, m_StartX, m_FloorHeight, m_StartZ, m_EndX + 1, b, m_EndZ + 1, E_BLOCK_MOSSY_COBBLESTONE, E_BLOCK_COBBLESTONE); // Floor + ReplaceCuboidRandom( + a_ChunkDesc, + m_StartX, + m_FloorHeight, + m_StartZ, + m_EndX + 1, + b, + m_EndZ + 1, + E_BLOCK_MOSSY_COBBLESTONE, + E_BLOCK_COBBLESTONE + ); // Floor ReplaceCuboid(a_ChunkDesc, m_StartX + 1, b, m_StartZ + 1, m_EndX, t, m_EndZ, E_BLOCK_AIR); // Insides // Walls: - ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_StartZ, m_StartX + 1, t, m_EndZ, E_BLOCK_COBBLESTONE); // XM wall - ReplaceCuboid(a_ChunkDesc, m_EndX, b, m_StartZ, m_EndX + 1, t, m_EndZ, E_BLOCK_COBBLESTONE); // XP wall - ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_StartZ, m_EndX + 1, t, m_StartZ + 1, E_BLOCK_COBBLESTONE); // ZM wall - ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_EndZ, m_EndX + 1, t, m_EndZ + 1, E_BLOCK_COBBLESTONE); // ZP wall + ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_StartZ, m_StartX + 1, t, m_EndZ, E_BLOCK_COBBLESTONE); // XM wall + ReplaceCuboid(a_ChunkDesc, m_EndX, b, m_StartZ, m_EndX + 1, t, m_EndZ, E_BLOCK_COBBLESTONE); // XP wall + ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_StartZ, m_EndX + 1, t, m_StartZ + 1, E_BLOCK_COBBLESTONE); // ZM wall + ReplaceCuboid(a_ChunkDesc, m_StartX, b, m_EndZ, m_EndX + 1, t, m_EndZ + 1, E_BLOCK_COBBLESTONE); // ZP wall // Place chests: TryPlaceChest(a_ChunkDesc, m_Chest1); @@ -267,18 +294,16 @@ protected: // Place the spawner: int CenterX = (m_StartX + m_EndX) / 2 - a_ChunkDesc.GetChunkX() * cChunkDef::Width; int CenterZ = (m_StartZ + m_EndZ) / 2 - a_ChunkDesc.GetChunkZ() * cChunkDef::Width; - if ( - (CenterX >= 0) && (CenterX < cChunkDef::Width) && - (CenterZ >= 0) && (CenterZ < cChunkDef::Width) - ) + if ((CenterX >= 0) && (CenterX < cChunkDef::Width) && (CenterZ >= 0) && (CenterZ < cChunkDef::Width)) { a_ChunkDesc.SetBlockTypeMeta(CenterX, b, CenterZ, E_BLOCK_MOB_SPAWNER, 0); - cMobSpawnerEntity * MobSpawner = static_cast<cMobSpawnerEntity *>(a_ChunkDesc.GetBlockEntity(CenterX, b, CenterZ)); + cMobSpawnerEntity * MobSpawner = + static_cast<cMobSpawnerEntity *>(a_ChunkDesc.GetBlockEntity(CenterX, b, CenterZ)); ASSERT((MobSpawner != nullptr) && (MobSpawner->GetBlockType() == E_BLOCK_MOB_SPAWNER)); MobSpawner->SetEntity(m_MonsterType); } } -} ; +}; @@ -287,7 +312,14 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cDungeonRoomsFinisher: -cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainShapeGen & a_ShapeGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib) : +cDungeonRoomsFinisher::cDungeonRoomsFinisher( + cTerrainShapeGen & a_ShapeGen, + int a_Seed, + int a_GridSize, + int a_MaxSize, + int a_MinSize, + const AString & a_HeightDistrib +) : Super(a_Seed + 100, a_GridSize, a_GridSize, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 1024), m_ShapeGen(a_ShapeGen), m_MaxHalfSize((a_MaxSize + 1) / 2), @@ -308,7 +340,12 @@ cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainShapeGen & a_ShapeGen, int -cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) +cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure( + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ +) { // Select a random room size in each direction: int rnd = m_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) / 7; @@ -335,5 +372,6 @@ cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int } // Create the dungeon room descriptor: - return cStructurePtr(new cDungeonRoom(a_GridX, a_GridZ, a_OriginX, a_OriginZ, HalfSizeX, HalfSizeZ, height, m_Noise)); + return cStructurePtr(new cDungeonRoom(a_GridX, a_GridZ, a_OriginX, a_OriginZ, HalfSizeX, HalfSizeZ, height, m_Noise) + ); } diff --git a/src/Generating/DungeonRoomsFinisher.h b/src/Generating/DungeonRoomsFinisher.h index bd5380448..92e2a747b 100644 --- a/src/Generating/DungeonRoomsFinisher.h +++ b/src/Generating/DungeonRoomsFinisher.h @@ -16,21 +16,25 @@ -class cDungeonRoomsFinisher: - public cGridStructGen +class cDungeonRoomsFinisher : public cGridStructGen { using Super = cGridStructGen; -public: - + public: /** Creates a new dungeon room finisher. a_ShapeGen is the underlying terrain shape generator, so that the rooms can always be placed under the terrain. a_MaxSize and a_MinSize are the maximum and minimum sizes of the room's internal (air) area, in blocks across. a_HeightDistrib is the string defining the height distribution for the rooms (cProbabDistrib format). */ - cDungeonRoomsFinisher(cTerrainShapeGen & a_ShapeGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib); - -protected: - + cDungeonRoomsFinisher( + cTerrainShapeGen & a_ShapeGen, + int a_Seed, + int a_GridSize, + int a_MaxSize, + int a_MinSize, + const AString & a_HeightDistrib + ); + + protected: /** The shape gen that is used for limiting the rooms' Y coords */ cTerrainShapeGen & m_ShapeGen; @@ -40,10 +44,11 @@ protected: /** Minimum half-size (from center to wall) of the dungeon room's inner (air) area. Default is 2 (vanilla). */ int m_MinHalfSize; - /** The height probability distribution to make the spawners more common in layers 10 - 40, less common outside this range. */ + /** The height probability distribution to make the spawners more common in layers 10 - 40, less common outside this + * range. */ cProbabDistrib m_HeightProbability; // cGridStructGen overrides: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; -} ; +}; diff --git a/src/Generating/EndGen.cpp b/src/Generating/EndGen.cpp index a0aa672dc..8c90a1d4a 100644 --- a/src/Generating/EndGen.cpp +++ b/src/Generating/EndGen.cpp @@ -20,9 +20,9 @@ enum INTERPOL_Z = 4, // Size of chunk data, downscaled before interpolation: - DIM_X = 16 / INTERPOL_X + 1, + DIM_X = 16 / INTERPOL_X + 1, DIM_Y = 256 / INTERPOL_Y + 1, - DIM_Z = 16 / INTERPOL_Z + 1, + DIM_Z = 16 / INTERPOL_Z + 1, }; @@ -63,16 +63,31 @@ void cEndGen::InitializeShapeGen(cIniFile & a_IniFile) m_IslandThickness = a_IniFile.GetValueSetI("Generator", "EndGenIslandThickness", m_IslandThickness); m_IslandYOffset = a_IniFile.GetValueSetI("Generator", "EndGenIslandYOffset", m_IslandYOffset); - m_MainIslandFrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenMainFrequencyX", m_MainIslandFrequencyX)); - m_MainIslandFrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenMainFrequencyY", m_MainIslandFrequencyY)); - m_MainIslandFrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenMainFrequencyZ", m_MainIslandFrequencyZ)); - m_MainIslandMinThreshold = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenMainMinThreshold", m_MainIslandMinThreshold)); - - m_SmallIslandFrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenSmallFrequencyX", m_SmallIslandFrequencyX)); - m_SmallIslandFrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenSmallFrequencyY", m_SmallIslandFrequencyY)); - m_SmallIslandFrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenSmallFrequencyZ", m_SmallIslandFrequencyZ)); - m_SmallIslandMinThreshold = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenSmallMinThreshold", m_SmallIslandMinThreshold)); - + m_MainIslandFrequencyX = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenMainFrequencyX", m_MainIslandFrequencyX) + ); + m_MainIslandFrequencyY = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenMainFrequencyY", m_MainIslandFrequencyY) + ); + m_MainIslandFrequencyZ = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "EndGenMainFrequencyZ", m_MainIslandFrequencyZ) + ); + m_MainIslandMinThreshold = static_cast<NOISE_DATATYPE>( + a_IniFile.GetValueSetF("Generator", "EndGenMainMinThreshold", m_MainIslandMinThreshold) + ); + + m_SmallIslandFrequencyX = static_cast<NOISE_DATATYPE>( + a_IniFile.GetValueSetF("Generator", "EndGenSmallFrequencyX", m_SmallIslandFrequencyX) + ); + m_SmallIslandFrequencyY = static_cast<NOISE_DATATYPE>( + a_IniFile.GetValueSetF("Generator", "EndGenSmallFrequencyY", m_SmallIslandFrequencyY) + ); + m_SmallIslandFrequencyZ = static_cast<NOISE_DATATYPE>( + a_IniFile.GetValueSetF("Generator", "EndGenSmallFrequencyZ", m_SmallIslandFrequencyZ) + ); + m_SmallIslandMinThreshold = static_cast<NOISE_DATATYPE>( + a_IniFile.GetValueSetF("Generator", "EndGenSmallMinThreshold", m_SmallIslandMinThreshold) + ); } @@ -101,18 +116,19 @@ void cEndGen::GenerateNoiseArray(void) NOISE_DATATYPE Workspace[DIM_X * DIM_Y * DIM_Z]; // [x + DIM_X * z + DIM_X * DIM_Z * y] // Choose the frequency to use depending on the distance from spawn. - auto distanceFromSpawn = cChunkDef::RelativeToAbsolute({ cChunkDef::Width / 2, 0, cChunkDef::Width / 2 }, m_LastChunkCoords).Length(); + auto distanceFromSpawn = + cChunkDef::RelativeToAbsolute({cChunkDef::Width / 2, 0, cChunkDef::Width / 2}, m_LastChunkCoords).Length(); auto frequencyX = distanceFromSpawn > m_MainIslandSize * 2 ? m_SmallIslandFrequencyX : m_MainIslandFrequencyX; auto frequencyY = distanceFromSpawn > m_MainIslandSize * 2 ? m_SmallIslandFrequencyY : m_MainIslandFrequencyY; auto frequencyZ = distanceFromSpawn > m_MainIslandSize * 2 ? m_SmallIslandFrequencyZ : m_MainIslandFrequencyZ; // Generate the downscaled noise: - auto StartX = static_cast<NOISE_DATATYPE>(m_LastChunkCoords.m_ChunkX * cChunkDef::Width) / frequencyX; - auto EndX = static_cast<NOISE_DATATYPE>((m_LastChunkCoords.m_ChunkX + 1) * cChunkDef::Width) / frequencyX; - auto StartZ = static_cast<NOISE_DATATYPE>(m_LastChunkCoords.m_ChunkZ * cChunkDef::Width) / frequencyZ; - auto EndZ = static_cast<NOISE_DATATYPE>((m_LastChunkCoords.m_ChunkZ + 1) * cChunkDef::Width) / frequencyZ; + auto StartX = static_cast<NOISE_DATATYPE>(m_LastChunkCoords.m_ChunkX * cChunkDef::Width) / frequencyX; + auto EndX = static_cast<NOISE_DATATYPE>((m_LastChunkCoords.m_ChunkX + 1) * cChunkDef::Width) / frequencyX; + auto StartZ = static_cast<NOISE_DATATYPE>(m_LastChunkCoords.m_ChunkZ * cChunkDef::Width) / frequencyZ; + auto EndZ = static_cast<NOISE_DATATYPE>((m_LastChunkCoords.m_ChunkZ + 1) * cChunkDef::Width) / frequencyZ; auto StartY = 0.0f; - auto EndY = static_cast<NOISE_DATATYPE>(cChunkDef::Height) / frequencyY; + auto EndY = static_cast<NOISE_DATATYPE>(cChunkDef::Height) / frequencyY; m_Perlin.Generate3D(NoiseData, DIM_X, DIM_Z, DIM_Y, StartX, EndX, StartZ, EndZ, StartY, EndY, Workspace); // Add distance: @@ -144,15 +160,17 @@ void cEndGen::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) int MaxY = std::min(static_cast<int>(1.75 * m_IslandThickness + m_IslandYOffset), cChunkDef::Height - 1); // Choose which threshold to use depending on the distance from spawn. - double chunkDistanceFromSpawn = cChunkDef::RelativeToAbsolute({ cChunkDef::Width / 2, 0, cChunkDef::Width / 2 }, a_ChunkCoords).Length(); - double minThreshold = chunkDistanceFromSpawn > m_MainIslandSize * 2 ? m_SmallIslandMinThreshold : m_MainIslandMinThreshold; + double chunkDistanceFromSpawn = + cChunkDef::RelativeToAbsolute({cChunkDef::Width / 2, 0, cChunkDef::Width / 2}, a_ChunkCoords).Length(); + double minThreshold = + chunkDistanceFromSpawn > m_MainIslandSize * 2 ? m_SmallIslandMinThreshold : m_MainIslandMinThreshold; for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) { // Calculate the required treshold based on the distance from spawn. // This way a void can be generated between the main island and the other islands. - double distanceFromSpawn = cChunkDef::RelativeToAbsolute({ x, 0, z }, a_ChunkCoords).Length(); + double distanceFromSpawn = cChunkDef::RelativeToAbsolute({x, 0, z}, a_ChunkCoords).Length(); double pow = std::pow((distanceFromSpawn - m_MainIslandSize) / m_MainIslandSize / 2, 3); double mult = 3 * ((distanceFromSpawn - m_MainIslandSize) / m_MainIslandSize); double threshold = std::min(pow - mult, minThreshold); @@ -163,7 +181,13 @@ void cEndGen::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) } for (int y = m_IslandYOffset; y < MaxY; y++) { - cChunkDesc::SetShapeIsSolidAt(a_Shape, x, y, z, m_NoiseArray[(y - m_IslandYOffset) * 17 * 17 + z * 17 + x] <= threshold); + cChunkDesc::SetShapeIsSolidAt( + a_Shape, + x, + y, + z, + m_NoiseArray[(y - m_IslandYOffset) * 17 * 17 + z * 17 + x] <= threshold + ); } for (int y = MaxY; y < cChunkDef::Height; y++) { @@ -194,7 +218,3 @@ void cEndGen::ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & } // for x } // for z } - - - - diff --git a/src/Generating/EndGen.h b/src/Generating/EndGen.h index 4763352b2..3b17e14ba 100644 --- a/src/Generating/EndGen.h +++ b/src/Generating/EndGen.h @@ -16,15 +16,13 @@ -class cEndGen : - public cTerrainShapeGen, - public cTerrainCompositionGen +class cEndGen : public cTerrainShapeGen, + public cTerrainCompositionGen { -public: + public: cEndGen(int a_Seed); -protected: - + protected: /** Seed for the noise */ int m_Seed; @@ -67,4 +65,4 @@ protected: // cTerrainCompositionGen overrides: virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) override; -} ; +}; diff --git a/src/Generating/EnderDragonFightStructuresGen.cpp b/src/Generating/EnderDragonFightStructuresGen.cpp index 89292e078..ed3eaec2f 100644 --- a/src/Generating/EnderDragonFightStructuresGen.cpp +++ b/src/Generating/EnderDragonFightStructuresGen.cpp @@ -6,59 +6,106 @@ #include "../Entities/EnderCrystal.h" #include "../WorldStorage/SchematicFileSerializer.h" -const std::array<Vector3i, 48> cEnderDragonFightStructuresGen::m_CagePos = -{ - { - // First layer - {-2, -1, -2}, {-2, -1, -1}, {-2, -1, 0}, {-2, -1, 1}, {-2, -1, 2}, - {2, -1, -2}, {2, -1, -1}, {2, -1, 0}, {2, -1, 1}, {2, -1, 2}, - {-1, -1, -2}, {0, -1, -2}, {1, -1, -2}, - {-1, -1, 2}, {0, -1, 2}, {1, -1, 2}, - - // Second layer - {-2, 0, -2}, {-2, 0, -1}, {-2, 0, 0}, {-2, 0, 1}, {-2, 0, 2}, - {2, 0, -2}, {2, 0, -1}, {2, 0, 0}, {2, 0, 1}, {2, 0, 2}, - {-1, 0, -2}, {0, 0, -2}, {1, 0, -2}, - {-1, 0, 2}, {0, 0, 2}, {1, 0, 2}, - - // Third layer - {-2, 1, -2}, {-2, 1, -1}, {-2, 1, 0}, {-2, 1, 1}, {-2, 1, 2}, - {2, 1, -2}, {2, 1, -1}, {2, 1, 0}, {2, 1, 1}, {2, 1, 2}, - {-1, 1, -2}, {0, 1, -2}, {1, 1, -2}, - {-1, 1, 2}, {0, 1, 2}, {1, 1, 2}, - } -}; - - - - - -const std::array<Vector3i, 26> cEnderDragonFightStructuresGen::m_CageAir = -{ - { - // First layer - {-1, -1, -1}, {0, -1, -1}, {1, -1, -1}, - {-1, -1, 1}, {0, -1, 1}, {1, -1, 1}, - {-1, -1, 0}, {1, -1, 0}, - - // Second layer - {-1, 0, -1}, {0, 0, -1}, {1, 0, -1}, - {-1, 0, 1}, {0, 0, 1}, {1, 0, 1}, - {-1, 0, 0}, {1, 0, 0}, {0, 0, 0}, - - // Third layer - {-1, 1, -1}, {0, 1, -1}, {1, 1, -1}, - {-1, 1, 1}, {0, 1, 1}, {1, 1, 1}, - {-1, 1, 0}, {1, 1, 0}, {0, 1, 0}, - } -}; +const std::array<Vector3i, 48> cEnderDragonFightStructuresGen::m_CagePos = {{ + // First layer + {-2, -1, -2}, + {-2, -1, -1}, + {-2, -1, 0}, + {-2, -1, 1}, + {-2, -1, 2}, + {2, -1, -2}, + {2, -1, -1}, + {2, -1, 0}, + {2, -1, 1}, + {2, -1, 2}, + {-1, -1, -2}, + {0, -1, -2}, + {1, -1, -2}, + {-1, -1, 2}, + {0, -1, 2}, + {1, -1, 2}, + + // Second layer + {-2, 0, -2}, + {-2, 0, -1}, + {-2, 0, 0}, + {-2, 0, 1}, + {-2, 0, 2}, + {2, 0, -2}, + {2, 0, -1}, + {2, 0, 0}, + {2, 0, 1}, + {2, 0, 2}, + {-1, 0, -2}, + {0, 0, -2}, + {1, 0, -2}, + {-1, 0, 2}, + {0, 0, 2}, + {1, 0, 2}, + + // Third layer + {-2, 1, -2}, + {-2, 1, -1}, + {-2, 1, 0}, + {-2, 1, 1}, + {-2, 1, 2}, + {2, 1, -2}, + {2, 1, -1}, + {2, 1, 0}, + {2, 1, 1}, + {2, 1, 2}, + {-1, 1, -2}, + {0, 1, -2}, + {1, 1, -2}, + {-1, 1, 2}, + {0, 1, 2}, + {1, 1, 2}, +}}; + + + + + +const std::array<Vector3i, 26> cEnderDragonFightStructuresGen::m_CageAir = {{ + // First layer + {-1, -1, -1}, + {0, -1, -1}, + {1, -1, -1}, + {-1, -1, 1}, + {0, -1, 1}, + {1, -1, 1}, + {-1, -1, 0}, + {1, -1, 0}, + + // Second layer + {-1, 0, -1}, + {0, 0, -1}, + {1, 0, -1}, + {-1, 0, 1}, + {0, 0, 1}, + {1, 0, 1}, + {-1, 0, 0}, + {1, 0, 0}, + {0, 0, 0}, + + // Third layer + {-1, 1, -1}, + {0, 1, -1}, + {1, 1, -1}, + {-1, 1, 1}, + {0, 1, 1}, + {1, 1, 1}, + {-1, 1, 0}, + {1, 1, 0}, + {0, 1, 0}, +}}; cEnderDragonFightStructuresGen::cEnderDragonFightStructuresGen(int a_Seed) : - m_Noise(a_Seed) + m_Noise(a_Seed) { } @@ -70,13 +117,21 @@ void cEnderDragonFightStructuresGen::Init(const AString & a_TowerProperties, int { const auto ChunkWidth = cChunkDef::Width; // Loads the fountain schematic - if (!cFile::IsFile(AString("Prefabs") + cFile::GetPathSeparator() + "SinglePieceStructures" + cFile::GetPathSeparator() + "EndFountain.schematic")) + if (!cFile::IsFile( + AString("Prefabs") + cFile::GetPathSeparator() + "SinglePieceStructures" + cFile::GetPathSeparator() + + "EndFountain.schematic" + )) { - LOGWARNING("EnderDragonFightStructuresGen is missing its end fountain prefab, please update your Cuberite server files! There will be no end fountain!"); + LOGWARNING("EnderDragonFightStructuresGen is missing its end fountain prefab, please update your Cuberite " + "server files! There will be no end fountain!"); } else { - cSchematicFileSerializer::LoadFromSchematicFile(m_Fountain, AString("Prefabs") + cFile::GetPathSeparator() + "SinglePieceStructures" + cFile::GetPathSeparator() + "EndFountain.schematic"); + cSchematicFileSerializer::LoadFromSchematicFile( + m_Fountain, + AString("Prefabs") + cFile::GetPathSeparator() + "SinglePieceStructures" + cFile::GetPathSeparator() + + "EndFountain.schematic" + ); } // Reads the given tower properties @@ -87,10 +142,16 @@ void cEnderDragonFightStructuresGen::Init(const AString & a_TowerProperties, int const auto TowerPropertyVector = StringSplitAndTrim(TowerProperty, "|"); if (TowerPropertyVector.size() != 3) { - LOGWARNING("Got unknown parameters on generating obsidian pillars: %s, Please use \"Height|Radius|HasCage\"; ...", TowerProperty); + LOGWARNING( + "Got unknown parameters on generating obsidian pillars: %s, Please use \"Height|Radius|HasCage\"; ...", + TowerProperty + ); continue; } - int Height = std::min(std::stoi(TowerPropertyVector[0]), cChunkDef::Height - 2); // The highest block placed is two blocks above the given height (the cage above some towers) + int Height = std::min( + std::stoi(TowerPropertyVector[0]), + cChunkDef::Height - 2 + ); // The highest block placed is two blocks above the given height (the cage above some towers) int Radius = std::stoi(TowerPropertyVector[1]); bool HasCage; if (NoCaseCompare(TowerPropertyVector[2], "true") == 0) @@ -103,7 +164,11 @@ void cEnderDragonFightStructuresGen::Init(const AString & a_TowerProperties, int } else { - LOGWARNING("Got unknown value for boolean of the tower: %s should have a cage! %s. Tower will not be generated!", TowerProperty, TowerPropertyVector[2]); + LOGWARNING( + "Got unknown value for boolean of the tower: %s should have a cage! %s. Tower will not be generated!", + TowerProperty, + TowerPropertyVector[2] + ); continue; } TowerProperties.push_back({Vector3d(), Height, Radius, HasCage}); @@ -111,7 +176,11 @@ void cEnderDragonFightStructuresGen::Init(const AString & a_TowerProperties, int // A random angle in radian double Angle = m_Noise.IntNoise1D(m_Noise.GetSeed()) * M_PI + M_PI; // Shuffles the order of the towers - std::shuffle(TowerProperties.begin(), TowerProperties.end(), std::default_random_engine(static_cast<std::default_random_engine::result_type>(m_Noise.GetSeed()))); + std::shuffle( + TowerProperties.begin(), + TowerProperties.end(), + std::default_random_engine(static_cast<std::default_random_engine::result_type>(m_Noise.GetSeed())) + ); // Generate Positions in a circle for (size_t I = 0; I < TowerProperties.size(); I++) { @@ -119,9 +188,11 @@ void cEnderDragonFightStructuresGen::Init(const AString & a_TowerProperties, int TowerProperties[I].m_Pos = TowerPos; // Check all crossed chunks - for (int X = -TowerProperties[I].m_Radius - ChunkWidth; X <= TowerProperties[I].m_Radius + ChunkWidth; X+=std::min(TowerProperties[I].m_Radius, ChunkWidth)) + for (int X = -TowerProperties[I].m_Radius - ChunkWidth; X <= TowerProperties[I].m_Radius + ChunkWidth; + X += std::min(TowerProperties[I].m_Radius, ChunkWidth)) { - for (int Z = -TowerProperties[I].m_Radius - ChunkWidth; Z <= TowerProperties[I].m_Radius + ChunkWidth; Z+=std::min(TowerProperties[I].m_Radius, ChunkWidth)) + for (int Z = -TowerProperties[I].m_Radius - ChunkWidth; Z <= TowerProperties[I].m_Radius + ChunkWidth; + Z += std::min(TowerProperties[I].m_Radius, ChunkWidth)) { auto Chunk = cChunkDef::BlockToChunk({TowerPos.x + X, 0, TowerPos.z + Z}); // Update limits @@ -151,13 +222,11 @@ void cEnderDragonFightStructuresGen::Init(const AString & a_TowerProperties, int -void cEnderDragonFightStructuresGen::GenFinish(cChunkDesc &a_ChunkDesc) +void cEnderDragonFightStructuresGen::GenFinish(cChunkDesc & a_ChunkDesc) { auto Coords = a_ChunkDesc.GetChunkCoords(); // If not in the chunks to write - if ((Coords.m_ChunkX > m_MaxX) || - (Coords.m_ChunkX < m_MinX) || - (Coords.m_ChunkZ > m_MaxZ) || + if ((Coords.m_ChunkX > m_MaxX) || (Coords.m_ChunkX < m_MinX) || (Coords.m_ChunkZ > m_MaxZ) || (Coords.m_ChunkZ < m_MinZ)) { return; @@ -167,10 +236,11 @@ void cEnderDragonFightStructuresGen::GenFinish(cChunkDesc &a_ChunkDesc) { /* auto EnderDragon = std::make_unique<cEnderDragon>(); - EnderDragon->SetPosition({0.0, static_cast<double>(a_ChunkDesc.GetHeight(0, 0) + 20), 0.0}); // Spawns the dragon 20 blocks above the terrain at (0, 0) - a_ChunkDesc.GetEntities().emplace_back(std::move(EnderDragon)); + EnderDragon->SetPosition({0.0, static_cast<double>(a_ChunkDesc.GetHeight(0, 0) + 20), 0.0}); // Spawns the + dragon 20 blocks above the terrain at (0, 0) a_ChunkDesc.GetEntities().emplace_back(std::move(EnderDragon)); */ // Todo: 25.10.20 - Add the ender dragon spawning when the dragon behaves properly - 12xx12 - a_ChunkDesc.WriteBlockArea(m_Fountain, + a_ChunkDesc.WriteBlockArea( + m_Fountain, static_cast<int>(FloorC(-m_Fountain.GetSizeX() / 2)), 62, static_cast<int>(FloorC(-m_Fountain.GetSizeX() / 2)), @@ -179,7 +249,8 @@ void cEnderDragonFightStructuresGen::GenFinish(cChunkDesc &a_ChunkDesc) } else if (Coords == cChunkCoords({-1, 0})) { - a_ChunkDesc.WriteBlockArea(m_Fountain, + a_ChunkDesc.WriteBlockArea( + m_Fountain, cChunkDef::Width - static_cast<int>(FloorC(m_Fountain.GetSizeX() / 2)), 62, static_cast<int>(FloorC(-m_Fountain.GetSizeZ() / 2)), @@ -188,19 +259,23 @@ void cEnderDragonFightStructuresGen::GenFinish(cChunkDesc &a_ChunkDesc) } else if (Coords == cChunkCoords({0, -1})) { - a_ChunkDesc.WriteBlockArea(m_Fountain, + a_ChunkDesc.WriteBlockArea( + m_Fountain, static_cast<int>(FloorC(-m_Fountain.GetSizeX() / 2)), 62, cChunkDef::Width - static_cast<int>(FloorC(m_Fountain.GetSizeZ() / 2)), - cBlockArea::msSpongePrint); + cBlockArea::msSpongePrint + ); } else if (Coords == cChunkCoords({-1, -1})) { - a_ChunkDesc.WriteBlockArea(m_Fountain, + a_ChunkDesc.WriteBlockArea( + m_Fountain, cChunkDef::Width - static_cast<int>(FloorC(m_Fountain.GetSizeX() / 2)), 62, cChunkDef::Width - static_cast<int>(FloorC(m_Fountain.GetSizeZ() / 2)), - cBlockArea::msSpongePrint); + cBlockArea::msSpongePrint + ); } auto It = m_TowerPos.find(Coords); if (It == m_TowerPos.end()) @@ -217,7 +292,7 @@ void cEnderDragonFightStructuresGen::GenFinish(cChunkDesc &a_ChunkDesc) -void cEnderDragonFightStructuresGen::PlaceTower(cChunkDesc &a_ChunkDesc, const sTowerProperties & a_Properties) +void cEnderDragonFightStructuresGen::PlaceTower(cChunkDesc & a_ChunkDesc, const sTowerProperties & a_Properties) { auto Pos = cChunkDef::AbsoluteToRelative(a_Properties.m_Pos, a_ChunkDesc.GetChunkCoords()); // Place obsidian pillar @@ -229,7 +304,8 @@ void cEnderDragonFightStructuresGen::PlaceTower(cChunkDesc &a_ChunkDesc, const s if (cChunkDef::IsValidRelPos(NewPos)) { // The 3 was achieved by trial and error till the shape matched the notchian implementation - if ((NewPos - Vector3i(Pos.x, 1, Pos.z)).SqrLength() < a_Properties.m_Radius * a_Properties.m_Radius - 3) + if ((NewPos - Vector3i(Pos.x, 1, Pos.z)).SqrLength() < + a_Properties.m_Radius * a_Properties.m_Radius - 3) { for (int Y = 0; Y <= a_Properties.m_Height - 2; Y++) { @@ -248,7 +324,12 @@ void cEnderDragonFightStructuresGen::PlaceTower(cChunkDesc &a_ChunkDesc, const s { if (cChunkDef::IsValidRelPos(Vector3d(Pos.x, a_Properties.m_Height, Pos.z) + Offset)) { - a_ChunkDesc.SetBlockType(Pos.x + Offset.x, a_Properties.m_Height + Offset.y, Pos.z + Offset.z, E_BLOCK_IRON_BARS); + a_ChunkDesc.SetBlockType( + Pos.x + Offset.x, + a_Properties.m_Height + Offset.y, + Pos.z + Offset.z, + E_BLOCK_IRON_BARS + ); } } // Remove any block that may generate inside the cage @@ -256,7 +337,8 @@ void cEnderDragonFightStructuresGen::PlaceTower(cChunkDesc &a_ChunkDesc, const s { if (cChunkDef::IsValidRelPos(Pos + Offset)) { - a_ChunkDesc.SetBlockType(Pos.x + Offset.x, a_Properties.m_Height + Offset.y, Pos.z + Offset.z, E_BLOCK_AIR); + a_ChunkDesc + .SetBlockType(Pos.x + Offset.x, a_Properties.m_Height + Offset.y, Pos.z + Offset.z, E_BLOCK_AIR); } } // Place roof @@ -279,7 +361,8 @@ void cEnderDragonFightStructuresGen::PlaceTower(cChunkDesc &a_ChunkDesc, const s // Spawn the fire a_ChunkDesc.SetBlockType(Pos.x, a_Properties.m_Height, Pos.z, E_BLOCK_FIRE); // Spawn the ender crystal of the origin position is in this chunk - auto EnderCrystal = std::make_unique<cEnderCrystal>(Vector3d(0.5, a_Properties.m_Height, 0.5) + a_Properties.m_Pos, true); + auto EnderCrystal = + std::make_unique<cEnderCrystal>(Vector3d(0.5, a_Properties.m_Height, 0.5) + a_Properties.m_Pos, true); a_ChunkDesc.GetEntities().emplace_back(std::move(EnderCrystal)); } } diff --git a/src/Generating/EnderDragonFightStructuresGen.h b/src/Generating/EnderDragonFightStructuresGen.h index 7d415e80b..3108d6051 100644 --- a/src/Generating/EnderDragonFightStructuresGen.h +++ b/src/Generating/EnderDragonFightStructuresGen.h @@ -9,14 +9,13 @@ https://minecraft.wiki/w/Ender_Dragon #include "FinishGen.h" -class cEnderDragonFightStructuresGen : - public cFinishGen +class cEnderDragonFightStructuresGen : public cFinishGen { -public: + public: cEnderDragonFightStructuresGen(int a_Seed); void Init(const AString & a_TowerProperties, int a_Radius); -protected: + protected: struct sTowerProperties { Vector3i m_Pos; @@ -33,6 +32,6 @@ protected: int m_MinX = -1, m_MaxX = 1, m_MinZ = -1, m_MaxZ = 1; - void GenFinish(cChunkDesc &a_ChunkDesc) override; + void GenFinish(cChunkDesc & a_ChunkDesc) override; void PlaceTower(cChunkDesc & a_ChunkDesc, const sTowerProperties & a_TowerProperties); }; diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index f899a1dbb..f8a1cb82b 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -20,14 +20,15 @@ -#define DEF_NETHER_WATER_SPRINGS "0, 1; 255, 1" -#define DEF_NETHER_LAVA_SPRINGS "0, 0; 30, 0; 31, 50; 120, 50; 127, 0" -#define DEF_OVERWORLD_WATER_SPRINGS "0, 0; 10, 10; 11, 75; 16, 83; 20, 83; 24, 78; 32, 62; 40, 40; 44, 15; 48, 7; 56, 2; 64, 1; 255, 0" -#define DEF_OVERWORLD_LAVA_SPRINGS "0, 0; 10, 5; 11, 45; 48, 2; 64, 1; 255, 0" -#define DEF_END_WATER_SPRINGS "0, 1; 255, 1" -#define DEF_END_LAVA_SPRINGS "0, 1; 255, 1" -#define DEF_ANIMAL_SPAWN_PERCENT 10 -#define DEF_NO_ANIMALS 0 +#define DEF_NETHER_WATER_SPRINGS "0, 1; 255, 1" +#define DEF_NETHER_LAVA_SPRINGS "0, 0; 30, 0; 31, 50; 120, 50; 127, 0" +#define DEF_OVERWORLD_WATER_SPRINGS \ + "0, 0; 10, 10; 11, 75; 16, 83; 20, 83; 24, 78; 32, 62; 40, 40; 44, 15; 48, 7; 56, 2; 64, 1; 255, 0" +#define DEF_OVERWORLD_LAVA_SPRINGS "0, 0; 10, 5; 11, 45; 48, 2; 64, 1; 255, 0" +#define DEF_END_WATER_SPRINGS "0, 1; 255, 1" +#define DEF_END_LAVA_SPRINGS "0, 1; 255, 1" +#define DEF_ANIMAL_SPAWN_PERCENT 10 +#define DEF_NO_ANIMALS 0 @@ -89,7 +90,13 @@ void cFinishGenNetherClumpFoliage::GenFinish(cChunkDesc & a_ChunkDesc) -void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_Block) +void cFinishGenNetherClumpFoliage::TryPlaceClump( + cChunkDesc & a_ChunkDesc, + int a_RelX, + int a_RelY, + int a_RelZ, + BLOCKTYPE a_Block +) { bool IsFireBlock = a_Block == E_BLOCK_FIRE; @@ -137,11 +144,8 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a int zz = a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z; for (int y = MinY; y < MaxY; y++) { - if ( - ((x < 0) || (x >= cChunkDef::Width)) || - ((y < 0) || (y >= cChunkDef::Height)) || - ((z < 0) || (z >= cChunkDef::Width)) - ) + if (((x < 0) || (x >= cChunkDef::Width)) || ((y < 0) || (y >= cChunkDef::Height)) || + ((z < 0) || (z >= cChunkDef::Width))) { continue; } @@ -228,7 +232,14 @@ void cFinishGenClumpTopBlock::GenFinish(cChunkDesc & a_ChunkDesc) Weight -= Block.m_Weight; if (Weight < 0) { - TryPlaceFoliageClump(a_ChunkDesc, PosX, PosZ, Block.m_BlockType, Block.m_BlockMeta, Block.m_BlockType == E_BLOCK_BIG_FLOWER); + TryPlaceFoliageClump( + a_ChunkDesc, + PosX, + PosZ, + Block.m_BlockType, + Block.m_BlockMeta, + Block.m_BlockType == E_BLOCK_BIG_FLOWER + ); break; } } @@ -239,12 +250,21 @@ void cFinishGenClumpTopBlock::GenFinish(cChunkDesc & a_ChunkDesc) -void cFinishGenClumpTopBlock::TryPlaceFoliageClump(cChunkDesc & a_ChunkDesc, int a_CenterX, int a_CenterZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_IsDoubleTall) +void cFinishGenClumpTopBlock::TryPlaceFoliageClump( + cChunkDesc & a_ChunkDesc, + int a_CenterX, + int a_CenterZ, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_BlockMeta, + bool a_IsDoubleTall +) { int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); - int NumBlocks = m_Noise.IntNoise2DInt(a_CenterX + ChunkX * 16, a_CenterZ + ChunkZ * 16) % (MAX_NUM_FOLIAGE - MIN_NUM_FOLIAGE) + MIN_NUM_FOLIAGE + 1; + int NumBlocks = + m_Noise.IntNoise2DInt(a_CenterX + ChunkX * 16, a_CenterZ + ChunkZ * 16) % (MAX_NUM_FOLIAGE - MIN_NUM_FOLIAGE) + + MIN_NUM_FOLIAGE + 1; for (int i = 1; i < NumBlocks; i++) { int Rnd = m_Noise.IntNoise2DInt(ChunkX + ChunkZ + i, ChunkX - ChunkZ - i) / 59; @@ -259,11 +279,9 @@ void cFinishGenClumpTopBlock::TryPlaceFoliageClump(cChunkDesc & a_ChunkDesc, int } auto GroundBlockType = a_ChunkDesc.GetBlockType(x, Top, z); - if ( - (GroundBlockType == E_BLOCK_GRASS) || ( - (GroundBlockType == E_BLOCK_MYCELIUM) && ((a_BlockType == E_BLOCK_RED_MUSHROOM) || (a_BlockType == E_BLOCK_BROWN_MUSHROOM)) - ) - ) + if ((GroundBlockType == E_BLOCK_GRASS) || + ((GroundBlockType == E_BLOCK_MYCELIUM) && + ((a_BlockType == E_BLOCK_RED_MUSHROOM) || (a_BlockType == E_BLOCK_BROWN_MUSHROOM)))) { a_ChunkDesc.SetBlockTypeMeta(x, Top + 1, z, a_BlockType, a_BlockMeta); if (a_IsDoubleTall) @@ -277,14 +295,16 @@ void cFinishGenClumpTopBlock::TryPlaceFoliageClump(cChunkDesc & a_ChunkDesc, int } } } - } -void cFinishGenClumpTopBlock::ParseConfigurationString(const AString & a_RawClumpInfo, std::vector<BiomeInfo> & a_Output) +void cFinishGenClumpTopBlock::ParseConfigurationString( + const AString & a_RawClumpInfo, + std::vector<BiomeInfo> & a_Output +) { // Initialize the vector for all biomes. for (int i = static_cast<int>(a_Output.size()); i <= static_cast<int>(biMaxVariantBiome); i++) @@ -298,7 +318,10 @@ void cFinishGenClumpTopBlock::ParseConfigurationString(const AString & a_RawClum // Information about a clump is divided in 2 parts. The biomes they can be in and the blocks that can be placed. if (ClumpInfo.size() != 2) { - LOGWARNING("OverworldClumpFoliage: Data missing for \"%s\". Please divide biome and blocks with a semi colon", a_RawClumpInfo.c_str()); + LOGWARNING( + "OverworldClumpFoliage: Data missing for \"%s\". Please divide biome and blocks with a semi colon", + a_RawClumpInfo.c_str() + ); return; } @@ -325,13 +348,19 @@ void cFinishGenClumpTopBlock::ParseConfigurationString(const AString & a_RawClum int MinNumClump = 1; if (!StringToInteger(BiomeInfo[1], MinNumClump)) { - LOGWARNING("OverworldClumpFoliage: Invalid data in \"%s\". Second parameter is either not existing or a number", RawBiomeInfo.c_str()); + LOGWARNING( + "OverworldClumpFoliage: Invalid data in \"%s\". Second parameter is either not existing or a " + "number", + RawBiomeInfo.c_str() + ); continue; } a_Output[BiomeIndex].m_MinNumClumpsPerChunk = MinNumClump; - // In case the minimum number is higher than the current maximum value we change the max to the minimum value. - a_Output[BiomeIndex].m_MaxNumClumpsPerChunk = std::max(MinNumClump, a_Output[BiomeIndex].m_MaxNumClumpsPerChunk); + // In case the minimum number is higher than the current maximum value we change the max to the minimum + // value. + a_Output[BiomeIndex].m_MaxNumClumpsPerChunk = + std::max(MinNumClump, a_Output[BiomeIndex].m_MaxNumClumpsPerChunk); } else if (BiomeInfo.size() == 3) { @@ -339,7 +368,10 @@ void cFinishGenClumpTopBlock::ParseConfigurationString(const AString & a_RawClum int MinNumClumps = 0, MaxNumClumps = 1; if (!StringToInteger(BiomeInfo[1], MinNumClumps) || !StringToInteger(BiomeInfo[2], MaxNumClumps)) { - LOGWARNING("Invalid data in \"%s\". Second parameter is either not existing or a number", RawBiomeInfo.c_str()); + LOGWARNING( + "Invalid data in \"%s\". Second parameter is either not existing or a number", + RawBiomeInfo.c_str() + ); continue; } @@ -359,7 +391,9 @@ void cFinishGenClumpTopBlock::ParseConfigurationString(const AString & a_RawClum // Construct the FoliageInfo: a_Output[BiomeIndex].m_Blocks.emplace_back( - static_cast<BLOCKTYPE>(Block.m_ItemType), static_cast<NIBBLETYPE>(Block.m_ItemDamage), 100 + static_cast<BLOCKTYPE>(Block.m_ItemType), + static_cast<NIBBLETYPE>(Block.m_ItemDamage), + 100 ); } } @@ -369,7 +403,10 @@ void cFinishGenClumpTopBlock::ParseConfigurationString(const AString & a_RawClum -std::vector<cFinishGenClumpTopBlock::BiomeInfo> cFinishGenClumpTopBlock::ParseIniFile(cIniFile & a_IniFile, const AString & a_ClumpPrefix) +std::vector<cFinishGenClumpTopBlock::BiomeInfo> cFinishGenClumpTopBlock::ParseIniFile( + cIniFile & a_IniFile, + const AString & a_ClumpPrefix +) { std::vector<cFinishGenClumpTopBlock::BiomeInfo> Foliage; int NumGeneratorValues = a_IniFile.GetNumValues("Generator"); @@ -386,14 +423,64 @@ std::vector<cFinishGenClumpTopBlock::BiomeInfo> cFinishGenClumpTopBlock::ParseIn if (Foliage.empty()) { - cFinishGenClumpTopBlock::ParseConfigurationString(a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-1", "Forest, -2, 2; ForestHills, -3, 2; FlowerForest = yellowflower; redflower; lilac; rosebush"), Foliage); - cFinishGenClumpTopBlock::ParseConfigurationString(a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-2", "Plains, -2, 1; SunflowerPlains = yellowflower; redflower; azurebluet; redtulip; orangetulip; whitetulip; pinktulip; oxeyedaisy"), Foliage); - cFinishGenClumpTopBlock::ParseConfigurationString(a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-3", "SunflowerPlains, 1, 2 = sunflower"), Foliage); - cFinishGenClumpTopBlock::ParseConfigurationString(a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-4", "FlowerForest, 2, 5 = allium; redtulip; orangetulip; whitetulip; pinktulip; oxeyedaisy"), Foliage); - cFinishGenClumpTopBlock::ParseConfigurationString(a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-5", "Swampland; SwamplandM = brownmushroom; redmushroom; blueorchid"), Foliage); - cFinishGenClumpTopBlock::ParseConfigurationString(a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-6", "MushroomIsland; MushroomShore; MegaTaiga; MegaTaigaHills; MegaSpruceTaiga; MegaSpruceTaigaHills = brownmushroom; redmushroom"), Foliage); - cFinishGenClumpTopBlock::ParseConfigurationString(a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-7", "RoofedForest, 1, 5; RoofedForestM, 1, 5 = rosebush; peony; lilac; grass"), Foliage); - cFinishGenClumpTopBlock::ParseConfigurationString(a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-8", "MegaTaiga; MegaTaigaHills = deadbush"), Foliage); + cFinishGenClumpTopBlock::ParseConfigurationString( + a_IniFile.GetValueSet( + "Generator", + a_ClumpPrefix + "-1", + "Forest, -2, 2; ForestHills, -3, 2; FlowerForest = yellowflower; redflower; lilac; rosebush" + ), + Foliage + ); + cFinishGenClumpTopBlock::ParseConfigurationString( + a_IniFile.GetValueSet( + "Generator", + a_ClumpPrefix + "-2", + "Plains, -2, 1; SunflowerPlains = yellowflower; redflower; azurebluet; redtulip; orangetulip; " + "whitetulip; pinktulip; oxeyedaisy" + ), + Foliage + ); + cFinishGenClumpTopBlock::ParseConfigurationString( + a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-3", "SunflowerPlains, 1, 2 = sunflower"), + Foliage + ); + cFinishGenClumpTopBlock::ParseConfigurationString( + a_IniFile.GetValueSet( + "Generator", + a_ClumpPrefix + "-4", + "FlowerForest, 2, 5 = allium; redtulip; orangetulip; whitetulip; pinktulip; oxeyedaisy" + ), + Foliage + ); + cFinishGenClumpTopBlock::ParseConfigurationString( + a_IniFile.GetValueSet( + "Generator", + a_ClumpPrefix + "-5", + "Swampland; SwamplandM = brownmushroom; redmushroom; blueorchid" + ), + Foliage + ); + cFinishGenClumpTopBlock::ParseConfigurationString( + a_IniFile.GetValueSet( + "Generator", + a_ClumpPrefix + "-6", + "MushroomIsland; MushroomShore; MegaTaiga; MegaTaigaHills; MegaSpruceTaiga; MegaSpruceTaigaHills = " + "brownmushroom; redmushroom" + ), + Foliage + ); + cFinishGenClumpTopBlock::ParseConfigurationString( + a_IniFile.GetValueSet( + "Generator", + a_ClumpPrefix + "-7", + "RoofedForest, 1, 5; RoofedForestM, 1, 5 = rosebush; peony; lilac; grass" + ), + Foliage + ); + cFinishGenClumpTopBlock::ParseConfigurationString( + a_IniFile.GetValueSet("Generator", a_ClumpPrefix + "-8", "MegaTaiga; MegaTaigaHills = deadbush"), + Foliage + ); } return Foliage; @@ -411,7 +498,8 @@ void cFinishGenGlowStone::GenFinish(cChunkDesc & a_ChunkDesc) int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); - // Change the number of attempts to create a vein depending on the maximum height of the chunk. A standard Nether could have 5 veins at most. + // Change the number of attempts to create a vein depending on the maximum height of the chunk. A standard Nether + // could have 5 veins at most. int NumGlowStone = m_Noise.IntNoise2DInt(ChunkX, ChunkZ) % a_ChunkDesc.GetMaxHeight() / 23; for (int i = 1; i <= NumGlowStone; i++) @@ -421,7 +509,7 @@ void cFinishGenGlowStone::GenFinish(cChunkDesc & a_ChunkDesc) // Generate X / Z coordinates. int X = Size + (m_Noise.IntNoise2DInt(i, Size) % (cChunkDef::Width - Size * 2)); - int Z = Size + (m_Noise.IntNoise2DInt(X, i) % (cChunkDef::Width - Size * 2)); + int Z = Size + (m_Noise.IntNoise2DInt(X, i) % (cChunkDef::Width - Size * 2)); int Height = a_ChunkDesc.GetHeight(X, Z); for (int y = Height; y > Size; y--) @@ -454,22 +542,32 @@ void cFinishGenGlowStone::GenFinish(cChunkDesc & a_ChunkDesc) -void cFinishGenGlowStone::TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, int a_Size, int a_NumStrings) +void cFinishGenGlowStone::TryPlaceGlowstone( + cChunkDesc & a_ChunkDesc, + int a_RelX, + int a_RelY, + int a_RelZ, + int a_Size, + int a_NumStrings +) { // The starting point of every glowstone string Vector3i StartPoint = Vector3i(a_RelX, a_RelY, a_RelZ); // Array with possible directions for a string of glowstone to go to. - const Vector3i AvailableDirections[] = - { - { -1, 0, 0 }, { 1, 0, 0 }, - { 0, -1, 0 }, // Don't let the glowstone go up - { 0, 0, -1 }, { 0, 0, 1 }, + const Vector3i AvailableDirections[] = { + {-1, 0, 0}, + {1, 0, 0}, + {0, -1, 0}, // Don't let the glowstone go up + {0, 0, -1}, + {0, 0, 1}, // Diagonal direction. Only X or Z with Y. // If all were changed the glowstone string looks awkward - { 0, -1, 1 }, { 1, -1, 0 }, - { 0, -1, -1 }, { -1, -1, 0 }, + {0, -1, 1}, + {1, -1, 0}, + {0, -1, -1}, + {-1, -1, 0}, }; @@ -484,13 +582,18 @@ void cFinishGenGlowStone::TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX for (int j = 0; j < a_Size; j++) { - Vector3i Direction = AvailableDirections[static_cast<size_t>(m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i, CurrentPos.z)) % ARRAYCOUNT(AvailableDirections)]; + Vector3i Direction = AvailableDirections + [static_cast<size_t>(m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i, CurrentPos.z)) % + ARRAYCOUNT(AvailableDirections)]; int Attempts = 2; // multiply by 1 would make no difference, so multiply by 2 instead while (Direction.Equals(PreviousDirection)) { // To make the glowstone branches look better we want to make the direction change every time. - Direction = AvailableDirections[static_cast<size_t>(m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i * Attempts, CurrentPos.z)) % ARRAYCOUNT(AvailableDirections)]; + Direction = AvailableDirections + [static_cast<size_t>(m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i * Attempts, CurrentPos.z) + ) % + ARRAYCOUNT(AvailableDirections)]; Attempts++; } @@ -499,7 +602,8 @@ void cFinishGenGlowStone::TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX // Update the position of the glowstone string CurrentPos += Direction; - if (cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z)) && (a_ChunkDesc.GetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z) != E_BLOCK_GLOWSTONE)) + if (cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z)) && + (a_ChunkDesc.GetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z) != E_BLOCK_GLOWSTONE)) { // The glowstone hit something solid, and it wasn't glowstone. Stop the string. break; @@ -529,7 +633,8 @@ void cFinishGenTallGrass::GenFinish(cChunkDesc & a_ChunkDesc) int BiomeDensity = GetBiomeDensity(a_ChunkDesc.GetBiome(x, z)); // Choose if we want to place long grass here. If not then bail out: - if ((m_Noise.IntNoise2DInt(xx + m_Noise.IntNoise1DInt(xx), zz + m_Noise.IntNoise1DInt(zz)) / 7 % 100) > BiomeDensity) + if ((m_Noise.IntNoise2DInt(xx + m_Noise.IntNoise1DInt(xx), zz + m_Noise.IntNoise1DInt(zz)) / 7 % 100) > + BiomeDensity) { continue; } @@ -546,13 +651,8 @@ void cFinishGenTallGrass::GenFinish(cChunkDesc & a_ChunkDesc) auto BlockBelow = a_ChunkDesc.GetBlockType(x, y - 1, z); bool failed = false; // marker if the search for a valid position was successful - while ( - (BlockBelow == E_BLOCK_LEAVES) || - (BlockBelow == E_BLOCK_NEW_LEAVES) || - (BlockBelow == E_BLOCK_LOG) || - (BlockBelow == E_BLOCK_NEW_LOG) || - (BlockBelow == E_BLOCK_AIR) - ) + while ((BlockBelow == E_BLOCK_LEAVES) || (BlockBelow == E_BLOCK_NEW_LEAVES) || + (BlockBelow == E_BLOCK_LOG) || (BlockBelow == E_BLOCK_NEW_LOG) || (BlockBelow == E_BLOCK_AIR)) { y--; if (!cChunkDef::IsValidHeight({x, y - 1, z})) @@ -569,11 +669,11 @@ void cFinishGenTallGrass::GenFinish(cChunkDesc & a_ChunkDesc) } // Check if long grass can be placed: - if ( - (a_ChunkDesc.GetBlockType(x, y, z) != E_BLOCK_AIR) || - ((a_ChunkDesc.GetBlockType(x, y - 1, z) != E_BLOCK_GRASS) && (a_ChunkDesc.GetBlockType(x, y - 1, z) != E_BLOCK_DIRT)) + if ((a_ChunkDesc.GetBlockType(x, y, z) != E_BLOCK_AIR) || + ((a_ChunkDesc.GetBlockType(x, y - 1, z) != E_BLOCK_GRASS) && + (a_ChunkDesc.GetBlockType(x, y - 1, z) != E_BLOCK_DIRT)) - ) + ) { continue; } @@ -596,7 +696,9 @@ void cFinishGenTallGrass::GenFinish(cChunkDesc & a_ChunkDesc) NIBBLETYPE Meta; if (CanGrassGrow(a_ChunkDesc.GetBiome(x, z))) { - Meta = (m_Noise.IntNoise2DInt(xx * 100, zz * 100) / 7 % 100) > 25 ? E_META_BIG_FLOWER_DOUBLE_TALL_GRASS : E_META_BIG_FLOWER_LARGE_FERN; + Meta = (m_Noise.IntNoise2DInt(xx * 100, zz * 100) / 7 % 100) > 25 + ? E_META_BIG_FLOWER_DOUBLE_TALL_GRASS + : E_META_BIG_FLOWER_LARGE_FERN; } else { @@ -849,10 +951,7 @@ bool cFinishGenSprinkleFoliage::TryAddCactus(cChunkDesc & a_ChunkDesc, int a_Rel } // We'll be doing comparison to neighbors, so require the coords to be 1 block away from the chunk edges: - if ( - (a_RelX < 1) || (a_RelX >= cChunkDef::Width - 1) || - (a_RelZ < 1) || (a_RelZ >= cChunkDef::Width - 1) - ) + if ((a_RelX < 1) || (a_RelX >= cChunkDef::Width - 1) || (a_RelZ < 1) || (a_RelZ >= cChunkDef::Width - 1)) { return false; } @@ -862,12 +961,10 @@ bool cFinishGenSprinkleFoliage::TryAddCactus(cChunkDesc & a_ChunkDesc, int a_Rel const bool cactusExists = i != 0; const int y = a_RelY + 1; - if ( - cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(a_RelX + 1, y, a_RelZ)) || - cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(a_RelX - 1, y, a_RelZ)) || - cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(a_RelX, y, a_RelZ + 1)) || - cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(a_RelX, y, a_RelZ - 1)) - ) + if (cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(a_RelX + 1, y, a_RelZ)) || + cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(a_RelX - 1, y, a_RelZ)) || + cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(a_RelX, y, a_RelZ + 1)) || + cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(a_RelX, y, a_RelZ - 1))) { return cactusExists; } @@ -909,22 +1006,17 @@ bool cFinishGenSprinkleFoliage::TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_ } // We'll be doing comparison to neighbors, so require the coords to be 1 block away from the chunk edges: - if ( - (a_RelX < 1) || (a_RelX >= cChunkDef::Width - 1) || - (a_RelZ < 1) || (a_RelZ >= cChunkDef::Width - 1) - ) + if ((a_RelX < 1) || (a_RelX >= cChunkDef::Width - 1) || (a_RelZ < 1) || (a_RelZ >= cChunkDef::Width - 1)) { return false; } // Water is required next to the block below the sugarcane (if the block below isn't sugarcane already) - if ( - !IsWater(a_ChunkDesc.GetBlockType(a_RelX - 1, a_RelY, a_RelZ)) && + if (!IsWater(a_ChunkDesc.GetBlockType(a_RelX - 1, a_RelY, a_RelZ)) && !IsWater(a_ChunkDesc.GetBlockType(a_RelX + 1, a_RelY, a_RelZ)) && - !IsWater(a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ - 1)) && - !IsWater(a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ + 1)) && - a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ) != E_BLOCK_SUGARCANE - ) + !IsWater(a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ - 1)) && + !IsWater(a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ + 1)) && + a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ) != E_BLOCK_SUGARCANE) { return false; } @@ -972,7 +1064,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) } const float xx = static_cast<float>(BlockX); - float val1 = m_Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f); + float val1 = m_Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f); float val2 = m_Noise.CubicNoise2D(xx * 0.01f, zz * 0.01f); switch (a_ChunkDesc.GetBlockType(x, Top, z)) { @@ -1017,12 +1109,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) bool cFinishGenSprinkleFoliage::IsDesertVariant(EMCSBiome a_Biome) { - return - ( - (a_Biome == biDesertHills) || - (a_Biome == biDesert) || - (a_Biome == biDesertM) - ); + return ((a_Biome == biDesertHills) || (a_Biome == biDesert) || (a_Biome == biDesertM)); } @@ -1055,12 +1142,10 @@ void cFinishGenSoulsandRims::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - if ( - ((a_ChunkDesc.GetBlockType(x, y + 1, z) != E_BLOCK_AIR) && - ( a_ChunkDesc.GetBlockType(x, y + 2, z) != E_BLOCK_AIR)) || + if (((a_ChunkDesc.GetBlockType(x, y + 1, z) != E_BLOCK_AIR) && + (a_ChunkDesc.GetBlockType(x, y + 2, z) != E_BLOCK_AIR)) || ((a_ChunkDesc.GetBlockType(x, y - 1, z) != E_BLOCK_AIR) && - ( a_ChunkDesc.GetBlockType(x, y - 2, z) != E_BLOCK_AIR)) - ) + (a_ChunkDesc.GetBlockType(x, y - 2, z) != E_BLOCK_AIR))) { continue; } @@ -1225,14 +1310,15 @@ void cFinishGenBottomLava::GenFinish(cChunkDesc & a_ChunkDesc) cChunkDef::BlockTypes & BlockTypes = a_ChunkDesc.GetBlockTypes(); for (int y = m_Level; y > 0; y--) { - for (int z = 0; z < cChunkDef::Width; z++) for (int x = 0; x < cChunkDef::Width; x++) - { - const auto Index = cChunkDef::MakeIndex(x, y, z); - if (BlockTypes[Index] == E_BLOCK_AIR) + for (int z = 0; z < cChunkDef::Width; z++) + for (int x = 0; x < cChunkDef::Width; x++) { - BlockTypes[Index] = E_BLOCK_STATIONARY_LAVA; - } - } // for x, for z + const auto Index = cChunkDef::MakeIndex(x, y, z); + if (BlockTypes[Index] == E_BLOCK_AIR) + { + BlockTypes[Index] = E_BLOCK_STATIONARY_LAVA; + } + } // for x, for z } // for y } @@ -1243,7 +1329,11 @@ void cFinishGenBottomLava::GenFinish(cChunkDesc & a_ChunkDesc) //////////////////////////////////////////////////////////////////////////////// // cFinishGenPreSimulator: -cFinishGenPreSimulator::cFinishGenPreSimulator(bool a_PreSimulateFallingBlocks, bool a_PreSimulateWater, bool a_PreSimulateLava) : +cFinishGenPreSimulator::cFinishGenPreSimulator( + bool a_PreSimulateFallingBlocks, + bool a_PreSimulateWater, + bool a_PreSimulateLava +) : m_PreSimulateFallingBlocks(a_PreSimulateFallingBlocks), m_PreSimulateWater(a_PreSimulateWater), m_PreSimulateLava(a_PreSimulateLava) @@ -1264,12 +1354,22 @@ void cFinishGenPreSimulator::GenFinish(cChunkDesc & a_ChunkDesc) if (m_PreSimulateWater) { - StationarizeFluid(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap(), E_BLOCK_WATER, E_BLOCK_STATIONARY_WATER); + StationarizeFluid( + a_ChunkDesc.GetBlockTypes(), + a_ChunkDesc.GetHeightMap(), + E_BLOCK_WATER, + E_BLOCK_STATIONARY_WATER + ); } if (m_PreSimulateLava) { - StationarizeFluid(a_ChunkDesc.GetBlockTypes(), a_ChunkDesc.GetHeightMap(), E_BLOCK_LAVA, E_BLOCK_STATIONARY_LAVA); + StationarizeFluid( + a_ChunkDesc.GetBlockTypes(), + a_ChunkDesc.GetHeightMap(), + E_BLOCK_LAVA, + E_BLOCK_STATIONARY_LAVA + ); } // TODO: other operations } @@ -1341,8 +1441,8 @@ void cFinishGenPreSimulator::CollapseSandGravel(cChunkDesc & a_ChunkDesc) void cFinishGenPreSimulator::StationarizeFluid( - cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change - cChunkDef::HeightMap & a_HeightMap, // Height map to read + cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change + cChunkDef::HeightMap & a_HeightMap, // Height map to read BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid ) @@ -1362,14 +1462,7 @@ void cFinishGenPreSimulator::StationarizeFluid( static const struct { int x, y, z; - } Coords[] = - { - {1, 0, 0}, - {-1, 0, 0}, - {0, 0, 1}, - {0, 0, -1}, - {0, -1, 0} - } ; + } Coords[] = {{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, -1, 0}}; BLOCKTYPE BlockToSet = a_StationaryFluid; // By default, don't simulate this block for (size_t i = 0; i < ARRAYCOUNT(Coords); i++) { @@ -1377,7 +1470,8 @@ void cFinishGenPreSimulator::StationarizeFluid( { continue; } - BLOCKTYPE Neighbor = cChunkDef::GetBlock(a_BlockTypes, x + Coords[i].x, y + Coords[i].y, z + Coords[i].z); + BLOCKTYPE Neighbor = + cChunkDef::GetBlock(a_BlockTypes, x + Coords[i].x, y + Coords[i].y, z + Coords[i].z); if ((Neighbor == E_BLOCK_AIR) || cFluidSimulator::CanWashAway(Neighbor)) { // There is an air / washable neighbor, simulate this block @@ -1422,8 +1516,15 @@ void cFinishGenPreSimulator::StationarizeFluid( //////////////////////////////////////////////////////////////////////////////// // cFinishGenFluidSprings: -cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cIniFile & a_IniFile, eDimension a_Dimension) : - m_Noise(a_Seed + a_Fluid * 100), // Need to take fluid into account, otherwise water and lava springs generate next to each other +cFinishGenFluidSprings::cFinishGenFluidSprings( + int a_Seed, + BLOCKTYPE a_Fluid, + cIniFile & a_IniFile, + eDimension a_Dimension +) : + m_Noise( + a_Seed + a_Fluid * 100 + ), // Need to take fluid into account, otherwise water and lava springs generate next to each other m_HeightDistribution(cChunkDef::Height - 1), m_Fluid(a_Fluid) { @@ -1460,7 +1561,8 @@ cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cI AString HeightDistribution = a_IniFile.GetValueSet(SectionName, "HeightDistribution", DefaultHeightDistribution); if (!m_HeightDistribution.SetDefString(HeightDistribution) || (m_HeightDistribution.GetSum() <= 0)) { - LOGWARNING("[%sSprings]: HeightDistribution is invalid, using the default of \"%s\".", + LOGWARNING( + "[%sSprings]: HeightDistribution is invalid, using the default of \"%s\".", (a_Fluid == E_BLOCK_WATER) ? "Water" : "Lava", DefaultHeightDistribution.c_str() ); @@ -1475,7 +1577,8 @@ cFinishGenFluidSprings::cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cI void cFinishGenFluidSprings::GenFinish(cChunkDesc & a_ChunkDesc) { - int ChanceRnd = (m_Noise.IntNoise3DInt(128 * a_ChunkDesc.GetChunkX(), 512, 256 * a_ChunkDesc.GetChunkZ()) / 13) % 100; + int ChanceRnd = + (m_Noise.IntNoise3DInt(128 * a_ChunkDesc.GetChunkX(), 512, 256 * a_ChunkDesc.GetChunkZ()) / 13) % 100; if (ChanceRnd > m_Chance) { // Not in this chunk @@ -1528,14 +1631,13 @@ bool cFinishGenFluidSprings::TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int static const struct { int x, y, z; - } Coords[] = - { - {-1, 0, 0}, - { 1, 0, 0}, - { 0, -1, 0}, - { 0, 0, -1}, - { 0, 0, 1}, - } ; + } Coords[] = { + {-1, 0, 0}, + {1, 0, 0}, + {0, -1, 0}, + {0, 0, -1}, + {0, 0, 1}, + }; int NumAirNeighbors = 0; for (size_t i = 0; i < ARRAYCOUNT(Coords); i++) { @@ -1593,10 +1695,14 @@ cFinishGenPassiveMobs::cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, e break; } } // switch (dimension) - m_AnimalProbability = a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); + m_AnimalProbability = + a_IniFile.GetValueSetI(SectionName, "AnimalSpawnChunkPercentage", DefaultAnimalSpawnChunkPercentage); if ((m_AnimalProbability < 0) || (m_AnimalProbability > 100)) { - LOGWARNING("[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", DefaultAnimalSpawnChunkPercentage); + LOGWARNING( + "[Animals]: AnimalSpawnChunkPercentage is invalid, using the default of \"%d\".", + DefaultAnimalSpawnChunkPercentage + ); m_AnimalProbability = DefaultAnimalSpawnChunkPercentage; } } @@ -1627,7 +1733,13 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) { int PackCenterX = (m_Noise.IntNoise2DInt(chunkX + chunkZ, Tries) / 7) % cChunkDef::Width; int PackCenterZ = (m_Noise.IntNoise2DInt(chunkX, chunkZ + Tries) / 7) % cChunkDef::Width; - if (TrySpawnAnimals(a_ChunkDesc, PackCenterX, a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), PackCenterZ, RandomMob)) + if (TrySpawnAnimals( + a_ChunkDesc, + PackCenterX, + a_ChunkDesc.GetHeight(PackCenterX, PackCenterZ), + PackCenterZ, + RandomMob + )) { for (int i = 0; i < 3; i++) { @@ -1645,15 +1757,21 @@ void cFinishGenPassiveMobs::GenFinish(cChunkDesc & a_ChunkDesc) -bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, eMonsterType AnimalToSpawn) +bool cFinishGenPassiveMobs::TrySpawnAnimals( + cChunkDesc & a_ChunkDesc, + int a_RelX, + int a_RelY, + int a_RelZ, + eMonsterType AnimalToSpawn +) { if ((a_RelY >= cChunkDef::Height - 1) || (a_RelY <= 0)) { return false; } - BLOCKTYPE BlockAtHead = a_ChunkDesc.GetBlockType(a_RelX, a_RelY + 1, a_RelZ); - BLOCKTYPE BlockAtFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ); + BLOCKTYPE BlockAtHead = a_ChunkDesc.GetBlockType(a_RelX, a_RelY + 1, a_RelZ); + BLOCKTYPE BlockAtFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY, a_RelZ); BLOCKTYPE BlockUnderFeet = a_ChunkDesc.GetBlockType(a_RelX, a_RelY - 1, a_RelZ); // Check block below (opaque, grass, water), and above (air) @@ -1661,19 +1779,14 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX { return false; } - if ( - (AnimalToSpawn != mtSquid) && - (BlockAtHead != E_BLOCK_AIR) && - (BlockAtFeet != E_BLOCK_AIR) && - (!cBlockInfo::IsTransparent(BlockUnderFeet)) - ) + if ((AnimalToSpawn != mtSquid) && (BlockAtHead != E_BLOCK_AIR) && (BlockAtFeet != E_BLOCK_AIR) && + (!cBlockInfo::IsTransparent(BlockUnderFeet))) { return false; } - if ( - (BlockUnderFeet != E_BLOCK_GRASS) && - ((AnimalToSpawn == mtWolf) || (AnimalToSpawn == mtRabbit) || (AnimalToSpawn == mtCow) || (AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig)) - ) + if ((BlockUnderFeet != E_BLOCK_GRASS) && + ((AnimalToSpawn == mtWolf) || (AnimalToSpawn == mtRabbit) || (AnimalToSpawn == mtCow) || + (AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig))) { return false; } @@ -1720,7 +1833,8 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) return mtInvalidType; } - auto RandMob = (static_cast<size_t>(m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size()); + auto RandMob = + (static_cast<size_t>(m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size()); return ListOfSpawnables[RandMob]; } @@ -1736,12 +1850,15 @@ void cFinishGenOres::GenFinish(cChunkDesc & a_ChunkDesc) int seq = 1; // Generate the ores from the ore list. - for (const auto & ore: m_OreInfos) + for (const auto & ore : m_OreInfos) { GenerateOre( a_ChunkDesc, - ore.m_BlockType, ore.m_BlockMeta, - ore.m_MaxHeight, ore.m_NumNests, ore.m_NestSize, + ore.m_BlockType, + ore.m_BlockMeta, + ore.m_MaxHeight, + ore.m_NumNests, + ore.m_NestSize, seq ); seq++; @@ -1754,17 +1871,16 @@ void cFinishGenOres::GenFinish(cChunkDesc & a_ChunkDesc) const cFinishGenOres::OreInfos & cFinishGenOres::DefaultOverworldOres(void) { - static OreInfos res - { + static OreInfos res { // OreType, OreMeta, MaxHeight, NumNests, NestSize - {E_BLOCK_COAL_ORE, 0, 127, 20, 16}, - {E_BLOCK_IRON_ORE, 0, 64, 20, 8}, - {E_BLOCK_GOLD_ORE, 0, 32, 2, 8}, - {E_BLOCK_REDSTONE_ORE, 0, 16, 8, 7}, - {E_BLOCK_DIAMOND_ORE, 0, 15, 1, 7}, - {E_BLOCK_LAPIS_ORE, 0, 30, 1, 6}, - {E_BLOCK_EMERALD_ORE, 0, 32, 11, 1}, - {E_BLOCK_SILVERFISH_EGG, 0, 64, 7, 9}, + {E_BLOCK_COAL_ORE, 0, 127, 20, 16}, + {E_BLOCK_IRON_ORE, 0, 64, 20, 8}, + {E_BLOCK_GOLD_ORE, 0, 32, 2, 8}, + {E_BLOCK_REDSTONE_ORE, 0, 16, 8, 7}, + {E_BLOCK_DIAMOND_ORE, 0, 15, 1, 7}, + {E_BLOCK_LAPIS_ORE, 0, 30, 1, 6}, + {E_BLOCK_EMERALD_ORE, 0, 32, 11, 1}, + {E_BLOCK_SILVERFISH_EGG, 0, 64, 7, 9}, }; return res; } @@ -1775,10 +1891,9 @@ const cFinishGenOres::OreInfos & cFinishGenOres::DefaultOverworldOres(void) const cFinishGenOres::OreInfos & cFinishGenOres::DefaultNetherOres(void) { - static OreInfos res - { + static OreInfos res { // OreType, OreMeta, MaxHeight, NumNests, NestSize - {E_BLOCK_NETHER_QUARTZ_ORE, 0, 127, 20, 8}, + {E_BLOCK_NETHER_QUARTZ_ORE, 0, 127, 20, 8}, }; return res; } @@ -1789,14 +1904,13 @@ const cFinishGenOres::OreInfos & cFinishGenOres::DefaultNetherOres(void) const cFinishGenOres::OreInfos & cFinishGenOres::DefaultNaturalPatches(void) { - static OreInfos res - { + static OreInfos res { // OreType, OreMeta, MaxHeight, NumNests, NestSize - {E_BLOCK_DIRT, 0, 127, 20, 32}, - {E_BLOCK_GRAVEL, 0, 127, 10, 32}, - {E_BLOCK_STONE, E_META_STONE_GRANITE, 127, 20, 32}, - {E_BLOCK_STONE, E_META_STONE_DIORITE, 127, 20, 32}, - {E_BLOCK_STONE, E_META_STONE_ANDESITE, 127, 20, 32}, + {E_BLOCK_DIRT, 0, 127, 20, 32}, + {E_BLOCK_GRAVEL, 0, 127, 10, 32}, + {E_BLOCK_STONE, E_META_STONE_GRANITE, 127, 20, 32}, + {E_BLOCK_STONE, E_META_STONE_DIORITE, 127, 20, 32}, + {E_BLOCK_STONE, E_META_STONE_ANDESITE, 127, 20, 32}, }; return res; } @@ -1812,13 +1926,16 @@ cFinishGenOres::OreInfos cFinishGenOres::OreInfosFromString(const AString & a_Or OreInfos res; auto ores = StringSplitAndTrim(a_OreInfosString, "|"); - for (const auto & ore: ores) + for (const auto & ore : ores) { auto parts = StringSplitAndTrim(ore, ":"); if (parts.size() != 5) { - LOGWARNING("Cannot parse ore information from string, not enough OreInfo members (exp 5, got %d). Offending item: \"%s\".", - static_cast<unsigned>(parts.size()), ore.c_str() + LOGWARNING( + "Cannot parse ore information from string, not enough OreInfo members (exp 5, got %d). Offending item: " + "\"%s\".", + static_cast<unsigned>(parts.size()), + ore.c_str() ); continue; } @@ -1830,12 +1947,8 @@ cFinishGenOres::OreInfos cFinishGenOres::OreInfosFromString(const AString & a_Or } NIBBLETYPE oreMeta; int maxHeight, numNests, nestSize; - if ( - !StringToInteger(parts[1], oreMeta) || - !StringToInteger(parts[2], maxHeight) || - !StringToInteger(parts[3], numNests) || - !StringToInteger(parts[4], nestSize) - ) + if (!StringToInteger(parts[1], oreMeta) || !StringToInteger(parts[2], maxHeight) || + !StringToInteger(parts[3], numNests) || !StringToInteger(parts[4], nestSize)) { LOGWARNING("Cannot parse ore information from string, invalid number in OreInfo \"%s\".", ore.c_str()); continue; @@ -1852,15 +1965,19 @@ cFinishGenOres::OreInfos cFinishGenOres::OreInfosFromString(const AString & a_Or AString cFinishGenOres::OreInfosToString(const cFinishGenOres::OreInfos & a_OreInfos) { AString res; - for (const auto & ore: a_OreInfos) + for (const auto & ore : a_OreInfos) { if (!res.empty()) { res.append(" | "); } - res.append(fmt::format(FMT_STRING("{}:{}:{}:{}:{}"), - ItemTypeToString(ore.m_BlockType), ore.m_BlockMeta, - ore.m_MaxHeight, ore.m_NumNests, ore.m_NestSize + res.append(fmt::format( + FMT_STRING("{}:{}:{}:{}:{}"), + ItemTypeToString(ore.m_BlockType), + ore.m_BlockMeta, + ore.m_MaxHeight, + ore.m_NumNests, + ore.m_NestSize )); } // for ore - a_OreInfos[] return res; @@ -1884,30 +2001,30 @@ void cFinishGenOres::SetSeed(int a_Seed) void cFinishGenOreNests::GenerateOre( cChunkDesc & a_ChunkDesc, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta, - int a_MaxHeight, int a_NumNests, int a_NestSize, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta, + int a_MaxHeight, + int a_NumNests, + int a_NestSize, int a_Seq ) { - // This function generates several "nests" of ore, each nest consisting of number of ore blocks relatively adjacent to each other. - // It does so by making a random XYZ walk and adding ore along the way in cuboids of different (random) sizes - // Only "terraformable" blocks get replaced with ore, all other blocks stay (so the nest can actually be smaller than specified). + // This function generates several "nests" of ore, each nest consisting of number of ore blocks relatively adjacent + // to each other. It does so by making a random XYZ walk and adding ore along the way in cuboids of different + // (random) sizes Only "terraformable" blocks get replaced with ore, all other blocks stay (so the nest can actually + // be smaller than specified). // If there is an attempt to generate Emerald ores in a chunk with no mountains biome abort // There are just four points sampled to avoid searching all 16 * 16 blocks: if (a_OreType == E_BLOCK_EMERALD_ORE) { - const auto BiomeSampleOne = a_ChunkDesc.GetBiome( 4, 4); - const auto BiomeSampleTwo = a_ChunkDesc.GetBiome( 4, 12); - const auto BiomeSampleThree = a_ChunkDesc.GetBiome(12, 4); - const auto BiomeSampleFour = a_ChunkDesc.GetBiome(12, 12); + const auto BiomeSampleOne = a_ChunkDesc.GetBiome(4, 4); + const auto BiomeSampleTwo = a_ChunkDesc.GetBiome(4, 12); + const auto BiomeSampleThree = a_ChunkDesc.GetBiome(12, 4); + const auto BiomeSampleFour = a_ChunkDesc.GetBiome(12, 12); - if ( - !IsBiomeMountain(BiomeSampleOne) && - !IsBiomeMountain(BiomeSampleTwo) && - !IsBiomeMountain(BiomeSampleThree) && - !IsBiomeMountain(BiomeSampleFour) - ) + if (!IsBiomeMountain(BiomeSampleOne) && !IsBiomeMountain(BiomeSampleTwo) && + !IsBiomeMountain(BiomeSampleThree) && !IsBiomeMountain(BiomeSampleFour)) { return; } @@ -1917,17 +2034,13 @@ void cFinishGenOreNests::GenerateOre( // https://minecraft.wiki/w/Gold_Ore if (a_OreType == E_BLOCK_GOLD_ORE) { - const auto BiomeSampleOne = a_ChunkDesc.GetBiome( 4, 4); - const auto BiomeSampleTwo = a_ChunkDesc.GetBiome( 4, 12); - const auto BiomeSampleThree = a_ChunkDesc.GetBiome(12, 4); - const auto BiomeSampleFour = a_ChunkDesc.GetBiome(12, 12); + const auto BiomeSampleOne = a_ChunkDesc.GetBiome(4, 4); + const auto BiomeSampleTwo = a_ChunkDesc.GetBiome(4, 12); + const auto BiomeSampleThree = a_ChunkDesc.GetBiome(12, 4); + const auto BiomeSampleFour = a_ChunkDesc.GetBiome(12, 12); - if ( - IsBiomeMesa(BiomeSampleOne) || - IsBiomeMesa(BiomeSampleTwo) || - IsBiomeMesa(BiomeSampleThree) || - IsBiomeMesa(BiomeSampleFour) - ) + if (IsBiomeMesa(BiomeSampleOne) || IsBiomeMesa(BiomeSampleTwo) || IsBiomeMesa(BiomeSampleThree) || + IsBiomeMesa(BiomeSampleFour)) { a_MaxHeight = 76; a_NumNests = 22; // 2 times default + 20 times mesa bonus @@ -1936,17 +2049,13 @@ void cFinishGenOreNests::GenerateOre( if (a_OreType == E_BLOCK_SILVERFISH_EGG) { - const auto BiomeSampleOne = a_ChunkDesc.GetBiome( 4, 4); - const auto BiomeSampleTwo = a_ChunkDesc.GetBiome( 4, 12); - const auto BiomeSampleThree = a_ChunkDesc.GetBiome(12, 4); - const auto BiomeSampleFour = a_ChunkDesc.GetBiome(12, 12); + const auto BiomeSampleOne = a_ChunkDesc.GetBiome(4, 4); + const auto BiomeSampleTwo = a_ChunkDesc.GetBiome(4, 12); + const auto BiomeSampleThree = a_ChunkDesc.GetBiome(12, 4); + const auto BiomeSampleFour = a_ChunkDesc.GetBiome(12, 12); - if ( - !IsBiomeMountain(BiomeSampleOne) && - !IsBiomeMountain(BiomeSampleTwo) && - !IsBiomeMountain(BiomeSampleThree) && - !IsBiomeMountain(BiomeSampleFour) - ) + if (!IsBiomeMountain(BiomeSampleOne) && !IsBiomeMountain(BiomeSampleTwo) && + !IsBiomeMountain(BiomeSampleThree) && !IsBiomeMountain(BiomeSampleFour)) { return; } @@ -1965,7 +2074,8 @@ void cFinishGenOreNests::GenerateOre( nestRnd /= cChunkDef::Width; int BaseY = nestRnd % a_MaxHeight; nestRnd /= a_MaxHeight; - int NestSize = a_NestSize + (nestRnd % (std::max(a_NestSize, 4) / 4)); // The actual nest size may be up to 1 / 4 larger + int NestSize = + a_NestSize + (nestRnd % (std::max(a_NestSize, 4) / 4)); // The actual nest size may be up to 1 / 4 larger int Num = 0; while (Num < NestSize) { @@ -2065,21 +2175,65 @@ void cFinishGenOrePockets::Initialize(cIniFile & a_IniFile, const AString & a_Ge void cFinishGenOrePockets::GenerateOre( cChunkDesc & a_ChunkDesc, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta, - int a_MaxHeight, int a_NumNests, int a_NestSize, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta, + int a_MaxHeight, + int a_NumNests, + int a_NestSize, int a_Seq ) { // This function generates several "pockets" of the specified ore // Each chunk can contain only pockets that are generated for that chunk, or for its XM / ZM neighbors. - // Generate for the 3 neighbors in the XP / ZP direction as well, so that pockets crossing the boundaries are accounted for as well: + // Generate for the 3 neighbors in the XP / ZP direction as well, so that pockets crossing the boundaries are + // accounted for as well: int chunkZ = a_ChunkDesc.GetChunkZ(); int chunkX = a_ChunkDesc.GetChunkX(); - imprintChunkOrePockets(chunkX - 1, chunkZ - 1, a_ChunkDesc, a_OreType, a_OreMeta, a_MaxHeight, a_NumNests, a_NestSize, a_Seq); - imprintChunkOrePockets(chunkX - 1, chunkZ, a_ChunkDesc, a_OreType, a_OreMeta, a_MaxHeight, a_NumNests, a_NestSize, a_Seq); - imprintChunkOrePockets(chunkX, chunkZ - 1, a_ChunkDesc, a_OreType, a_OreMeta, a_MaxHeight, a_NumNests, a_NestSize, a_Seq); - imprintChunkOrePockets(chunkX, chunkZ, a_ChunkDesc, a_OreType, a_OreMeta, a_MaxHeight, a_NumNests, a_NestSize, a_Seq); + imprintChunkOrePockets( + chunkX - 1, + chunkZ - 1, + a_ChunkDesc, + a_OreType, + a_OreMeta, + a_MaxHeight, + a_NumNests, + a_NestSize, + a_Seq + ); + imprintChunkOrePockets( + chunkX - 1, + chunkZ, + a_ChunkDesc, + a_OreType, + a_OreMeta, + a_MaxHeight, + a_NumNests, + a_NestSize, + a_Seq + ); + imprintChunkOrePockets( + chunkX, + chunkZ - 1, + a_ChunkDesc, + a_OreType, + a_OreMeta, + a_MaxHeight, + a_NumNests, + a_NestSize, + a_Seq + ); + imprintChunkOrePockets( + chunkX, + chunkZ, + a_ChunkDesc, + a_OreType, + a_OreMeta, + a_MaxHeight, + a_NumNests, + a_NestSize, + a_Seq + ); } @@ -2087,10 +2241,14 @@ void cFinishGenOrePockets::GenerateOre( void cFinishGenOrePockets::imprintChunkOrePockets( - int a_ChunkX, int a_ChunkZ, + int a_ChunkX, + int a_ChunkZ, cChunkDesc & a_ChunkDesc, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta, - int a_MaxHeight, int a_NumNests, int a_NestSize, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta, + int a_MaxHeight, + int a_NumNests, + int a_NestSize, int a_Seq ) { @@ -2106,12 +2264,7 @@ void cFinishGenOrePockets::imprintChunkOrePockets( nestRnd /= cChunkDef::Width; int baseY = nestRnd % a_MaxHeight; nestRnd /= a_MaxHeight; - imprintPocket( - a_ChunkDesc, - baseX, baseY, baseZ, - a_NestSize, i + 200 * a_Seq, - a_OreType, a_OreMeta - ); + imprintPocket(a_ChunkDesc, baseX, baseY, baseZ, a_NestSize, i + 200 * a_Seq, a_OreType, a_OreMeta); } // for i - NumNests } @@ -2121,16 +2274,20 @@ void cFinishGenOrePockets::imprintChunkOrePockets( void cFinishGenOrePockets::imprintPocket( cChunkDesc & a_ChunkDesc, - int a_MinPocketX, int a_PocketY, int a_MinPocketZ, - int a_NestSize, int a_Seq, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta + int a_MinPocketX, + int a_PocketY, + int a_MinPocketZ, + int a_NestSize, + int a_Seq, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta ) { // A line segment in a random direction is chosen. Then, several spheres are formed along this line segment, // with their diameters diminishing towards the line ends (one half of a sinusoid) double x1 = static_cast<double>(a_MinPocketX) + 0.5; - double y1 = static_cast<double>(a_PocketY) + 0.5; + double y1 = static_cast<double>(a_PocketY) + 0.5; double z1 = static_cast<double>(a_MinPocketZ) + 0.5; int rnd = m_Noise.IntNoise2DInt(a_MinPocketX + 7 * a_Seq, a_MinPocketZ + a_PocketY * 11) / 7; double angle = static_cast<double>(rnd % 256) / (256.0 * M_PI / 2.0); // range [0 .. pi / 2] @@ -2163,8 +2320,12 @@ void cFinishGenOrePockets::imprintPocket( void cFinishGenOrePockets::imprintSphere( cChunkDesc & a_ChunkDesc, - double a_SphereX, double a_SphereY, double a_SphereZ, double a_Radius, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta + double a_SphereX, + double a_SphereY, + double a_SphereZ, + double a_Radius, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta ) { // Get the sphere's bounding box, unioned with the chunk's bounding box (possibly empty): @@ -2239,7 +2400,8 @@ void cFinishGenOrePockets::imprintSphere( -cFinishGenForestRocks::cFinishGenForestRocks(int a_Seed, cIniFile & a_IniFile) : m_Noise(a_Seed) +cFinishGenForestRocks::cFinishGenForestRocks(int a_Seed, cIniFile & a_IniFile) : + m_Noise(a_Seed) { } @@ -2254,7 +2416,7 @@ void cFinishGenForestRocks::GenFinish(cChunkDesc & a_ChunkDesc) m_Noise.IntNoise2DInt(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()) % cChunkDef::Width, 0, m_Noise.IntNoise2DInt(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()) % cChunkDef::Width - ); + ); Pos.y = a_ChunkDesc.GetHeight(Pos.x, Pos.z) % cChunkDef::Height; auto Biome = a_ChunkDesc.GetBiome(Pos.x, Pos.z); @@ -2294,7 +2456,8 @@ void cFinishGenForestRocks::GenFinish(cChunkDesc & a_ChunkDesc) Pos.y -= Radius - 1; - // Pos.y = Clamp(Pos.y - m_Noise.IntNoise2DInt(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()) % Radius + 1, 0, cChunkDef::Height); + // Pos.y = Clamp(Pos.y - m_Noise.IntNoise2DInt(a_ChunkDesc.GetChunkX(), a_ChunkDesc.GetChunkZ()) % Radius + 1, 0, + // cChunkDef::Height); for (int x = -Radius; x <= Radius; x++) { @@ -2302,7 +2465,7 @@ void cFinishGenForestRocks::GenFinish(cChunkDesc & a_ChunkDesc) { for (int z = -Radius; z <= Radius; z++) { - if (!cChunkDef::IsValidRelPos({ Pos.x + x, Pos.y + y, Pos.z + z })) + if (!cChunkDef::IsValidRelPos({Pos.x + x, Pos.y + y, Pos.z + z})) { continue; } diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index dae05ffa8..9d53ab837 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -26,56 +26,51 @@ -class cFinishGenSnow : - public cFinishGen +class cFinishGenSnow : public cFinishGen { -protected: + protected: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cFinishGenIce : - public cFinishGen +class cFinishGenIce : public cFinishGen { -protected: + protected: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cFinishGenNetherClumpFoliage : - public cFinishGen +class cFinishGenNetherClumpFoliage : public cFinishGen { -public: + public: cFinishGenNetherClumpFoliage(int a_Seed) : - m_Noise(a_Seed), - m_Seed(a_Seed) + m_Noise(a_Seed), m_Seed(a_Seed) { } -protected: + protected: cNoise m_Noise; - int m_Seed; + int m_Seed; void TryPlaceClump(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_Block); virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cFinishGenClumpTopBlock : - public cFinishGen +class cFinishGenClumpTopBlock : public cFinishGen { -public: + public: // Contains the meta, type and weight for a clump block struct FoliageInfo { @@ -84,10 +79,9 @@ public: int m_Weight; FoliageInfo(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_Weight) : - m_BlockType(a_BlockType), - m_BlockMeta(a_BlockMeta), - m_Weight(a_Weight) - {} + m_BlockType(a_BlockType), m_BlockMeta(a_BlockMeta), m_Weight(a_Weight) + { + } }; // Contains the minimum and maximum amount of clumps for a biome and it's blocks. @@ -98,34 +92,34 @@ public: std::vector<FoliageInfo> m_Blocks; BiomeInfo() : - m_MinNumClumpsPerChunk(0), - m_MaxNumClumpsPerChunk(2), - m_Blocks() - {} + m_MinNumClumpsPerChunk(0), m_MaxNumClumpsPerChunk(2), m_Blocks() + { + } BiomeInfo(int a_MinNumClumpsPerChunk, int a_MaxNumClumpsPerChunk, std::vector<FoliageInfo> a_Blocks) : m_MinNumClumpsPerChunk(a_MinNumClumpsPerChunk), m_MaxNumClumpsPerChunk(a_MaxNumClumpsPerChunk), m_Blocks(std::move(a_Blocks)) - {} + { + } }; cFinishGenClumpTopBlock(int a_Seed, std::vector<BiomeInfo> a_BlockList) : - m_Noise(a_Seed), - m_FlowersPerBiome() + m_Noise(a_Seed), m_FlowersPerBiome() { std::swap(a_BlockList, m_FlowersPerBiome); } /** Parses a string and puts a vector with a length of biMaxVariantBiome in a_Output. - The format of the string is "<Biomes separated with a comma>;<Blocks separated with a comma>". This can also be repeated with a | */ + The format of the string is "<Biomes separated with a comma>;<Blocks separated with a comma>". This can also be + repeated with a | */ static void ParseConfigurationString(const AString & a_String, std::vector<BiomeInfo> & a_Output); /** Parses an inifile in search for all clumps */ static std::vector<BiomeInfo> ParseIniFile(cIniFile & a_IniFile, const AString & a_ClumpPrefix); -protected: + protected: cNoise m_Noise; std::vector<BiomeInfo> m_FlowersPerBiome; @@ -138,7 +132,14 @@ protected: /** The maximum range a foliage can be placed from the center of the clump */ const int RANGE_FROM_CENTER = 5; - void TryPlaceFoliageClump(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_IsDoubleTall); + void TryPlaceFoliageClump( + cChunkDesc & a_ChunkDesc, + int a_RelX, + int a_RelZ, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_BlockMeta, + bool a_IsDoubleTall + ); virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; }; @@ -146,35 +147,35 @@ protected: -class cFinishGenGlowStone : - public cFinishGen +class cFinishGenGlowStone : public cFinishGen { -public: + public: cFinishGenGlowStone(int a_Seed) : - m_Noise(a_Seed), - m_Seed(a_Seed) + m_Noise(a_Seed), m_Seed(a_Seed) { } -protected: + protected: cNoise m_Noise; - int m_Seed; + int m_Seed; void TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, int a_Size, int a_NumStrings); virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cFinishGenTallGrass : - public cFinishGen +class cFinishGenTallGrass : public cFinishGen { -public: - cFinishGenTallGrass(int a_Seed) : m_Noise(a_Seed), m_Seed(a_Seed) {} + public: + cFinishGenTallGrass(int a_Seed) : + m_Noise(a_Seed), m_Seed(a_Seed) + { + } -protected: + protected: cNoise m_Noise; int m_Seed; @@ -191,21 +192,19 @@ protected: -class cFinishGenVines : - public cFinishGen +class cFinishGenVines : public cFinishGen { -public: + public: cFinishGenVines(int a_Seed, int a_Level) : - m_Noise(a_Seed), - m_Level(a_Level) + m_Noise(a_Seed), m_Level(a_Level) { } bool IsJungleVariant(EMCSBiome a_Biome); -protected: + protected: cNoise m_Noise; - int m_Level; + int m_Level; virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; }; @@ -214,46 +213,47 @@ protected: -class cFinishGenSoulsandRims : - public cFinishGen +class cFinishGenSoulsandRims : public cFinishGen { -public: + public: cFinishGenSoulsandRims(int a_Seed) : m_Noise(a_Seed) { } -protected: + protected: cNoise m_Noise; virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cFinishGenSprinkleFoliage : - public cFinishGen +class cFinishGenSprinkleFoliage : public cFinishGen { -public: - cFinishGenSprinkleFoliage(int a_Seed, int a_MaxCactusHeight, int a_MaxSugarcaneHeight): + public: + cFinishGenSprinkleFoliage(int a_Seed, int a_MaxCactusHeight, int a_MaxSugarcaneHeight) : m_Noise(a_Seed), m_Seed(a_Seed), m_MaxCactusHeight(a_MaxCactusHeight), m_MaxSugarcaneHeight(a_MaxSugarcaneHeight) { } -protected: + + protected: cNoise m_Noise; - int m_Seed; - int m_MaxCactusHeight; - int m_MaxSugarcaneHeight; + int m_Seed; + int m_MaxCactusHeight; + int m_MaxSugarcaneHeight; - /** Tries to place sugarcane at the coords specified, returns true if successful, updates the top variable (hence the & a_RefY) */ + /** Tries to place sugarcane at the coords specified, returns true if successful, updates the top variable (hence + * the & a_RefY) */ bool TryAddSugarcane(cChunkDesc & a_ChunkDesc, int a_RelX, HEIGHTTYPE & a_RelY, int a_RelZ); - /** Tries to place cactus at the coords specified, returns true if successful, updates the top variable (hence the & a_RefY) */ + /** Tries to place cactus at the coords specified, returns true if successful, updates the top variable (hence the & + * a_RefY) */ bool TryAddCactus(cChunkDesc & a_ChunkDesc, int a_RelX, HEIGHTTYPE & a_RelY, int a_RelZ); // Returns true is the specified biome is a desert or its variant @@ -261,7 +261,7 @@ protected: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; @@ -271,10 +271,9 @@ protected: Used for: - Lilypads finisher - DeadBushes finisher */ -class cFinishGenSingleTopBlock : - public cFinishGen +class cFinishGenSingleTopBlock : public cFinishGen { -public: + public: typedef std::vector<BLOCKTYPE> BlockList; bool m_IsAllowedBelow[256]; @@ -283,12 +282,13 @@ public: cFinishGenSingleTopBlock( - int a_Seed, BLOCKTYPE a_BlockType, BiomeList a_Biomes, int a_Amount, + int a_Seed, + BLOCKTYPE a_BlockType, + BiomeList a_Biomes, + int a_Amount, BlockList a_AllowedBelow ) : - m_Noise(a_Seed), - m_BlockType(a_BlockType), - m_Amount(a_Amount) + m_Noise(a_Seed), m_BlockType(a_BlockType), m_Amount(a_Amount) { // Initialize all the block types. for (size_t idx = 0; idx < ARRAYCOUNT(m_IsAllowedBelow); ++idx) @@ -315,7 +315,7 @@ public: } } -protected: + protected: cNoise m_Noise; BLOCKTYPE m_BlockType; @@ -326,55 +326,47 @@ protected: int GetNumToGen(const cChunkDef::BiomeMap & a_BiomeMap); /** Returns true if the given biome is a biome that is allowed. */ - inline bool IsAllowedBiome(EMCSBiome a_Biome) - { - return m_IsBiomeAllowed[a_Biome]; - } + inline bool IsAllowedBiome(EMCSBiome a_Biome) { return m_IsBiomeAllowed[a_Biome]; } /** Returns true if the given blocktype may be below m_BlockType */ - inline bool IsAllowedBlockBelow(BLOCKTYPE a_BlockBelow) - { - return m_IsAllowedBelow[a_BlockBelow]; - } + inline bool IsAllowedBlockBelow(BLOCKTYPE a_BlockBelow) { return m_IsAllowedBelow[a_BlockBelow]; } // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cFinishGenBottomLava : - public cFinishGen +class cFinishGenBottomLava : public cFinishGen { -public: + public: cFinishGenBottomLava(int a_Level) : m_Level(a_Level) { } int GetLevel(void) const { return m_Level; } -protected: + + protected: int m_Level; // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cFinishGenPreSimulator : - public cFinishGen +class cFinishGenPreSimulator : public cFinishGen { -public: + public: cFinishGenPreSimulator(bool a_PreSimulateFallingBlocks, bool a_PreSimulateWater, bool a_PreSimulateLava); -protected: - + protected: bool m_PreSimulateFallingBlocks; bool m_PreSimulateWater; bool m_PreSimulateLava; @@ -386,39 +378,37 @@ protected: - if all surroundings are of the same fluid, makes it stationary; otherwise makes it flowing (excl. top) - all fluid on the chunk's edge is made flowing */ void StationarizeFluid( - cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change - cChunkDef::HeightMap & a_HeightMap, // Height map to read + cChunkDef::BlockTypes & a_BlockTypes, // Block types to read and change + cChunkDef::HeightMap & a_HeightMap, // Height map to read BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid ); // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cFinishGenFluidSprings : - public cFinishGen +class cFinishGenFluidSprings : public cFinishGen { -public: + public: cFinishGenFluidSprings(int a_Seed, BLOCKTYPE a_Fluid, cIniFile & a_IniFile, eDimension a_Dimension); -protected: - - cNoise m_Noise; + protected: + cNoise m_Noise; cProbabDistrib m_HeightDistribution; - BLOCKTYPE m_Fluid; - int m_Chance; ///< Chance, [0..100], that a spring will be generated in a chunk + BLOCKTYPE m_Fluid; + int m_Chance; ///< Chance, [0..100], that a spring will be generated in a chunk // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; /** Tries to place a spring at the specified coords, checks neighbors. Returns true if successful. */ bool TryPlaceSpring(cChunkDesc & a_ChunkDesc, int x, int y, int z); -} ; +}; @@ -426,15 +416,12 @@ protected: /** This class populates generated chunks with packs of biome-dependant animals Animals: cows, sheep, pigs, mooshrooms, squid, horses, wolves, ocelots */ -class cFinishGenPassiveMobs : - public cFinishGen +class cFinishGenPassiveMobs : public cFinishGen { -public: - + public: cFinishGenPassiveMobs(int a_Seed, cIniFile & a_IniFile, eDimension a_Dimension); -protected: - + protected: /** The noise used as the source of randomness */ cNoise m_Noise; @@ -445,13 +432,14 @@ protected: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; - /** Returns false if an animal cannot spawn at given coords, else adds it to the chunk's entity list and returns true */ + /** Returns false if an animal cannot spawn at given coords, else adds it to the chunk's entity list and returns + * true */ bool TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int x, int y, int z, eMonsterType AnimalToSpawn); /** Picks a random animal from biome-dependant list for a random position in the chunk. Returns the chosen mob type, or mtInvalid if no mob chosen. */ eMonsterType GetRandomMob(cChunkDesc & a_ChunkDesc); -} ; +}; @@ -460,28 +448,23 @@ protected: /** Base class for generators that have an ore list attached to them. Provides the storage and parsing for the ore list, as well as the generic plumbing for generating individual ores. Descendants should override GenerateOre() to provide the specific ore generation technique. -Note that this class uses the "Nest" terminology for individual packs of ore, it doesn't imply any shape or algorithm. */ -class cFinishGenOres: - public cFinishGen +Note that this class uses the "Nest" terminology for individual packs of ore, it doesn't imply any shape or algorithm. +*/ +class cFinishGenOres : public cFinishGen { using Super = cFinishGen; -public: - + public: struct OreInfo { - BLOCKTYPE m_BlockType; // The type of the nest. + BLOCKTYPE m_BlockType; // The type of the nest. NIBBLETYPE m_BlockMeta; // The block meta - int m_MaxHeight; // The highest possible a nest can occur - int m_NumNests; // How many nests per chunk - int m_NestSize; // The amount of blocks a nest can have. + int m_MaxHeight; // The highest possible a nest can occur + int m_NumNests; // How many nests per chunk + int m_NestSize; // The amount of blocks a nest can have. OreInfo() : - m_BlockType(0), - m_BlockMeta(0), - m_MaxHeight(0), - m_NumNests(0), - m_NestSize(0) + m_BlockType(0), m_BlockMeta(0), m_MaxHeight(0), m_NumNests(0), m_NestSize(0) { } @@ -497,9 +480,8 @@ public: typedef std::vector<OreInfo> OreInfos; - cFinishGenOres(int a_Seed, const OreInfos & a_OreInfos): - m_Noise(a_Seed), - m_OreInfos(a_OreInfos) + cFinishGenOres(int a_Seed, const OreInfos & a_OreInfos) : + m_Noise(a_Seed), m_OreInfos(a_OreInfos) { } @@ -512,7 +494,8 @@ public: /** Returns a vector of OreInfo structures describing the default Nether ores, usable in the constructor. */ static const OreInfos & DefaultNetherOres(void); - /** Returns a vector of OreInfo structures describing the default Overworld non-ore pockets (dirt, diorite etc), usable in the constructor. */ + /** Returns a vector of OreInfo structures describing the default Overworld non-ore pockets (dirt, diorite etc), + * usable in the constructor. */ static const OreInfos & DefaultNaturalPatches(void); /** Parses the parameter string into OreInfos array. @@ -528,7 +511,7 @@ public: /** (Re-)sets the seed used by the internal generating mechanisms. */ void SetSeed(int a_Seed); -protected: + protected: /** The noise used for generating. */ cNoise m_Noise; @@ -537,11 +520,15 @@ protected: /** Generates a single ore in the specified chunk image. - a_Seq is the sequencing number (used as a complement to seed to make each ore in the same chunk have different nests) */ + a_Seq is the sequencing number (used as a complement to seed to make each ore in the same chunk have different + nests) */ virtual void GenerateOre( cChunkDesc & a_ChunkDesc, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta, - int a_MaxHeight, int a_NumNests, int a_NestSize, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta, + int a_MaxHeight, + int a_NumNests, + int a_NestSize, int a_Seq ) = 0; @@ -552,64 +539,71 @@ protected: -class cFinishGenOreNests: - public cFinishGenOres +class cFinishGenOreNests : public cFinishGenOres { using Super = cFinishGenOres; -public: - - cFinishGenOreNests(int a_Seed, const OreInfos & a_OreInfos): + public: + cFinishGenOreNests(int a_Seed, const OreInfos & a_OreInfos) : Super(a_Seed, a_OreInfos) - {} - -protected: + { + } + protected: // cFinishGenOreClumps overrides: virtual void GenerateOre( cChunkDesc & a_ChunkDesc, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta, - int a_MaxHeight, int a_NumNests, int a_NestSize, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta, + int a_MaxHeight, + int a_NumNests, + int a_NestSize, int a_Seq ) override; -} ; +}; -class cFinishGenOrePockets: - public cFinishGenOres +class cFinishGenOrePockets : public cFinishGenOres { using Super = cFinishGenOres; -public: - - cFinishGenOrePockets(int a_Seed, const OreInfos & a_OreInfos): + public: + cFinishGenOrePockets(int a_Seed, const OreInfos & a_OreInfos) : Super(a_Seed, a_OreInfos) - {} + { + } /** Reads the configuration from the specified INI file. - a_GenName is the name of the generator (this class may be used for OrePockets and DirtPockets, each has a different default). */ + a_GenName is the name of the generator (this class may be used for OrePockets and DirtPockets, each has a different + default). */ void Initialize(cIniFile & a_IniFile, const AString & a_GenName); -protected: - + protected: // cFinishGenOreClumps overrides: virtual void GenerateOre( cChunkDesc & a_ChunkDesc, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta, - int a_MaxNestHeight, int a_NumNests, int a_NestSize, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta, + int a_MaxNestHeight, + int a_NumNests, + int a_NestSize, int a_Seq ) override; - /** Calculates the pockets for the specified chunk and imprints them into the specified ChunkDesc (not necessarily the same chunk). - a_Seq is the sequence number of the ore, to provide another source of randomness. */ + /** Calculates the pockets for the specified chunk and imprints them into the specified ChunkDesc (not necessarily + the same chunk). a_Seq is the sequence number of the ore, to provide another source of randomness. */ void imprintChunkOrePockets( - int a_ChunkX, int a_ChunkZ, + int a_ChunkX, + int a_ChunkZ, cChunkDesc & a_ChunkDesc, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta, - int a_MaxHeight, int a_NumNests, int a_NestSize, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta, + int a_MaxHeight, + int a_NumNests, + int a_NestSize, int a_Seq ); @@ -618,16 +612,24 @@ protected: a_Seq is the sequence number of the ore, to provide another source of randomness. */ void imprintPocket( cChunkDesc & a_ChunkDesc, - int a_MinPocketX, int a_PocketY, int a_MinPocketZ, - int a_NestSize, int a_Seq, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta + int a_MinPocketX, + int a_PocketY, + int a_MinPocketZ, + int a_NestSize, + int a_Seq, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta ); /** Imprints a single sphere of the specified ore at the specified coords. */ void imprintSphere( cChunkDesc & a_ChunkDesc, - double a_SphereX, double a_SphereY, double a_SphereZ, double a_Radius, - BLOCKTYPE a_OreType, NIBBLETYPE a_OreMeta + double a_SphereX, + double a_SphereY, + double a_SphereZ, + double a_Radius, + BLOCKTYPE a_OreType, + NIBBLETYPE a_OreMeta ); }; @@ -635,13 +637,12 @@ protected: -class cFinishGenForestRocks: - public cFinishGen +class cFinishGenForestRocks : public cFinishGen { -public: + public: cFinishGenForestRocks(int a_Seed, cIniFile & a_IniFile); virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -private: + private: cNoise m_Noise; }; diff --git a/src/Generating/GridStructGen.cpp b/src/Generating/GridStructGen.cpp index 4a565f220..9868aa15f 100644 --- a/src/Generating/GridStructGen.cpp +++ b/src/Generating/GridStructGen.cpp @@ -1,7 +1,8 @@ // GridStructGen.cpp -// Implements the cGridStructGen class representing a common base class for structure generators that place structures in a semi-random grid +// Implements the cGridStructGen class representing a common base class for structure generators that place structures +// in a semi-random grid #include "Globals.h" #include "GridStructGen.h" @@ -16,24 +17,22 @@ /** A cStructure descendant representing an empty structure. Used when the generator descended from cGridStructGen doesn't return any structure, to keep at least the Origin coords so that the structure isn't queried over and over again. */ -class cEmptyStructure: - public cGridStructGen::cStructure +class cEmptyStructure : public cGridStructGen::cStructure { using Super = cGridStructGen::cStructure; -public: - + public: cEmptyStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ) { } -protected: + protected: virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override { // Do nothing } -} ; +}; @@ -41,9 +40,12 @@ protected: cGridStructGen::cGridStructGen( int a_Seed, - int a_GridSizeX, int a_GridSizeZ, - int a_MaxOffsetX, int a_MaxOffsetZ, - int a_MaxStructureSizeX, int a_MaxStructureSizeZ, + int a_GridSizeX, + int a_GridSizeZ, + int a_MaxOffsetX, + int a_MaxOffsetZ, + int a_MaxStructureSizeX, + int a_MaxStructureSizeZ, size_t a_MaxCacheSize ) : m_Seed(a_Seed), @@ -66,13 +68,17 @@ cGridStructGen::cGridStructGen( LOG("Grid Size cannot be zero, setting to 1"); m_GridSizeZ = 1; } - size_t NumStructuresPerQuery = static_cast<size_t>(((m_MaxStructureSizeX + m_MaxOffsetX) / m_GridSizeX + 1) * ((m_MaxStructureSizeZ + m_MaxOffsetZ) / m_GridSizeZ + 1)); + size_t NumStructuresPerQuery = static_cast<size_t>( + ((m_MaxStructureSizeX + m_MaxOffsetX) / m_GridSizeX + 1) * + ((m_MaxStructureSizeZ + m_MaxOffsetZ) / m_GridSizeZ + 1) + ); if (NumStructuresPerQuery > m_MaxCacheSize) { m_MaxCacheSize = NumStructuresPerQuery * 4; LOGINFO( "cGridStructGen: The cache size is too small (%u), increasing the cache size to %u to avoid inefficiency.", - static_cast<unsigned>(a_MaxCacheSize), static_cast<unsigned>(m_MaxCacheSize) + static_cast<unsigned>(a_MaxCacheSize), + static_cast<unsigned>(m_MaxCacheSize) ); } } @@ -81,7 +87,7 @@ cGridStructGen::cGridStructGen( -cGridStructGen::cGridStructGen(int a_Seed): +cGridStructGen::cGridStructGen(int a_Seed) : m_BaseSeed(a_Seed), m_Seed(a_Seed), m_Noise(a_Seed), @@ -102,13 +108,13 @@ cGridStructGen::cGridStructGen(int a_Seed): void cGridStructGen::SetGeneratorParams(const AStringMap & a_GeneratorParams) { ASSERT(m_Cache.empty()); // No changing the params after chunks are generated - m_GridSizeX = GetStringMapInteger<int> (a_GeneratorParams, "GridSizeX", m_GridSizeX); - m_GridSizeZ = GetStringMapInteger<int> (a_GeneratorParams, "GridSizeZ", m_GridSizeZ); - m_MaxOffsetX = GetStringMapInteger<int> (a_GeneratorParams, "MaxOffsetX", m_MaxOffsetX); - m_MaxOffsetZ = GetStringMapInteger<int> (a_GeneratorParams, "MaxOffsetZ", m_MaxOffsetZ); - m_MaxStructureSizeX = GetStringMapInteger<int> (a_GeneratorParams, "MaxStructureSizeX", m_MaxStructureSizeX); - m_MaxStructureSizeZ = GetStringMapInteger<int> (a_GeneratorParams, "MaxStructureSizeZ", m_MaxStructureSizeZ); - m_MaxCacheSize = GetStringMapInteger<size_t>(a_GeneratorParams, "MaxCacheSize", m_MaxCacheSize); + m_GridSizeX = GetStringMapInteger<int>(a_GeneratorParams, "GridSizeX", m_GridSizeX); + m_GridSizeZ = GetStringMapInteger<int>(a_GeneratorParams, "GridSizeZ", m_GridSizeZ); + m_MaxOffsetX = GetStringMapInteger<int>(a_GeneratorParams, "MaxOffsetX", m_MaxOffsetX); + m_MaxOffsetZ = GetStringMapInteger<int>(a_GeneratorParams, "MaxOffsetZ", m_MaxOffsetZ); + m_MaxStructureSizeX = GetStringMapInteger<int>(a_GeneratorParams, "MaxStructureSizeX", m_MaxStructureSizeX); + m_MaxStructureSizeZ = GetStringMapInteger<int>(a_GeneratorParams, "MaxStructureSizeZ", m_MaxStructureSizeZ); + m_MaxCacheSize = GetStringMapInteger<size_t>(a_GeneratorParams, "MaxCacheSize", m_MaxCacheSize); // Silently fix out-of-range parameters: if (m_MaxOffsetX < 1) @@ -149,10 +155,8 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur // Walk the cache, move each structure that we want into a_Structures: for (cStructurePtrs::iterator itr = m_Cache.begin(), end = m_Cache.end(); itr != end;) { - if ( - ((*itr)->m_GridX >= MinX) && ((*itr)->m_GridX < MaxX) && - ((*itr)->m_GridZ >= MinZ) && ((*itr)->m_GridZ < MaxZ) - ) + if (((*itr)->m_GridX >= MinX) && ((*itr)->m_GridX < MaxX) && ((*itr)->m_GridZ >= MinZ) && + ((*itr)->m_GridZ < MaxZ)) { // want a_Structures.push_back(*itr); @@ -183,8 +187,10 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur } // for itr - a_Structures[] if (!Found) { - int OriginX = GridX + ((m_Noise.IntNoise2DInt(GridX + 3, GridZ + 5) / 7) % (m_MaxOffsetX * 2)) - m_MaxOffsetX; - int OriginZ = GridZ + ((m_Noise.IntNoise2DInt(GridX + 5, GridZ + 3) / 7) % (m_MaxOffsetZ * 2)) - m_MaxOffsetZ; + int OriginX = + GridX + ((m_Noise.IntNoise2DInt(GridX + 3, GridZ + 5) / 7) % (m_MaxOffsetX * 2)) - m_MaxOffsetX; + int OriginZ = + GridZ + ((m_Noise.IntNoise2DInt(GridX + 5, GridZ + 3) / 7) % (m_MaxOffsetZ * 2)) - m_MaxOffsetZ; cStructurePtr Structure = CreateStructure(GridX, GridZ, OriginX, OriginZ); if (Structure.get() == nullptr) { @@ -196,7 +202,7 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur } // for x // Copy a_Forts into m_Cache to the beginning: - cStructurePtrs StructuresCopy (a_Structures); + cStructurePtrs StructuresCopy(a_Structures); m_Cache.splice(m_Cache.begin(), StructuresCopy, StructuresCopy.begin(), StructuresCopy.end()); // Trim the cache if it's too long: @@ -228,8 +234,3 @@ void cGridStructGen::GenFinish(cChunkDesc & a_ChunkDesc) (*itr)->DrawIntoChunk(a_ChunkDesc); } // for itr - Structures[] } - - - - - diff --git a/src/Generating/GridStructGen.h b/src/Generating/GridStructGen.h index 49d138217..0f06862ca 100644 --- a/src/Generating/GridStructGen.h +++ b/src/Generating/GridStructGen.h @@ -1,7 +1,8 @@ // GridStructGen.h -// Declares the cGridStructGen class representing a common base class for structure generators that place structures in a semi-random grid +// Declares the cGridStructGen class representing a common base class for structure generators that place structures in +// a semi-random grid @@ -41,14 +42,13 @@ The descendant must use a specific cStructure descendant to provide the actual s The structure must provide the DrawIntoChunk() function that generates the structure into the chunk data, and can override the GetCacheCost() function that returns the cost of that structure in the cache. */ -class cGridStructGen : - public cFinishGen +class cGridStructGen : public cFinishGen { -public: + public: /** Represents a single structure that occupies the grid point. Knows how to draw itself into a chunk. */ class cStructure { - public: + public: /** The grid point for which the structure is generated. */ int m_GridX, m_GridZ; @@ -57,11 +57,8 @@ public: /** Creates a structure that has its origin set at the specified coords. */ - cStructure (int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : - m_GridX(a_GridX), - m_GridZ(a_GridZ), - m_OriginX(a_OriginX), - m_OriginZ(a_OriginZ) + cStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : + m_GridX(a_GridX), m_GridZ(a_GridZ), m_OriginX(a_OriginX), m_OriginZ(a_OriginZ) { } @@ -73,16 +70,19 @@ public: /** Returns the cost of keeping this structure in the cache */ virtual size_t GetCacheCost(void) const { return 1; } - } ; + }; typedef std::shared_ptr<cStructure> cStructurePtr; typedef std::list<cStructurePtr> cStructurePtrs; cGridStructGen( int a_Seed, - int a_GridSizeX, int a_GridSizeZ, - int a_MaxOffsetX, int a_MaxOffsetZ, - int a_MaxStructureSizeX, int a_MaxStructureSizeZ, + int a_GridSizeX, + int a_GridSizeZ, + int a_MaxOffsetX, + int a_MaxOffsetZ, + int a_MaxStructureSizeX, + int a_MaxStructureSizeZ, size_t a_MaxCacheSize ); @@ -97,12 +97,13 @@ public: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -protected: + protected: /** Base seed of the world for which the generator generates chunk. */ int m_BaseSeed; /** Seed for generating grid offsets and also available for descendants. - Calculated from m_BaseSeed by adding the SeedOffset parameter loaded from the cubeset file (if applicable); otherwise the same as m_BaseSeed. */ + Calculated from m_BaseSeed by adding the SeedOffset parameter loaded from the cubeset file (if applicable); + otherwise the same as m_BaseSeed. */ int m_Seed; /** The noise used for generating grid offsets. */ @@ -149,9 +150,4 @@ protected: // Functions for the descendants to override: /** Create a new structure at the specified gridpoint */ virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) = 0; -} ; - - - - - +}; diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp index 2e4b4fb3c..978fae4a8 100644 --- a/src/Generating/HeiGen.cpp +++ b/src/Generating/HeiGen.cpp @@ -19,39 +19,97 @@ //////////////////////////////////////////////////////////////////////////////// // cHeiGenSteppy: -class cHeiGenSteppy: - public cTerrainHeightGen +class cHeiGenSteppy : public cTerrainHeightGen { -public: + public: cHeiGenSteppy(int a_Seed) : m_Seed(a_Seed) { - m_Gen = - std::make_shared<cProtIntGenWeightAvg<16, 1, 0>>( - std::make_shared<cProtIntGenSmooth> (a_Seed + 1, - std::make_shared<cProtIntGenZoom> (a_Seed + 2, - std::make_shared<cProtIntGenSmooth> (a_Seed + 3, - std::make_shared<cProtIntGenZoom> (a_Seed + 4, - std::make_shared<cProtIntGenAddRnd> (a_Seed + 5, 1, - std::make_shared<cProtIntGenSmooth> (a_Seed + 6, - std::make_shared<cProtIntGenZoom> (a_Seed + 7, - std::make_shared<cProtIntGenRndBetween> (a_Seed + 8, 60, - std::make_shared<cProtIntGenAddRnd> (a_Seed + 9, 1, - std::make_shared<cProtIntGenSmooth> (a_Seed + 1, - std::make_shared<cProtIntGenZoom> (a_Seed + 2, - std::make_shared<cProtIntGenRndBetween> (a_Seed + 3, 60, - std::make_shared<cProtIntGenSmooth> (a_Seed + 4, - std::make_shared<cProtIntGenZoom> (a_Seed + 5, - std::make_shared<cProtIntGenRndBetween> (a_Seed + 6, 60, - std::make_shared<cProtIntGenRndChoice> (a_Seed + 7, 10, 50, 50, - std::make_shared<cProtIntGenSmooth> (a_Seed + 8, - std::make_shared<cProtIntGenZoom> (a_Seed + 9, - std::make_shared<cProtIntGenRndChoice> (a_Seed + 1, 10, 50, 50, - std::make_shared<cProtIntGenAddRnd> (a_Seed + 2, 2, - std::make_shared<cProtIntGenZoom> (a_Seed + 3, - std::make_shared<cProtIntGenZoom> (a_Seed + 4, - std::make_shared<cProtIntGenChoice> (a_Seed + 5, 10) - ))))))))))))))))))))))); + m_Gen = std::make_shared<cProtIntGenWeightAvg<16, 1, 0>>(std::make_shared<cProtIntGenSmooth>( + a_Seed + 1, + std::make_shared<cProtIntGenZoom>( + a_Seed + 2, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 3, + std::make_shared<cProtIntGenZoom>( + a_Seed + 4, + std::make_shared<cProtIntGenAddRnd>( + a_Seed + 5, + 1, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 6, + std::make_shared<cProtIntGenZoom>( + a_Seed + 7, + std::make_shared<cProtIntGenRndBetween>( + a_Seed + 8, + 60, + std::make_shared<cProtIntGenAddRnd>( + a_Seed + 9, + 1, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 1, + std::make_shared<cProtIntGenZoom>( + a_Seed + 2, + std::make_shared<cProtIntGenRndBetween>( + a_Seed + 3, + 60, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 4, + std::make_shared<cProtIntGenZoom>( + a_Seed + 5, + std::make_shared<cProtIntGenRndBetween>( + a_Seed + 6, + 60, + std::make_shared<cProtIntGenRndChoice>( + a_Seed + 7, + 10, + 50, + 50, + std::make_shared<cProtIntGenSmooth>( + a_Seed + 8, + std::make_shared<cProtIntGenZoom>( + a_Seed + 9, + std::make_shared<cProtIntGenRndChoice>( + a_Seed + 1, + 10, + 50, + 50, + std::make_shared<cProtIntGenAddRnd>( + a_Seed + 2, + 2, + std::make_shared< + cProtIntGenZoom>( + a_Seed + 3, + std::make_shared< + cProtIntGenZoom>( + a_Seed + 4, + std::make_shared< + cProtIntGenChoice>( + a_Seed + 5, + 10 + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + )); } // cTerrainHeightGen overrides: @@ -59,8 +117,11 @@ public: { int heights[cChunkDef::Width * cChunkDef::Width]; m_Gen->GetInts( - a_ChunkCoords.m_ChunkX * cChunkDef::Width, a_ChunkCoords.m_ChunkZ * cChunkDef::Width, - static_cast<size_t>(cChunkDef::Width), static_cast<size_t>(cChunkDef::Width), heights + a_ChunkCoords.m_ChunkX * cChunkDef::Width, + a_ChunkCoords.m_ChunkZ * cChunkDef::Width, + static_cast<size_t>(cChunkDef::Width), + static_cast<size_t>(cChunkDef::Width), + heights ); for (size_t i = 0; i < ARRAYCOUNT(heights); i++) { @@ -68,7 +129,7 @@ public: } } -protected: + protected: int m_Seed; std::shared_ptr<cProtIntGen> m_Gen; @@ -107,11 +168,7 @@ void cHeiGenFlat::InitializeHeightGen(cIniFile & a_IniFile) // cHeiGenCache: cHeiGenCache::cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, size_t a_CacheSize) : - m_HeiGenToCache(a_HeiGenToCache), - m_CacheSize(a_CacheSize), - m_NumHits(0), - m_NumMisses(0), - m_TotalChain(0) + m_HeiGenToCache(a_HeiGenToCache), m_CacheSize(a_CacheSize), m_NumHits(0), m_NumMisses(0), m_TotalChain(0) { m_CacheOrder.resize(a_CacheSize); m_CacheData.resize(a_CacheSize); @@ -130,8 +187,8 @@ void cHeiGenCache::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap /* if (((m_NumHits + m_NumMisses) % 1024) == 10) { - LOGD("HeiGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / (m_NumHits + m_NumMisses)); - LOGD("HeiGenCache: Avg cache chain length: %.2f", static_cast<double>(m_TotalChain) / m_NumHits); + LOGD("HeiGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / (m_NumHits + + m_NumMisses)); LOGD("HeiGenCache: Avg cache chain length: %.2f", static_cast<double>(m_TotalChain) / m_NumHits); } //*/ @@ -219,9 +276,12 @@ bool cHeiGenCache::GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_Rel //////////////////////////////////////////////////////////////////////////////// // cHeiGenMultiCache: -cHeiGenMultiCache::cHeiGenMultiCache(std::unique_ptr<cTerrainHeightGen> a_HeiGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches): - m_NumSubCaches(a_NumSubCaches), - m_Underlying(std::move(a_HeiGenToCache)) +cHeiGenMultiCache::cHeiGenMultiCache( + std::unique_ptr<cTerrainHeightGen> a_HeiGenToCache, + size_t a_SubCacheSize, + size_t a_NumSubCaches +) : + m_NumSubCaches(a_NumSubCaches), m_Underlying(std::move(a_HeiGenToCache)) { // Create the individual sub-caches: m_SubCaches.reserve(a_NumSubCaches); @@ -238,7 +298,9 @@ cHeiGenMultiCache::cHeiGenMultiCache(std::unique_ptr<cTerrainHeightGen> a_HeiGen void cHeiGenMultiCache::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) { // Get the subcache responsible for this chunk: - const size_t cacheIdx = (static_cast<size_t>(a_ChunkCoords.m_ChunkX) + m_CoeffZ * static_cast<size_t>(a_ChunkCoords.m_ChunkZ)) % m_NumSubCaches; + const size_t cacheIdx = + (static_cast<size_t>(a_ChunkCoords.m_ChunkX) + m_CoeffZ * static_cast<size_t>(a_ChunkCoords.m_ChunkZ)) % + m_NumSubCaches; // Ask the subcache: m_SubCaches[cacheIdx]->GenHeightMap(a_ChunkCoords, a_HeightMap); @@ -328,7 +390,8 @@ void cHeiGenClassic::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightM { const float xx = static_cast<float>(a_ChunkCoords.m_ChunkX * cChunkDef::Width + x); - HEIGHTTYPE hei = static_cast<HEIGHTTYPE>(Clamp(static_cast<int>(64 + (GetNoise(xx * 0.05f, zz * 0.05f) * 16)), 10, 250)); + HEIGHTTYPE hei = + static_cast<HEIGHTTYPE>(Clamp(static_cast<int>(64 + (GetNoise(xx * 0.05f, zz * 0.05f) * 16)), 10, 250)); cChunkDef::SetHeight(a_HeightMap, x, z, hei); } // for x } // for z @@ -343,9 +406,9 @@ void cHeiGenClassic::InitializeHeightGen(cIniFile & a_IniFile) m_HeightFreq1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq1", 0.1)); m_HeightFreq2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq2", 1.0)); m_HeightFreq3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq3", 2.0)); - m_HeightAmp1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp1", 1.0)); - m_HeightAmp2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp2", 0.5)); - m_HeightAmp3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp3", 0.5)); + m_HeightAmp1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp1", 1.0)); + m_HeightAmp2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp2", 0.5)); + m_HeightAmp3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp3", 0.5)); } @@ -356,10 +419,7 @@ void cHeiGenClassic::InitializeHeightGen(cIniFile & a_IniFile) // cHeiGenMountains: cHeiGenMountains::cHeiGenMountains(int a_Seed) : - m_Seed(a_Seed), - m_MountainNoise(a_Seed + 100), - m_DitchNoise(a_Seed + 200), - m_Perlin(a_Seed + 300) + m_Seed(a_Seed), m_MountainNoise(a_Seed + 100), m_DitchNoise(a_Seed + 200), m_Perlin(a_Seed + 300) { } @@ -370,9 +430,9 @@ cHeiGenMountains::cHeiGenMountains(int a_Seed) : void cHeiGenMountains::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) { NOISE_DATATYPE StartX = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkX * cChunkDef::Width); - NOISE_DATATYPE EndX = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkX * cChunkDef::Width + cChunkDef::Width - 1); + NOISE_DATATYPE EndX = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkX * cChunkDef::Width + cChunkDef::Width - 1); NOISE_DATATYPE StartZ = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width); - NOISE_DATATYPE EndZ = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width + cChunkDef::Width - 1); + NOISE_DATATYPE EndZ = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width + cChunkDef::Width - 1); NOISE_DATATYPE Workspace[16 * 16]; NOISE_DATATYPE MountainNoise[16 * 16]; NOISE_DATATYPE DitchNoise[16 * 16]; @@ -386,7 +446,9 @@ void cHeiGenMountains::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::Heigh for (int x = 0; x < cChunkDef::Width; x++) { int idx = IdxZ + x; - HEIGHTTYPE hei = static_cast<HEIGHTTYPE>(Clamp(100 - static_cast<int>((MountainNoise[idx] - DitchNoise[idx] + PerlinNoise[idx]) * 15), 10, 250)); + HEIGHTTYPE hei = static_cast<HEIGHTTYPE>( + Clamp(100 - static_cast<int>((MountainNoise[idx] - DitchNoise[idx] + PerlinNoise[idx]) * 15), 10, 250) + ); cChunkDef::SetHeight(a_HeightMap, x, z, hei); } // for x } // for z @@ -399,10 +461,10 @@ void cHeiGenMountains::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::Heigh void cHeiGenMountains::InitializeHeightGen(cIniFile & a_IniFile) { // TODO: Read the params from an INI file - m_MountainNoise.AddOctave(0.1f, 0.2f); + m_MountainNoise.AddOctave(0.1f, 0.2f); m_MountainNoise.AddOctave(0.05f, 0.4f); m_MountainNoise.AddOctave(0.02f, 1.0f); - m_DitchNoise.AddOctave(0.1f, 0.2f); + m_DitchNoise.AddOctave(0.1f, 0.2f); m_DitchNoise.AddOctave(0.05f, 0.4f); m_DitchNoise.AddOctave(0.02f, 1.0f); @@ -416,95 +478,187 @@ void cHeiGenMountains::InitializeHeightGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cHeiGenBiomal: -const cHeiGenBiomal::sGenParam cHeiGenBiomal::m_GenParam[256] = -{ +const cHeiGenBiomal::sGenParam cHeiGenBiomal::m_GenParam[256] = { /* Fast-changing | Middle-changing | Slow-changing | */ /* Biome | Freq1 | Amp1 | Freq2 | Amp2 | Freq3 | Amp3 | BaseHeight */ - /* biOcean */ { 0.1f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 50}, - /* biPlains */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, - /* biDesert */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, - /* biExtremeHills */ { 0.2f, 4.0f, 0.05f, 20.0f, 0.01f, 16.0f, 100}, - /* biForest */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, - /* biTaiga */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, - /* biSwampland */ { 0.1f, 1.1f, 0.05f, 1.5f, 0.02f, 2.5f, 61.5}, - /* biRiver */ { 0.2f, 0.1f, 0.05f, 0.1f, 0.01f, 0.1f, 56}, - /* biNether */ { 0.1f, 0.0f, 0.01f, 0.0f, 0.01f, 0.0f, 0}, // Unused, but must be here due to indexing - /* biSky */ { 0.1f, 0.0f, 0.01f, 0.0f, 0.01f, 0.0f, 0}, // Unused, but must be here due to indexing - /* biFrozenOcean */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, - /* biFrozenRiver */ { 0.2f, 0.1f, 0.05f, 0.1f, 0.01f, 0.1f, 56}, - /* biIcePlains */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, - /* biIceMountains */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, - /* biMushroomIsland */ { 0.1f, 2.0f, 0.05f, 8.0f, 0.01f, 6.0f, 80}, - /* biMushroomShore */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 64}, - /* biBeach */ { 0.1f, 0.5f, 0.05f, 1.0f, 0.01f, 1.0f, 64}, - /* biDesertHills */ { 0.2f, 2.0f, 0.05f, 5.0f, 0.01f, 4.0f, 75}, - /* biForestHills */ { 0.2f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 80}, - /* biTaigaHills */ { 0.2f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 80}, - /* biExtremeHillsEdge */ { 0.2f, 3.0f, 0.05f, 16.0f, 0.01f, 12.0f, 80}, - /* biJungle */ { 0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, - /* biJungleHills */ { 0.2f, 3.0f, 0.05f, 12.0f, 0.01f, 10.0f, 80}, - /* biJungleEdge */ { 0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, - /* biDeepOcean */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, - /* biStoneBeach */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, - /* biColdBeach */ { 0.1f, 0.5f, 0.05f, 1.0f, 0.01f, 1.0f, 64}, - /* biBirchForest */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, - /* biBirchForestHills */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, - /* biRoofedForest */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, - /* biColdTaiga */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, - /* biColdTaigaHills */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, - /* biMegaTaiga */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, - /* biMegaTaigaHills */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, - /* biExtremeHillsPlus */ { 0.2f, 4.0f, 0.05f, 20.0f, 0.01f, 16.0f, 120}, - /* biSavanna */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, - /* biSavannaPlateau */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, - /* biMesa */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 70}, // 165 - /* biMesaPlateauF */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, - /* biMesaPlateau */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, + /* biOcean */ {0.1f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 50}, + /* biPlains */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, + /* biDesert */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, + /* biExtremeHills */ {0.2f, 4.0f, 0.05f, 20.0f, 0.01f, 16.0f, 100}, + /* biForest */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, + /* biTaiga */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, + /* biSwampland */ {0.1f, 1.1f, 0.05f, 1.5f, 0.02f, 2.5f, 61.5}, + /* biRiver */ {0.2f, 0.1f, 0.05f, 0.1f, 0.01f, 0.1f, 56}, + /* biNether */ {0.1f, 0.0f, 0.01f, 0.0f, 0.01f, 0.0f, 0}, // Unused, but must be here due to indexing + /* biSky */ {0.1f, 0.0f, 0.01f, 0.0f, 0.01f, 0.0f, 0}, // Unused, but must be here due to indexing + /* biFrozenOcean */ {0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, + /* biFrozenRiver */ {0.2f, 0.1f, 0.05f, 0.1f, 0.01f, 0.1f, 56}, + /* biIcePlains */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, + /* biIceMountains */ {0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, + /* biMushroomIsland */ {0.1f, 2.0f, 0.05f, 8.0f, 0.01f, 6.0f, 80}, + /* biMushroomShore */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 64}, + /* biBeach */ {0.1f, 0.5f, 0.05f, 1.0f, 0.01f, 1.0f, 64}, + /* biDesertHills */ {0.2f, 2.0f, 0.05f, 5.0f, 0.01f, 4.0f, 75}, + /* biForestHills */ {0.2f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 80}, + /* biTaigaHills */ {0.2f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 80}, + /* biExtremeHillsEdge */ {0.2f, 3.0f, 0.05f, 16.0f, 0.01f, 12.0f, 80}, + /* biJungle */ {0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, + /* biJungleHills */ {0.2f, 3.0f, 0.05f, 12.0f, 0.01f, 10.0f, 80}, + /* biJungleEdge */ {0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, + /* biDeepOcean */ {0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, + /* biStoneBeach */ {0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, + /* biColdBeach */ {0.1f, 0.5f, 0.05f, 1.0f, 0.01f, 1.0f, 64}, + /* biBirchForest */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, + /* biBirchForestHills */ {0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, + /* biRoofedForest */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, + /* biColdTaiga */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, + /* biColdTaigaHills */ {0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, + /* biMegaTaiga */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, + /* biMegaTaigaHills */ {0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, + /* biExtremeHillsPlus */ {0.2f, 4.0f, 0.05f, 20.0f, 0.01f, 16.0f, 120}, + /* biSavanna */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, + /* biSavannaPlateau */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, + /* biMesa */ {0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 70}, // 165 + /* biMesaPlateauF */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, + /* biMesaPlateau */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // biomes 40 .. 128 are unused, 89 empty placeholders here: - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 40 .. 49 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 50 .. 59 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 60 .. 69 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 70 .. 79 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 80 .. 89 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 90 .. 99 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 100 .. 109 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 110 .. 119 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 120 .. 128 - - /* biSunflowerPlains */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 129 - /* biDesertM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 130 - /* biExtremeHillsM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 131 - /* biFlowerForest */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 132 - /* biTaigaM */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 133 - /* biSwamplandM */ { 1.0f, 3.0f, 1.10f, 7.0f, 0.01f, 0.01f, 60}, // 134 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 40 .. 49 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 50 .. 59 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 60 .. 69 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 70 .. 79 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 80 .. 89 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 90 .. 99 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 100 .. 109 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 110 .. 119 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 120 .. 128 + + /* biSunflowerPlains */ {0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 129 + /* biDesertM */ {0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 130 + /* biExtremeHillsM */ {0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 131 + /* biFlowerForest */ {0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 132 + /* biTaigaM */ {0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 133 + /* biSwamplandM */ {1.0f, 3.0f, 1.10f, 7.0f, 0.01f, 0.01f, 60}, // 134 // Biomes 135 .. 139 unused, 5 empty placeholders here: - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 135 .. 139 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 135 .. 139 - /* biIcePlainsSpikes */ { 0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 140 + /* biIcePlainsSpikes */ {0.1f, 2.0f, 0.05f, 12.0f, 0.01f, 10.0f, 40}, // 140 // Biomes 141 .. 148 unused, 8 empty placeholders here: - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 141 .. 148 - - /* biJungleM */ { 0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, // 149 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 150 - /* biJungleEdgeM */ { 0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, // 151 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 152 .. 154 - /* biBirchForestM */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 155 - /* biBirchForestHillsM */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, // 156 - /* biRoofedForestM */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 157 - /* biColdTaigaM */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 158 - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 159 - /* biMegaSpruceTaiga */ { 0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 160 - /* biMegaSpruceTaigaHills */ { 0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, // 161 - /* biExtremeHillsPlusM */ { 0.2f, 4.0f, 0.05f, 20.0f, 0.01f, 16.0f, 120}, // 162 - /* biSavannaM */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, // 163 - /* biSavannaPlateauM */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // 164 - /* biMesaBryce */ { 0.2f, 2.0f, 0.1f, 30.0f, 0.01f, 8.0f, 80}, - /* biMesaPlateauFM */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // 166 - /* biMesaPlateauM */ { 0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // 167 -} ; + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 141 .. 148 + + /* biJungleM */ {0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, // 149 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 150 + /* biJungleEdgeM */ {0.1f, 3.0f, 0.05f, 6.0f, 0.01f, 6.0f, 70}, // 151 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 152 .. 154 + /* biBirchForestM */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 155 + /* biBirchForestHillsM */ {0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, // 156 + /* biRoofedForestM */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 157 + /* biColdTaigaM */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 158 + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0}, // 159 + /* biMegaSpruceTaiga */ {0.1f, 1.0f, 0.05f, 2.0f, 0.01f, 4.0f, 70}, // 160 + /* biMegaSpruceTaigaHills */ {0.2f, 2.0f, 0.05f, 10.0f, 0.01f, 8.0f, 80}, // 161 + /* biExtremeHillsPlusM */ {0.2f, 4.0f, 0.05f, 20.0f, 0.01f, 16.0f, 120}, // 162 + /* biSavannaM */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 68}, // 163 + /* biSavannaPlateauM */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // 164 + /* biMesaBryce */ {0.2f, 2.0f, 0.1f, 30.0f, 0.01f, 8.0f, 80}, + /* biMesaPlateauFM */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // 166 + /* biMesaPlateauM */ {0.1f, 1.0f, 0.05f, 1.5f, 0.01f, 4.0f, 80}, // 167 +}; @@ -559,7 +713,13 @@ void cHeiGenBiomal::InitializeHeightGen(cIniFile & a_IniFile) -NOISE_DATATYPE cHeiGenBiomal::GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const cHeiGenBiomal::BiomeNeighbors & a_BiomeNeighbors) +NOISE_DATATYPE cHeiGenBiomal::GetHeightAt( + int a_RelX, + int a_RelZ, + int a_ChunkX, + int a_ChunkZ, + const cHeiGenBiomal::BiomeNeighbors & a_BiomeNeighbors +) { // Sum up how many biomes of each type there are in the neighborhood: int BiomeCounts[256]; @@ -606,9 +766,15 @@ NOISE_DATATYPE cHeiGenBiomal::GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, ASSERT(m_GenParam[i].m_HeightFreq3 < 1000); */ - NOISE_DATATYPE oct1 = m_Noise.CubicNoise2D(BlockX * m_GenParam[i].m_HeightFreq1, BlockZ * m_GenParam[i].m_HeightFreq1) * m_GenParam[i].m_HeightAmp1; - NOISE_DATATYPE oct2 = m_Noise.CubicNoise2D(BlockX * m_GenParam[i].m_HeightFreq2, BlockZ * m_GenParam[i].m_HeightFreq2) * m_GenParam[i].m_HeightAmp2; - NOISE_DATATYPE oct3 = m_Noise.CubicNoise2D(BlockX * m_GenParam[i].m_HeightFreq3, BlockZ * m_GenParam[i].m_HeightFreq3) * m_GenParam[i].m_HeightAmp3; + NOISE_DATATYPE oct1 = + m_Noise.CubicNoise2D(BlockX * m_GenParam[i].m_HeightFreq1, BlockZ * m_GenParam[i].m_HeightFreq1) * + m_GenParam[i].m_HeightAmp1; + NOISE_DATATYPE oct2 = + m_Noise.CubicNoise2D(BlockX * m_GenParam[i].m_HeightFreq2, BlockZ * m_GenParam[i].m_HeightFreq2) * + m_GenParam[i].m_HeightAmp2; + NOISE_DATATYPE oct3 = + m_Noise.CubicNoise2D(BlockX * m_GenParam[i].m_HeightFreq3, BlockZ * m_GenParam[i].m_HeightFreq3) * + m_GenParam[i].m_HeightAmp3; Height += BiomeCounts[i] * (m_GenParam[i].m_BaseHeight + oct1 + oct2 + oct3); } NOISE_DATATYPE res = Height / Sum; @@ -627,20 +793,16 @@ NOISE_DATATYPE cHeiGenBiomal::GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, //////////////////////////////////////////////////////////////////////////////// // cHeiGenMinMax: -class cHeiGenMinMax: - public cTerrainHeightGen +class cHeiGenMinMax : public cTerrainHeightGen { using Super = cTerrainHeightGen; /** Size of the averaging process, in columns (for each direction). Must be less than 16. */ static const int AVERAGING_SIZE = 4; -public: - - cHeiGenMinMax(int a_Seed, cBiomeGen & a_BiomeGen): - m_Noise(a_Seed), - m_BiomeGen(a_BiomeGen), - m_TotalWeight(0) + public: + cHeiGenMinMax(int a_Seed, cBiomeGen & a_BiomeGen) : + m_Noise(a_Seed), m_BiomeGen(a_BiomeGen), m_TotalWeight(0) { // Initialize the weights: for (int z = 0; z <= AVERAGING_SIZE * 2; z++) @@ -653,9 +815,9 @@ public: } // Initialize the Perlin generator: - m_Perlin.AddOctave(0.04f, 0.2f); - m_Perlin.AddOctave(0.02f, 0.1f); - m_Perlin.AddOctave(0.01f, 0.05f); + m_Perlin.AddOctave(0.04f, 0.2f); + m_Perlin.AddOctave(0.02f, 0.1f); + m_Perlin.AddOctave(0.01f, 0.05f); } @@ -663,10 +825,14 @@ public: { // Generate the biomes for the 3 * 3 neighbors: cChunkDef::BiomeMap neighborBiomes[3][3]; - for (int z = 0; z < 3; z++) for (int x = 0; x < 3; x++) - { - m_BiomeGen.GenBiomes({a_ChunkCoords.m_ChunkX + x - 1, a_ChunkCoords.m_ChunkZ + z - 1}, neighborBiomes[z][x]); - } + for (int z = 0; z < 3; z++) + for (int x = 0; x < 3; x++) + { + m_BiomeGen.GenBiomes( + {a_ChunkCoords.m_ChunkX + x - 1, a_ChunkCoords.m_ChunkZ + z - 1}, + neighborBiomes[z][x] + ); + } // Get the min and max heights based on the biomes: double minHeight[cChunkDef::Width * cChunkDef::Width]; @@ -680,13 +846,13 @@ public: for (int relz = 0; relz <= AVERAGING_SIZE * 2; relz++) { int bz = z + 16 + relz - AVERAGING_SIZE; // Biome Z coord relative to the neighborBiomes start - int cz = bz / 16; // Chunk Z coord relative to the neighborBiomes start - bz = bz % 16; // Biome Z coord relative to cz in neighborBiomes + int cz = bz / 16; // Chunk Z coord relative to the neighborBiomes start + bz = bz % 16; // Biome Z coord relative to cz in neighborBiomes for (int relx = 0; relx <= AVERAGING_SIZE * 2; relx++) { int bx = x + 16 + relx - AVERAGING_SIZE; // Biome X coord relative to the neighborBiomes start - int cx = bx / 16; // Chunk X coord relative to the neighborBiomes start - bx = bx % 16; // Biome X coord relative to cz in neighborBiomes + int cx = bx / 16; // Chunk X coord relative to the neighborBiomes start + bx = bx % 16; // Biome X coord relative to cz in neighborBiomes // Get the biome's min and max heights: double bmin, bmax; @@ -730,7 +896,7 @@ public: // No settings available } -protected: + protected: cNoise m_Noise; cPerlinNoise m_Perlin; @@ -750,67 +916,250 @@ protected: { switch (a_Biome) { - case biBeach: a_Min = 61; a_Max = 64; break; - case biBirchForest: a_Min = 63; a_Max = 75; break; - case biBirchForestHills: a_Min = 63; a_Max = 90; break; - case biBirchForestHillsM: a_Min = 63; a_Max = 90; break; - case biBirchForestM: a_Min = 63; a_Max = 75; break; - case biColdBeach: a_Min = 61; a_Max = 64; break; - case biColdTaiga: a_Min = 63; a_Max = 75; break; - case biColdTaigaHills: a_Min = 63; a_Max = 90; break; - case biColdTaigaM: a_Min = 63; a_Max = 75; break; - case biDeepOcean: a_Min = 30; a_Max = 60; break; - case biDesert: a_Min = 63; a_Max = 70; break; - case biDesertHills: a_Min = 63; a_Max = 85; break; - case biDesertM: a_Min = 63; a_Max = 70; break; - case biEnd: a_Min = 10; a_Max = 100; break; - case biExtremeHills: a_Min = 60; a_Max = 120; break; - case biExtremeHillsEdge: a_Min = 63; a_Max = 100; break; - case biExtremeHillsM: a_Min = 60; a_Max = 120; break; - case biExtremeHillsPlus: a_Min = 60; a_Max = 140; break; - case biExtremeHillsPlusM: a_Min = 60; a_Max = 140; break; - case biFlowerForest: a_Min = 63; a_Max = 75; break; - case biForest: a_Min = 63; a_Max = 75; break; - case biForestHills: a_Min = 63; a_Max = 90; break; - case biFrozenOcean: a_Min = 45; a_Max = 64; break; - case biFrozenRiver: a_Min = 60; a_Max = 62; break; - case biIceMountains: a_Min = 63; a_Max = 90; break; - case biIcePlains: a_Min = 63; a_Max = 70; break; - case biIcePlainsSpikes: a_Min = 60; a_Max = 70; break; - case biJungle: a_Min = 60; a_Max = 80; break; - case biJungleEdge: a_Min = 62; a_Max = 75; break; - case biJungleEdgeM: a_Min = 62; a_Max = 75; break; - case biJungleHills: a_Min = 60; a_Max = 90; break; - case biJungleM: a_Min = 60; a_Max = 75; break; - case biMegaSpruceTaiga: a_Min = 63; a_Max = 75; break; - case biMegaSpruceTaigaHills: a_Min = 63; a_Max = 90; break; - case biMegaTaiga: a_Min = 63; a_Max = 75; break; - case biMegaTaigaHills: a_Min = 63; a_Max = 90; break; - case biMesa: a_Min = 63; a_Max = 90; break; - case biMesaBryce: a_Min = 60; a_Max = 67; break; - case biMesaPlateau: a_Min = 75; a_Max = 85; break; - case biMesaPlateauF: a_Min = 80; a_Max = 90; break; - case biMesaPlateauFM: a_Min = 80; a_Max = 90; break; - case biMesaPlateauM: a_Min = 75; a_Max = 85; break; - case biMushroomIsland: a_Min = 63; a_Max = 90; break; - case biMushroomShore: a_Min = 60; a_Max = 75; break; - case biNether: a_Min = 10; a_Max = 100; break; - case biOcean: a_Min = 45; a_Max = 64; break; - case biPlains: a_Min = 63; a_Max = 70; break; - case biRiver: a_Min = 60; a_Max = 62; break; - case biRoofedForest: a_Min = 63; a_Max = 75; break; - case biRoofedForestM: a_Min = 63; a_Max = 75; break; - case biSavanna: a_Min = 63; a_Max = 75; break; - case biSavannaM: a_Min = 63; a_Max = 80; break; - case biSavannaPlateau: a_Min = 75; a_Max = 100; break; - case biSavannaPlateauM: a_Min = 80; a_Max = 160; break; - case biStoneBeach: a_Min = 60; a_Max = 64; break; - case biSunflowerPlains: a_Min = 63; a_Max = 70; break; - case biSwampland: a_Min = 60; a_Max = 67; break; - case biSwamplandM: a_Min = 61; a_Max = 67; break; - case biTaiga: a_Min = 63; a_Max = 75; break; - case biTaigaHills: a_Min = 63; a_Max = 90; break; - case biTaigaM: a_Min = 63; a_Max = 80; break; + case biBeach: + a_Min = 61; + a_Max = 64; + break; + case biBirchForest: + a_Min = 63; + a_Max = 75; + break; + case biBirchForestHills: + a_Min = 63; + a_Max = 90; + break; + case biBirchForestHillsM: + a_Min = 63; + a_Max = 90; + break; + case biBirchForestM: + a_Min = 63; + a_Max = 75; + break; + case biColdBeach: + a_Min = 61; + a_Max = 64; + break; + case biColdTaiga: + a_Min = 63; + a_Max = 75; + break; + case biColdTaigaHills: + a_Min = 63; + a_Max = 90; + break; + case biColdTaigaM: + a_Min = 63; + a_Max = 75; + break; + case biDeepOcean: + a_Min = 30; + a_Max = 60; + break; + case biDesert: + a_Min = 63; + a_Max = 70; + break; + case biDesertHills: + a_Min = 63; + a_Max = 85; + break; + case biDesertM: + a_Min = 63; + a_Max = 70; + break; + case biEnd: + a_Min = 10; + a_Max = 100; + break; + case biExtremeHills: + a_Min = 60; + a_Max = 120; + break; + case biExtremeHillsEdge: + a_Min = 63; + a_Max = 100; + break; + case biExtremeHillsM: + a_Min = 60; + a_Max = 120; + break; + case biExtremeHillsPlus: + a_Min = 60; + a_Max = 140; + break; + case biExtremeHillsPlusM: + a_Min = 60; + a_Max = 140; + break; + case biFlowerForest: + a_Min = 63; + a_Max = 75; + break; + case biForest: + a_Min = 63; + a_Max = 75; + break; + case biForestHills: + a_Min = 63; + a_Max = 90; + break; + case biFrozenOcean: + a_Min = 45; + a_Max = 64; + break; + case biFrozenRiver: + a_Min = 60; + a_Max = 62; + break; + case biIceMountains: + a_Min = 63; + a_Max = 90; + break; + case biIcePlains: + a_Min = 63; + a_Max = 70; + break; + case biIcePlainsSpikes: + a_Min = 60; + a_Max = 70; + break; + case biJungle: + a_Min = 60; + a_Max = 80; + break; + case biJungleEdge: + a_Min = 62; + a_Max = 75; + break; + case biJungleEdgeM: + a_Min = 62; + a_Max = 75; + break; + case biJungleHills: + a_Min = 60; + a_Max = 90; + break; + case biJungleM: + a_Min = 60; + a_Max = 75; + break; + case biMegaSpruceTaiga: + a_Min = 63; + a_Max = 75; + break; + case biMegaSpruceTaigaHills: + a_Min = 63; + a_Max = 90; + break; + case biMegaTaiga: + a_Min = 63; + a_Max = 75; + break; + case biMegaTaigaHills: + a_Min = 63; + a_Max = 90; + break; + case biMesa: + a_Min = 63; + a_Max = 90; + break; + case biMesaBryce: + a_Min = 60; + a_Max = 67; + break; + case biMesaPlateau: + a_Min = 75; + a_Max = 85; + break; + case biMesaPlateauF: + a_Min = 80; + a_Max = 90; + break; + case biMesaPlateauFM: + a_Min = 80; + a_Max = 90; + break; + case biMesaPlateauM: + a_Min = 75; + a_Max = 85; + break; + case biMushroomIsland: + a_Min = 63; + a_Max = 90; + break; + case biMushroomShore: + a_Min = 60; + a_Max = 75; + break; + case biNether: + a_Min = 10; + a_Max = 100; + break; + case biOcean: + a_Min = 45; + a_Max = 64; + break; + case biPlains: + a_Min = 63; + a_Max = 70; + break; + case biRiver: + a_Min = 60; + a_Max = 62; + break; + case biRoofedForest: + a_Min = 63; + a_Max = 75; + break; + case biRoofedForestM: + a_Min = 63; + a_Max = 75; + break; + case biSavanna: + a_Min = 63; + a_Max = 75; + break; + case biSavannaM: + a_Min = 63; + a_Max = 80; + break; + case biSavannaPlateau: + a_Min = 75; + a_Max = 100; + break; + case biSavannaPlateauM: + a_Min = 80; + a_Max = 160; + break; + case biStoneBeach: + a_Min = 60; + a_Max = 64; + break; + case biSunflowerPlains: + a_Min = 63; + a_Max = 70; + break; + case biSwampland: + a_Min = 60; + a_Max = 67; + break; + case biSwamplandM: + a_Min = 61; + a_Max = 67; + break; + case biTaiga: + a_Min = 63; + a_Max = 75; + break; + case biTaigaHills: + a_Min = 63; + a_Max = 90; + break; + case biTaigaM: + a_Min = 63; + a_Max = 80; + break; case biInvalidBiome: case biNumBiomes: case biVariant: @@ -832,7 +1181,12 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cTerrainHeightGen: -std::unique_ptr<cTerrainHeightGen> cTerrainHeightGen::CreateHeightGen(cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault) +std::unique_ptr<cTerrainHeightGen> cTerrainHeightGen::CreateHeightGen( + cIniFile & a_IniFile, + cBiomeGen & a_BiomeGen, + int a_Seed, + bool & a_CacheOffByDefault +) { AString HeightGenName = a_IniFile.GetValueSet("Generator", "HeightGen", ""); if (HeightGenName.empty()) @@ -854,14 +1208,14 @@ std::unique_ptr<cTerrainHeightGen> cTerrainHeightGen::CreateHeightGen(cIniFile & } else if (NoCaseCompare(HeightGenName, "DistortedHeightmap") == 0) { - // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it - // Return an empty pointer, the caller will create the proper generator: + // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the + // default out of it Return an empty pointer, the caller will create the proper generator: return nullptr; } else if (NoCaseCompare(HeightGenName, "End") == 0) { - // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it - // Return an empty pointer, the caller will create the proper generator: + // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the + // default out of it Return an empty pointer, the caller will create the proper generator: return nullptr; } else if (NoCaseCompare(HeightGenName, "MinMax") == 0) @@ -874,8 +1228,8 @@ std::unique_ptr<cTerrainHeightGen> cTerrainHeightGen::CreateHeightGen(cIniFile & } else if (NoCaseCompare(HeightGenName, "BiomalNoise3D") == 0) { - // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it - // Return an empty pointer, the caller will create the proper generator: + // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the + // default out of it Return an empty pointer, the caller will create the proper generator: return nullptr; } else if (NoCaseCompare(HeightGenName, "Steppy") == 0) @@ -884,8 +1238,8 @@ std::unique_ptr<cTerrainHeightGen> cTerrainHeightGen::CreateHeightGen(cIniFile & } else if (NoCaseCompare(HeightGenName, "Noise3D") == 0) { - // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it - // Return an empty pointer, the caller will create the proper generator: + // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the + // default out of it Return an empty pointer, the caller will create the proper generator: return nullptr; } else if (NoCaseCompare(HeightGenName, "Biomal") == 0) @@ -918,8 +1272,3 @@ std::unique_ptr<cTerrainHeightGen> cTerrainHeightGen::CreateHeightGen(cIniFile & return res; } - - - - - diff --git a/src/Generating/HeiGen.h b/src/Generating/HeiGen.h index 6f2101043..d40c052c5 100644 --- a/src/Generating/HeiGen.h +++ b/src/Generating/HeiGen.h @@ -24,10 +24,9 @@ Also implements the heightmap cache /** A simple cache that stores N most recently generated chunks' heightmaps; N being settable upon creation */ -class cHeiGenCache : - public cTerrainHeightGen +class cHeiGenCache : public cTerrainHeightGen { -public: + public: cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, size_t a_CacheSize); // cTerrainHeightGen overrides: @@ -37,42 +36,46 @@ public: /** Retrieves height at the specified point in the cache, returns true if found, false if not found */ bool GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height); -protected: + protected: struct sCacheData { cChunkCoords m_Coords; cChunkDef::HeightMap m_HeightMap; /** Default constructor: Fill in bogus coords, so that the item is not used until properly calculated. */ - sCacheData(): + sCacheData() : m_Coords(0x7fffffff, 0x7fffffff) - {} - } ; + { + } + }; /** The terrain height generator that is being cached. */ cTerrainHeightGen & m_HeiGenToCache; // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data - size_t m_CacheSize; - std::vector<size_t> m_CacheOrder; // MRU-ized order, indices into m_CacheData array - std::vector<sCacheData> m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used + size_t m_CacheSize; + std::vector<size_t> m_CacheOrder; // MRU-ized order, indices into m_CacheData array + std::vector<sCacheData> m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used // Cache statistics size_t m_NumHits; size_t m_NumMisses; size_t m_TotalChain; // Number of cache items walked to get to a hit (only added for hits) -} ; +}; /** Caches heightmaps in multiple underlying caches to improve the distribution and lower the chain length. */ -class cHeiGenMultiCache: - public cTerrainHeightGen +class cHeiGenMultiCache : public cTerrainHeightGen { -public: - cHeiGenMultiCache(std::unique_ptr<cTerrainHeightGen> a_HeightGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches); + public: + cHeiGenMultiCache( + std::unique_ptr<cTerrainHeightGen> a_HeightGenToCache, + size_t a_SubCacheSize, + size_t a_NumSubCaches + ); // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; @@ -81,8 +84,7 @@ public: /** Retrieves height at the specified point in the cache, returns true if found, false if not found */ bool GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height); -protected: - + protected: /** The coefficient used to turn Z coords into index (x + Coeff * z). */ static const size_t m_CoeffZ = 5; @@ -100,33 +102,32 @@ protected: -class cHeiGenFlat : - public cTerrainHeightGen +class cHeiGenFlat : public cTerrainHeightGen { -public: - cHeiGenFlat(void) : m_Height(5) {} - -protected: + public: + cHeiGenFlat(void) : + m_Height(5) + { + } + protected: HEIGHTTYPE m_Height; // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; virtual void InitializeHeightGen(cIniFile & a_IniFile) override; -} ; +}; -class cHeiGenClassic : - public cTerrainHeightGen +class cHeiGenClassic : public cTerrainHeightGen { -public: + public: cHeiGenClassic(int a_Seed); -protected: - + protected: int m_Seed; cNoise m_Noise; float m_HeightFreq1, m_HeightAmp1; @@ -138,20 +139,18 @@ protected: // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; virtual void InitializeHeightGen(cIniFile & a_IniFile) override; -} ; +}; -class cHeiGenMountains : - public cTerrainHeightGen +class cHeiGenMountains : public cTerrainHeightGen { -public: + public: cHeiGenMountains(int a_Seed); -protected: - + protected: int m_Seed; cRidgedMultiNoise m_MountainNoise; cRidgedMultiNoise m_DitchNoise; @@ -160,35 +159,32 @@ protected: // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; virtual void InitializeHeightGen(cIniFile & a_IniFile) override; -} ; +}; -class cHeiGenBiomal: - public cTerrainHeightGen +class cHeiGenBiomal : public cTerrainHeightGen { using Super = cTerrainHeightGen; -public: - - cHeiGenBiomal(int a_Seed, cBiomeGen & a_BiomeGen): - m_Noise(a_Seed), - m_BiomeGen(a_BiomeGen) + public: + cHeiGenBiomal(int a_Seed, cBiomeGen & a_BiomeGen) : + m_Noise(a_Seed), m_BiomeGen(a_BiomeGen) { } // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; - virtual HEIGHTTYPE GetHeightAt(int a_BlockX, int a_BlockZ) override // Need to provide this override due to clang's overzealous detection of overloaded virtuals + virtual HEIGHTTYPE GetHeightAt(int a_BlockX, int a_BlockZ) + override // Need to provide this override due to clang's overzealous detection of overloaded virtuals { return Super::GetHeightAt(a_BlockX, a_BlockZ); } virtual void InitializeHeightGen(cIniFile & a_IniFile) override; -protected: - + protected: typedef cChunkDef::BiomeMap BiomeNeighbors[3][3]; cNoise m_Noise; @@ -201,9 +197,15 @@ protected: float m_HeightFreq2, m_HeightAmp2; float m_HeightFreq3, m_HeightAmp3; float m_BaseHeight; - } ; + }; static const sGenParam m_GenParam[256]; - NOISE_DATATYPE GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const BiomeNeighbors & a_BiomeNeighbors); -} ; + NOISE_DATATYPE GetHeightAt( + int a_RelX, + int a_RelZ, + int a_ChunkX, + int a_ChunkZ, + const BiomeNeighbors & a_BiomeNeighbors + ); +}; diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index b56567f9f..bfc489102 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -37,24 +37,22 @@ by using templates. /** Constants representing the biome group designators. */ -const int bgOcean = 0; -const int bgDesert = 1; -const int bgTemperate = 2; -const int bgMountains = 3; -const int bgIce = 4; +const int bgOcean = 0; +const int bgDesert = 1; +const int bgTemperate = 2; +const int bgMountains = 3; +const int bgIce = 4; const int bgLandOceanMax = 4; // Maximum biome group value generated in the landOcean generator -const int bgfRare = 1024; // Flag added to values to generate rare biomes for the group +const int bgfRare = 1024; // Flag added to values to generate rare biomes for the group /** Interface that all the generator classes provide. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGen +template <int SizeX, int SizeZ = SizeX> class cIntGen { -public: - + public: using IntGenType = cIntGen<SizeX, SizeZ>; /** Force a virtual destructor in all descendants. @@ -66,67 +64,57 @@ public: /** Generates the array of templated size into a_Values, based on given min coords. */ virtual void GetInts(int a_MinX, int a_MinZ, Values & a_Values) = 0; - }; // Code adapted from https://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer -template<int... > -struct sSeq +template <int...> struct sSeq { }; -template<int N, int... S> -struct sGens : sGens<N - 1, N - 1, S...> +template <int N, int... S> struct sGens : sGens<N - 1, N - 1, S...> { }; -template<int... S> -struct sGens<0, S...> +template <int... S> struct sGens<0, S...> { using type = sSeq<S...>; }; -template<class Gen, class... Args> -class cIntGenFactory +template <class Gen, class... Args> class cIntGenFactory { -public: - + public: using Generator = Gen; - cIntGenFactory(Args&&... a_args) : + cIntGenFactory(Args &&... a_args) : m_args(std::make_tuple<Args...>(std::forward<Args>(a_args)...)) { } - template <class LhsGen> - std::shared_ptr<Gen> construct(LhsGen&& a_Lhs) + template <class LhsGen> std::shared_ptr<Gen> construct(LhsGen && a_Lhs) { return construct_impl<LhsGen>(std::forward<LhsGen>(a_Lhs), typename sGens<sizeof...(Args)>::type()); } -private: + private: std::tuple<Args...> m_args; - template <class LhsGen, int... S> - std::shared_ptr<Gen> construct_impl(LhsGen&& a_Lhs, sSeq<S...>) + template <class LhsGen, int... S> std::shared_ptr<Gen> construct_impl(LhsGen && a_Lhs, sSeq<S...>) { return std::make_shared<Gen>(std::get<S>(m_args)..., std::forward<LhsGen>(a_Lhs)); } - }; -template<class T, class RhsGen, class... Args> -std::shared_ptr<RhsGen> operator| (std::shared_ptr<T> a_Lhs, cIntGenFactory<RhsGen, Args...> a_Rhs) +template <class T, class RhsGen, class... Args> +std::shared_ptr<RhsGen> operator|(std::shared_ptr<T> a_Lhs, cIntGenFactory<RhsGen, Args...> a_Rhs) { return a_Rhs.construct(static_cast<std::shared_ptr<typename T::IntGenType>>(a_Lhs)); } -template<class Gen, class... Args> -cIntGenFactory<Gen, Args...> MakeIntGen(Args&&... a_Args) +template <class Gen, class... Args> cIntGenFactory<Gen, Args...> MakeIntGen(Args &&... a_Args) { return cIntGenFactory<Gen, Args...>(std::forward<Args>(a_Args)...); } @@ -134,20 +122,17 @@ cIntGenFactory<Gen, Args...> MakeIntGen(Args&&... a_Args) /** Provides additional cNoise member and its helper functions. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenWithNoise: - public cIntGen<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenWithNoise : public cIntGen<SizeX, SizeZ> { using Super = cIntGen<SizeX, SizeZ>; -public: - - cIntGenWithNoise(int a_Seed): + public: + cIntGenWithNoise(int a_Seed) : m_Noise(a_Seed) { } -protected: + protected: cNoise m_Noise; /** Chooses one of a_Val1 or a_Val2, based on m_Noise and the coordinates for querying the noise. */ @@ -176,15 +161,12 @@ protected: /** Generates a 2D array of random integers in the specified range [0 .. Range). */ -template <int Range, int SizeX, int SizeZ = SizeX> -class cIntGenChoice: - public cIntGenWithNoise<SizeX, SizeZ> +template <int Range, int SizeX, int SizeZ = SizeX> class cIntGenChoice : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -public: - - cIntGenChoice(int a_Seed): + public: + cIntGenChoice(int a_Seed) : Super(a_Seed) { } @@ -210,17 +192,13 @@ public: /** Decides between the ocean and landmass biomes. Has a threshold (in percent) of how much land, the larger the threshold, the more land. Generates 0 for ocean, biome group ID for landmass. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenLandOcean: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenLandOcean : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -public: - - cIntGenLandOcean(int a_Seed, int a_Threshold): - Super(a_Seed), - m_Threshold(a_Threshold) + public: + cIntGenLandOcean(int a_Seed, int a_Threshold) : + Super(a_Seed), m_Threshold(a_Threshold) { } @@ -244,7 +222,7 @@ public: } } -protected: + protected: int m_Threshold; }; @@ -255,25 +233,20 @@ protected: /** Zooms the underlying value array to twice the size. Uses random-neighbor for the pixels in-between. This means that the zoome out image is randomly distorted. Applying zoom several times provides all the distortion that the generators need. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenZoom: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenZoom : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -protected: - + protected: static const int m_LowerSizeX = (SizeX / 2) + 2; static const int m_LowerSizeZ = (SizeZ / 2) + 2; -public: - + public: using Underlying = std::shared_ptr<cIntGen<m_LowerSizeX, m_LowerSizeZ>>; - cIntGenZoom(int a_Seed, Underlying a_UnderlyingGen): - Super(a_Seed), - m_UnderlyingGen(a_UnderlyingGen) + cIntGenZoom(int a_Seed, Underlying a_UnderlyingGen) : + Super(a_Seed), m_UnderlyingGen(a_UnderlyingGen) { } @@ -304,7 +277,7 @@ public: int RndZ = (z + lowerMinZ) * 2; cache[idx] = PrevZ0; cache[idx + lowStepX] = Super::ChooseRandomOne(RndX, RndZ + 1, PrevZ0, PrevZ1); - cache[idx + 1] = Super::ChooseRandomOne(RndX, RndZ - 1, PrevZ0, ValX1Z0); + cache[idx + 1] = Super::ChooseRandomOne(RndX, RndZ - 1, PrevZ0, ValX1Z0); cache[idx + 1 + lowStepX] = Super::ChooseRandomOne(RndX, RndZ, PrevZ0, ValX1Z0, PrevZ1, ValX1Z1); idx += 2; PrevZ0 = ValX1Z0; @@ -319,7 +292,7 @@ public: } } -protected: + protected: Underlying m_UnderlyingGen; }; @@ -329,23 +302,19 @@ protected: /** Smoothes out some artifacts generated by the zooming - mostly single-pixel values. Compares each pixel to its neighbors and if the neighbors are equal, changes the pixel to their value. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenSmooth: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenSmooth : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; static const int m_LowerSizeX = SizeX + 2; static const int m_LowerSizeZ = SizeZ + 2; -public: - + public: using Underlying = std::shared_ptr<cIntGen<m_LowerSizeX, m_LowerSizeZ>>; - cIntGenSmooth(int a_Seed, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(a_Underlying) + cIntGenSmooth(int a_Seed, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(a_Underlying) { } @@ -363,10 +332,10 @@ public: int NoiseZ = a_MinZ + z; for (int x = 0; x < SizeX; x++) { - int val = lowerData[x + 1 + (z + 1) * m_LowerSizeX]; - int above = lowerData[x + 1 + z * m_LowerSizeX]; + int val = lowerData[x + 1 + (z + 1) * m_LowerSizeX]; + int above = lowerData[x + 1 + z * m_LowerSizeX]; int below = lowerData[x + 1 + (z + 2) * m_LowerSizeX]; - int left = lowerData[x + (z + 1) * m_LowerSizeX]; + int left = lowerData[x + (z + 1) * m_LowerSizeX]; int right = lowerData[x + 2 + (z + 1) * m_LowerSizeX]; if ((left == right) && (above == below)) @@ -398,7 +367,7 @@ public: } } -protected: + protected: Underlying m_Underlying; }; @@ -407,21 +376,18 @@ protected: /** Converts land biomes at the edge of an ocean into the respective beach biome. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenBeaches: - public cIntGen<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenBeaches : public cIntGen<SizeX, SizeZ> { using Super = cIntGen<SizeX, SizeZ>; static const int m_UnderlyingSizeX = SizeX + 2; static const int m_UnderlyingSizeZ = SizeZ + 2; -public: - + public: using Underlying = std::shared_ptr<cIntGen<m_UnderlyingSizeX, m_UnderlyingSizeZ>>; - cIntGenBeaches(Underlying a_Underlying): + cIntGenBeaches(Underlying a_Underlying) : m_Underlying(a_Underlying) { } @@ -430,8 +396,7 @@ public: virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Map for biome -> its beach: - static const int ToBeach[] = - { + static const int ToBeach[] = { /* biOcean */ biOcean, /* biPlains */ biBeach, /* biDesert */ biBeach, @@ -483,10 +448,10 @@ public: { for (int x = 0; x < SizeX; x++) { - int val = lowerValues[x + 1 + (z + 1) * m_UnderlyingSizeX]; - int above = lowerValues[x + 1 + z * m_UnderlyingSizeX]; + int val = lowerValues[x + 1 + (z + 1) * m_UnderlyingSizeX]; + int above = lowerValues[x + 1 + z * m_UnderlyingSizeX]; int below = lowerValues[x + 1 + (z + 2) * m_UnderlyingSizeX]; - int left = lowerValues[x + (z + 1) * m_UnderlyingSizeX]; + int left = lowerValues[x + (z + 1) * m_UnderlyingSizeX]; int right = lowerValues[x + 2 + (z + 1) * m_UnderlyingSizeX]; if (!IsBiomeOcean(val)) { @@ -501,7 +466,7 @@ public: } } -protected: + protected: Underlying m_Underlying; }; @@ -511,21 +476,16 @@ protected: /** Generates the underlying numbers and then randomly changes some ocean group pixels into random land biome group pixels, based on the predefined chance. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenAddIslands: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenAddIslands : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -public: - + public: using Underlying = std::shared_ptr<cIntGen<SizeX, SizeZ>>; - cIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying): - Super(a_Seed), - m_Chance(a_Chance), - m_Underlying(a_Underlying) + cIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying) : + Super(a_Seed), m_Chance(a_Chance), m_Underlying(a_Underlying) { } @@ -549,7 +509,7 @@ public: } // for z } -protected: + protected: /** Chance, in permille, of an island being generated in ocean. */ int m_Chance; @@ -561,21 +521,18 @@ protected: /** A filter that adds an edge biome group between two biome groups that need an edge between them. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenBiomeGroupEdges: - public cIntGen<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenBiomeGroupEdges : public cIntGen<SizeX, SizeZ> { using Super = cIntGen<SizeX, SizeZ>; static const int m_UnderlyingSizeX = SizeX + 2; static const int m_UnderlyingSizeZ = SizeZ + 2; -public: - + public: using Underlying = std::shared_ptr<cIntGen<m_UnderlyingSizeX, m_UnderlyingSizeZ>>; - cIntGenBiomeGroupEdges(Underlying a_Underlying): + cIntGenBiomeGroupEdges(Underlying a_Underlying) : m_Underlying(a_Underlying) { } @@ -592,22 +549,18 @@ public: { for (int x = 0; x < SizeX; x++) { - int val = lowerValues[x + 1 + (z + 1) * m_UnderlyingSizeX]; - int above = lowerValues[x + 1 + z * m_UnderlyingSizeX]; + int val = lowerValues[x + 1 + (z + 1) * m_UnderlyingSizeX]; + int above = lowerValues[x + 1 + z * m_UnderlyingSizeX]; int below = lowerValues[x + 1 + (z + 2) * m_UnderlyingSizeX]; - int left = lowerValues[x + (z + 1) * m_UnderlyingSizeX]; + int left = lowerValues[x + (z + 1) * m_UnderlyingSizeX]; int right = lowerValues[x + 2 + (z + 1) * m_UnderlyingSizeX]; switch (val) { // Desert should neighbor only oceans, desert and temperates; change to temperate when another: case bgDesert: { - if ( - !isDesertCompatible(above) || - !isDesertCompatible(below) || - !isDesertCompatible(left) || - !isDesertCompatible(right) - ) + if (!isDesertCompatible(above) || !isDesertCompatible(below) || !isDesertCompatible(left) || + !isDesertCompatible(right)) { val = bgTemperate; } @@ -617,12 +570,7 @@ public: // Ice should not neighbor deserts; change to temperate: case bgIce: { - if ( - (above == bgDesert) || - (below == bgDesert) || - (left == bgDesert) || - (right == bgDesert) - ) + if ((above == bgDesert) || (below == bgDesert) || (left == bgDesert) || (right == bgDesert)) { val = bgTemperate; } @@ -634,7 +582,7 @@ public: } // for z } -protected: + protected: Underlying m_Underlying; @@ -663,20 +611,16 @@ protected: /** Turns biome group indices into real biomes. For each pixel, takes its biome group and chooses a random biome from that group; replaces the value with that biome. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenBiomes: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenBiomes : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -public: - + public: using Underlying = std::shared_ptr<cIntGen<SizeX, SizeZ>>; - cIntGenBiomes(int a_Seed, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(a_Underlying) + cIntGenBiomes(int a_Seed, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(a_Underlying) { } @@ -684,74 +628,88 @@ public: virtual void GetInts(int a_MinX, int a_MinZ, typename Super::Values & a_Values) override { // Define the per-biome-group biomes: - static const int oceanBiomes[] = - { + static const int oceanBiomes[] = { biOcean, // biDeepOcean, }; // Same as oceanBiomes, there are no rare oceanic biomes (mushroom islands are handled separately) - static const int rareOceanBiomes[] = - { + static const int rareOceanBiomes[] = { biOcean, }; - static const int desertBiomes[] = - { - biDesert, biDesert, biDesert, biDesert, biDesert, biDesert, biSavanna, biSavanna, biPlains, + static const int desertBiomes[] = { + biDesert, + biDesert, + biDesert, + biDesert, + biDesert, + biDesert, + biSavanna, + biSavanna, + biPlains, }; - static const int rareDesertBiomes[] = - { - biMesaPlateau, biMesaPlateauF, + static const int rareDesertBiomes[] = { + biMesaPlateau, + biMesaPlateauF, }; - static const int temperateBiomes[] = - { - biForest, biForest, biRoofedForest, biExtremeHills, biPlains, biBirchForest, biSwampland, + static const int temperateBiomes[] = { + biForest, + biForest, + biRoofedForest, + biExtremeHills, + biPlains, + biBirchForest, + biSwampland, }; - static const int rareTemperateBiomes[] = - { + static const int rareTemperateBiomes[] = { biJungle, // Jungle is not strictly temperate, but let's piggyback it here }; - static const int mountainBiomes[] = - { - biExtremeHills, biForest, biTaiga, biPlains, + static const int mountainBiomes[] = { + biExtremeHills, + biForest, + biTaiga, + biPlains, }; - static const int rareMountainBiomes[] = - { + static const int rareMountainBiomes[] = { biMegaTaiga, }; - static const int iceBiomes[] = - { - biIcePlains, biIcePlains, biIcePlains, biIcePlains, biColdTaiga, + static const int iceBiomes[] = { + biIcePlains, + biIcePlains, + biIcePlains, + biIcePlains, + biColdTaiga, }; // Same as iceBiomes, there's no rare ice biome - static const int rareIceBiomes[] = - { - biIcePlains, biIcePlains, biIcePlains, biIcePlains, biColdTaiga, + static const int rareIceBiomes[] = { + biIcePlains, + biIcePlains, + biIcePlains, + biIcePlains, + biColdTaiga, }; - static const cBiomesInGroups biomesInGroups[] = - { - /* bgOcean */ { static_cast<int>(ARRAYCOUNT(oceanBiomes)), oceanBiomes}, - /* bgDesert */ { static_cast<int>(ARRAYCOUNT(desertBiomes)), desertBiomes}, - /* bgTemperate */ { static_cast<int>(ARRAYCOUNT(temperateBiomes)), temperateBiomes}, - /* bgMountains */ { static_cast<int>(ARRAYCOUNT(mountainBiomes)), mountainBiomes}, - /* bgIce */ { static_cast<int>(ARRAYCOUNT(iceBiomes)), iceBiomes}, + static const cBiomesInGroups biomesInGroups[] = { + /* bgOcean */ {static_cast<int>(ARRAYCOUNT(oceanBiomes)), oceanBiomes}, + /* bgDesert */ {static_cast<int>(ARRAYCOUNT(desertBiomes)), desertBiomes}, + /* bgTemperate */ {static_cast<int>(ARRAYCOUNT(temperateBiomes)), temperateBiomes}, + /* bgMountains */ {static_cast<int>(ARRAYCOUNT(mountainBiomes)), mountainBiomes}, + /* bgIce */ {static_cast<int>(ARRAYCOUNT(iceBiomes)), iceBiomes}, }; - static const cBiomesInGroups rareBiomesInGroups[] = - { - /* bgOcean */ { static_cast<int>(ARRAYCOUNT(rareOceanBiomes)), rareOceanBiomes}, - /* bgDesert */ { static_cast<int>(ARRAYCOUNT(rareDesertBiomes)), rareDesertBiomes}, - /* bgTemperate */ { static_cast<int>(ARRAYCOUNT(rareTemperateBiomes)), rareTemperateBiomes}, - /* bgMountains */ { static_cast<int>(ARRAYCOUNT(rareMountainBiomes)), rareMountainBiomes}, - /* bgIce */ { static_cast<int>(ARRAYCOUNT(rareIceBiomes)), rareIceBiomes}, + static const cBiomesInGroups rareBiomesInGroups[] = { + /* bgOcean */ {static_cast<int>(ARRAYCOUNT(rareOceanBiomes)), rareOceanBiomes}, + /* bgDesert */ {static_cast<int>(ARRAYCOUNT(rareDesertBiomes)), rareDesertBiomes}, + /* bgTemperate */ {static_cast<int>(ARRAYCOUNT(rareTemperateBiomes)), rareTemperateBiomes}, + /* bgMountains */ {static_cast<int>(ARRAYCOUNT(rareMountainBiomes)), rareMountainBiomes}, + /* bgIce */ {static_cast<int>(ARRAYCOUNT(rareIceBiomes)), rareIceBiomes}, }; // Generate the underlying values, representing biome groups: @@ -764,17 +722,16 @@ public: for (int x = 0; x < SizeX; x++) { size_t val = static_cast<size_t>(a_Values[x + IdxZ]); - const cBiomesInGroups & Biomes = (val > bgfRare) ? - rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] : - biomesInGroups[val % ARRAYCOUNT(biomesInGroups)]; + const cBiomesInGroups & Biomes = (val > bgfRare) + ? rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] + : biomesInGroups[val % ARRAYCOUNT(biomesInGroups)]; int rnd = (Super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7); a_Values[x + IdxZ] = Biomes.Biomes[rnd % Biomes.Count]; } } } -protected: - + protected: struct cBiomesInGroups { const int Count; @@ -791,23 +748,16 @@ protected: /** Randomly replaces pixels of one value to another value, using the given chance. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenReplaceRandomly: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenReplaceRandomly : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -public: - + public: using Underlying = std::shared_ptr<cIntGen<SizeX, SizeZ>>; - cIntGenReplaceRandomly(int a_From, int a_To, int a_Chance, int a_Seed, Underlying a_Underlying): - Super(a_Seed), - m_From(a_From), - m_To(a_To), - m_Chance(a_Chance), - m_Underlying(a_Underlying) + cIntGenReplaceRandomly(int a_From, int a_To, int a_Chance, int a_Seed, Underlying a_Underlying) : + Super(a_Seed), m_From(a_From), m_To(a_To), m_Chance(a_Chance), m_Underlying(a_Underlying) { } @@ -837,7 +787,7 @@ public: } -protected: + protected: /** The original value to be replaced. */ int m_From; @@ -858,20 +808,16 @@ protected: It first checks for oceans, if there is an ocean in the Biomes, it keeps the ocean. If there's no ocean, it checks Rivers for a river, if there is a river, it uses the Biomes to select either regular river or frozen river, based on the biome. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenMixRivers: - public cIntGen<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenMixRivers : public cIntGen<SizeX, SizeZ> { using Super = cIntGen<SizeX, SizeZ>; -public: - + public: using Underlying = std::shared_ptr<cIntGen<SizeX, SizeZ>>; - cIntGenMixRivers(Underlying a_Biomes, Underlying a_Rivers): - m_Biomes(a_Biomes), - m_Rivers(a_Rivers) + cIntGenMixRivers(Underlying a_Biomes, Underlying a_Rivers) : + m_Biomes(a_Biomes), m_Rivers(a_Rivers) { } @@ -914,7 +860,7 @@ public: } // for z } -protected: + protected: Underlying m_Biomes; Underlying m_Rivers; }; @@ -926,23 +872,19 @@ protected: /** Generates a river based on the underlying data. This is basically an edge detector over the underlying data. The rivers are the edges where the underlying data changes from one pixel to its neighbor. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenRiver: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenRiver : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; static const int UnderlyingSizeX = SizeX + 2; static const int UnderlyingSizeZ = SizeZ + 2; -public: - + public: using Underlying = std::shared_ptr<cIntGen<UnderlyingSizeX, UnderlyingSizeZ>>; - cIntGenRiver(int a_Seed, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(a_Underlying) + cIntGenRiver(int a_Seed, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(a_Underlying) { } @@ -960,9 +902,9 @@ public: { int Above = Cache[x + 1 + z * UnderlyingSizeX]; int Below = Cache[x + 1 + (z + 2) * UnderlyingSizeX]; - int Left = Cache[x + (z + 1) * UnderlyingSizeX]; + int Left = Cache[x + (z + 1) * UnderlyingSizeX]; int Right = Cache[x + 2 + (z + 1) * UnderlyingSizeX]; - int val = Cache[x + 1 + (z + 1) * UnderlyingSizeX]; + int val = Cache[x + 1 + (z + 1) * UnderlyingSizeX]; if ((val == Above) && (val == Below) && (val == Left) && (val == Right)) { @@ -977,7 +919,7 @@ public: } // for z } -protected: + protected: Underlying m_Underlying; }; @@ -987,25 +929,19 @@ protected: /** Turns some of the oceans into the specified biome. Used for mushroom and deep ocean. The biome is only placed if at least 3 of its neighbors are ocean and only with the specified chance. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenAddToOcean: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenAddToOcean : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; static const int UnderlyingSizeX = SizeX + 2; static const int UnderlyingSizeZ = SizeZ + 2; -public: - + public: using Underlying = std::shared_ptr<cIntGen<UnderlyingSizeX, UnderlyingSizeZ>>; - cIntGenAddToOcean(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying): - Super(a_Seed), - m_Chance(a_Chance), - m_ToValue(a_ToValue), - m_Underlying(a_Underlying) + cIntGenAddToOcean(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying) : + Super(a_Seed), m_Chance(a_Chance), m_ToValue(a_ToValue), m_Underlying(a_Underlying) { } @@ -1031,7 +967,7 @@ public: // Count the ocean neighbors: int Above = Cache[x + 1 + z * UnderlyingSizeX]; int Below = Cache[x + 1 + (z + 2) * UnderlyingSizeX]; - int Left = Cache[x + (z + 1) * UnderlyingSizeX]; + int Left = Cache[x + (z + 1) * UnderlyingSizeX]; int Right = Cache[x + 2 + (z + 1) * UnderlyingSizeX]; int NumOceanNeighbors = 0; if (IsBiomeOcean(Above)) @@ -1052,10 +988,8 @@ public: } // If at least 3 ocean neighbors and the chance is right, change: - if ( - (NumOceanNeighbors >= 3) && - ((Super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7) % 1000 < m_Chance) - ) + if ((NumOceanNeighbors >= 3) && + ((Super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7) % 1000 < m_Chance)) { a_Values[x + z * SizeX] = m_ToValue; } @@ -1067,7 +1001,7 @@ public: } // for z } -protected: + protected: /** Chance, in permille, of changing the biome. */ int m_Chance; @@ -1082,22 +1016,16 @@ protected: /** Changes random pixels of the underlying data to the specified value. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenSetRandomly: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenSetRandomly : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -public: - + public: using Underlying = std::shared_ptr<cIntGen<SizeX, SizeZ>>; - cIntGenSetRandomly(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying): - Super(a_Seed), - m_Chance(a_Chance), - m_ToValue(a_ToValue), - m_Underlying(a_Underlying) + cIntGenSetRandomly(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying) : + Super(a_Seed), m_Chance(a_Chance), m_ToValue(a_ToValue), m_Underlying(a_Underlying) { } @@ -1121,7 +1049,7 @@ public: } } -protected: + protected: /** Chance, in permille, of changing each pixel. */ int m_Chance; @@ -1136,21 +1064,16 @@ protected: /** Adds a "rare" flag to random biome groups, based on the given chance. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenRareBiomeGroups: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenRareBiomeGroups : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -public: - + public: using Underlying = std::shared_ptr<cIntGen<SizeX, SizeZ>>; - cIntGenRareBiomeGroups(int a_Seed, int a_Chance, Underlying a_Underlying): - Super(a_Seed), - m_Chance(a_Chance), - m_Underlying(a_Underlying) + cIntGenRareBiomeGroups(int a_Seed, int a_Chance, Underlying a_Underlying) : + Super(a_Seed), m_Chance(a_Chance), m_Underlying(a_Underlying) { } @@ -1175,7 +1098,7 @@ public: } } -protected: + protected: /** Chance, in permille, of changing each pixel into the rare biome group. */ int m_Chance; @@ -1189,21 +1112,16 @@ protected: /** Changes biomes in the parent data into an alternate versions (usually "hill" variants), in such places that have their alterations set. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenAlternateBiomes: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenAlternateBiomes : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -public: - + public: using Underlying = std::shared_ptr<cIntGen<SizeX, SizeZ>>; - cIntGenAlternateBiomes(int a_Seed, Underlying a_Alterations, Underlying a_BaseBiomes): - Super(a_Seed), - m_Alterations(a_Alterations), - m_BaseBiomes(a_BaseBiomes) + cIntGenAlternateBiomes(int a_Seed, Underlying a_Alterations, Underlying a_BaseBiomes) : + Super(a_Seed), m_Alterations(a_Alterations), m_BaseBiomes(a_BaseBiomes) { } @@ -1229,26 +1147,26 @@ public: switch (val) { case biBirchForest: val = biBirchForestHills; break; - case biDesert: val = biDesertHills; break; + case biDesert: val = biDesertHills; break; case biExtremeHills: val = biExtremeHillsPlus; break; - case biForest: val = biForestHills; break; - case biIcePlains: val = biIceMountains; break; - case biJungle: val = biJungleHills; break; - case biMegaTaiga: val = biMegaTaigaHills; break; - case biMesaPlateau: val = biMesa; break; - case biMesaPlateauF: val = biMesa; break; - case biMesaPlateauM: val = biMesa; break; - case biMesaPlateauFM: val = biMesa; break; - case biPlains: val = biForest; break; - case biRoofedForest: val = biPlains; break; - case biSavanna: val = biSavannaPlateau; break; - case biTaiga: val = biTaigaHills; break; + case biForest: val = biForestHills; break; + case biIcePlains: val = biIceMountains; break; + case biJungle: val = biJungleHills; break; + case biMegaTaiga: val = biMegaTaigaHills; break; + case biMesaPlateau: val = biMesa; break; + case biMesaPlateauF: val = biMesa; break; + case biMesaPlateauM: val = biMesa; break; + case biMesaPlateauFM: val = biMesa; break; + case biPlains: val = biForest; break; + case biRoofedForest: val = biPlains; break; + case biSavanna: val = biSavannaPlateau; break; + case biTaiga: val = biTaigaHills; break; } a_Values[idx] = val; } // for idx - a_Values[] } -protected: + protected: Underlying m_Alterations; Underlying m_BaseBiomes; }; @@ -1258,23 +1176,19 @@ protected: /** Adds an edge between two specifically incompatible biomes, such as mesa and forest. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenBiomeEdges: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenBiomeEdges : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; static const int m_LowerSizeX = SizeX + 2; static const int m_LowerSizeZ = SizeZ + 2; -public: - + public: using Underlying = std::shared_ptr<cIntGen<m_LowerSizeX, m_LowerSizeZ>>; - cIntGenBiomeEdges(int a_Seed, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(a_Underlying) + cIntGenBiomeEdges(int a_Seed, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(a_Underlying) { } @@ -1291,9 +1205,9 @@ public: for (int x = 0; x < SizeX; x++) { int biome = lowerValues[x + 1 + (z + 1) * m_LowerSizeX]; - int above = lowerValues[x + 1 + z * m_LowerSizeX]; + int above = lowerValues[x + 1 + z * m_LowerSizeX]; int below = lowerValues[x + 1 + (z + 2) * m_LowerSizeX]; - int left = lowerValues[x + (z + 1) * m_LowerSizeX]; + int left = lowerValues[x + (z + 1) * m_LowerSizeX]; int right = lowerValues[x + 2 + (z + 1) * m_LowerSizeX]; switch (biome) @@ -1302,12 +1216,10 @@ public: case biDesertM: case biDesertHills: { - if ( - IsBiomeVeryCold(static_cast<EMCSBiome>(above)) || + if (IsBiomeVeryCold(static_cast<EMCSBiome>(above)) || IsBiomeVeryCold(static_cast<EMCSBiome>(below)) || - IsBiomeVeryCold(static_cast<EMCSBiome>(left)) || - IsBiomeVeryCold(static_cast<EMCSBiome>(right)) - ) + IsBiomeVeryCold(static_cast<EMCSBiome>(left)) || + IsBiomeVeryCold(static_cast<EMCSBiome>(right))) { biome = biPlains; } @@ -1319,12 +1231,8 @@ public: case biMesaPlateauFM: case biMesaPlateauM: { - if ( - !isMesaCompatible(above) || - !isMesaCompatible(below) || - !isMesaCompatible(left) || - !isMesaCompatible(right) - ) + if (!isMesaCompatible(above) || !isMesaCompatible(below) || !isMesaCompatible(left) || + !isMesaCompatible(right)) { biome = biDesert; } @@ -1334,12 +1242,8 @@ public: case biJungle: case biJungleM: { - if ( - !isJungleCompatible(above) || - !isJungleCompatible(below) || - !isJungleCompatible(left) || - !isJungleCompatible(right) - ) + if (!isJungleCompatible(above) || !isJungleCompatible(below) || !isJungleCompatible(left) || + !isJungleCompatible(right)) { biome = (biome == biJungle) ? biJungleEdge : biJungleEdgeM; } @@ -1349,12 +1253,10 @@ public: case biSwampland: case biSwamplandM: { - if ( - IsBiomeNoDownfall(static_cast<EMCSBiome>(above)) || + if (IsBiomeNoDownfall(static_cast<EMCSBiome>(above)) || IsBiomeNoDownfall(static_cast<EMCSBiome>(below)) || - IsBiomeNoDownfall(static_cast<EMCSBiome>(left)) || - IsBiomeNoDownfall(static_cast<EMCSBiome>(right)) - ) + IsBiomeNoDownfall(static_cast<EMCSBiome>(left)) || + IsBiomeNoDownfall(static_cast<EMCSBiome>(right))) { biome = biPlains; } @@ -1368,7 +1270,7 @@ public: } -protected: + protected: Underlying m_Underlying; @@ -1422,21 +1324,16 @@ protected: /** Changes biomes in the parent data into their alternate versions ("M" variants), in such places that have their alterations set. */ -template <int SizeX, int SizeZ = SizeX> -class cIntGenMBiomes: - public cIntGenWithNoise<SizeX, SizeZ> +template <int SizeX, int SizeZ = SizeX> class cIntGenMBiomes : public cIntGenWithNoise<SizeX, SizeZ> { using Super = cIntGenWithNoise<SizeX, SizeZ>; -public: - + public: using Underlying = std::shared_ptr<cIntGen<SizeX, SizeZ>>; - cIntGenMBiomes(int a_Seed, Underlying a_Alteration, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(a_Underlying), - m_Alteration(a_Alteration) + cIntGenMBiomes(int a_Seed, Underlying a_Alteration, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(a_Underlying), m_Alteration(a_Alteration) { } @@ -1459,31 +1356,31 @@ public: // Ice spikes biome was removed from here, because it was generated way too often switch (a_Values[idx]) { - case biPlains: a_Values[idx] = biSunflowerPlains; break; - case biDesert: a_Values[idx] = biDesertM; break; - case biExtremeHills: a_Values[idx] = biExtremeHillsM; break; - case biForest: a_Values[idx] = biFlowerForest; break; - case biTaiga: a_Values[idx] = biTaigaM; break; - case biSwampland: a_Values[idx] = biSwamplandM; break; - case biJungle: a_Values[idx] = biJungleM; break; - case biJungleEdge: a_Values[idx] = biJungleEdgeM; break; - case biBirchForest: a_Values[idx] = biBirchForestM; break; - case biBirchForestHills: a_Values[idx] = biBirchForestHillsM; break; - case biRoofedForest: a_Values[idx] = biRoofedForestM; break; - case biColdTaiga: a_Values[idx] = biColdTaigaM; break; - case biMegaSpruceTaiga: a_Values[idx] = biMegaSpruceTaiga; break; + case biPlains: a_Values[idx] = biSunflowerPlains; break; + case biDesert: a_Values[idx] = biDesertM; break; + case biExtremeHills: a_Values[idx] = biExtremeHillsM; break; + case biForest: a_Values[idx] = biFlowerForest; break; + case biTaiga: a_Values[idx] = biTaigaM; break; + case biSwampland: a_Values[idx] = biSwamplandM; break; + case biJungle: a_Values[idx] = biJungleM; break; + case biJungleEdge: a_Values[idx] = biJungleEdgeM; break; + case biBirchForest: a_Values[idx] = biBirchForestM; break; + case biBirchForestHills: a_Values[idx] = biBirchForestHillsM; break; + case biRoofedForest: a_Values[idx] = biRoofedForestM; break; + case biColdTaiga: a_Values[idx] = biColdTaigaM; break; + case biMegaSpruceTaiga: a_Values[idx] = biMegaSpruceTaiga; break; case biMegaSpruceTaigaHills: a_Values[idx] = biMegaSpruceTaigaHills; break; - case biExtremeHillsPlus: a_Values[idx] = biExtremeHillsPlusM; break; - case biSavanna: a_Values[idx] = biSavannaM; break; - case biSavannaPlateau: a_Values[idx] = biSavannaPlateauM; break; - case biMesa: a_Values[idx] = biMesaBryce; break; - case biMesaPlateauF: a_Values[idx] = biMesaPlateauFM; break; - case biMesaPlateau: a_Values[idx] = biMesaBryce; break; + case biExtremeHillsPlus: a_Values[idx] = biExtremeHillsPlusM; break; + case biSavanna: a_Values[idx] = biSavannaM; break; + case biSavannaPlateau: a_Values[idx] = biSavannaPlateauM; break; + case biMesa: a_Values[idx] = biMesaBryce; break; + case biMesaPlateauF: a_Values[idx] = biMesaPlateauFM; break; + case biMesaPlateau: a_Values[idx] = biMesaBryce; break; } } // for idx - a_Values[] / alterations[] } -protected: + protected: Underlying m_Underlying; Underlying m_Alteration; }; diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index 189b28095..265fb79d4 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -28,14 +28,14 @@ in a depth-first processing. Each of the descendants will branch randomly, if no class cMineShaft abstract { -public: + public: enum eKind { mskDirtRoom, mskCorridor, mskCrossing, mskStaircase, - } ; + }; enum eDirection @@ -44,34 +44,28 @@ public: dirZP, dirXM, dirZM, - } ; + }; cStructGenMineShafts::cMineShaftSystem & m_ParentSystem; - eKind m_Kind; + eKind m_Kind; cCuboid m_BoundingBox; cMineShaft(cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, eKind a_Kind) : - m_ParentSystem(a_ParentSystem), - m_Kind(a_Kind) + m_ParentSystem(a_ParentSystem), m_Kind(a_Kind) { } cMineShaft(cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, eKind a_Kind, const cCuboid & a_BoundingBox) : - m_ParentSystem(a_ParentSystem), - m_Kind(a_Kind), - m_BoundingBox(a_BoundingBox) + m_ParentSystem(a_ParentSystem), m_Kind(a_Kind), m_BoundingBox(a_BoundingBox) { } virtual ~cMineShaft() {} /** Returns true if this mineshaft intersects the specified cuboid */ - bool DoesIntersect(const cCuboid & a_Other) - { - return m_BoundingBox.DoesIntersect(a_Other); - } + bool DoesIntersect(const cCuboid & a_Other) { return m_BoundingBox.DoesIntersect(a_Other); } /** If recursion level is not too large, appends more branches to the parent system, using exit points specific to this class. */ @@ -79,7 +73,7 @@ public: /** Imprints this shape into the specified chunk's data */ virtual void ProcessChunk(cChunkDesc & a_ChunkDesc) = 0; -} ; +}; using cMineShafts = std::vector<cMineShaft *>; @@ -87,53 +81,57 @@ using cMineShafts = std::vector<cMineShaft *>; -class cMineShaftDirtRoom: - public cMineShaft +class cMineShaftDirtRoom : public cMineShaft { using Super = cMineShaft; -public: - + public: cMineShaftDirtRoom(cStructGenMineShafts::cMineShaftSystem & a_Parent, cNoise & a_Noise); // cMineShaft overrides: virtual void AppendBranches(int a_RecursionLevel, cNoise & a_Noise) override; virtual void ProcessChunk(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cMineShaftCorridor: - public cMineShaft +class cMineShaftCorridor : public cMineShaft { using Super = cMineShaft; -public: - + public: /** Creates a new Corridor attached to the specified pivot point and direction. Checks all ParentSystem's objects and disallows intersecting. Initializes the new object to fit. May return nullptr if cannot fit. */ static cMineShaft * CreateAndFit( cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, - int a_PivotX, int a_PivotY, int a_PivotZ, eDirection a_Direction, + int a_PivotX, + int a_PivotY, + int a_PivotZ, + eDirection a_Direction, cNoise & a_Noise ); -protected: + protected: static const int MAX_SEGMENTS = 5; - int m_NumSegments; + int m_NumSegments; eDirection m_Direction; - bool m_HasFullBeam[MAX_SEGMENTS]; ///< If true, segment at that index has a full beam support (planks in the top center block) - int m_ChestPosition; ///< If <0, no chest; otherwise an offset from m_BoundingBox's p1.x or p1.z, depenging on m_Direction - int m_SpawnerPosition; ///< If <0, no spawner; otherwise an offset from m_BoundingBox's p1.x or p1.z, depenging on m_Direction - bool m_HasTracks; ///< If true, random tracks will be placed on the floor + bool m_HasFullBeam[MAX_SEGMENTS]; ///< If true, segment at that index has a full beam support (planks in the top + ///< center block) + int m_ChestPosition; ///< If <0, no chest; otherwise an offset from m_BoundingBox's p1.x or p1.z, depenging on + ///< m_Direction + int m_SpawnerPosition; ///< If <0, no spawner; otherwise an offset from m_BoundingBox's p1.x or p1.z, depenging on + ///< m_Direction + bool m_HasTracks; ///< If true, random tracks will be placed on the floor cMineShaftCorridor( cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, - const cCuboid & a_BoundingBox, int a_NumSegments, eDirection a_Direction, + const cCuboid & a_BoundingBox, + int a_NumSegments, + eDirection a_Direction, cNoise & a_Noise ); @@ -152,52 +150,51 @@ protected: /** Randomly places torches around the central beam block */ void PlaceTorches(cChunkDesc & a_ChunkDesc); -} ; +}; -class cMineShaftCrossing: - public cMineShaft +class cMineShaftCrossing : public cMineShaft { using Super = cMineShaft; -public: - + public: /** Creates a new Crossing attached to the specified pivot point and direction. Checks all ParentSystem's objects and disallows intersecting. Initializes the new object to fit. May return nullptr if cannot fit. */ static cMineShaft * CreateAndFit( cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, - int a_PivotX, int a_PivotY, int a_PivotZ, eDirection a_Direction, + int a_PivotX, + int a_PivotY, + int a_PivotZ, + eDirection a_Direction, cNoise & a_Noise ); -protected: + protected: cMineShaftCrossing(cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, const cCuboid & a_BoundingBox); // cMineShaft overrides: virtual void AppendBranches(int a_RecursionLevel, cNoise & a_Noise) override; virtual void ProcessChunk(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cMineShaftStaircase: - public cMineShaft +class cMineShaftStaircase : public cMineShaft { using Super = cMineShaft; -public: - + public: enum eSlope { sUp, sDown, - } ; + }; /** Creates a new Staircase attached to the specified pivot point and direction. Checks all ParentSystem's objects and disallows intersecting. Initializes the new object to fit. @@ -205,13 +202,16 @@ public: */ static cMineShaft * CreateAndFit( cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, - int a_PivotX, int a_PivotY, int a_PivotZ, eDirection a_Direction, + int a_PivotX, + int a_PivotY, + int a_PivotZ, + eDirection a_Direction, cNoise & a_Noise ); -protected: + protected: eDirection m_Direction; - eSlope m_Slope; + eSlope m_Slope; cMineShaftStaircase( @@ -224,36 +224,41 @@ protected: // cMineShaft overrides: virtual void AppendBranches(int a_RecursionLevel, cNoise & a_Noise) override; virtual void ProcessChunk(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cStructGenMineShafts::cMineShaftSystem: - public cGridStructGen::cStructure +class cStructGenMineShafts::cMineShaftSystem : public cGridStructGen::cStructure { using Super = cGridStructGen::cStructure; -public: - - int m_GridSize; ///< Maximum offset of the dirtroom from grid center, * 2, in each direction - int m_MaxRecursion; ///< Maximum recursion level (initialized from cStructGenMineShafts::m_MaxRecursion) - int m_ProbLevelCorridor; ///< Probability level of a branch object being the corridor - int m_ProbLevelCrossing; ///< Probability level of a branch object being the crossing, minus Corridor - int m_ProbLevelStaircase; ///< Probability level of a branch object being the staircase, minus Crossing - int m_ChanceChest; ///< Chance [0 .. 250] that a corridor has a chest in it - int m_ChanceSpawner; ///< Chance [0 .. 250] that a corridor has a spawner in it - int m_ChanceTorch; ///< Chance [0 .. 10k] for a torch appearing attached to a corridor's beam - cMineShafts m_MineShafts; ///< List of cMineShaft descendants that comprise this system - cCuboid m_BoundingBox; ///< Bounding box into which all of the components need to fit + public: + int m_GridSize; ///< Maximum offset of the dirtroom from grid center, * 2, in each direction + int m_MaxRecursion; ///< Maximum recursion level (initialized from cStructGenMineShafts::m_MaxRecursion) + int m_ProbLevelCorridor; ///< Probability level of a branch object being the corridor + int m_ProbLevelCrossing; ///< Probability level of a branch object being the crossing, minus Corridor + int m_ProbLevelStaircase; ///< Probability level of a branch object being the staircase, minus Crossing + int m_ChanceChest; ///< Chance [0 .. 250] that a corridor has a chest in it + int m_ChanceSpawner; ///< Chance [0 .. 250] that a corridor has a spawner in it + int m_ChanceTorch; ///< Chance [0 .. 10k] for a torch appearing attached to a corridor's beam + cMineShafts m_MineShafts; ///< List of cMineShaft descendants that comprise this system + cCuboid m_BoundingBox; ///< Bounding box into which all of the components need to fit /** Creates and generates the entire system */ cMineShaftSystem( - int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, - int a_GridSize, int a_MaxSystemSize, cNoise & a_Noise, - int a_ProbLevelCorridor, int a_ProbLevelCrossing, int a_ProbLevelStaircase + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ, + int a_GridSize, + int a_MaxSystemSize, + cNoise & a_Noise, + int a_ProbLevelCorridor, + int a_ProbLevelCrossing, + int a_ProbLevelStaircase ); virtual ~cMineShaftSystem() override; @@ -262,17 +267,21 @@ public: if it fits, appends it to the list and calls its AppendBranches() */ void AppendBranch( - int a_BlockX, int a_BlockY, int a_BlockZ, - cMineShaft::eDirection a_Direction, cNoise & a_Noise, + int a_BlockX, + int a_BlockY, + int a_BlockZ, + cMineShaft::eDirection a_Direction, + cNoise & a_Noise, int a_RecursionLevel ); - /** Returns true if none of the objects in m_MineShafts intersect with the specified bounding box and the bounding box is valid */ + /** Returns true if none of the objects in m_MineShafts intersect with the specified bounding box and the bounding + * box is valid */ bool CanAppend(const cCuboid & a_BoundingBox); // cGridStructGen::cStructure overrides: virtual void DrawIntoChunk(cChunkDesc & a_Chunk) override; -} ; +}; @@ -282,9 +291,16 @@ public: // cStructGenMineShafts::cMineShaftSystem: cStructGenMineShafts::cMineShaftSystem::cMineShaftSystem( - int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, - int a_GridSize, int a_MaxSystemSize, cNoise & a_Noise, - int a_ProbLevelCorridor, int a_ProbLevelCrossing, int a_ProbLevelStaircase + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ, + int a_GridSize, + int a_MaxSystemSize, + cNoise & a_Noise, + int a_ProbLevelCorridor, + int a_ProbLevelCrossing, + int a_ProbLevelStaircase ) : Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_GridSize(a_GridSize), @@ -302,7 +318,7 @@ cStructGenMineShafts::cMineShaftSystem::cMineShaftSystem( m_MineShafts.push_back(Start); m_BoundingBox.Assign( - {Start->m_BoundingBox.p1.x - a_MaxSystemSize / 2, 2, Start->m_BoundingBox.p1.z - a_MaxSystemSize / 2}, + {Start->m_BoundingBox.p1.x - a_MaxSystemSize / 2, 2, Start->m_BoundingBox.p1.z - a_MaxSystemSize / 2}, {Start->m_BoundingBox.p2.x + a_MaxSystemSize / 2, 50, Start->m_BoundingBox.p2.z + a_MaxSystemSize / 2} ); @@ -344,8 +360,11 @@ void cStructGenMineShafts::cMineShaftSystem::DrawIntoChunk(cChunkDesc & a_Chunk) void cStructGenMineShafts::cMineShaftSystem::AppendBranch( - int a_PivotX, int a_PivotY, int a_PivotZ, - cMineShaft::eDirection a_Direction, cNoise & a_Noise, + int a_PivotX, + int a_PivotY, + int a_PivotZ, + cMineShaft::eDirection a_Direction, + cNoise & a_Noise, int a_RecursionLevel ) { @@ -435,17 +454,45 @@ void cMineShaftDirtRoom::AppendBranches(int a_RecursionLevel, cNoise & a_Noise) for (int x = m_BoundingBox.p1.x + 1; x < m_BoundingBox.p2.x; x += 4) { int rnd = a_Noise.IntNoise3DInt(x, a_RecursionLevel, m_BoundingBox.p1.z) / 7; - m_ParentSystem.AppendBranch(x, m_BoundingBox.p1.y + (rnd % Height), m_BoundingBox.p1.z - 1, dirZM, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + x, + m_BoundingBox.p1.y + (rnd % Height), + m_BoundingBox.p1.z - 1, + dirZM, + a_Noise, + a_RecursionLevel + ); rnd >>= 4; - m_ParentSystem.AppendBranch(x, m_BoundingBox.p1.y + (rnd % Height), m_BoundingBox.p2.z + 1, dirZP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + x, + m_BoundingBox.p1.y + (rnd % Height), + m_BoundingBox.p2.z + 1, + dirZP, + a_Noise, + a_RecursionLevel + ); } for (int z = m_BoundingBox.p1.z + 1; z < m_BoundingBox.p2.z; z += 4) { int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x, a_RecursionLevel, z) / 13; - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x - 1, m_BoundingBox.p1.y + (rnd % Height), z, dirXM, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x - 1, + m_BoundingBox.p1.y + (rnd % Height), + z, + dirXM, + a_Noise, + a_RecursionLevel + ); rnd >>= 4; - m_ParentSystem.AppendBranch(m_BoundingBox.p2.x + 1, m_BoundingBox.p1.y + (rnd % Height), z, dirXP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p2.x + 1, + m_BoundingBox.p1.y + (rnd % Height), + z, + dirXP, + a_Noise, + a_RecursionLevel + ); } } @@ -457,12 +504,8 @@ void cMineShaftDirtRoom::ProcessChunk(cChunkDesc & a_ChunkDesc) { int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width; int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; - if ( - (m_BoundingBox.p1.x > BlockX + cChunkDef::Width) || - (m_BoundingBox.p1.z > BlockZ + cChunkDef::Width) || - (m_BoundingBox.p2.x < BlockX) || - (m_BoundingBox.p2.z < BlockZ) - ) + if ((m_BoundingBox.p1.x > BlockX + cChunkDef::Width) || (m_BoundingBox.p1.z > BlockZ + cChunkDef::Width) || + (m_BoundingBox.p2.x < BlockX) || (m_BoundingBox.p2.z < BlockZ)) { // Early bailout - cannot intersect this chunk return; @@ -500,7 +543,9 @@ void cMineShaftDirtRoom::ProcessChunk(cChunkDesc & a_ChunkDesc) cMineShaftCorridor::cMineShaftCorridor( cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, - const cCuboid & a_BoundingBox, int a_NumSegments, eDirection a_Direction, + const cCuboid & a_BoundingBox, + int a_NumSegments, + eDirection a_Direction, cNoise & a_Noise ) : Super(a_ParentSystem, mskCorridor, a_BoundingBox), @@ -538,20 +583,40 @@ cMineShaftCorridor::cMineShaftCorridor( cMineShaft * cMineShaftCorridor::CreateAndFit( cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, - int a_PivotX, int a_PivotY, int a_PivotZ, eDirection a_Direction, + int a_PivotX, + int a_PivotY, + int a_PivotZ, + eDirection a_Direction, cNoise & a_Noise ) { cCuboid BoundingBox(a_PivotX, a_PivotY - 1, a_PivotZ); BoundingBox.p2.y += 3; - int rnd = a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + static_cast<int>(a_ParentSystem.m_MineShafts.size()), a_PivotZ) / 7; + int rnd = + a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + static_cast<int>(a_ParentSystem.m_MineShafts.size()), a_PivotZ) / 7; int NumSegments = 2 + (rnd) % (MAX_SEGMENTS - 1); // 2 .. MAX_SEGMENTS switch (a_Direction) { - case dirXP: BoundingBox.p2.x += NumSegments * 5 - 1; BoundingBox.p1.z -= 1; BoundingBox.p2.z += 1; break; - case dirXM: BoundingBox.p1.x -= NumSegments * 5 - 1; BoundingBox.p1.z -= 1; BoundingBox.p2.z += 1; break; - case dirZP: BoundingBox.p2.z += NumSegments * 5 - 1; BoundingBox.p1.x -= 1; BoundingBox.p2.x += 1; break; - case dirZM: BoundingBox.p1.z -= NumSegments * 5 - 1; BoundingBox.p1.x -= 1; BoundingBox.p2.x += 1; break; + case dirXP: + BoundingBox.p2.x += NumSegments * 5 - 1; + BoundingBox.p1.z -= 1; + BoundingBox.p2.z += 1; + break; + case dirXM: + BoundingBox.p1.x -= NumSegments * 5 - 1; + BoundingBox.p1.z -= 1; + BoundingBox.p2.z += 1; + break; + case dirZP: + BoundingBox.p2.z += NumSegments * 5 - 1; + BoundingBox.p1.x -= 1; + BoundingBox.p2.x += 1; + break; + case dirZM: + BoundingBox.p1.z -= NumSegments * 5 - 1; + BoundingBox.p1.x -= 1; + BoundingBox.p2.x += 1; + break; } if (!a_ParentSystem.CanAppend(BoundingBox)) { @@ -566,67 +631,172 @@ cMineShaft * cMineShaftCorridor::CreateAndFit( void cMineShaftCorridor::AppendBranches(int a_RecursionLevel, cNoise & a_Noise) { - int Outerrnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 7; + int Outerrnd = + a_Noise.IntNoise3DInt(m_BoundingBox.p1.x, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 7; // Prefer the same height, but allow for up to one block height displacement: int OuterHeight = m_BoundingBox.p1.y + ((Outerrnd % 4) + ((Outerrnd >> 3) % 3)) / 2; switch (m_Direction) { case dirXM: { - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x - 1, OuterHeight, m_BoundingBox.p1.z + 1, dirXM, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x - 1, + OuterHeight, + m_BoundingBox.p1.z + 1, + dirXM, + a_Noise, + a_RecursionLevel + ); for (int i = m_NumSegments; i >= 0; i--) { - int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x + i + 10, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 11; + int rnd = a_Noise.IntNoise3DInt( + m_BoundingBox.p1.x + i + 10, + m_BoundingBox.p1.y + a_RecursionLevel, + m_BoundingBox.p1.z + ) / + 11; int Height = m_BoundingBox.p1.y + ((rnd % 4) + ((rnd >> 3) % 3)) / 2; rnd >>= 6; int Ofs = 1 + rnd % (m_NumSegments * 5 - 2); - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + Ofs, Height, m_BoundingBox.p1.z - 1, dirZM, a_Noise, a_RecursionLevel); - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + Ofs, Height, m_BoundingBox.p2.z + 1, dirZP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x + Ofs, + Height, + m_BoundingBox.p1.z - 1, + dirZM, + a_Noise, + a_RecursionLevel + ); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x + Ofs, + Height, + m_BoundingBox.p2.z + 1, + dirZP, + a_Noise, + a_RecursionLevel + ); } break; } case dirXP: { - m_ParentSystem.AppendBranch(m_BoundingBox.p2.x + 1, OuterHeight, m_BoundingBox.p1.z + 1, dirXP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p2.x + 1, + OuterHeight, + m_BoundingBox.p1.z + 1, + dirXP, + a_Noise, + a_RecursionLevel + ); for (int i = m_NumSegments; i >= 0; i--) { - int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x + i + 10, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 11; + int rnd = a_Noise.IntNoise3DInt( + m_BoundingBox.p1.x + i + 10, + m_BoundingBox.p1.y + a_RecursionLevel, + m_BoundingBox.p1.z + ) / + 11; int Height = m_BoundingBox.p1.y + ((rnd % 4) + ((rnd >> 3) % 3)) / 2; rnd >>= 6; int Ofs = 1 + rnd % (m_NumSegments * 5 - 2); - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + Ofs, Height, m_BoundingBox.p1.z - 1, dirZM, a_Noise, a_RecursionLevel); - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + Ofs, Height, m_BoundingBox.p2.z + 1, dirZP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x + Ofs, + Height, + m_BoundingBox.p1.z - 1, + dirZM, + a_Noise, + a_RecursionLevel + ); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x + Ofs, + Height, + m_BoundingBox.p2.z + 1, + dirZP, + a_Noise, + a_RecursionLevel + ); } break; } case dirZM: { - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + 1, OuterHeight, m_BoundingBox.p1.z - 1, dirZM, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x + 1, + OuterHeight, + m_BoundingBox.p1.z - 1, + dirZM, + a_Noise, + a_RecursionLevel + ); for (int i = m_NumSegments; i >= 0; i--) { - int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x + i + 10, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 11; + int rnd = a_Noise.IntNoise3DInt( + m_BoundingBox.p1.x + i + 10, + m_BoundingBox.p1.y + a_RecursionLevel, + m_BoundingBox.p1.z + ) / + 11; int Height = m_BoundingBox.p1.y + ((rnd % 4) + ((rnd >> 3) % 3)) / 2; rnd >>= 6; int Ofs = 1 + rnd % (m_NumSegments * 5 - 2); - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x - 1, Height, m_BoundingBox.p1.z + Ofs, dirXM, a_Noise, a_RecursionLevel); - m_ParentSystem.AppendBranch(m_BoundingBox.p2.x + 1, Height, m_BoundingBox.p1.z + Ofs, dirXP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x - 1, + Height, + m_BoundingBox.p1.z + Ofs, + dirXM, + a_Noise, + a_RecursionLevel + ); + m_ParentSystem.AppendBranch( + m_BoundingBox.p2.x + 1, + Height, + m_BoundingBox.p1.z + Ofs, + dirXP, + a_Noise, + a_RecursionLevel + ); } break; } case dirZP: { - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + 1, OuterHeight, m_BoundingBox.p2.z + 1, dirZP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x + 1, + OuterHeight, + m_BoundingBox.p2.z + 1, + dirZP, + a_Noise, + a_RecursionLevel + ); for (int i = m_NumSegments; i >= 0; i--) { - int rnd = a_Noise.IntNoise3DInt(m_BoundingBox.p1.x + i + 10, m_BoundingBox.p1.y + a_RecursionLevel, m_BoundingBox.p1.z) / 11; + int rnd = a_Noise.IntNoise3DInt( + m_BoundingBox.p1.x + i + 10, + m_BoundingBox.p1.y + a_RecursionLevel, + m_BoundingBox.p1.z + ) / + 11; int Height = m_BoundingBox.p1.y + ((rnd % 4) + ((rnd >> 3) % 3)) / 2; rnd >>= 6; int Ofs = 1 + rnd % (m_NumSegments * 5 - 2); - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x - 1, Height, m_BoundingBox.p1.z + Ofs, dirXM, a_Noise, a_RecursionLevel); - m_ParentSystem.AppendBranch(m_BoundingBox.p2.x + 1, Height, m_BoundingBox.p1.z + Ofs, dirXP, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x - 1, + Height, + m_BoundingBox.p1.z + Ofs, + dirXM, + a_Noise, + a_RecursionLevel + ); + m_ParentSystem.AppendBranch( + m_BoundingBox.p2.x + 1, + Height, + m_BoundingBox.p1.z + Ofs, + dirXP, + a_Noise, + a_RecursionLevel + ); } break; } @@ -654,7 +824,7 @@ void cMineShaftCorridor::ProcessChunk(cChunkDesc & a_ChunkDesc) { // Cobwebs around the spider spawner a_ChunkDesc.RandomFillRelCuboid(RelBoundingBox, E_BLOCK_COBWEB, 0, (BlockX ^ (BlockZ + BlockZ)), 8000); - a_ChunkDesc.RandomFillRelCuboid(Top, E_BLOCK_COBWEB, 0, (BlockX ^ (BlockZ + BlockX)), 5000); + a_ChunkDesc.RandomFillRelCuboid(Top, E_BLOCK_COBWEB, 0, (BlockX ^ (BlockZ + BlockX)), 5000); } a_ChunkDesc.RandomFillRelCuboid(Top, E_BLOCK_COBWEB, 0, (BlockX ^ (BlockZ + BlockX + 10)), 500); RelBoundingBox.p1.y = m_BoundingBox.p1.y; @@ -745,21 +915,20 @@ void cMineShaftCorridor::ProcessChunk(cChunkDesc & a_ChunkDesc) void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc) { - static const cLootProbab LootProbab[] = - { + static const cLootProbab LootProbab[] = { // Item, MinAmount, MaxAmount, Weight - { cItem(E_ITEM_IRON), 1, 5, 10 }, - { cItem(E_ITEM_GOLD), 1, 3, 5 }, - { cItem(E_ITEM_REDSTONE_DUST), 4, 9, 5 }, - { cItem(E_ITEM_DIAMOND), 1, 2, 3 }, - { cItem(E_ITEM_DYE, 1, 4), 4, 9, 5 }, // lapis lazuli dye - { cItem(E_ITEM_COAL), 3, 8, 10 }, - { cItem(E_ITEM_BREAD), 1, 3, 15 }, - { cItem(E_ITEM_IRON_PICKAXE), 1, 1, 1 }, - { cItem(E_BLOCK_MINECART_TRACKS), 4, 8, 1 }, - { cItem(E_ITEM_MELON_SEEDS), 2, 4, 10 }, - { cItem(E_ITEM_PUMPKIN_SEEDS), 2, 4, 10 }, - } ; + {cItem(E_ITEM_IRON), 1, 5, 10}, + {cItem(E_ITEM_GOLD), 1, 3, 5}, + {cItem(E_ITEM_REDSTONE_DUST), 4, 9, 5}, + {cItem(E_ITEM_DIAMOND), 1, 2, 3}, + {cItem(E_ITEM_DYE, 1, 4), 4, 9, 5}, // lapis lazuli dye + {cItem(E_ITEM_COAL), 3, 8, 10}, + {cItem(E_ITEM_BREAD), 1, 3, 15}, + {cItem(E_ITEM_IRON_PICKAXE), 1, 1, 1}, + {cItem(E_BLOCK_MINECART_TRACKS), 4, 8, 1}, + {cItem(E_ITEM_MELON_SEEDS), 2, 4, 10}, + {cItem(E_ITEM_PUMPKIN_SEEDS), 2, 4, 10}, + }; if (m_ChestPosition < 0) { @@ -795,13 +964,11 @@ void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc) UNREACHABLE("Unsupported corridor direction"); }(); - if ( - (x >= 0) && (x < cChunkDef::Width) && - (z >= 0) && (z < cChunkDef::Width) - ) + if ((x >= 0) && (x < cChunkDef::Width) && (z >= 0) && (z < cChunkDef::Width)) { a_ChunkDesc.SetBlockTypeMeta(x, m_BoundingBox.p1.y + 1, z, E_BLOCK_CHEST, Meta); - cChestEntity * ChestEntity = static_cast<cChestEntity *>(a_ChunkDesc.GetBlockEntity(x, m_BoundingBox.p1.y + 1, z)); + cChestEntity * ChestEntity = + static_cast<cChestEntity *>(a_ChunkDesc.GetBlockEntity(x, m_BoundingBox.p1.y + 1, z)); ASSERT((ChestEntity != nullptr) && (ChestEntity->GetBlockType() == E_BLOCK_CHEST)); cNoise Noise(a_ChunkDesc.GetChunkX() ^ a_ChunkDesc.GetChunkZ()); int NumSlots = 3 + ((Noise.IntNoise3DInt(x, m_BoundingBox.p1.y, z) / 11) % 4); @@ -844,7 +1011,13 @@ void cMineShaftCorridor::PlaceTracks(cChunkDesc & a_ChunkDesc) break; } } // switch (direction) - a_ChunkDesc.RandomFillRelCuboid(Box, E_BLOCK_MINECART_TRACKS, Meta, a_ChunkDesc.GetChunkX() + a_ChunkDesc.GetChunkZ(), 6000); + a_ChunkDesc.RandomFillRelCuboid( + Box, + E_BLOCK_MINECART_TRACKS, + Meta, + a_ChunkDesc.GetChunkX() + a_ChunkDesc.GetChunkZ(), + 6000 + ); } @@ -875,13 +1048,13 @@ void cMineShaftCorridor::PlaceSpawner(cChunkDesc & a_ChunkDesc) break; } } - if ( - (SpawnerRelX >= 0) && (SpawnerRelX < cChunkDef::Width) && - (SpawnerRelZ >= 0) && (SpawnerRelZ < cChunkDef::Width) - ) + if ((SpawnerRelX >= 0) && (SpawnerRelX < cChunkDef::Width) && (SpawnerRelZ >= 0) && + (SpawnerRelZ < cChunkDef::Width)) { a_ChunkDesc.SetBlockTypeMeta(SpawnerRelX, m_BoundingBox.p1.y + 1, SpawnerRelZ, E_BLOCK_MOB_SPAWNER, 0); - cMobSpawnerEntity * MobSpawner = static_cast<cMobSpawnerEntity *>(a_ChunkDesc.GetBlockEntity(SpawnerRelX, m_BoundingBox.p1.y + 1, SpawnerRelZ)); + cMobSpawnerEntity * MobSpawner = static_cast<cMobSpawnerEntity *>( + a_ChunkDesc.GetBlockEntity(SpawnerRelX, m_BoundingBox.p1.y + 1, SpawnerRelZ) + ); ASSERT((MobSpawner != nullptr) && (MobSpawner->GetBlockType() == E_BLOCK_MOB_SPAWNER)); MobSpawner->SetEntity(mtCaveSpider); } @@ -975,7 +1148,10 @@ void cMineShaftCorridor::PlaceTorches(cChunkDesc & a_ChunkDesc) //////////////////////////////////////////////////////////////////////////////// // cMineShaftCrossing: -cMineShaftCrossing::cMineShaftCrossing(cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, const cCuboid & a_BoundingBox) : +cMineShaftCrossing::cMineShaftCrossing( + cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, + const cCuboid & a_BoundingBox +) : Super(a_ParentSystem, mskCrossing, a_BoundingBox) { } @@ -986,12 +1162,16 @@ cMineShaftCrossing::cMineShaftCrossing(cStructGenMineShafts::cMineShaftSystem & cMineShaft * cMineShaftCrossing::CreateAndFit( cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, - int a_PivotX, int a_PivotY, int a_PivotZ, eDirection a_Direction, + int a_PivotX, + int a_PivotY, + int a_PivotZ, + eDirection a_Direction, cNoise & a_Noise ) { cCuboid BoundingBox(a_PivotX, a_PivotY - 1, a_PivotZ); - int rnd = a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + static_cast<int>(a_ParentSystem.m_MineShafts.size()), a_PivotZ) / 7; + int rnd = + a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + static_cast<int>(a_ParentSystem.m_MineShafts.size()), a_PivotZ) / 7; BoundingBox.p2.y += 3; if ((rnd % 4) < 2) { @@ -1007,10 +1187,26 @@ cMineShaft * cMineShaftCrossing::CreateAndFit( } switch (a_Direction) { - case dirXP: BoundingBox.p2.x += 4; BoundingBox.p1.z -= 2; BoundingBox.p2.z += 2; break; - case dirXM: BoundingBox.p1.x -= 4; BoundingBox.p1.z -= 2; BoundingBox.p2.z += 2; break; - case dirZP: BoundingBox.p2.z += 4; BoundingBox.p1.x -= 2; BoundingBox.p2.x += 2; break; - case dirZM: BoundingBox.p1.z -= 4; BoundingBox.p1.x -= 2; BoundingBox.p2.x += 2; break; + case dirXP: + BoundingBox.p2.x += 4; + BoundingBox.p1.z -= 2; + BoundingBox.p2.z += 2; + break; + case dirXM: + BoundingBox.p1.x -= 4; + BoundingBox.p1.z -= 2; + BoundingBox.p2.z += 2; + break; + case dirZP: + BoundingBox.p2.z += 4; + BoundingBox.p1.x -= 2; + BoundingBox.p2.x += 2; + break; + case dirZM: + BoundingBox.p1.z -= 4; + BoundingBox.p1.x -= 2; + BoundingBox.p2.x += 2; + break; } if (!a_ParentSystem.CanAppend(BoundingBox)) { @@ -1029,19 +1225,18 @@ void cMineShaftCrossing::AppendBranches(int a_RecursionLevel, cNoise & a_Noise) { int x, y, z; eDirection dir; - } Exits[] = - { + } Exits[] = { // Bottom level: - {-1, 1, 2, dirXM}, - { 2, 1, -1, dirZM}, - { 5, 1, 2, dirXP}, - { 2, 1, 5, dirZP}, + {-1, 1, 2, dirXM}, + {2, 1, -1, dirZM}, + {5, 1, 2, dirXP}, + {2, 1, 5, dirZP}, // Top level: - {-1, 5, 2, dirXM}, - { 2, 5, -1, dirZM}, - { 5, 5, 2, dirXP}, - { 2, 5, 5, dirZP}, - } ; + {-1, 5, 2, dirXM}, + {2, 5, -1, dirZM}, + {5, 5, 2, dirXP}, + {2, 5, 5, dirZP}, + }; for (size_t i = 0; i < ARRAYCOUNT(Exits); i++) { if (m_BoundingBox.p1.y + Exits[i].y >= m_BoundingBox.p2.y) @@ -1051,7 +1246,14 @@ void cMineShaftCrossing::AppendBranches(int a_RecursionLevel, cNoise & a_Noise) } int Height = m_BoundingBox.p1.y + Exits[i].y; - m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + Exits[i].x, Height, m_BoundingBox.p1.z + Exits[i].z, Exits[i].dir, a_Noise, a_RecursionLevel); + m_ParentSystem.AppendBranch( + m_BoundingBox.p1.x + Exits[i].x, + Height, + m_BoundingBox.p1.z + Exits[i].z, + Exits[i].dir, + a_Noise, + a_RecursionLevel + ); } // for i } @@ -1085,17 +1287,17 @@ void cMineShaftCrossing::ProcessChunk(cChunkDesc & a_ChunkDesc) // The air on the edges: int Mid = Floor + 2; - a_ChunkDesc.FillRelCuboid(box.p1.x, box.p1.x, Floor, Mid, box.p1.z + 1, box.p2.z - 1, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid(box.p2.x, box.p2.x, Floor, Mid, box.p1.z + 1, box.p2.z - 1, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Floor, Mid, box.p1.z, box.p1.z, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Floor, Mid, box.p2.z, box.p2.z, E_BLOCK_AIR, 0); + a_ChunkDesc.FillRelCuboid(box.p1.x, box.p1.x, Floor, Mid, box.p1.z + 1, box.p2.z - 1, E_BLOCK_AIR, 0); + a_ChunkDesc.FillRelCuboid(box.p2.x, box.p2.x, Floor, Mid, box.p1.z + 1, box.p2.z - 1, E_BLOCK_AIR, 0); + a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Floor, Mid, box.p1.z, box.p1.z, E_BLOCK_AIR, 0); + a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Floor, Mid, box.p2.z, box.p2.z, E_BLOCK_AIR, 0); Mid += 2; if (Mid < Ceil) { - a_ChunkDesc.FillRelCuboid(box.p1.x, box.p1.x, Mid, Ceil, box.p1.z + 1, box.p2.z - 1, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid(box.p2.x, box.p2.x, Mid, Ceil, box.p1.z + 1, box.p2.z - 1, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Mid, Ceil, box.p1.z, box.p1.z, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Mid, Ceil, box.p2.z, box.p2.z, E_BLOCK_AIR, 0); + a_ChunkDesc.FillRelCuboid(box.p1.x, box.p1.x, Mid, Ceil, box.p1.z + 1, box.p2.z - 1, E_BLOCK_AIR, 0); + a_ChunkDesc.FillRelCuboid(box.p2.x, box.p2.x, Mid, Ceil, box.p1.z + 1, box.p2.z - 1, E_BLOCK_AIR, 0); + a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Mid, Ceil, box.p1.z, box.p1.z, E_BLOCK_AIR, 0); + a_ChunkDesc.FillRelCuboid(box.p1.x + 1, box.p2.x - 1, Mid, Ceil, box.p2.z, box.p2.z, E_BLOCK_AIR, 0); } // The floor, if needed: @@ -1116,9 +1318,7 @@ cMineShaftStaircase::cMineShaftStaircase( eDirection a_Direction, eSlope a_Slope ) : - Super(a_ParentSystem, mskStaircase, a_BoundingBox), - m_Direction(a_Direction), - m_Slope(a_Slope) + Super(a_ParentSystem, mskStaircase, a_BoundingBox), m_Direction(a_Direction), m_Slope(a_Slope) { } @@ -1128,11 +1328,15 @@ cMineShaftStaircase::cMineShaftStaircase( cMineShaft * cMineShaftStaircase::CreateAndFit( cStructGenMineShafts::cMineShaftSystem & a_ParentSystem, - int a_PivotX, int a_PivotY, int a_PivotZ, eDirection a_Direction, + int a_PivotX, + int a_PivotY, + int a_PivotZ, + eDirection a_Direction, cNoise & a_Noise ) { - int rnd = a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + static_cast<int>(a_ParentSystem.m_MineShafts.size()), a_PivotZ) / 7; + int rnd = + a_Noise.IntNoise3DInt(a_PivotX, a_PivotY + static_cast<int>(a_ParentSystem.m_MineShafts.size()), a_PivotZ) / 7; cCuboid Box; switch (a_Direction) { @@ -1179,10 +1383,22 @@ void cMineShaftStaircase::AppendBranches(int a_RecursionLevel, cNoise & a_Noise) int Height = m_BoundingBox.p1.y + ((m_Slope == sDown) ? 1 : 5); switch (m_Direction) { - case dirXM: m_ParentSystem.AppendBranch(m_BoundingBox.p1.x - 1, Height, m_BoundingBox.p1.z + 1, dirXM, a_Noise, a_RecursionLevel); break; - case dirXP: m_ParentSystem.AppendBranch(m_BoundingBox.p2.x + 1, Height, m_BoundingBox.p1.z + 1, dirXP, a_Noise, a_RecursionLevel); break; - case dirZM: m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + 1, Height, m_BoundingBox.p1.z - 1, dirZM, a_Noise, a_RecursionLevel); break; - case dirZP: m_ParentSystem.AppendBranch(m_BoundingBox.p1.x + 1, Height, m_BoundingBox.p2.z + 1, dirZP, a_Noise, a_RecursionLevel); break; + case dirXM: + m_ParentSystem + .AppendBranch(m_BoundingBox.p1.x - 1, Height, m_BoundingBox.p1.z + 1, dirXM, a_Noise, a_RecursionLevel); + break; + case dirXP: + m_ParentSystem + .AppendBranch(m_BoundingBox.p2.x + 1, Height, m_BoundingBox.p1.z + 1, dirXP, a_Noise, a_RecursionLevel); + break; + case dirZM: + m_ParentSystem + .AppendBranch(m_BoundingBox.p1.x + 1, Height, m_BoundingBox.p1.z - 1, dirZM, a_Noise, a_RecursionLevel); + break; + case dirZP: + m_ParentSystem + .AppendBranch(m_BoundingBox.p1.x + 1, Height, m_BoundingBox.p2.z + 1, dirZP, a_Noise, a_RecursionLevel); + break; } } @@ -1196,12 +1412,7 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; cCuboid RelB(m_BoundingBox); RelB.Move({-BlockX, 0, -BlockZ}); - if ( - (RelB.p1.x >= cChunkDef::Width) || - (RelB.p1.z >= cChunkDef::Width) || - (RelB.p2.x < 0) || - (RelB.p2.z < 0) - ) + if ((RelB.p1.x >= cChunkDef::Width) || (RelB.p1.z >= cChunkDef::Width) || (RelB.p2.x < 0) || (RelB.p2.z < 0)) { // No intersection between this staircase and this chunk return; @@ -1216,15 +1427,44 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) { case dirXM: { - a_ChunkDesc.FillRelCuboid (RelB.p2.x - 1, RelB.p2.x, SFloor, SFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p1.x + 1, DFloor, DFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); - a_ChunkDesc.FloorRelCuboid(RelB.p2.x - 1, RelB.p2.x, SFloor - 1, SFloor - 1, RelB.p1.z, RelB.p2.z, E_BLOCK_PLANKS, 0); - a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p1.x + 1, DFloor - 1, DFloor - 1, RelB.p1.z, RelB.p2.z, E_BLOCK_PLANKS, 0); + a_ChunkDesc + .FillRelCuboid(RelB.p2.x - 1, RelB.p2.x, SFloor, SFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); + a_ChunkDesc + .FillRelCuboid(RelB.p1.x, RelB.p1.x + 1, DFloor, DFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); + a_ChunkDesc.FloorRelCuboid( + RelB.p2.x - 1, + RelB.p2.x, + SFloor - 1, + SFloor - 1, + RelB.p1.z, + RelB.p2.z, + E_BLOCK_PLANKS, + 0 + ); + a_ChunkDesc.FloorRelCuboid( + RelB.p1.x, + RelB.p1.x + 1, + DFloor - 1, + DFloor - 1, + RelB.p1.z, + RelB.p2.z, + E_BLOCK_PLANKS, + 0 + ); Box.Assign({RelB.p2.x - 2, SFloor + InitAdd, RelB.p1.z}, {RelB.p2.x - 2, SFloor + 3 + InitAdd, RelB.p2.z}); for (int i = 0; i < 4; i++) { a_ChunkDesc.FillRelCuboid(Box, E_BLOCK_AIR, 0); - a_ChunkDesc.FloorRelCuboid(Box.p1.x, Box.p2.x, Box.p1.y - 1, Box.p1.y - 1, Box.p1.z, Box.p2.z, E_BLOCK_PLANKS, 0); + a_ChunkDesc.FloorRelCuboid( + Box.p1.x, + Box.p2.x, + Box.p1.y - 1, + Box.p1.y - 1, + Box.p1.z, + Box.p2.z, + E_BLOCK_PLANKS, + 0 + ); Box.Move({-1, Add, 0}); } break; @@ -1232,15 +1472,44 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) case dirXP: { - a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p1.x + 1, SFloor, SFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid (RelB.p2.x - 1, RelB.p2.x, DFloor, DFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); - a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p1.x + 1, SFloor - 1, SFloor - 1, RelB.p1.z, RelB.p2.z, E_BLOCK_PLANKS, 0); - a_ChunkDesc.FloorRelCuboid(RelB.p2.x - 1, RelB.p2.x, DFloor - 1, DFloor - 1, RelB.p1.z, RelB.p2.z, E_BLOCK_PLANKS, 0); + a_ChunkDesc + .FillRelCuboid(RelB.p1.x, RelB.p1.x + 1, SFloor, SFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); + a_ChunkDesc + .FillRelCuboid(RelB.p2.x - 1, RelB.p2.x, DFloor, DFloor + 2, RelB.p1.z, RelB.p2.z, E_BLOCK_AIR, 0); + a_ChunkDesc.FloorRelCuboid( + RelB.p1.x, + RelB.p1.x + 1, + SFloor - 1, + SFloor - 1, + RelB.p1.z, + RelB.p2.z, + E_BLOCK_PLANKS, + 0 + ); + a_ChunkDesc.FloorRelCuboid( + RelB.p2.x - 1, + RelB.p2.x, + DFloor - 1, + DFloor - 1, + RelB.p1.z, + RelB.p2.z, + E_BLOCK_PLANKS, + 0 + ); Box.Assign({RelB.p1.x + 2, SFloor + InitAdd, RelB.p1.z}, {RelB.p1.x + 2, SFloor + 3 + InitAdd, RelB.p2.z}); for (int i = 0; i < 4; i++) { a_ChunkDesc.FillRelCuboid(Box, E_BLOCK_AIR, 0); - a_ChunkDesc.FloorRelCuboid(Box.p1.x, Box.p2.x, Box.p1.y - 1, Box.p1.y - 1, Box.p1.z, Box.p2.z, E_BLOCK_PLANKS, 0); + a_ChunkDesc.FloorRelCuboid( + Box.p1.x, + Box.p2.x, + Box.p1.y - 1, + Box.p1.y - 1, + Box.p1.z, + Box.p2.z, + E_BLOCK_PLANKS, + 0 + ); Box.Move({1, Add, 0}); } break; @@ -1248,15 +1517,44 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) case dirZM: { - a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p2.x, SFloor, SFloor + 2, RelB.p2.z - 1, RelB.p2.z, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p2.x, DFloor, DFloor + 2, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_AIR, 0); - a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p2.x, SFloor - 1, SFloor - 1, RelB.p2.z - 1, RelB.p2.z, E_BLOCK_PLANKS, 0); - a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p2.x, DFloor - 1, DFloor - 1, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_PLANKS, 0); + a_ChunkDesc + .FillRelCuboid(RelB.p1.x, RelB.p2.x, SFloor, SFloor + 2, RelB.p2.z - 1, RelB.p2.z, E_BLOCK_AIR, 0); + a_ChunkDesc + .FillRelCuboid(RelB.p1.x, RelB.p2.x, DFloor, DFloor + 2, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_AIR, 0); + a_ChunkDesc.FloorRelCuboid( + RelB.p1.x, + RelB.p2.x, + SFloor - 1, + SFloor - 1, + RelB.p2.z - 1, + RelB.p2.z, + E_BLOCK_PLANKS, + 0 + ); + a_ChunkDesc.FloorRelCuboid( + RelB.p1.x, + RelB.p2.x, + DFloor - 1, + DFloor - 1, + RelB.p1.z, + RelB.p1.z + 1, + E_BLOCK_PLANKS, + 0 + ); Box.Assign({RelB.p1.x, SFloor + InitAdd, RelB.p2.z - 2}, {RelB.p2.x, SFloor + 3 + InitAdd, RelB.p2.z - 2}); for (int i = 0; i < 4; i++) { a_ChunkDesc.FillRelCuboid(Box, E_BLOCK_AIR, 0); - a_ChunkDesc.FloorRelCuboid(Box.p1.x, Box.p2.x, Box.p1.y - 1, Box.p1.y - 1, Box.p1.z, Box.p2.z, E_BLOCK_PLANKS, 0); + a_ChunkDesc.FloorRelCuboid( + Box.p1.x, + Box.p2.x, + Box.p1.y - 1, + Box.p1.y - 1, + Box.p1.z, + Box.p2.z, + E_BLOCK_PLANKS, + 0 + ); Box.Move({0, Add, -1}); } break; @@ -1264,15 +1562,44 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) case dirZP: { - a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p2.x, SFloor, SFloor + 2, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_AIR, 0); - a_ChunkDesc.FillRelCuboid (RelB.p1.x, RelB.p2.x, DFloor, DFloor + 2, RelB.p2.z - 1, RelB.p2.z, E_BLOCK_AIR, 0); - a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p2.x, SFloor - 1, SFloor - 1, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_PLANKS, 0); - a_ChunkDesc.FloorRelCuboid(RelB.p1.x, RelB.p2.x, DFloor - 1, DFloor - 1, RelB.p2.z - 1, RelB.p2.z, E_BLOCK_PLANKS, 0); + a_ChunkDesc + .FillRelCuboid(RelB.p1.x, RelB.p2.x, SFloor, SFloor + 2, RelB.p1.z, RelB.p1.z + 1, E_BLOCK_AIR, 0); + a_ChunkDesc + .FillRelCuboid(RelB.p1.x, RelB.p2.x, DFloor, DFloor + 2, RelB.p2.z - 1, RelB.p2.z, E_BLOCK_AIR, 0); + a_ChunkDesc.FloorRelCuboid( + RelB.p1.x, + RelB.p2.x, + SFloor - 1, + SFloor - 1, + RelB.p1.z, + RelB.p1.z + 1, + E_BLOCK_PLANKS, + 0 + ); + a_ChunkDesc.FloorRelCuboid( + RelB.p1.x, + RelB.p2.x, + DFloor - 1, + DFloor - 1, + RelB.p2.z - 1, + RelB.p2.z, + E_BLOCK_PLANKS, + 0 + ); Box.Assign({RelB.p1.x, SFloor + InitAdd, RelB.p1.z + 2}, {RelB.p2.x, SFloor + 3 + InitAdd, RelB.p1.z + 2}); for (int i = 0; i < 4; i++) { a_ChunkDesc.FillRelCuboid(Box, E_BLOCK_AIR, 0); - a_ChunkDesc.FloorRelCuboid(Box.p1.x, Box.p2.x, Box.p1.y - 1, Box.p1.y - 1, Box.p1.z, Box.p2.z, E_BLOCK_PLANKS, 0); + a_ChunkDesc.FloorRelCuboid( + Box.p1.x, + Box.p2.x, + Box.p1.y - 1, + Box.p1.y - 1, + Box.p1.z, + Box.p2.z, + E_BLOCK_PLANKS, + 0 + ); Box.Move({0, Add, 1}); } break; @@ -1289,8 +1616,13 @@ void cMineShaftStaircase::ProcessChunk(cChunkDesc & a_ChunkDesc) // cStructGenMineShafts: cStructGenMineShafts::cStructGenMineShafts( - int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxSystemSize, - int a_ChanceCorridor, int a_ChanceCrossing, int a_ChanceStaircase + int a_Seed, + int a_GridSize, + int a_MaxOffset, + int a_MaxSystemSize, + int a_ChanceCorridor, + int a_ChanceCrossing, + int a_ChanceStaircase ) : Super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSystemSize, a_MaxSystemSize, 100), m_GridSize(a_GridSize), @@ -1305,11 +1637,23 @@ cStructGenMineShafts::cStructGenMineShafts( -cGridStructGen::cStructurePtr cStructGenMineShafts::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) +cGridStructGen::cStructurePtr cStructGenMineShafts::CreateStructure( + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ +) { - return cStructurePtr(new cMineShaftSystem(a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_GridSize, m_MaxSystemSize, m_Noise, m_ProbLevelCorridor, m_ProbLevelCrossing, m_ProbLevelStaircase)); + return cStructurePtr(new cMineShaftSystem( + a_GridX, + a_GridZ, + a_OriginX, + a_OriginZ, + m_GridSize, + m_MaxSystemSize, + m_Noise, + m_ProbLevelCorridor, + m_ProbLevelCrossing, + m_ProbLevelStaircase + )); } - - - - diff --git a/src/Generating/MineShafts.h b/src/Generating/MineShafts.h index 43eff2055..e3f6595a2 100644 --- a/src/Generating/MineShafts.h +++ b/src/Generating/MineShafts.h @@ -15,18 +15,22 @@ -class cStructGenMineShafts : - public cGridStructGen +class cStructGenMineShafts : public cGridStructGen { typedef cGridStructGen Super; -public: + public: cStructGenMineShafts( - int a_Seed, int a_GridSize, int a_MaxOffset, int a_MaxSystemSize, - int a_ChanceCorridor, int a_ChanceCrossing, int a_ChanceStaircase + int a_Seed, + int a_GridSize, + int a_MaxOffset, + int a_MaxSystemSize, + int a_ChanceCorridor, + int a_ChanceCrossing, + int a_ChanceStaircase ); -protected: + protected: friend class cMineShaft; friend class cMineShaftDirtRoom; friend class cMineShaftCorridor; @@ -34,16 +38,12 @@ protected: friend class cMineShaftStaircase; class cMineShaftSystem; // fwd: MineShafts.cpp - int m_GridSize; ///< Average spacing of the systems - int m_MaxSystemSize; ///< Maximum blcok size of a mineshaft system - int m_ProbLevelCorridor; ///< Probability level of a branch object being the corridor - int m_ProbLevelCrossing; ///< Probability level of a branch object being the crossing, minus Corridor - int m_ProbLevelStaircase; ///< Probability level of a branch object being the staircase, minus Crossing + int m_GridSize; ///< Average spacing of the systems + int m_MaxSystemSize; ///< Maximum blcok size of a mineshaft system + int m_ProbLevelCorridor; ///< Probability level of a branch object being the corridor + int m_ProbLevelCrossing; ///< Probability level of a branch object being the crossing, minus Corridor + int m_ProbLevelStaircase; ///< Probability level of a branch object being the staircase, minus Crossing // cGridStructGen overrides: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; -} ; - - - - +}; diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp index ecf135a26..2882d147e 100644 --- a/src/Generating/Noise3DGenerator.cpp +++ b/src/Generating/Noise3DGenerator.cpp @@ -148,21 +148,19 @@ public: //////////////////////////////////////////////////////////////////////////////// // cNoise3DGenerator: -cNoise3DGenerator::cNoise3DGenerator(): - Super(), - m_Perlin(1000), - m_Cubic(1000) +cNoise3DGenerator::cNoise3DGenerator() : + Super(), m_Perlin(1000), m_Cubic(1000) { - m_Perlin.AddOctave(1, 1); - m_Perlin.AddOctave(2, 0.5); - m_Perlin.AddOctave(4, 0.25); - m_Perlin.AddOctave(8, 0.125); + m_Perlin.AddOctave(1, 1); + m_Perlin.AddOctave(2, 0.5); + m_Perlin.AddOctave(4, 0.25); + m_Perlin.AddOctave(8, 0.125); m_Perlin.AddOctave(16, 0.0625); - m_Cubic.AddOctave(1, 1); - m_Cubic.AddOctave(2, 0.5); - m_Cubic.AddOctave(4, 0.25); - m_Cubic.AddOctave(8, 0.125); + m_Cubic.AddOctave(1, 1); + m_Cubic.AddOctave(2, 0.5); + m_Cubic.AddOctave(4, 0.25); + m_Cubic.AddOctave(8, 0.125); m_Cubic.AddOctave(16, 0.0625); } @@ -182,13 +180,14 @@ cNoise3DGenerator::~cNoise3DGenerator() void cNoise3DGenerator::Initialize(cIniFile & a_IniFile) { // Params: - m_SeaLevel = a_IniFile.GetValueSetI("Generator", "SeaLevel", 62); - m_HeightAmplification = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DHeightAmplification", 0.1)); - m_MidPoint = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DMidPoint", 68)); - m_FrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyX", 8)); - m_FrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyY", 8)); - m_FrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyZ", 8)); - m_AirThreshold = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DAirThreshold", 0.5)); + m_SeaLevel = a_IniFile.GetValueSetI("Generator", "SeaLevel", 62); + m_HeightAmplification = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DHeightAmplification", 0.1)); + m_MidPoint = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DMidPoint", 68)); + m_FrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyX", 8)); + m_FrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyY", 8)); + m_FrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyZ", 8)); + m_AirThreshold = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DAirThreshold", 0.5)); } @@ -237,7 +236,7 @@ void cNoise3DGenerator::Generate(cChunkDesc & a_ChunkDesc) } a_ChunkDesc.UpdateHeightmap(); - ComposeTerrain (a_ChunkDesc); + ComposeTerrain(a_ChunkDesc); } @@ -250,12 +249,12 @@ void cNoise3DGenerator::GenerateNoiseArray(cChunkCoords a_ChunkCoords, NOISE_DAT NOISE_DATATYPE NoiseW[DIM_X * DIM_Y * DIM_Z]; // Workspace that the noise calculation can use and trash // Our noise array has different layout, XZY, instead of regular chunk's XYZ, that's why the coords are "renamed" - NOISE_DATATYPE StartX = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkX * cChunkDef::Width) / m_FrequencyX; - NOISE_DATATYPE EndX = static_cast<NOISE_DATATYPE>((a_ChunkCoords.m_ChunkX + 1) * cChunkDef::Width) / m_FrequencyX; - NOISE_DATATYPE StartZ = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width) / m_FrequencyZ; - NOISE_DATATYPE EndZ = static_cast<NOISE_DATATYPE>((a_ChunkCoords.m_ChunkZ + 1) * cChunkDef::Width) / m_FrequencyZ; + NOISE_DATATYPE StartX = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkX * cChunkDef::Width) / m_FrequencyX; + NOISE_DATATYPE EndX = static_cast<NOISE_DATATYPE>((a_ChunkCoords.m_ChunkX + 1) * cChunkDef::Width) / m_FrequencyX; + NOISE_DATATYPE StartZ = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width) / m_FrequencyZ; + NOISE_DATATYPE EndZ = static_cast<NOISE_DATATYPE>((a_ChunkCoords.m_ChunkZ + 1) * cChunkDef::Width) / m_FrequencyZ; NOISE_DATATYPE StartY = 0; - NOISE_DATATYPE EndY = static_cast<NOISE_DATATYPE>(256) / m_FrequencyY; + NOISE_DATATYPE EndY = static_cast<NOISE_DATATYPE>(256) / m_FrequencyY; m_Perlin.Generate3D(NoiseO, DIM_X, DIM_Y, DIM_Z, StartX, EndX, StartY, EndY, StartZ, EndZ, NoiseW); @@ -283,10 +282,7 @@ void cNoise3DGenerator::GenerateNoiseArray(cChunkCoords a_ChunkCoords, NOISE_DAT } // Upscale the Perlin noise into full-blown chunk dimensions: - LinearUpscale3DArray( - NoiseO, DIM_X, DIM_Y, DIM_Z, - a_OutNoise, UPSCALE_X, UPSCALE_Y, UPSCALE_Z - ); + LinearUpscale3DArray(NoiseO, DIM_X, DIM_Y, DIM_Z, a_OutNoise, UPSCALE_X, UPSCALE_Y, UPSCALE_Z); } @@ -375,21 +371,26 @@ void cNoise3DComposable::Initialize(cIniFile & a_IniFile) { // Params: // The defaults generate extreme hills terrain - m_HeightAmplification = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DHeightAmplification", 0.045)); - m_MidPoint = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DMidPoint", 75)); - m_FrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyX", 40)); - m_FrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyY", 40)); - m_FrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyZ", 40)); - m_BaseFrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DBaseFrequencyX", 40)); - m_BaseFrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DBaseFrequencyZ", 40)); - m_ChoiceFrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DChoiceFrequencyX", 40)); - m_ChoiceFrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DChoiceFrequencyY", 80)); - m_ChoiceFrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DChoiceFrequencyZ", 40)); - m_AirThreshold = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DAirThreshold", 0)); - int NumChoiceOctaves = a_IniFile.GetValueSetI("Generator", "Noise3DNumChoiceOctaves", 4); + m_HeightAmplification = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DHeightAmplification", 0.045)); + m_MidPoint = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DMidPoint", 75)); + m_FrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyX", 40)); + m_FrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyY", 40)); + m_FrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyZ", 40)); + m_BaseFrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DBaseFrequencyX", 40)); + m_BaseFrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DBaseFrequencyZ", 40)); + m_ChoiceFrequencyX = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DChoiceFrequencyX", 40)); + m_ChoiceFrequencyY = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DChoiceFrequencyY", 80)); + m_ChoiceFrequencyZ = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DChoiceFrequencyZ", 40)); + m_AirThreshold = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DAirThreshold", 0)); + int NumChoiceOctaves = a_IniFile.GetValueSetI("Generator", "Noise3DNumChoiceOctaves", 4); int NumDensityOctaves = a_IniFile.GetValueSetI("Generator", "Noise3DNumDensityOctaves", 6); - int NumBaseOctaves = a_IniFile.GetValueSetI("Generator", "Noise3DNumBaseOctaves", 6); - NOISE_DATATYPE BaseNoiseAmplitude = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DBaseAmplitude", 1)); + int NumBaseOctaves = a_IniFile.GetValueSetI("Generator", "Noise3DNumBaseOctaves", 6); + NOISE_DATATYPE BaseNoiseAmplitude = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "Noise3DBaseAmplitude", 1)); // Add octaves for the choice noise: NOISE_DATATYPE wavlen = 1, ampl = 0.5; @@ -401,7 +402,8 @@ void cNoise3DComposable::Initialize(cIniFile & a_IniFile) } // Add octaves for the density noises: - wavlen = 1; ampl = 1; + wavlen = 1; + ampl = 1; for (int i = 0; i < NumDensityOctaves; i++) { m_DensityNoiseA.AddOctave(wavlen, ampl); @@ -411,7 +413,8 @@ void cNoise3DComposable::Initialize(cIniFile & a_IniFile) } // Add octaves for the base noise: - wavlen = 1; ampl = BaseNoiseAmplitude; + wavlen = 1; + ampl = BaseNoiseAmplitude; for (int i = 0; i < NumBaseOctaves; i++) { m_BaseNoise.AddOctave(wavlen, ampl); @@ -441,11 +444,57 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords) NOISE_DATATYPE BaseNoise[5 * 5]; NOISE_DATATYPE BlockX = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkX * cChunkDef::Width); NOISE_DATATYPE BlockZ = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width); - // Note that we have to swap the X and Y coords, because noise generator uses [x + SizeX * y + SizeX * SizeY * z] ordering and we want "BlockY" to be "x": - m_ChoiceNoise.Generate3D (ChoiceNoise, 33, 5, 5, 0, 257 / m_ChoiceFrequencyY, BlockX / m_ChoiceFrequencyX, (BlockX + 17) / m_ChoiceFrequencyX, BlockZ / m_ChoiceFrequencyZ, (BlockZ + 17) / m_ChoiceFrequencyZ, Workspace); - m_DensityNoiseA.Generate3D(DensityNoiseA, 33, 5, 5, 0, 257 / m_FrequencyY, BlockX / m_FrequencyX, (BlockX + 17) / m_FrequencyX, BlockZ / m_FrequencyZ, (BlockZ + 17) / m_FrequencyZ, Workspace); - m_DensityNoiseB.Generate3D(DensityNoiseB, 33, 5, 5, 0, 257 / m_FrequencyY, BlockX / m_FrequencyX, (BlockX + 17) / m_FrequencyX, BlockZ / m_FrequencyZ, (BlockZ + 17) / m_FrequencyZ, Workspace); - m_BaseNoise.Generate2D (BaseNoise, 5, 5, BlockX / m_BaseFrequencyX, (BlockX + 17) / m_BaseFrequencyX, BlockZ / m_FrequencyZ, (BlockZ + 17) / m_FrequencyZ, Workspace); + // Note that we have to swap the X and Y coords, because noise generator uses [x + SizeX * y + SizeX * SizeY * z] + // ordering and we want "BlockY" to be "x": + m_ChoiceNoise.Generate3D( + ChoiceNoise, + 33, + 5, + 5, + 0, + 257 / m_ChoiceFrequencyY, + BlockX / m_ChoiceFrequencyX, + (BlockX + 17) / m_ChoiceFrequencyX, + BlockZ / m_ChoiceFrequencyZ, + (BlockZ + 17) / m_ChoiceFrequencyZ, + Workspace + ); + m_DensityNoiseA.Generate3D( + DensityNoiseA, + 33, + 5, + 5, + 0, + 257 / m_FrequencyY, + BlockX / m_FrequencyX, + (BlockX + 17) / m_FrequencyX, + BlockZ / m_FrequencyZ, + (BlockZ + 17) / m_FrequencyZ, + Workspace + ); + m_DensityNoiseB.Generate3D( + DensityNoiseB, + 33, + 5, + 5, + 0, + 257 / m_FrequencyY, + BlockX / m_FrequencyX, + (BlockX + 17) / m_FrequencyX, + BlockZ / m_FrequencyZ, + (BlockZ + 17) / m_FrequencyZ, + Workspace + ); + m_BaseNoise.Generate2D( + BaseNoise, + 5, + 5, + BlockX / m_BaseFrequencyX, + (BlockX + 17) / m_BaseFrequencyX, + BlockZ / m_FrequencyZ, + (BlockZ + 17) / m_FrequencyZ, + Workspace + ); // Calculate the final noise based on the partial noises: for (int z = 0; z < 5; z++) @@ -457,7 +506,8 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords) { NOISE_DATATYPE AddHeight = (static_cast<NOISE_DATATYPE>(y * 8) - m_MidPoint) * m_HeightAmplification; - // If "underground", make the terrain smoother by forcing the vertical linear gradient into steeper slope: + // If "underground", make the terrain smoother by forcing the vertical linear gradient into steeper + // slope: if (AddHeight < 0) { AddHeight *= 4; @@ -471,7 +521,8 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords) // Decide between the two density noises: int idx = 33 * x + 33 * 5 * z + y; - Workspace[idx] = ClampedLerp(DensityNoiseA[idx], DensityNoiseB[idx], 8 * (ChoiceNoise[idx] + 0.5f)) + AddHeight + curBaseNoise; + Workspace[idx] = ClampedLerp(DensityNoiseA[idx], DensityNoiseB[idx], 8 * (ChoiceNoise[idx] + 0.5f)) + + AddHeight + curBaseNoise; } } } @@ -493,7 +544,8 @@ void cNoise3DComposable::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape { for (int y = 0; y < cChunkDef::Height; y++) { - a_Shape[y + x * 256 + z * 256 * 16] = (m_NoiseArray[y + 257 * x + 257 * 17 * z] > m_AirThreshold) ? 0 : 1; + a_Shape[y + x * 256 + z * 256 * 16] = + (m_NoiseArray[y + 257 * x + 257 * 17 * z] > m_AirThreshold) ? 0 : 1; } } // for x } // for z @@ -512,7 +564,10 @@ cBiomalNoise3DComposable::cBiomalNoise3DComposable(int a_Seed, cBiomeGen & a_Bio m_DensityNoiseB(a_Seed + 2), m_BaseNoise(a_Seed + 3), m_BiomeGen(a_BiomeGen), - m_LastChunkCoords(0x7fffffff, 0x7fffffff) // Set impossible coords for the chunk so that it's always considered stale + m_LastChunkCoords( + 0x7fffffff, + 0x7fffffff + ) // Set impossible coords for the chunk so that it's always considered stale { // Generate the weight distribution for summing up neighboring biomes: m_WeightSum = 0; @@ -520,7 +575,9 @@ cBiomalNoise3DComposable::cBiomalNoise3DComposable(int a_Seed, cBiomeGen & a_Bio { for (int x = 0; x <= AVERAGING_SIZE * 2; x++) { - m_Weight[z][x] = static_cast<NOISE_DATATYPE>((AVERAGING_SIZE - std::abs(AVERAGING_SIZE - x)) + (AVERAGING_SIZE - std::abs(AVERAGING_SIZE - z))); + m_Weight[z][x] = static_cast<NOISE_DATATYPE>( + (AVERAGING_SIZE - std::abs(AVERAGING_SIZE - x)) + (AVERAGING_SIZE - std::abs(AVERAGING_SIZE - z)) + ); m_WeightSum += m_Weight[z][x]; } } @@ -534,20 +591,26 @@ void cBiomalNoise3DComposable::Initialize(cIniFile & a_IniFile) { // Params: // The defaults generate extreme hills terrain - m_SeaLevel = a_IniFile.GetValueSetI("Generator", "SeaLevel", 62); - m_FrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DFrequencyX", 40)); - m_FrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DFrequencyY", 40)); - m_FrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DFrequencyZ", 40)); - m_BaseFrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DBaseFrequencyX", 40)); - m_BaseFrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DBaseFrequencyZ", 40)); - m_ChoiceFrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DChoiceFrequencyX", 40)); - m_ChoiceFrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DChoiceFrequencyY", 80)); - m_ChoiceFrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DChoiceFrequencyZ", 40)); - m_AirThreshold = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DAirThreshold", 0)); - int NumChoiceOctaves = a_IniFile.GetValueSetI("Generator", "BiomalNoise3DNumChoiceOctaves", 4); + m_SeaLevel = a_IniFile.GetValueSetI("Generator", "SeaLevel", 62); + m_FrequencyX = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DFrequencyX", 40)); + m_FrequencyY = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DFrequencyY", 40)); + m_FrequencyZ = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DFrequencyZ", 40)); + m_BaseFrequencyX = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DBaseFrequencyX", 40)); + m_BaseFrequencyZ = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DBaseFrequencyZ", 40)); + m_ChoiceFrequencyX = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DChoiceFrequencyX", 40)); + m_ChoiceFrequencyY = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DChoiceFrequencyY", 80)); + m_ChoiceFrequencyZ = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DChoiceFrequencyZ", 40)); + m_AirThreshold = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DAirThreshold", 0)); + int NumChoiceOctaves = a_IniFile.GetValueSetI("Generator", "BiomalNoise3DNumChoiceOctaves", 4); int NumDensityOctaves = a_IniFile.GetValueSetI("Generator", "BiomalNoise3DNumDensityOctaves", 6); - int NumBaseOctaves = a_IniFile.GetValueSetI("Generator", "BiomalNoise3DNumBaseOctaves", 6); - NOISE_DATATYPE BaseNoiseAmplitude = static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DBaseAmplitude", 1)); + int NumBaseOctaves = a_IniFile.GetValueSetI("Generator", "BiomalNoise3DNumBaseOctaves", 6); + NOISE_DATATYPE BaseNoiseAmplitude = + static_cast<NOISE_DATATYPE>(a_IniFile.GetValueSetF("Generator", "BiomalNoise3DBaseAmplitude", 1)); // Add octaves for the choice noise: NOISE_DATATYPE wavlen = 1, ampl = 0.5; @@ -559,7 +622,8 @@ void cBiomalNoise3DComposable::Initialize(cIniFile & a_IniFile) } // Add octaves for the density noises: - wavlen = 1; ampl = 1; + wavlen = 1; + ampl = 1; for (int i = 0; i < NumDensityOctaves; i++) { m_DensityNoiseA.AddOctave(wavlen, ampl); @@ -569,7 +633,8 @@ void cBiomalNoise3DComposable::Initialize(cIniFile & a_IniFile) } // Add octaves for the base noise: - wavlen = 1; ampl = BaseNoiseAmplitude; + wavlen = 1; + ampl = BaseNoiseAmplitude; for (int i = 0; i < NumBaseOctaves; i++) { m_BaseNoise.AddOctave(wavlen, ampl); @@ -604,11 +669,57 @@ void cBiomalNoise3DComposable::GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCo NOISE_DATATYPE BaseNoise[5 * 5]; NOISE_DATATYPE BlockX = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkX * cChunkDef::Width); NOISE_DATATYPE BlockZ = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width); - // Note that we have to swap the X and Y coords, because noise generator uses [x + SizeX * y + SizeX * SizeY * z] ordering and we want "BlockY" to be "x": - m_ChoiceNoise.Generate3D (ChoiceNoise, 33, 5, 5, 0, 257 / m_ChoiceFrequencyY, BlockX / m_ChoiceFrequencyX, (BlockX + 17) / m_ChoiceFrequencyX, BlockZ / m_ChoiceFrequencyZ, (BlockZ + 17) / m_ChoiceFrequencyZ, Workspace); - m_DensityNoiseA.Generate3D(DensityNoiseA, 33, 5, 5, 0, 257 / m_FrequencyY, BlockX / m_FrequencyX, (BlockX + 17) / m_FrequencyX, BlockZ / m_FrequencyZ, (BlockZ + 17) / m_FrequencyZ, Workspace); - m_DensityNoiseB.Generate3D(DensityNoiseB, 33, 5, 5, 0, 257 / m_FrequencyY, BlockX / m_FrequencyX, (BlockX + 17) / m_FrequencyX, BlockZ / m_FrequencyZ, (BlockZ + 17) / m_FrequencyZ, Workspace); - m_BaseNoise.Generate2D (BaseNoise, 5, 5, BlockX / m_BaseFrequencyX, (BlockX + 17) / m_BaseFrequencyX, BlockZ / m_FrequencyZ, (BlockZ + 17) / m_FrequencyZ, Workspace); + // Note that we have to swap the X and Y coords, because noise generator uses [x + SizeX * y + SizeX * SizeY * z] + // ordering and we want "BlockY" to be "x": + m_ChoiceNoise.Generate3D( + ChoiceNoise, + 33, + 5, + 5, + 0, + 257 / m_ChoiceFrequencyY, + BlockX / m_ChoiceFrequencyX, + (BlockX + 17) / m_ChoiceFrequencyX, + BlockZ / m_ChoiceFrequencyZ, + (BlockZ + 17) / m_ChoiceFrequencyZ, + Workspace + ); + m_DensityNoiseA.Generate3D( + DensityNoiseA, + 33, + 5, + 5, + 0, + 257 / m_FrequencyY, + BlockX / m_FrequencyX, + (BlockX + 17) / m_FrequencyX, + BlockZ / m_FrequencyZ, + (BlockZ + 17) / m_FrequencyZ, + Workspace + ); + m_DensityNoiseB.Generate3D( + DensityNoiseB, + 33, + 5, + 5, + 0, + 257 / m_FrequencyY, + BlockX / m_FrequencyX, + (BlockX + 17) / m_FrequencyX, + BlockZ / m_FrequencyZ, + (BlockZ + 17) / m_FrequencyZ, + Workspace + ); + m_BaseNoise.Generate2D( + BaseNoise, + 5, + 5, + BlockX / m_BaseFrequencyX, + (BlockX + 17) / m_BaseFrequencyX, + BlockZ / m_FrequencyZ, + (BlockZ + 17) / m_FrequencyZ, + Workspace + ); // Calculate the final noise based on the partial noises: for (int z = 0; z < 5; z++) @@ -622,7 +733,8 @@ void cBiomalNoise3DComposable::GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCo { NOISE_DATATYPE AddHeight = (static_cast<NOISE_DATATYPE>(y * 8) - curMidPoint) * curHeightAmp; - // If "underground", make the terrain smoother by forcing the vertical linear gradient into steeper slope: + // If "underground", make the terrain smoother by forcing the vertical linear gradient into steeper + // slope: if (AddHeight < 0) { AddHeight *= 4; @@ -635,7 +747,8 @@ void cBiomalNoise3DComposable::GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCo // Decide between the two density noises: int idx = 33 * x + y + 33 * 5 * z; - Workspace[idx] = ClampedLerp(DensityNoiseA[idx], DensityNoiseB[idx], 8 * (ChoiceNoise[idx] + 0.5f)) + AddHeight + curBaseNoise; + Workspace[idx] = ClampedLerp(DensityNoiseA[idx], DensityNoiseB[idx], 8 * (ChoiceNoise[idx] + 0.5f)) + + AddHeight + curBaseNoise; } } } @@ -646,7 +759,11 @@ void cBiomalNoise3DComposable::GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCo -void cBiomalNoise3DComposable::CalcBiomeParamArrays(cChunkCoords a_ChunkCoords, ChunkParam & a_HeightAmp, ChunkParam & a_MidPoint) +void cBiomalNoise3DComposable::CalcBiomeParamArrays( + cChunkCoords a_ChunkCoords, + ChunkParam & a_HeightAmp, + ChunkParam & a_MidPoint +) { // Generate the 3 * 3 chunks of biomes around this chunk: cChunkDef::BiomeMap neighborBiomes[3 * 3]; @@ -654,7 +771,10 @@ void cBiomalNoise3DComposable::CalcBiomeParamArrays(cChunkCoords a_ChunkCoords, { for (int x = 0; x < 3; x++) { - m_BiomeGen.GenBiomes({a_ChunkCoords.m_ChunkX + x - 1, a_ChunkCoords.m_ChunkZ + z - 1}, neighborBiomes[x + 3 * z]); + m_BiomeGen.GenBiomes( + {a_ChunkCoords.m_ChunkX + x - 1, a_ChunkCoords.m_ChunkZ + z - 1}, + neighborBiomes[x + 3 * z] + ); } } @@ -668,14 +788,15 @@ void cBiomalNoise3DComposable::CalcBiomeParamArrays(cChunkCoords a_ChunkCoords, // Add up the biomes around this point: for (int relz = 0; relz <= AVERAGING_SIZE * 2; ++relz) { - int colz = 16 + z * 4 + relz - AVERAGING_SIZE; // Biome Z coord relative to the neighborBiomes start - int neicellz = colz / 16; // Chunk Z coord relative to the neighborBiomes start - int neirelz = colz % 16; // Biome Z coord relative to cz in neighborBiomes + int colz = 16 + z * 4 + relz - AVERAGING_SIZE; // Biome Z coord relative to the neighborBiomes start + int neicellz = colz / 16; // Chunk Z coord relative to the neighborBiomes start + int neirelz = colz % 16; // Biome Z coord relative to cz in neighborBiomes for (int relx = 0; relx <= AVERAGING_SIZE * 2; ++relx) { - int colx = 16 + x * 4 + relx - AVERAGING_SIZE; // Biome X coord relative to the neighborBiomes start - int neicellx = colx / 16; // Chunk X coord relative to the neighborBiomes start - int neirelx = colx % 16; // Biome X coord relative to cz in neighborBiomes + int colx = + 16 + x * 4 + relx - AVERAGING_SIZE; // Biome X coord relative to the neighborBiomes start + int neicellx = colx / 16; // Chunk X coord relative to the neighborBiomes start + int neirelx = colx % 16; // Biome X coord relative to cz in neighborBiomes EMCSBiome biome = cChunkDef::GetBiome(neighborBiomes[neicellx + neicellz * 3], neirelx, neirelz); NOISE_DATATYPE heightAmp, midPoint; GetBiomeParams(biome, heightAmp, midPoint); @@ -693,71 +814,258 @@ void cBiomalNoise3DComposable::CalcBiomeParamArrays(cChunkCoords a_ChunkCoords, -void cBiomalNoise3DComposable::GetBiomeParams(EMCSBiome a_Biome, NOISE_DATATYPE & a_HeightAmp, NOISE_DATATYPE & a_MidPoint) +void cBiomalNoise3DComposable::GetBiomeParams( + EMCSBiome a_Biome, + NOISE_DATATYPE & a_HeightAmp, + NOISE_DATATYPE & a_MidPoint +) { switch (a_Biome) { - case biBeach: a_HeightAmp = 0.2f; a_MidPoint = 60; break; - case biBirchForest: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biBirchForestHills: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - case biBirchForestHillsM: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - case biBirchForestM: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biColdBeach: a_HeightAmp = 0.3f; a_MidPoint = 62; break; - case biColdTaiga: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biColdTaigaM: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biColdTaigaHills: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - case biDesertHills: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - case biDeepOcean: a_HeightAmp = 0.17f; a_MidPoint = 35; break; - case biDesert: a_HeightAmp = 0.29f; a_MidPoint = 62; break; - case biDesertM: a_HeightAmp = 0.29f; a_MidPoint = 62; break; - case biEnd: a_HeightAmp = 0.15f; a_MidPoint = 64; break; - case biExtremeHills: a_HeightAmp = 0.045f; a_MidPoint = 75; break; - case biExtremeHillsEdge: a_HeightAmp = 0.1f; a_MidPoint = 70; break; - case biExtremeHillsM: a_HeightAmp = 0.045f; a_MidPoint = 75; break; - case biExtremeHillsPlus: a_HeightAmp = 0.04f; a_MidPoint = 80; break; - case biExtremeHillsPlusM: a_HeightAmp = 0.04f; a_MidPoint = 80; break; - case biFlowerForest: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biForest: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biForestHills: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - case biFrozenRiver: a_HeightAmp = 0.4f; a_MidPoint = 54; break; - case biFrozenOcean: a_HeightAmp = 0.12f; a_MidPoint = 45; break; - case biIceMountains: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - case biIcePlains: a_HeightAmp = 0.3f; a_MidPoint = 62; break; - case biIcePlainsSpikes: a_HeightAmp = 0.3f; a_MidPoint = 62; break; - case biJungle: a_HeightAmp = 0.1f; a_MidPoint = 63; break; - case biJungleEdge: a_HeightAmp = 0.15f; a_MidPoint = 62; break; - case biJungleEdgeM: a_HeightAmp = 0.15f; a_MidPoint = 62; break; - case biJungleHills: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - case biJungleM: a_HeightAmp = 0.1f; a_MidPoint = 63; break; - case biMegaSpruceTaiga: a_HeightAmp = 0.09f; a_MidPoint = 64; break; - case biMegaSpruceTaigaHills: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - case biMegaTaiga: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biMegaTaigaHills: a_HeightAmp = 0.075f; a_MidPoint = 68; break; - case biMesa: a_HeightAmp = 0.09f; a_MidPoint = 61; break; - case biMesaBryce: a_HeightAmp = 0.15f; a_MidPoint = 61; break; - case biMesaPlateau: a_HeightAmp = 0.25f; a_MidPoint = 86; break; - case biMesaPlateauF: a_HeightAmp = 0.25f; a_MidPoint = 96; break; - case biMesaPlateauFM: a_HeightAmp = 0.25f; a_MidPoint = 96; break; - case biMesaPlateauM: a_HeightAmp = 0.25f; a_MidPoint = 86; break; - case biMushroomShore: a_HeightAmp = 0.075f; a_MidPoint = 60; break; - case biMushroomIsland: a_HeightAmp = 0.06f; a_MidPoint = 80; break; - case biNether: a_HeightAmp = 0.01f; a_MidPoint = 64; break; - case biOcean: a_HeightAmp = 0.12f; a_MidPoint = 45; break; - case biPlains: a_HeightAmp = 0.3f; a_MidPoint = 62; break; - case biRiver: a_HeightAmp = 0.4f; a_MidPoint = 54; break; - case biRoofedForest: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biRoofedForestM: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biSavanna: a_HeightAmp = 0.3f; a_MidPoint = 62; break; - case biSavannaM: a_HeightAmp = 0.3f; a_MidPoint = 62; break; - case biSavannaPlateau: a_HeightAmp = 0.3f; a_MidPoint = 85; break; - case biSavannaPlateauM: a_HeightAmp = 0.012f; a_MidPoint = 105; break; - case biStoneBeach: a_HeightAmp = 0.075f; a_MidPoint = 60; break; - case biSunflowerPlains: a_HeightAmp = 0.3f; a_MidPoint = 62; break; - case biSwampland: a_HeightAmp = 0.25f; a_MidPoint = 59; break; - case biSwamplandM: a_HeightAmp = 0.11f; a_MidPoint = 59; break; - case biTaiga: a_HeightAmp = 0.1f; a_MidPoint = 64; break; - case biTaigaM: a_HeightAmp = 0.1f; a_MidPoint = 70; break; - case biTaigaHills: a_HeightAmp = 0.075f; a_MidPoint = 68; break; + case biBeach: + a_HeightAmp = 0.2f; + a_MidPoint = 60; + break; + case biBirchForest: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biBirchForestHills: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; + case biBirchForestHillsM: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; + case biBirchForestM: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biColdBeach: + a_HeightAmp = 0.3f; + a_MidPoint = 62; + break; + case biColdTaiga: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biColdTaigaM: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biColdTaigaHills: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; + case biDesertHills: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; + case biDeepOcean: + a_HeightAmp = 0.17f; + a_MidPoint = 35; + break; + case biDesert: + a_HeightAmp = 0.29f; + a_MidPoint = 62; + break; + case biDesertM: + a_HeightAmp = 0.29f; + a_MidPoint = 62; + break; + case biEnd: + a_HeightAmp = 0.15f; + a_MidPoint = 64; + break; + case biExtremeHills: + a_HeightAmp = 0.045f; + a_MidPoint = 75; + break; + case biExtremeHillsEdge: + a_HeightAmp = 0.1f; + a_MidPoint = 70; + break; + case biExtremeHillsM: + a_HeightAmp = 0.045f; + a_MidPoint = 75; + break; + case biExtremeHillsPlus: + a_HeightAmp = 0.04f; + a_MidPoint = 80; + break; + case biExtremeHillsPlusM: + a_HeightAmp = 0.04f; + a_MidPoint = 80; + break; + case biFlowerForest: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biForest: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biForestHills: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; + case biFrozenRiver: + a_HeightAmp = 0.4f; + a_MidPoint = 54; + break; + case biFrozenOcean: + a_HeightAmp = 0.12f; + a_MidPoint = 45; + break; + case biIceMountains: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; + case biIcePlains: + a_HeightAmp = 0.3f; + a_MidPoint = 62; + break; + case biIcePlainsSpikes: + a_HeightAmp = 0.3f; + a_MidPoint = 62; + break; + case biJungle: + a_HeightAmp = 0.1f; + a_MidPoint = 63; + break; + case biJungleEdge: + a_HeightAmp = 0.15f; + a_MidPoint = 62; + break; + case biJungleEdgeM: + a_HeightAmp = 0.15f; + a_MidPoint = 62; + break; + case biJungleHills: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; + case biJungleM: + a_HeightAmp = 0.1f; + a_MidPoint = 63; + break; + case biMegaSpruceTaiga: + a_HeightAmp = 0.09f; + a_MidPoint = 64; + break; + case biMegaSpruceTaigaHills: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; + case biMegaTaiga: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biMegaTaigaHills: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; + case biMesa: + a_HeightAmp = 0.09f; + a_MidPoint = 61; + break; + case biMesaBryce: + a_HeightAmp = 0.15f; + a_MidPoint = 61; + break; + case biMesaPlateau: + a_HeightAmp = 0.25f; + a_MidPoint = 86; + break; + case biMesaPlateauF: + a_HeightAmp = 0.25f; + a_MidPoint = 96; + break; + case biMesaPlateauFM: + a_HeightAmp = 0.25f; + a_MidPoint = 96; + break; + case biMesaPlateauM: + a_HeightAmp = 0.25f; + a_MidPoint = 86; + break; + case biMushroomShore: + a_HeightAmp = 0.075f; + a_MidPoint = 60; + break; + case biMushroomIsland: + a_HeightAmp = 0.06f; + a_MidPoint = 80; + break; + case biNether: + a_HeightAmp = 0.01f; + a_MidPoint = 64; + break; + case biOcean: + a_HeightAmp = 0.12f; + a_MidPoint = 45; + break; + case biPlains: + a_HeightAmp = 0.3f; + a_MidPoint = 62; + break; + case biRiver: + a_HeightAmp = 0.4f; + a_MidPoint = 54; + break; + case biRoofedForest: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biRoofedForestM: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biSavanna: + a_HeightAmp = 0.3f; + a_MidPoint = 62; + break; + case biSavannaM: + a_HeightAmp = 0.3f; + a_MidPoint = 62; + break; + case biSavannaPlateau: + a_HeightAmp = 0.3f; + a_MidPoint = 85; + break; + case biSavannaPlateauM: + a_HeightAmp = 0.012f; + a_MidPoint = 105; + break; + case biStoneBeach: + a_HeightAmp = 0.075f; + a_MidPoint = 60; + break; + case biSunflowerPlains: + a_HeightAmp = 0.3f; + a_MidPoint = 62; + break; + case biSwampland: + a_HeightAmp = 0.25f; + a_MidPoint = 59; + break; + case biSwamplandM: + a_HeightAmp = 0.11f; + a_MidPoint = 59; + break; + case biTaiga: + a_HeightAmp = 0.1f; + a_MidPoint = 64; + break; + case biTaigaM: + a_HeightAmp = 0.1f; + a_MidPoint = 70; + break; + case biTaigaHills: + a_HeightAmp = 0.075f; + a_MidPoint = 68; + break; case biInvalidBiome: case biNumBiomes: case biVariant: @@ -786,7 +1094,8 @@ void cBiomalNoise3DComposable::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc:: { for (int y = 0; y < cChunkDef::Height; y++) { - a_Shape[y + x * 256 + z * 256 * 16] = (m_NoiseArray[y + 257 * x + 257 * 17 * z] > m_AirThreshold) ? 0 : 1; + a_Shape[y + x * 256 + z * 256 * 16] = + (m_NoiseArray[y + 257 * x + 257 * 17 * z] > m_AirThreshold) ? 0 : 1; } } // for x } // for z diff --git a/src/Generating/Noise3DGenerator.h b/src/Generating/Noise3DGenerator.h index 9aceffc1d..820d1cbed 100644 --- a/src/Generating/Noise3DGenerator.h +++ b/src/Generating/Noise3DGenerator.h @@ -20,13 +20,11 @@ -class cNoise3DGenerator: - public cChunkGenerator +class cNoise3DGenerator : public cChunkGenerator { using Super = cChunkGenerator; -public: - + public: cNoise3DGenerator(); virtual ~cNoise3DGenerator() override; @@ -34,16 +32,16 @@ public: virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void Generate(cChunkDesc & a_ChunkDesc) override; -protected: + protected: // Linear interpolation step sizes, must be divisors of cChunkDef::Width and cChunkDef::Height, respectively: static const int UPSCALE_X = 4; static const int UPSCALE_Y = 8; static const int UPSCALE_Z = 4; // Linear interpolation buffer dimensions, calculated from the step sizes: - static const int DIM_X = 1 + cChunkDef::Width / UPSCALE_X; + static const int DIM_X = 1 + cChunkDef::Width / UPSCALE_X; static const int DIM_Y = 1 + cChunkDef::Height / UPSCALE_Y; - static const int DIM_Z = 1 + cChunkDef::Width / UPSCALE_Z; + static const int DIM_Z = 1 + cChunkDef::Width / UPSCALE_Z; /** The base 3D noise source for the actual composition */ cOctavedNoise<cInterp5DegNoise> m_Perlin; @@ -51,7 +49,7 @@ protected: /** The noise used for heightmap directing. */ cOctavedNoise<cInterp5DegNoise> m_Cubic; - int m_SeaLevel; + int m_SeaLevel; NOISE_DATATYPE m_HeightAmplification; NOISE_DATATYPE m_MidPoint; // Where the vertical "center" of the noise should be NOISE_DATATYPE m_FrequencyX; @@ -64,21 +62,20 @@ protected: /** Composes terrain - adds dirt, grass and sand */ void ComposeTerrain(cChunkDesc & a_ChunkDesc); -} ; +}; -class cNoise3DComposable : - public cTerrainShapeGen +class cNoise3DComposable : public cTerrainShapeGen { -public: + public: cNoise3DComposable(int a_Seed); void Initialize(cIniFile & a_IniFile); -protected: + protected: /** The 3D noise that is used to choose between density noise A and B. */ cOctavedNoise<cInterpolNoise<Interp5Deg>> m_ChoiceNoise; @@ -120,27 +117,27 @@ protected: NOISE_DATATYPE m_NoiseArray[17 * 17 * 257]; // x + 17 * z + 17 * 17 * y - /** Generates the 3D noise array used for terrain generation (m_NoiseArray), unless the LastChunk coords are equal to coords given */ + /** Generates the 3D noise array used for terrain generation (m_NoiseArray), unless the LastChunk coords are equal + * to coords given */ void GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords); // cTerrainHeightGen overrides: virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override; virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); } -} ; +}; -class cBiomalNoise3DComposable : - public cTerrainShapeGen +class cBiomalNoise3DComposable : public cTerrainShapeGen { -public: + public: cBiomalNoise3DComposable(int a_Seed, cBiomeGen & a_BiomeGen); void Initialize(cIniFile & a_IniFile); -protected: + protected: /** Number of columns around the pixel to query for biomes for averaging. Must be less than or equal to 16. */ static const int AVERAGING_SIZE = 9; @@ -194,7 +191,8 @@ protected: NOISE_DATATYPE m_WeightSum; - /** Generates the 3D noise array used for terrain generation (m_NoiseArray), unless the LastChunk coords are equal to coords given */ + /** Generates the 3D noise array used for terrain generation (m_NoiseArray), unless the LastChunk coords are equal + * to coords given */ void GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords); /** Calculates the biome-related parameters for the chunk. */ @@ -206,4 +204,4 @@ protected: // cTerrainShapeGen overrides: virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override; virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); } -} ; +}; diff --git a/src/Generating/PieceGeneratorBFSTree.cpp b/src/Generating/PieceGeneratorBFSTree.cpp index 2e26463f2..eb0a6af3d 100644 --- a/src/Generating/PieceGeneratorBFSTree.cpp +++ b/src/Generating/PieceGeneratorBFSTree.cpp @@ -1,7 +1,8 @@ // PieceGeneratorBFSTree.cpp -// Implements the cPieceGeneratorBFSTree class for generating structures composed of individual "pieces" in a simple tree +// Implements the cPieceGeneratorBFSTree class for generating structures composed of individual "pieces" in a simple +// tree /* The generator keeps a pool of currently-open connectors, chooses one at random and tries to place a piece on it, thus possibly extending the pool of open connectors with the new piece's ones (like breadth-first search). @@ -19,10 +20,8 @@ thus possibly extending the pool of open connectors with the new piece's ones (l //////////////////////////////////////////////////////////////////////////////// // cPieceGeneratorBFSTree: -cPieceGeneratorBFSTree::cPieceGeneratorBFSTree(cPiecePool & a_PiecePool, int a_Seed): - m_PiecePool(a_PiecePool), - m_Noise(a_Seed), - m_Seed(a_Seed) +cPieceGeneratorBFSTree::cPieceGeneratorBFSTree(cPiecePool & a_PiecePool, int a_Seed) : + m_PiecePool(a_PiecePool), m_Noise(a_Seed), m_Seed(a_Seed) { } @@ -30,7 +29,11 @@ cPieceGeneratorBFSTree::cPieceGeneratorBFSTree(cPiecePool & a_PiecePool, int a_S -cPlacedPiecePtr cPieceGeneratorBFSTree::PlaceStartingPiece(int a_BlockX, int a_BlockZ, cFreeConnectors & a_OutConnectors) +cPlacedPiecePtr cPieceGeneratorBFSTree::PlaceStartingPiece( + int a_BlockX, + int a_BlockZ, + cFreeConnectors & a_OutConnectors +) { m_PiecePool.Reset(); int rnd = m_Noise.IntNoise2DInt(a_BlockX, a_BlockZ) / 7; @@ -109,7 +112,10 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector( int WantedConnectorType = -a_Connector.m_Type; cPieces AvailablePieces = m_PiecePool.GetPiecesWithConnector(WantedConnectorType); Connections.reserve(AvailablePieces.size()); - Vector3i ConnPos = cPiece::cConnector::AddDirection(a_Connector.m_Pos, a_Connector.m_Direction); // The position at which the new connector should be placed - 1 block away from the current connector + Vector3i ConnPos = cPiece::cConnector::AddDirection( + a_Connector.m_Pos, + a_Connector.m_Direction + ); // The position at which the new connector should be placed - 1 block away from the current connector int WeightTotal = 0; for (cPieces::iterator itrP = AvailablePieces.begin(), endP = AvailablePieces.end(); itrP != endP; ++itrP) { @@ -130,7 +136,8 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector( continue; } // This is a same-type connector, find out how to rotate to it: - int NumCCWRotations = cPiece::cConnector::GetNumCCWRotationsToFit(a_Connector.m_Direction, itrC->m_Direction); + int NumCCWRotations = + cPiece::cConnector::GetNumCCWRotationsToFit(a_Connector.m_Direction, itrC->m_Direction); if ((NumCCWRotations < 0) || !(*itrP)->CanRotateCCW(NumCCWRotations)) { // Doesn't support this rotation @@ -138,7 +145,8 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector( } // Check if the piece's VerticalLimit allows this connection: - if ((verticalLimit != nullptr) && (!verticalLimit->CanBeAtHeight(ConnPos.x, ConnPos.z, ConnPos.y - itrC->m_Pos.y))) + if ((verticalLimit != nullptr) && + (!verticalLimit->CanBeAtHeight(ConnPos.x, ConnPos.z, ConnPos.y - itrC->m_Pos.y))) { continue; } @@ -163,7 +171,8 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector( // Choose a random connection from the list, based on the weights: int rnd = (m_Noise.IntNoise3DInt(a_Connector.m_Pos.x, a_Connector.m_Pos.y, a_Connector.m_Pos.z) / 7) % WeightTotal; size_t ChosenIndex = 0; - for (cConnections::const_iterator itr = Connections.begin(), end = Connections.end(); itr != end; ++itr, ++ChosenIndex) + for (cConnections::const_iterator itr = Connections.begin(), end = Connections.end(); itr != end; + ++itr, ++ChosenIndex) { rnd -= itr->m_Weight; if (rnd <= 0) @@ -188,7 +197,10 @@ bool cPieceGeneratorBFSTree::TryPlacePieceAtConnector( // This is the connector through which we have been connected to the parent, don't add continue; } - a_OutConnectors.emplace_back(PlacedPiece.get(), Conn.m_Piece->RotateMoveConnector(*itr, Conn.m_NumCCWRotations, ConnPos.x, ConnPos.y, ConnPos.z)); + a_OutConnectors.emplace_back( + PlacedPiece.get(), + Conn.m_Piece->RotateMoveConnector(*itr, Conn.m_NumCCWRotations, ConnPos.x, ConnPos.y, ConnPos.z) + ); } a_OutPieces.push_back(std::move(PlacedPiece)); @@ -290,18 +302,26 @@ void cPieceGeneratorBFSTree::PlacePieces(int a_BlockX, int a_BlockZ, int a_MaxDe //* // DEBUG: -void cPieceGeneratorBFSTree::DebugConnectorPool(const cPieceGeneratorBFSTree::cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed) +void cPieceGeneratorBFSTree::DebugConnectorPool( + const cPieceGeneratorBFSTree::cFreeConnectors & a_ConnectorPool, + size_t a_NumProcessed +) { fmt::print(" Connector pool: {0} items\n", a_ConnectorPool.size() - a_NumProcessed); size_t idx = 0; typedef cPieceGeneratorBFSTree::cFreeConnectors::difference_type difType; - for (auto itr = a_ConnectorPool.cbegin() + static_cast<difType>(a_NumProcessed), end = a_ConnectorPool.cend(); itr != end; ++itr, ++idx) + for (auto itr = a_ConnectorPool.cbegin() + static_cast<difType>(a_NumProcessed), end = a_ConnectorPool.cend(); + itr != end; + ++itr, ++idx) { - fmt::print(" {0}: {{{1}, {2}, {3}}}, type {4}, direction {5}, depth {6}\n", + fmt::print( + " {0}: {{{1}, {2}, {3}}}, type {4}, direction {5}, depth {6}\n", idx, - itr->m_Connector.m_Pos.x, itr->m_Connector.m_Pos.y, itr->m_Connector.m_Pos.z, + itr->m_Connector.m_Pos.x, + itr->m_Connector.m_Pos.y, + itr->m_Connector.m_Pos.z, itr->m_Connector.m_Type, cPiece::cConnector::DirectionToString(itr->m_Connector.m_Direction), itr->m_Piece->GetDepth() @@ -317,11 +337,13 @@ void cPieceGeneratorBFSTree::DebugConnectorPool(const cPieceGeneratorBFSTree::cF //////////////////////////////////////////////////////////////////////////////// // cPieceGeneratorBFSTree::cConnection: -cPieceGeneratorBFSTree::cConnection::cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations, int a_Weight) : - m_Piece(&a_Piece), - m_Connector(a_Connector), - m_NumCCWRotations(a_NumCCWRotations), - m_Weight(a_Weight) +cPieceGeneratorBFSTree::cConnection::cConnection( + cPiece & a_Piece, + cPiece::cConnector & a_Connector, + int a_NumCCWRotations, + int a_Weight +) : + m_Piece(&a_Piece), m_Connector(a_Connector), m_NumCCWRotations(a_NumCCWRotations), m_Weight(a_Weight) { } @@ -333,11 +355,6 @@ cPieceGeneratorBFSTree::cConnection::cConnection(cPiece & a_Piece, cPiece::cConn // cPieceGeneratorBFSTree::cFreeConnector: cPieceGeneratorBFSTree::cFreeConnector::cFreeConnector(cPlacedPiece * a_Piece, const cPiece::cConnector & a_Connector) : - m_Piece(a_Piece), - m_Connector(a_Connector) + m_Piece(a_Piece), m_Connector(a_Connector) { } - - - - diff --git a/src/Generating/PieceGeneratorBFSTree.h b/src/Generating/PieceGeneratorBFSTree.h index 33d2e5350..e261d78b7 100644 --- a/src/Generating/PieceGeneratorBFSTree.h +++ b/src/Generating/PieceGeneratorBFSTree.h @@ -18,7 +18,7 @@ class cPieceGeneratorBFSTree { -public: + public: /** Creates a new object tied to the specified PiecePool, using the specified seed. */ cPieceGeneratorBFSTree(cPiecePool & a_PiecePool, int a_Seed); @@ -28,15 +28,14 @@ public: void PlacePieces(int a_BlockX, int a_BlockZ, int a_MaxDepth, cPlacedPieces & a_OutPieces); -protected: - + protected: /** The type used for storing a connection from one piece to another, while building the piece tree. */ struct cConnection { - cPiece * m_Piece; // The piece being connected - cPiece::cConnector m_Connector; // The piece's connector being used (relative non-rotated coords) - int m_NumCCWRotations; // Number of rotations necessary to match the two connectors - int m_Weight; // Relative chance that this connection will be chosen + cPiece * m_Piece; // The piece being connected + cPiece::cConnector m_Connector; // The piece's connector being used (relative non-rotated coords) + int m_NumCCWRotations; // Number of rotations necessary to match the two connectors + int m_Weight; // Relative chance that this connection will be chosen cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations, int a_Weight); }; @@ -70,32 +69,29 @@ protected: /** Tries to place a new piece at the specified (placed) connector. Returns true if successful. */ bool TryPlacePieceAtConnector( - const cPlacedPiece & a_ParentPiece, // The existing piece to a new piece should be placed - const cPiece::cConnector & a_Connector, // The existing connector (world-coords) to which a new piece should be placed - cPlacedPieces & a_OutPieces, // Already placed pieces, to be checked for intersections - cFreeConnectors & a_OutConnectors // List of free connectors to which the new connectors will be placed + const cPlacedPiece & a_ParentPiece, // The existing piece to a new piece should be placed + const cPiece::cConnector & + a_Connector, // The existing connector (world-coords) to which a new piece should be placed + cPlacedPieces & a_OutPieces, // Already placed pieces, to be checked for intersections + cFreeConnectors & a_OutConnectors // List of free connectors to which the new connectors will be placed ); /** Checks if the specified piece would fit with the already-placed pieces, using the specified connector and number of CCW rotations. a_ExistingConnector is in world-coords and is already rotated properly - a_ToPos is the world-coords position on which the new connector should be placed (1 block away from a_ExistingConnector, in its Direction) - a_NewConnector is in the original (non-rotated) coords. - Returns true if the piece fits, false if not. */ + a_ToPos is the world-coords position on which the new connector should be placed (1 block away from + a_ExistingConnector, in its Direction) a_NewConnector is in the original (non-rotated) coords. Returns true if the + piece fits, false if not. */ bool CheckConnection( const cPiece::cConnector & a_ExistingConnector, // The existing connector - const Vector3i & a_ToPos, // The position on which the new connector should be placed - const cPiece & a_Piece, // The new piece - const cPiece::cConnector & a_NewConnector, // The connector of the new piece - int a_NumCCWRotations, // Number of rotations for the new piece to align the connector - const cPlacedPieces & a_OutPieces // All the already-placed pieces to check + const Vector3i & a_ToPos, // The position on which the new connector should be placed + const cPiece & a_Piece, // The new piece + const cPiece::cConnector & a_NewConnector, // The connector of the new piece + int a_NumCCWRotations, // Number of rotations for the new piece to align the connector + const cPlacedPieces & a_OutPieces // All the already-placed pieces to check ); /** DEBUG: Outputs all the connectors in the pool into stdout. a_NumProcessed signals the number of connectors from the pool that should be considered processed (not listed). */ void DebugConnectorPool(const cFreeConnectors & a_ConnectorPool, size_t a_NumProcessed); -} ; - - - - +}; diff --git a/src/Generating/PieceModifier.cpp b/src/Generating/PieceModifier.cpp index d81487bf8..ba25fd3d0 100644 --- a/src/Generating/PieceModifier.cpp +++ b/src/Generating/PieceModifier.cpp @@ -18,10 +18,9 @@ static const int SEED_OFFSET = 135 * 13; //////////////////////////////////////////////////////////////////////////////// /** A modifier which is pseudo-randomly replacing blocks to other types and metas. */ -class cPieceModifierRandomizeBlocks: - public cPiece::cPieceModifier +class cPieceModifierRandomizeBlocks : public cPiece::cPieceModifier { -public: + public: cPieceModifierRandomizeBlocks(void) : m_Seed() { @@ -44,7 +43,11 @@ public: BLOCKTYPE blockType = static_cast<BLOCKTYPE>(BlockStringToType(blocksToReplace[i])); if ((blockType == E_BLOCK_AIR) && !NoCaseCompare(blocksToReplace[i], "Air")) { - CONDWARNING(a_LogWarnings, "Cannot parse block type from string \"%s\"!", blocksToReplace[i].c_str()); + CONDWARNING( + a_LogWarnings, + "Cannot parse block type from string \"%s\"!", + blocksToReplace[i].c_str() + ); return false; } m_BlocksToReplace[blockType] = 1; @@ -97,7 +100,7 @@ public: { AString block = BlocksToRandomize[i]; - cRandomizedBlock Block{}; + cRandomizedBlock Block {}; if (isMultiMeta) { @@ -107,9 +110,12 @@ public: auto sqBrEnd = block.find(']'); if (sqBrEnd != block.size() - 1) { - CONDWARNING(a_LogWarnings, "If present, block meta params must be at the end of block to randomize definition \"%s\"!", block.c_str()); + CONDWARNING( + a_LogWarnings, + "If present, block meta params must be at the end of block to randomize definition \"%s\"!", + block.c_str() + ); return false; - } AString metaParamsStr = block.substr(sqBrStart + 1, block.size() - sqBrStart - 2); @@ -125,7 +131,6 @@ public: Block.m_MaxNoiseMeta = metaParamsInt[3]; block = block.substr(0, sqBrStart); - } // No meta randomization for this block } @@ -142,19 +147,14 @@ public: if ((BlockType != E_BLOCK_AIR) && !NoCaseCompare(BlockParams[0], "Air")) { // Failed to parse block type - CONDWARNING( - a_LogWarnings, "Cannot parse block type from string \"%s\"!", - BlockParams[0].c_str()); + CONDWARNING(a_LogWarnings, "Cannot parse block type from string \"%s\"!", BlockParams[0].c_str()); return false; } if (!StringToInteger(BlockParams[1], BlockWeight)) { // Failed to parse the crop weight: - CONDWARNING( - a_LogWarnings, - "Cannot parse block weight from string \"%s\"!", - BlockParams[1].c_str()); + CONDWARNING(a_LogWarnings, "Cannot parse block weight from string \"%s\"!", BlockParams[1].c_str()); return false; } @@ -188,7 +188,12 @@ public: if (!StringToInteger(MetaParams[i], Value)) { // Failed to parse meta parameter from string: - CONDWARNING(a_LogWarnings, "Cannot parse meta param from string \"%s\", meta: %s!", MetaParams[i].c_str(), a_Meta.c_str()); + CONDWARNING( + a_LogWarnings, + "Cannot parse meta param from string \"%s\", meta: %s!", + MetaParams[i].c_str(), + a_Meta.c_str() + ); return false; } @@ -237,7 +242,9 @@ public: { if (m_BlocksToReplace.count(BlockTypes[i])) { - float BlockRnd = PieceNoise.IntNoise2DInRange(a_PieceRot, static_cast<int>(i), 0.0F, static_cast<float>(m_AllWeights)); + float BlockRnd = + PieceNoise + .IntNoise2DInRange(a_PieceRot, static_cast<int>(i), 0.0F, static_cast<float>(m_AllWeights)); int weightDelta = 0; for (auto & blockToRnd : m_BlocksToRandomize) @@ -250,7 +257,16 @@ public: // Per block meta params if (blockToRnd.m_MinMeta < blockToRnd.m_MaxMeta) { - int BlockMetaRnd = std::clamp(static_cast<int>(PieceNoise.IntNoise2DInRange(a_PieceRot*2, static_cast<int>(i), static_cast<float>(blockToRnd.m_MinNoiseMeta), static_cast<float>(blockToRnd.m_MaxNoiseMeta))), blockToRnd.m_MinMeta, blockToRnd.m_MaxMeta); + int BlockMetaRnd = std::clamp( + static_cast<int>(PieceNoise.IntNoise2DInRange( + a_PieceRot * 2, + static_cast<int>(i), + static_cast<float>(blockToRnd.m_MinNoiseMeta), + static_cast<float>(blockToRnd.m_MaxNoiseMeta) + )), + blockToRnd.m_MinMeta, + blockToRnd.m_MaxMeta + ); BlockMetas[i] = static_cast<NIBBLETYPE>(BlockMetaRnd); } else if ((blockToRnd.m_MaxMeta > -1) && (blockToRnd.m_MaxMeta == blockToRnd.m_MinMeta)) @@ -265,7 +281,16 @@ public: // All blocks meta params if (m_MaxMeta > m_MinMeta) { - int BlockMetaRnd = std::clamp(static_cast<int>(PieceNoise.IntNoise2DInRange(a_PieceRot * 2, static_cast<int>(i), static_cast<float>(m_MinNoiseMeta), static_cast<float>(m_MaxNoiseMeta))), m_MinMeta, m_MaxMeta); + int BlockMetaRnd = std::clamp( + static_cast<int>(PieceNoise.IntNoise2DInRange( + a_PieceRot * 2, + static_cast<int>(i), + static_cast<float>(m_MinNoiseMeta), + static_cast<float>(m_MaxNoiseMeta) + )), + m_MinMeta, + m_MaxMeta + ); BlockMetas[i] = static_cast<NIBBLETYPE>(BlockMetaRnd); } else if ((m_MaxMeta > -1) && (m_MaxMeta == m_MinMeta)) @@ -277,11 +302,9 @@ public: } // for i - BlockTypes[] } - virtual void AssignSeed(int a_Seed) override - { - m_Seed = a_Seed + SEED_OFFSET; - } -protected: + virtual void AssignSeed(int a_Seed) override { m_Seed = a_Seed + SEED_OFFSET; } + + protected: int m_Seed; int m_AllWeights = 0; @@ -312,14 +335,22 @@ protected: //////////////////////////////////////////////////////////////////////////////// // CreatePieceModifierFromString: -bool CreatePieceModifierFromString(const AString & a_Definition, std::shared_ptr<cPiece::cPieceModifiers> & a_Modifiers, bool a_LogWarnings) +bool CreatePieceModifierFromString( + const AString & a_Definition, + std::shared_ptr<cPiece::cPieceModifiers> & a_Modifiers, + bool a_LogWarnings +) { auto idxCurlyStart = a_Definition.find('{'); auto idxCurlyFirstEnd = a_Definition.find('}'); if ((idxCurlyStart == AString::npos) && (idxCurlyFirstEnd == AString::npos)) { - CONDWARNING(a_LogWarnings, "Piece metadata \"Modifiers\" needs at least one valid modifier definition \"%s\"!", a_Definition.c_str()); + CONDWARNING( + a_LogWarnings, + "Piece metadata \"Modifiers\" needs at least one valid modifier definition \"%s\"!", + a_Definition.c_str() + ); return false; } @@ -381,7 +412,3 @@ bool CreatePieceModifierFromString(const AString & a_Definition, std::shared_ptr return true; } - - - - diff --git a/src/Generating/PieceModifier.h b/src/Generating/PieceModifier.h index 88fba5070..e6850d975 100644 --- a/src/Generating/PieceModifier.h +++ b/src/Generating/PieceModifier.h @@ -15,7 +15,11 @@ -bool CreatePieceModifierFromString(const AString & a_Definition, std::shared_ptr<cPiece::cPieceModifiers> & a_Modifiers, bool a_LogWarnings); +bool CreatePieceModifierFromString( + const AString & a_Definition, + std::shared_ptr<cPiece::cPieceModifiers> & a_Modifiers, + bool a_LogWarnings +); @@ -24,7 +28,7 @@ bool CreatePieceModifierFromString(const AString & a_Definition, std::shared_ptr /** Used to store block type, meta, weight and some more params */ class cRandomizedBlock { -public: + public: BLOCKTYPE m_Type; int m_Weight; diff --git a/src/Generating/PiecePool.cpp b/src/Generating/PiecePool.cpp index a7c28e75a..1c4dcd34d 100644 --- a/src/Generating/PiecePool.cpp +++ b/src/Generating/PiecePool.cpp @@ -1,8 +1,9 @@ // PiecePool.cpp // Implements the cPiecePool class representing a pool of cPieces - "parts" of a structure, used in piece-generators -// A cPiece is a single static part of a structure that can rotate around the Y axis, has connectors to other pieces and knows how to draw itself into the world. -// The pool manages the pieces and provides lists of its pieces matching criteria, and provides relative weights for the random distribution of pieces. +// A cPiece is a single static part of a structure that can rotate around the Y axis, has connectors to other pieces and +// knows how to draw itself into the world. The pool manages the pieces and provides lists of its pieces matching +// criteria, and provides relative weights for the random distribution of pieces. #include "Globals.h" #include "PiecePool.h" @@ -104,7 +105,13 @@ Vector3i cPiece::RotatePos(const Vector3i & a_Pos, int a_NumCCWRotations) const -cPiece::cConnector cPiece::RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const +cPiece::cConnector cPiece::RotateMoveConnector( + const cConnector & a_Connector, + int a_NumCCWRotations, + int a_MoveX, + int a_MoveY, + int a_MoveZ +) const { cPiece::cConnector res(a_Connector); @@ -184,9 +191,7 @@ cCuboid cPiece::RotateMoveHitBox(int a_NumCCWRotations, int a_MoveX, int a_MoveY // cPiece::cConnector: cPiece::cConnector::cConnector(int a_X, int a_Y, int a_Z, int a_Type, eDirection a_Direction) : - m_Pos(a_X, a_Y, a_Z), - m_Type(a_Type), - m_Direction(a_Direction) + m_Pos(a_X, a_Y, a_Z), m_Type(a_Type), m_Direction(a_Direction) { } @@ -195,9 +200,7 @@ cPiece::cConnector::cConnector(int a_X, int a_Y, int a_Z, int a_Type, eDirection cPiece::cConnector::cConnector(const Vector3i & a_Pos, int a_Type, eDirection a_Direction) : - m_Pos(a_Pos), - m_Type(a_Type), - m_Direction(a_Direction) + m_Pos(a_Pos), m_Type(a_Type), m_Direction(a_Direction) { } @@ -209,20 +212,20 @@ Vector3i cPiece::cConnector::AddDirection(const Vector3i & a_Pos, eDirection a_D { switch (a_Direction) { - case dirXM: return Vector3i(a_Pos.x - 1, a_Pos.y, a_Pos.z); - case dirXP: return Vector3i(a_Pos.x + 1, a_Pos.y, a_Pos.z); - case dirYM: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); - case dirYP: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); - case dirZM: return Vector3i(a_Pos.x, a_Pos.y, a_Pos.z - 1); - case dirZP: return Vector3i(a_Pos.x, a_Pos.y, a_Pos.z + 1); - case dirYM_XM_ZM: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); - case dirYM_XM_ZP: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); - case dirYM_XP_ZM: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); - case dirYM_XP_ZP: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); - case dirYP_XM_ZM: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); - case dirYP_XM_ZP: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); - case dirYP_XP_ZM: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); - case dirYP_XP_ZP: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); + case dirXM: return Vector3i(a_Pos.x - 1, a_Pos.y, a_Pos.z); + case dirXP: return Vector3i(a_Pos.x + 1, a_Pos.y, a_Pos.z); + case dirYM: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); + case dirYP: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); + case dirZM: return Vector3i(a_Pos.x, a_Pos.y, a_Pos.z - 1); + case dirZP: return Vector3i(a_Pos.x, a_Pos.y, a_Pos.z + 1); + case dirYM_XM_ZM: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); + case dirYM_XM_ZP: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); + case dirYM_XP_ZM: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); + case dirYM_XP_ZP: return Vector3i(a_Pos.x, a_Pos.y - 1, a_Pos.z); + case dirYP_XM_ZM: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); + case dirYP_XM_ZP: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); + case dirYP_XP_ZM: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); + case dirYP_XP_ZP: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); } UNREACHABLE("Unsupported connector direction"); } @@ -372,23 +375,23 @@ int cPiece::cConnector::GetNumCCWRotationsToFit(eDirection a_FixedDir, eDirectio // Translation of direction - direction -> number of CCW rotations needed: // You need DirectionRotationTable[fixed][rot] CCW turns to connect rot to fixed (they are opposite) // -1 if not possible - static const int DirectionRotationTable[14][14] = - { - /* YM, YP, ZM, ZP, XM, XP, YM-XM-ZM, YM-XM-ZP, YM-XP-ZM, YM-XP-ZP, YP-XM-ZM, YP-XM-ZP, YP-XP-ZM, YP-XP-ZP */ - /* YM */ { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - /* YP */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - /* ZM */ {-1, -1, 2, 0, 1, 3, -1, -1, -1, -1, -1, -1, -1, -1}, - /* ZP */ {-1, -1, 0, 2, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1}, - /* XM */ {-1, -1, 3, 1, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1}, - /* XP */ {-1, -1, 1, 3, 0, 2, -1, -1, -1, -1, -1, -1, -1, -1}, - /* YM-XM-ZM */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 1, 2}, - /* YM-XM-ZP */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 0, 2, 3}, - /* YM-XP-ZM */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 2, 0, 1}, - /* YM-XP-ZP */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 3, 0}, - /* YP-XM-ZM */ {-1, -1, -1, -1, -1, -1, 0, 3, 1, 2, -1, -1, -1, -1}, - /* YP-XM-ZP */ {-1, -1, -1, -1, -1, -1, 1, 0, 2, 3, -1, -1, -1, -1}, - /* YP-XP-ZM */ {-1, -1, -1, -1, -1, -1, 3, 2, 0, 1, -1, -1, -1, -1}, - /* YP-XP-ZP */ {-1, -1, -1, -1, -1, -1, 2, 1, 3, 0, -1, -1, -1, -1}, + static const int DirectionRotationTable[14][14] = { + /* YM, YP, ZM, ZP, XM, XP, YM-XM-ZM, YM-XM-ZP, YM-XP-ZM, YM-XP-ZP, YP-XM-ZM, YP-XM-ZP, YP-XP-ZM, + YP-XP-ZP */ + /* YM */ {0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + /* YP */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + /* ZM */ {-1, -1, 2, 0, 1, 3, -1, -1, -1, -1, -1, -1, -1, -1}, + /* ZP */ {-1, -1, 0, 2, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1}, + /* XM */ {-1, -1, 3, 1, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1}, + /* XP */ {-1, -1, 1, 3, 0, 2, -1, -1, -1, -1, -1, -1, -1, -1}, + /* YM-XM-ZM */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 1, 2}, + /* YM-XM-ZP */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 0, 2, 3}, + /* YM-XP-ZM */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 2, 0, 1}, + /* YM-XP-ZP */ {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 3, 0}, + /* YP-XM-ZM */ {-1, -1, -1, -1, -1, -1, 0, 3, 1, 2, -1, -1, -1, -1}, + /* YP-XM-ZP */ {-1, -1, -1, -1, -1, -1, 1, 0, 2, 3, -1, -1, -1, -1}, + /* YP-XP-ZM */ {-1, -1, -1, -1, -1, -1, 3, 2, 0, 1, -1, -1, -1, -1}, + /* YP-XP-ZP */ {-1, -1, -1, -1, -1, -1, 2, 1, 3, 0, -1, -1, -1, -1}, }; return DirectionRotationTable[a_FixedDir][a_RotatingDir]; @@ -417,8 +420,7 @@ bool cPiece::cConnector::StringToDirection(const AString & a_Value, eDirection & { const char * m_String; eDirection m_Value; - } StringDirections[] = - { + } StringDirections[] = { {"x-", dirXM}, {"x+", dirXP}, {"y-", dirYM}, @@ -465,7 +467,12 @@ bool cPiece::cConnector::StringToDirection(const AString & a_Value, eDirection & //////////////////////////////////////////////////////////////////////////////// // cPlacedPiece: -cPlacedPiece::cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece, const Vector3i & a_Coords, int a_NumCCWRotations) : +cPlacedPiece::cPlacedPiece( + const cPlacedPiece * a_Parent, + const cPiece & a_Piece, + const Vector3i & a_Coords, + int a_NumCCWRotations +) : m_Parent(a_Parent), m_Piece(&a_Piece), m_Coords(a_Coords), @@ -506,7 +513,3 @@ void cPlacedPiece::MoveToGroundBy(int a_OffsetY) m_Coords.y += a_OffsetY; m_HasBeenMovedToGround = true; } - - - - diff --git a/src/Generating/PiecePool.h b/src/Generating/PiecePool.h index 5897f32c7..adfa9204b 100644 --- a/src/Generating/PiecePool.h +++ b/src/Generating/PiecePool.h @@ -19,7 +19,7 @@ /** Represents a single piece. Can have multiple connectors of different types where other pieces can connect. */ class cPiece { -public: + public: // Force a virtual destructor in all descendants virtual ~cPiece() {} @@ -28,22 +28,25 @@ public: enum eDirection { // The following values correspond to equivalent eBlockFace values: - dirXM = BLOCK_FACE_XM, // Pointing towards the X- side of the prefab - dirXP = BLOCK_FACE_XP, // Pointing towards the X+ side of the prefab - dirYM = BLOCK_FACE_YM, // Pointing towards the Y- side of the prefab, doesn't change with rotation around the Y axis - dirYP = BLOCK_FACE_YP, // Pointing towards the Y+ side of the prefab, doesn't change with rotation around the Y axis - dirZM = BLOCK_FACE_ZM, // Pointing towards the Z- side of the prefab - dirZP = BLOCK_FACE_ZP, // Pointing towards the Z+ side of the prefab + dirXM = BLOCK_FACE_XM, // Pointing towards the X- side of the prefab + dirXP = BLOCK_FACE_XP, // Pointing towards the X+ side of the prefab + dirYM = BLOCK_FACE_YM, // Pointing towards the Y- side of the prefab, doesn't change with rotation around + // the Y axis + dirYP = BLOCK_FACE_YP, // Pointing towards the Y+ side of the prefab, doesn't change with rotation around + // the Y axis + dirZM = BLOCK_FACE_ZM, // Pointing towards the Z- side of the prefab + dirZP = BLOCK_FACE_ZP, // Pointing towards the Z+ side of the prefab // Special kind of the vertical connectors (changes with rotation around the Y axis) - dirYM_XM_ZM = BLOCK_FACE_MAX + 1, // Pointing towards the Y- side of the prefab, conceptually at the X- Z- corner of the block - dirYM_XM_ZP, // Pointing towards the Y- side of the prefab, conceptually at the X- Z+ corner of the block - dirYM_XP_ZM, // Pointing towards the Y- side of the prefab, conceptually at the X+ Z- corner of the block - dirYM_XP_ZP, // Pointing towards the Y- side of the prefab, conceptually at the X+ Z+ corner of the block - dirYP_XM_ZM, // Pointing towards the Y+ side of the prefab, conceptually at the X- Z- corner of the block - dirYP_XM_ZP, // Pointing towards the Y+ side of the prefab, conceptually at the X- Z+ corner of the block - dirYP_XP_ZM, // Pointing towards the Y+ side of the prefab, conceptually at the X+ Z- corner of the block - dirYP_XP_ZP, // Pointing towards the Y+ side of the prefab, conceptually at the X+ Z+ corner of the block + dirYM_XM_ZM = BLOCK_FACE_MAX + + 1, // Pointing towards the Y- side of the prefab, conceptually at the X- Z- corner of the block + dirYM_XM_ZP, // Pointing towards the Y- side of the prefab, conceptually at the X- Z+ corner of the block + dirYM_XP_ZM, // Pointing towards the Y- side of the prefab, conceptually at the X+ Z- corner of the block + dirYM_XP_ZP, // Pointing towards the Y- side of the prefab, conceptually at the X+ Z+ corner of the block + dirYP_XM_ZM, // Pointing towards the Y+ side of the prefab, conceptually at the X- Z- corner of the block + dirYP_XM_ZP, // Pointing towards the Y+ side of the prefab, conceptually at the X- Z+ corner of the block + dirYP_XP_ZM, // Pointing towards the Y+ side of the prefab, conceptually at the X+ Z- corner of the block + dirYP_XP_ZP, // Pointing towards the Y+ side of the prefab, conceptually at the X+ Z+ corner of the block }; /** Position relative to the piece */ @@ -80,10 +83,10 @@ public: /** Returns the direction corresponding to the given direction rotated 90 degrees CW around the Y axis. */ static eDirection RotateDirectionCW(eDirection a_Direction); - /** Returns the number of CCW rotations that a_RotatingDir requires in order to be the counter-direction of a_FixedDir. - Ie. if you have a connector with a_FixedDir and you're rotating a piece that has a connector with a_RotatingDir, - how many CCW rotations it needs to make the connectors compatible. - Returns -1 if it is impossible to fit the two directions. */ + /** Returns the number of CCW rotations that a_RotatingDir requires in order to be the counter-direction of + a_FixedDir. Ie. if you have a connector with a_FixedDir and you're rotating a piece that has a connector with + a_RotatingDir, how many CCW rotations it needs to make the connectors compatible. Returns -1 if it is impossible + to fit the two directions. */ static int GetNumCCWRotationsToFit(eDirection a_FixedDir, eDirection a_RotatingDir); /** Converts the string representation of a direction into the eDirection enum value. @@ -99,7 +102,7 @@ public: Descendants can override the GetVerticalPlacement() method to provide custom placement decisions. */ class cVerticalStrategy { - public: + public: // Force a virtual destructor in descendants virtual ~cVerticalStrategy() {} @@ -107,15 +110,21 @@ public: virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) = 0; /** Initializes the strategy's parameters from the string representation. - a_Params is the string containing only the parameters (substring after the first pipe character in the strategy description string). - If a_LogWarnings is true, logs any problems to the console. - Returns true if successful, false if the string parsing failed. - Used when loading the strategy from a file. */ + a_Params is the string containing only the parameters (substring after the first pipe character in the strategy + description string). If a_LogWarnings is true, logs any problems to the console. Returns true if successful, + false if the string parsing failed. Used when loading the strategy from a file. */ virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) = 0; /** Called when the piece pool is assigned to a generator, so that the strategies may bind to the underlying subgenerators. */ - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) {} + virtual void AssignGens( + int a_Seed, + cBiomeGen & a_BiomeGen, + cTerrainHeightGen & a_TerrainHeightGen, + int a_SeaLevel + ) + { + } }; typedef std::shared_ptr<cVerticalStrategy> cVerticalStrategyPtr; @@ -125,7 +134,7 @@ public: Each placed piece can have a limit, represented by this class, that gets queried for validity of the placement. */ class cVerticalLimit { - public: + public: virtual ~cVerticalLimit() {} /** Called to inquire whether the specified piece can be placed at the specified height. @@ -134,15 +143,21 @@ public: virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) = 0; /** Initializes the limit's parameters from the string representation. - a_Params is the string containing only the parameters (substring after the first pipe character in the limit description string). - Returns true if successful, false if the string parsing failed. - If a_LogWarnings is true, any error while parsing the string is output to the server console. - Used when loading the limit from a file. */ + a_Params is the string containing only the parameters (substring after the first pipe character in the limit + description string). Returns true if successful, false if the string parsing failed. If a_LogWarnings is true, + any error while parsing the string is output to the server console. Used when loading the limit from a file. */ virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) = 0; /** Called when the piece pool is assigned to a generator, so that the limits may bind to the underlying subgenerators. */ - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) {} + virtual void AssignGens( + int a_Seed, + cBiomeGen & a_BiomeGen, + cTerrainHeightGen & a_TerrainHeightGen, + int a_SeaLevel + ) + { + } }; typedef std::shared_ptr<cVerticalLimit> cVerticalLimitPtr; @@ -151,7 +166,7 @@ public: /** Base class (interface) for piece modifiers. */ class cPieceModifier { - public: + public: // Force a virtual destructor in descendants virtual ~cPieceModifier() {} @@ -215,20 +230,11 @@ public: m_VerticalStrategy = std::move(a_VerticalStrategy); } - cVerticalStrategyPtr GetVerticalStrategy(void) const - { - return m_VerticalStrategy; - } + cVerticalStrategyPtr GetVerticalStrategy(void) const { return m_VerticalStrategy; } - cVerticalLimitPtr GetVerticalLimit(void) const - { - return m_VerticalLimit; - } + cVerticalLimitPtr GetVerticalLimit(void) const { return m_VerticalLimit; } - cPieceModifiers GetModifiers(void) const - { - return m_Modifiers; - } + cPieceModifiers GetModifiers(void) const { return m_Modifiers; } /** Sets the vertical strategy based on the description in the string. If a_LogWarnings is true, logs the parsing problems into the server console. @@ -250,10 +256,21 @@ public: Vector3i RotatePos(const Vector3i & a_Pos, int a_NumCCWRotations) const; /** Returns a copy of the connector that is rotated and then moved by the specified amounts. */ - cConnector RotateMoveConnector(const cConnector & a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const; - - /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at a_ToConnectorPos. */ - cCuboid RotateHitBoxToConnector(const cConnector & a_MyConnector, const Vector3i & a_ToConnectorPos, int a_NumCCWRotations) const; + cConnector RotateMoveConnector( + const cConnector & a_Connector, + int a_NumCCWRotations, + int a_MoveX, + int a_MoveY, + int a_MoveZ + ) const; + + /** Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed at + * a_ToConnectorPos. */ + cCuboid RotateHitBoxToConnector( + const cConnector & a_MyConnector, + const Vector3i & a_ToConnectorPos, + int a_NumCCWRotations + ) const; /** Returns the hitbox after the specified number of CCW rotations and moved by the specified amounts. */ cCuboid RotateMoveHitBox(int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const; @@ -276,7 +293,7 @@ Provides lists of pieces based on criteria (IsStarting, HasConnector). Provides per-piece weights for random distribution of individual pieces. */ class cPiecePool { -public: + public: // Force a virtual destructor in all descendants: virtual ~cPiecePool() {} @@ -288,10 +305,11 @@ public: Multiple starting points are supported, one of the returned piece will be chosen. */ virtual cPieces GetStartingPieces(void) = 0; - /** Returns the relative weight with which the a_NewPiece is to be selected for placing under a_PlacedPiece through a_ExistingConnector. - a_ExistingConnector is the original connector, before any movement or rotation is applied to it. - This allows the pool to tweak the piece's chances, based on the previous pieces in the tree and the connector used. - The higher the number returned, the higher the chance the piece will be chosen. 0 means the piece will never be chosen. */ + /** Returns the relative weight with which the a_NewPiece is to be selected for placing under a_PlacedPiece through + a_ExistingConnector. a_ExistingConnector is the original connector, before any movement or rotation is applied to + it. This allows the pool to tweak the piece's chances, based on the previous pieces in the tree and the connector + used. The higher the number returned, the higher the chance the piece will be chosen. 0 means the piece will never + be chosen. */ virtual int GetPieceWeight( const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, @@ -303,12 +321,9 @@ public: /** Returns the relative weight with which the a_NewPiece is to be selected for placing as the first piece. This allows the pool to tweak the piece's chances. - The higher the number returned, the higher the chance the piece will be chosen. 0 means the piece will not be chosen. - If all pieces return 0, a random piece is chosen, with all equal chances. */ - virtual int GetStartingPieceWeight(const cPiece & a_NewPiece) - { - return 1; - } + The higher the number returned, the higher the chance the piece will be chosen. 0 means the piece will not be + chosen. If all pieces return 0, a random piece is chosen, with all equal chances. */ + virtual int GetStartingPieceWeight(const cPiece & a_NewPiece) { return 1; } /** Called after a piece is placed, to notify the pool that it has been used. The pool may adjust the pieces it will return the next time. */ @@ -326,16 +341,21 @@ public: /** Represents a single piece that has been placed to specific coords in the world. */ class cPlacedPiece { -public: - cPlacedPiece(const cPlacedPiece * a_Parent, const cPiece & a_Piece, const Vector3i & a_Coords, int a_NumCCWRotations); - - const cPlacedPiece * GetParent (void) const { return m_Parent; } - const cPiece & GetPiece (void) const { return *m_Piece; } - const Vector3i & GetCoords (void) const { return m_Coords; } - int GetNumCCWRotations (void) const { return m_NumCCWRotations; } - const cCuboid & GetHitBox (void) const { return m_HitBox; } - int GetDepth (void) const { return m_Depth; } - bool HasBeenMovedToGround(void) const { return m_HasBeenMovedToGround; } + public: + cPlacedPiece( + const cPlacedPiece * a_Parent, + const cPiece & a_Piece, + const Vector3i & a_Coords, + int a_NumCCWRotations + ); + + const cPlacedPiece * GetParent(void) const { return m_Parent; } + const cPiece & GetPiece(void) const { return *m_Piece; } + const Vector3i & GetCoords(void) const { return m_Coords; } + int GetNumCCWRotations(void) const { return m_NumCCWRotations; } + const cCuboid & GetHitBox(void) const { return m_HitBox; } + int GetDepth(void) const { return m_Depth; } + bool HasBeenMovedToGround(void) const { return m_HasBeenMovedToGround; } /** Returns the coords as a modifiable object. */ Vector3i & GetCoords(void) { return m_Coords; } @@ -353,13 +373,13 @@ public: Used eg. by village houses. */ void MoveToGroundBy(int a_OffsetY); -protected: + protected: const cPlacedPiece * m_Parent; const cPiece * m_Piece; Vector3i m_Coords; int m_NumCCWRotations; cCuboid m_HitBox; // Hitbox of the placed piece, in world coords - int m_Depth; // Depth in the generated piece tree + int m_Depth; // Depth in the generated piece tree /** Set to true once the piece has been moved Y-wise. Used eg. by village houses. */ diff --git a/src/Generating/PieceStructuresGen.cpp b/src/Generating/PieceStructuresGen.cpp index a0c30a538..1ac655798 100644 --- a/src/Generating/PieceStructuresGen.cpp +++ b/src/Generating/PieceStructuresGen.cpp @@ -13,14 +13,12 @@ -class cPieceStructuresGen::cGen: - public cGridStructGen +class cPieceStructuresGen::cGen : public cGridStructGen { using Super = cGridStructGen; -public: - - cGen(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel, const AString & a_Name): + public: + cGen(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel, const AString & a_Name) : Super(a_Seed), m_BiomeGen(a_BiomeGen), m_HeightGen(a_HeightGen), @@ -43,8 +41,11 @@ public: } if (NoCaseCompare(m_PiecePool.GetIntendedUse(), "PieceStructures") != 0) { - LOGWARNING("PieceStructures generator: File %s is intended for use in \"%s\", rather than piece structures. Loading the file, but the generator may behave unexpectedly.", - a_FileName.c_str(), m_PiecePool.GetIntendedUse().c_str() + LOGWARNING( + "PieceStructures generator: File %s is intended for use in \"%s\", rather than piece structures. " + "Loading the file, but the generator may behave unexpectedly.", + a_FileName.c_str(), + m_PiecePool.GetIntendedUse().c_str() ); } m_PiecePool.AssignGens(m_Seed, m_BiomeGen, m_HeightGen, m_SeaLevel); @@ -65,19 +66,25 @@ public: cPlacedPieces OutPieces; cPieceGeneratorBFSTree PieceTree(m_PiecePool, m_Seed); PieceTree.PlacePieces(a_OriginX, a_OriginZ, m_MaxDepth, OutPieces); - return std::make_shared<cPrefabStructure>(a_GridX, a_GridZ, a_OriginX, a_OriginZ, std::move(OutPieces), m_HeightGen); + return std::make_shared<cPrefabStructure>( + a_GridX, + a_GridZ, + a_OriginX, + a_OriginZ, + std::move(OutPieces), + m_HeightGen + ); } -protected: - + protected: /** The type used for storing a connection from one piece to another, while building the piece tree. */ struct cConnection { - cPiece * m_Piece; // The piece being connected - cPiece::cConnector m_Connector; // The piece's connector being used (relative non-rotated coords) - int m_NumCCWRotations; // Number of rotations necessary to match the two connectors - int m_Weight; // Relative chance that this connection will be chosen + cPiece * m_Piece; // The piece being connected + cPiece::cConnector m_Connector; // The piece's connector being used (relative non-rotated coords) + int m_NumCCWRotations; // Number of rotations necessary to match the two connectors + int m_Weight; // Relative chance that this connection will be chosen cConnection(cPiece & a_Piece, cPiece::cConnector & a_Connector, int a_NumCCWRotations, int a_Weight); }; @@ -97,7 +104,8 @@ protected: /** The underlying biome generator that defines whether the structure is created or not */ cBiomeGen & m_BiomeGen; - /** The underlying height generator, used to position the prefabs crossing chunk borders if they are set to FitGround. */ + /** The underlying height generator, used to position the prefabs crossing chunk borders if they are set to + * FitGround. */ cTerrainHeightGen & m_HeightGen; /** The world's sea level, if available. Used for some cVerticalStrategy descendants. */ @@ -120,7 +128,7 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cPieceStructuresGen: -cPieceStructuresGen::cPieceStructuresGen(int a_Seed): +cPieceStructuresGen::cPieceStructuresGen(int a_Seed) : m_Seed(a_Seed) { } @@ -129,13 +137,19 @@ cPieceStructuresGen::cPieceStructuresGen(int a_Seed): -bool cPieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen) +bool cPieceStructuresGen::Initialize( + const AString & a_Prefabs, + int a_SeaLevel, + cBiomeGen & a_BiomeGen, + cTerrainHeightGen & a_HeightGen +) { // Load each piecepool: auto Structures = StringSplitAndTrim(a_Prefabs, "|"); for (const auto & Structure : Structures) { - auto FileName = fmt::format(FMT_STRING("Prefabs{0}PieceStructures{0}{1}.cubeset"), cFile::PathSeparator(), Structure); + auto FileName = + fmt::format(FMT_STRING("Prefabs{0}PieceStructures{0}{1}.cubeset"), cFile::PathSeparator(), Structure); if (!cFile::IsFile(FileName)) { FileName.append(".gz"); @@ -155,7 +169,10 @@ bool cPieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel, // Report a warning if no generators available: if (m_Gens.empty()) { - LOGWARNING("The PieceStructures generator was asked to generate \"%s\", but none of the prefabs are valid.", a_Prefabs); + LOGWARNING( + "The PieceStructures generator was asked to generate \"%s\", but none of the prefabs are valid.", + a_Prefabs + ); return false; } return true; diff --git a/src/Generating/PieceStructuresGen.h b/src/Generating/PieceStructuresGen.h index 224e6b262..be5272045 100644 --- a/src/Generating/PieceStructuresGen.h +++ b/src/Generating/PieceStructuresGen.h @@ -21,13 +21,11 @@ cPieceGenerator instance. -class cPieceStructuresGen: - public cFinishGen +class cPieceStructuresGen : public cFinishGen { using Super = cFinishGen; -public: - + public: cPieceStructuresGen(int a_Seed); /** Initializes the generator based on the specified prefab sets. @@ -39,7 +37,7 @@ public: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -protected: + protected: /** The generator doing the work for a single prefab set. Forward-declared so that its implementation changes don't affect the header. */ class cGen; diff --git a/src/Generating/Prefab.cpp b/src/Generating/Prefab.cpp index 0a7b2a89b..ed67d3785 100644 --- a/src/Generating/Prefab.cpp +++ b/src/Generating/Prefab.cpp @@ -80,7 +80,13 @@ cPrefab::cPrefab(const cBlockArea & a_Image) : -cPrefab::cPrefab(const AString & a_BlockDefinitions, const AString & a_BlockData, int a_SizeX, int a_SizeY, int a_SizeZ) : +cPrefab::cPrefab( + const AString & a_BlockDefinitions, + const AString & a_BlockData, + int a_SizeX, + int a_SizeY, + int a_SizeZ +) : m_Size(a_SizeX, a_SizeY, a_SizeZ), m_AllowedRotations(0), m_MergeStrategy(cBlockArea::msOverwrite), @@ -149,10 +155,8 @@ void cPrefab::Draw(cChunkDesc & a_Dest, const Vector3i & a_Placement, int a_NumR const cBlockArea & Image = m_BlockArea[a_NumRotations]; // If the placement is outside this chunk, bail out: - if ( - (Placement.x > cChunkDef::Width) || (Placement.x + Image.GetSizeX() < 0) || - (Placement.z > cChunkDef::Width) || (Placement.z + Image.GetSizeZ() < 0) - ) + if ((Placement.x > cChunkDef::Width) || (Placement.x + Image.GetSizeX() < 0) || (Placement.z > cChunkDef::Width) || + (Placement.z + Image.GetSizeZ() < 0)) { return; } @@ -382,7 +386,8 @@ void cPrefab::ParseBlockImage(const CharMap & a_CharMap, const char * a_BlockIma { for (int z = 0; z < m_Size.z; z++) { - const unsigned char * BlockImage = reinterpret_cast<const unsigned char *>(a_BlockImage + y * m_Size.x * m_Size.z + z * m_Size.x); + const unsigned char * BlockImage = + reinterpret_cast<const unsigned char *>(a_BlockImage + y * m_Size.x * m_Size.z + z * m_Size.x); for (int x = 0; x < m_Size.x; x++) { const sBlockTypeDef & MappedValue = a_CharMap[BlockImage[x]]; @@ -432,7 +437,9 @@ void cPrefab::ParseConnectors(const char * a_ConnectorsDef) // Add the connector: m_Connectors.push_back(cPiece::cConnector( - atoi(Coords[0].c_str()), atoi(Coords[1].c_str()), atoi(Coords[2].c_str()), // Connector pos + atoi(Coords[0].c_str()), + atoi(Coords[1].c_str()), + atoi(Coords[2].c_str()), // Connector pos atoi(Defs[0].c_str()), // Connector type Direction )); @@ -524,7 +531,3 @@ bool cPrefab::CanRotateCCW(int a_NumRotations) const // Or the proper bit in m_AllowedRotations is set return (a_NumRotations == 0) || ((m_AllowedRotations & (1 << ((a_NumRotations + 3) % 4))) != 0); } - - - - diff --git a/src/Generating/Prefab.h b/src/Generating/Prefab.h index 6cec8caa0..08b8ab3cf 100644 --- a/src/Generating/Prefab.h +++ b/src/Generating/Prefab.h @@ -28,16 +28,16 @@ class cChunkDesc; -class cPrefab : - public cPiece +class cPrefab : public cPiece { -public: + public: /** How to handle the space between the prefab bottom and the terrain top. */ enum eExtendFloorStrategy { - efsNone, ///< No processing, the prefab is left "floating in the air" + efsNone, ///< No processing, the prefab is left "floating in the air" efsRepeatBottomTillNonAir, ///< Repeat the bottom-most block down until the first non-air block - efsRepeatBottomTillSolid, ///< Repeat the bottom-most block down until the first solid block; non-solids are overwritten + efsRepeatBottomTillSolid, ///< Repeat the bottom-most block down until the first solid block; non-solids are + ///< overwritten }; struct sDef @@ -87,7 +87,8 @@ public: /** The weight to add to this piece's base per-depth chance if the previous piece is the same. Can be positive or negative. - This is used e. g. to make nether bridges prefer spanning multiple segments or to penalize turrets next to each other. */ + This is used e. g. to make nether bridges prefer spanning multiple segments or to penalize turrets next to each + other. */ int m_AddWeightIfSame; /** If true, the piece will be moved Y-wise so that its first connector is sitting on the terrain. @@ -102,7 +103,8 @@ public: /** Creates a prefab based on the given BlockArea and allowed rotations. */ cPrefab(const cBlockArea & a_Image, int a_AllowedRotations); - /** Creates a prefab based on the given BlockArea. Allowed rotations can be added later on using SetAllowedRotations(). */ + /** Creates a prefab based on the given BlockArea. Allowed rotations can be added later on using + * SetAllowedRotations(). */ cPrefab(const cBlockArea & a_Image); /** Creates a prefab based on the specified block data, using the char-to-block map in a_BlockDefinitions. @@ -156,11 +158,11 @@ public: /** Sets the internal hitbox to the specified value. */ void SetHitBox(const cCuboid & a_HitBox) { m_HitBox = a_HitBox; } -protected: + protected: /** Packs complete definition of a single block, for per-letter assignment. */ struct sBlockTypeDef { - BLOCKTYPE m_BlockType; + BLOCKTYPE m_BlockType; NIBBLETYPE m_BlockMeta; }; @@ -206,7 +208,8 @@ protected: /** The weight to add to this piece's base per-depth chance if the previous piece is the same. Can be positive or negative. - This is used e. g. to make nether bridges prefer spanning multiple segments or to penalize turrets next to each other. */ + This is used e. g. to make nether bridges prefer spanning multiple segments or to penalize turrets next to each + other. */ int m_AddWeightIfSame; /** If true, the piece will be moved Y-wise so that its first connector is sitting on the terrain. @@ -224,7 +227,8 @@ protected: To be called only from this class's constructor! */ void AddRotatedBlockAreas(void); - /** Parses the CharMap in the definition into a CharMap binary data used for translating the definition into BlockArea. */ + /** Parses the CharMap in the definition into a CharMap binary data used for translating the definition into + * BlockArea. */ void ParseCharMap(CharMap & a_CharMapOut, const char * a_CharMapDef); /** Parses the Image in the definition into m_BlockArea[0]'s block types and metas, using the specified CharMap. */ @@ -233,7 +237,3 @@ protected: /** Parses the connectors definition text into m_Connectors member. */ void ParseConnectors(const char * a_ConnectorsDef); }; - - - - diff --git a/src/Generating/PrefabPiecePool.cpp b/src/Generating/PrefabPiecePool.cpp index 4293f38aa..7fc2b6c2c 100644 --- a/src/Generating/PrefabPiecePool.cpp +++ b/src/Generating/PrefabPiecePool.cpp @@ -1,7 +1,8 @@ // PrefabPiecePool.cpp -// Implements the cPrefabPiecePool class that represents a cPiecePool descendant that uses cPrefab instances as the pieces +// Implements the cPrefabPiecePool class that represents a cPiecePool descendant that uses cPrefab instances as the +// pieces #include "Globals.h" #include "PrefabPiecePool.h" @@ -18,14 +19,14 @@ static std::map<AString, cBlockArea::eMergeStrategy> & GetMergeStrategyMap(void) if (msmap.empty()) { // This is the first use, initialize the map: - msmap["msOverwrite"] = cBlockArea::msOverwrite; - msmap["msFillAir"] = cBlockArea::msFillAir; - msmap["msImprint"] = cBlockArea::msImprint; - msmap["msLake"] = cBlockArea::msLake; - msmap["msSpongePrint"] = cBlockArea::msSpongePrint; - msmap["msDifference"] = cBlockArea::msDifference; + msmap["msOverwrite"] = cBlockArea::msOverwrite; + msmap["msFillAir"] = cBlockArea::msFillAir; + msmap["msImprint"] = cBlockArea::msImprint; + msmap["msLake"] = cBlockArea::msLake; + msmap["msSpongePrint"] = cBlockArea::msSpongePrint; + msmap["msDifference"] = cBlockArea::msDifference; msmap["msSimpleCompare"] = cBlockArea::msSimpleCompare; - msmap["msMask"] = cBlockArea::msMask; + msmap["msMask"] = cBlockArea::msMask; } return msmap; } @@ -37,17 +38,17 @@ static std::map<AString, cBlockArea::eMergeStrategy> & GetMergeStrategyMap(void) //////////////////////////////////////////////////////////////////////////////// // cPrefabPiecePool: -cPrefabPiecePool::cPrefabPiecePool(void) -{ -} +cPrefabPiecePool::cPrefabPiecePool(void) {} cPrefabPiecePool::cPrefabPiecePool( - const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs, - const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs, + const cPrefab::sDef * a_PieceDefs, + size_t a_NumPieceDefs, + const cPrefab::sDef * a_StartingPieceDefs, + size_t a_NumStartingPieceDefs, int a_DefaultStartingPieceHeight ) { @@ -112,7 +113,8 @@ void cPrefabPiecePool::AddStartingPieceDefs( ) { ASSERT(a_StartingPieceDefs != nullptr); - auto verticalStrategy = CreateVerticalStrategyFromString(fmt::format(FMT_STRING("Fixed|{}"), a_DefaultPieceHeight), false); + auto verticalStrategy = + CreateVerticalStrategyFromString(fmt::format(FMT_STRING("Fixed|{}"), a_DefaultPieceHeight), false); for (size_t i = 0; i < a_NumStartingPieceDefs; i++) { cPrefab * Prefab = new cPrefab(a_StartingPieceDefs[i]); @@ -152,19 +154,24 @@ bool cPrefabPiecePool::LoadFromString(const AString & a_Contents, const AString try { const auto Extracted = Compression::Extractor().ExtractGZip( - { - reinterpret_cast<const std::byte *>(a_Contents.data()), a_Contents.size() - }); + {reinterpret_cast<const std::byte *>(a_Contents.data()), a_Contents.size()} + ); // Here we do an extra std::string conversion, hardly efficient, but... - // Better would be refactor into LoadFromByteView for the GZip decompression path, and getting cFile to support std::byte. + // Better would be refactor into LoadFromByteView for the GZip decompression path, and getting cFile to + // support std::byte. // ...so it'll do for now. return LoadFromString(std::string(Extracted.GetStringView()), a_FileName, a_LogWarnings); } catch (const std::exception & Oops) { - CONDWARNING(a_LogWarnings, "Failed to decompress Gzip data in file %s. %s", a_FileName.c_str(), Oops.what()); + CONDWARNING( + a_LogWarnings, + "Failed to decompress Gzip data in file %s. %s", + a_FileName.c_str(), + Oops.what() + ); return false; } } @@ -251,7 +258,7 @@ bool cPrefabPiecePool::LoadFromCubesetVer1(const AString & a_FileName, cLuaState while (true) { lua_pushinteger(a_LuaState, idx); // stk: [Pieces] [idx] - lua_gettable(a_LuaState, -2); // stk: [Pieces] [PieceItem] + lua_gettable(a_LuaState, -2); // stk: [Pieces] [PieceItem] if (!lua_istable(a_LuaState, -1)) { // The PieceItem is not present, we've iterated over all items @@ -272,7 +279,12 @@ bool cPrefabPiecePool::LoadFromCubesetVer1(const AString & a_FileName, cLuaState -bool cPrefabPiecePool::LoadCubesetPieceVer1(const AString & a_FileName, cLuaState & a_LuaState, int a_PieceIndex, bool a_LogWarnings) +bool cPrefabPiecePool::LoadCubesetPieceVer1( + const AString & a_FileName, + cLuaState & a_LuaState, + int a_PieceIndex, + bool a_LogWarnings +) { ASSERT(lua_istable(a_LuaState, -1)); @@ -285,16 +297,18 @@ bool cPrefabPiecePool::LoadCubesetPieceVer1(const AString & a_FileName, cLuaStat // Read the hitbox dimensions: cCuboid Hitbox; - if ( - !a_LuaState.GetNamedValue("Hitbox.MinX", Hitbox.p1.x) || + if (!a_LuaState.GetNamedValue("Hitbox.MinX", Hitbox.p1.x) || !a_LuaState.GetNamedValue("Hitbox.MinY", Hitbox.p1.y) || !a_LuaState.GetNamedValue("Hitbox.MinZ", Hitbox.p1.z) || !a_LuaState.GetNamedValue("Hitbox.MaxX", Hitbox.p2.x) || - !a_LuaState.GetNamedValue("Hitbox.MaxY", Hitbox.p2.y) || - !a_LuaState.GetNamedValue("Hitbox.MaxZ", Hitbox.p2.z) - ) + !a_LuaState.GetNamedValue("Hitbox.MaxY", Hitbox.p2.y) || !a_LuaState.GetNamedValue("Hitbox.MaxZ", Hitbox.p2.z)) { - CONDWARNING(a_LogWarnings, "Cannot load piece %s from file %s, it's missing hitbox information", PieceName, a_FileName); + CONDWARNING( + a_LogWarnings, + "Cannot load piece %s from file %s, it's missing hitbox information", + PieceName, + a_FileName + ); return false; } @@ -330,8 +344,11 @@ bool cPrefabPiecePool::LoadCubesetPieceVer1(const AString & a_FileName, cLuaStat { if (prefab->GetVerticalStrategy() == nullptr) { - CONDWARNING(a_LogWarnings, "Starting prefab %s in file %s doesn't have its VerticalStrategy set. Setting to Fixed|150.", - PieceName, a_FileName + CONDWARNING( + a_LogWarnings, + "Starting prefab %s in file %s doesn't have its VerticalStrategy set. Setting to Fixed|150.", + PieceName, + a_FileName ); VERIFY(prefab->SetVerticalStrategyFromString("Fixed|150", false)); } @@ -379,8 +396,13 @@ std::unique_ptr<cPrefab> cPrefabPiecePool::LoadPrefabFromCubesetVer1( } catch (const std::exception & Oops) { - CONDWARNING(a_LogWarnings, "Cannot load schematic file \"%s\" for piece %s in cubeset %s. %s", - SchematicFileName.c_str(), a_PieceName.c_str(), a_FileName.c_str(), Oops.what() + CONDWARNING( + a_LogWarnings, + "Cannot load schematic file \"%s\" for piece %s in cubeset %s. %s", + SchematicFileName.c_str(), + a_PieceName.c_str(), + a_FileName.c_str(), + Oops.what() ); return nullptr; } @@ -390,13 +412,16 @@ std::unique_ptr<cPrefab> cPrefabPiecePool::LoadPrefabFromCubesetVer1( // There's no referenced schematic file, load from BlockDefinitions / BlockData. // Get references to the data and the table.concat function: cLuaState::cRef TableConcat, BlockDefinitions, BlockData; - if ( - !a_LuaState.GetNamedGlobal("table.concat", TableConcat) || + if (!a_LuaState.GetNamedGlobal("table.concat", TableConcat) || !a_LuaState.GetNamedValue("BlockDefinitions", BlockDefinitions) || - !a_LuaState.GetNamedValue("BlockData", BlockData) - ) + !a_LuaState.GetNamedValue("BlockData", BlockData)) { - CONDWARNING(a_LogWarnings, "Cannot parse block data for piece %s in cubeset %s", a_PieceName.c_str(), a_FileName.c_str()); + CONDWARNING( + a_LogWarnings, + "Cannot parse block data for piece %s in cubeset %s", + a_PieceName.c_str(), + a_FileName.c_str() + ); return nullptr; } @@ -404,7 +429,12 @@ std::unique_ptr<cPrefab> cPrefabPiecePool::LoadPrefabFromCubesetVer1( AString BlockDefStr; if (!a_LuaState.Call(TableConcat, BlockDefinitions, "\n", cLuaState::Return, BlockDefStr)) { - CONDWARNING(a_LogWarnings, "Cannot concat block definitions for piece %s in cubeset %s", a_PieceName.c_str(), a_FileName.c_str()); + CONDWARNING( + a_LogWarnings, + "Cannot concat block definitions for piece %s in cubeset %s", + a_PieceName.c_str(), + a_FileName.c_str() + ); return nullptr; } @@ -412,28 +442,39 @@ std::unique_ptr<cPrefab> cPrefabPiecePool::LoadPrefabFromCubesetVer1( AString BlockDataStr; if (!a_LuaState.Call(TableConcat, BlockData, "", cLuaState::Return, BlockDataStr)) { - CONDWARNING(a_LogWarnings, "Cannot concat block data for piece %s in cubeset %s", a_PieceName.c_str(), a_FileName.c_str()); + CONDWARNING( + a_LogWarnings, + "Cannot concat block data for piece %s in cubeset %s", + a_PieceName.c_str(), + a_FileName.c_str() + ); return nullptr; } // Read the size: int SizeX = 0, SizeY = 0, SizeZ = 0; - if ( - !a_LuaState.GetNamedValue("Size.x", SizeX) || - !a_LuaState.GetNamedValue("Size.y", SizeY) || - !a_LuaState.GetNamedValue("Size.z", SizeZ) - ) - { - CONDWARNING(a_LogWarnings, "Cannot load piece %s from file %s, its size information is missing", a_PieceName.c_str(), a_FileName.c_str()); + if (!a_LuaState.GetNamedValue("Size.x", SizeX) || !a_LuaState.GetNamedValue("Size.y", SizeY) || + !a_LuaState.GetNamedValue("Size.z", SizeZ)) + { + CONDWARNING( + a_LogWarnings, + "Cannot load piece %s from file %s, its size information is missing", + a_PieceName.c_str(), + a_FileName.c_str() + ); return nullptr; } // Check that the size matches the data length: if (static_cast<size_t>(SizeX * SizeY * SizeZ) != BlockDataStr.size()) { - CONDWARNING(a_LogWarnings, "Cannot create piece %s from file %s, its size (%d) doesn't match the blockdata length (%u)", - a_PieceName.c_str(), a_FileName.c_str(), - SizeX * SizeY * SizeZ, static_cast<unsigned>(BlockDataStr.size()) + CONDWARNING( + a_LogWarnings, + "Cannot create piece %s from file %s, its size (%d) doesn't match the blockdata length (%u)", + a_PieceName.c_str(), + a_FileName.c_str(), + SizeX * SizeY * SizeZ, + static_cast<unsigned>(BlockDataStr.size()) ); return nullptr; } @@ -457,7 +498,12 @@ bool cPrefabPiecePool::ReadConnectorsCubesetVer1( auto conns = a_LuaState.WalkToValue("Connectors"); if (!conns.IsValid()) { - CONDWARNING(a_LogWarnings, "Cannot load piece %s from file %s, it has no connectors definition.", a_PieceName.c_str(), a_FileName.c_str()); + CONDWARNING( + a_LogWarnings, + "Cannot load piece %s from file %s, it has no connectors definition.", + a_PieceName.c_str(), + a_FileName.c_str() + ); return false; } @@ -467,7 +513,7 @@ bool cPrefabPiecePool::ReadConnectorsCubesetVer1( while (true) { lua_pushinteger(a_LuaState, idx); // stk: [Connectors] [idx] - lua_gettable(a_LuaState, -2); // stk: [Connectors] [conn] + lua_gettable(a_LuaState, -2); // stk: [Connectors] [conn] if (!lua_istable(a_LuaState, -1)) { // The connector is not present, we've iterated over all items @@ -477,19 +523,22 @@ bool cPrefabPiecePool::ReadConnectorsCubesetVer1( int Type = 0, RelX = 0, RelY = 0, RelZ = 0; AString DirectionStr; cPiece::cConnector::eDirection Direction = cPiece::cConnector::dirYM; - if ( - !a_LuaState.GetNamedValue("Type", Type) || - !a_LuaState.GetNamedValue("RelX", RelX) || - !a_LuaState.GetNamedValue("RelY", RelY) || - !a_LuaState.GetNamedValue("RelZ", RelZ) || + if (!a_LuaState.GetNamedValue("Type", Type) || !a_LuaState.GetNamedValue("RelX", RelX) || + !a_LuaState.GetNamedValue("RelY", RelY) || !a_LuaState.GetNamedValue("RelZ", RelZ) || !a_LuaState.GetNamedValue("Direction", DirectionStr) || - !cPiece::cConnector::StringToDirection(DirectionStr, Direction) - ) + !cPiece::cConnector::StringToDirection(DirectionStr, Direction)) { if (a_LogWarnings) { - FLOGWARNING("Piece {0} in file {1} has a malformed Connector at index {2} ({3}, type {4}, direction {5}). Skipping the connector.", - a_PieceName, a_FileName, idx, Vector3i{RelX, RelY, RelZ}, Type, DirectionStr + FLOGWARNING( + "Piece {0} in file {1} has a malformed Connector at index {2} ({3}, type {4}, direction {5}). " + "Skipping the connector.", + a_PieceName, + a_FileName, + idx, + Vector3i {RelX, RelY, RelZ}, + Type, + DirectionStr ); } res = false; @@ -526,12 +575,12 @@ bool cPrefabPiecePool::ReadPieceMetadataCubesetVer1( // Get the values: int AddWeightIfSame = 0, DefaultWeight = 100, MoveToGround = 0; AString DepthWeight, MergeStrategy, VerticalLimit, VerticalStrategy; - a_LuaState.GetNamedValue("AddWeightIfSame", AddWeightIfSame); - a_LuaState.GetNamedValue("DefaultWeight", DefaultWeight); - a_LuaState.GetNamedValue("DepthWeight", DepthWeight); - a_LuaState.GetNamedValue("MergeStrategy", MergeStrategy); - a_LuaState.GetNamedValue("MoveToGround", MoveToGround); - a_LuaState.GetNamedValue("VerticalLimit", VerticalLimit); + a_LuaState.GetNamedValue("AddWeightIfSame", AddWeightIfSame); + a_LuaState.GetNamedValue("DefaultWeight", DefaultWeight); + a_LuaState.GetNamedValue("DepthWeight", DepthWeight); + a_LuaState.GetNamedValue("MergeStrategy", MergeStrategy); + a_LuaState.GetNamedValue("MoveToGround", MoveToGround); + a_LuaState.GetNamedValue("VerticalLimit", VerticalLimit); a_LuaState.GetNamedValue("VerticalStrategy", VerticalStrategy); // Apply the values: @@ -542,8 +591,12 @@ bool cPrefabPiecePool::ReadPieceMetadataCubesetVer1( auto strategy = msmap.find(MergeStrategy); if (strategy == msmap.end()) { - CONDWARNING(a_LogWarnings, "Unknown merge strategy (\"%s\") specified for piece %s in file %s. Using msSpongePrint instead.", - MergeStrategy.c_str(), a_PieceName.c_str(), a_FileName.c_str() + CONDWARNING( + a_LogWarnings, + "Unknown merge strategy (\"%s\") specified for piece %s in file %s. Using msSpongePrint instead.", + MergeStrategy.c_str(), + a_PieceName.c_str(), + a_FileName.c_str() ); a_Prefab->SetMergeStrategy(cBlockArea::msSpongePrint); } @@ -560,10 +613,13 @@ bool cPrefabPiecePool::ReadPieceMetadataCubesetVer1( int ShouldExpandFloor; if (a_LuaState.GetNamedValue("ShouldExpandFloor", ShouldExpandFloor)) { - LOG("Piece \"%s\" in file \"%s\" is using the old \"ShouldExpandFloor\" attribute. Use the new \"ExpandFloorStrategy\" attribute instead for more options.", - a_PieceName.c_str(), a_FileName.c_str() + LOG("Piece \"%s\" in file \"%s\" is using the old \"ShouldExpandFloor\" attribute. Use the new " + "\"ExpandFloorStrategy\" attribute instead for more options.", + a_PieceName.c_str(), + a_FileName.c_str()); + a_Prefab->SetExtendFloorStrategy( + (ShouldExpandFloor != 0) ? cPrefab::efsRepeatBottomTillNonAir : cPrefab::efsNone ); - a_Prefab->SetExtendFloorStrategy((ShouldExpandFloor != 0) ? cPrefab::efsRepeatBottomTillNonAir : cPrefab::efsNone); } } else @@ -581,8 +637,11 @@ bool cPrefabPiecePool::ReadPieceMetadataCubesetVer1( { if (lcExpandFloorStrategyStr != "none") { - LOGWARNING("Piece \"%s\" in file \"%s\" is using an unknown \"ExpandFloorStrategy\" attribute value: \"%s\"", - a_PieceName.c_str(), a_FileName.c_str(), ExpandFloorStrategyStr.c_str() + LOGWARNING( + "Piece \"%s\" in file \"%s\" is using an unknown \"ExpandFloorStrategy\" attribute value: \"%s\"", + a_PieceName.c_str(), + a_FileName.c_str(), + ExpandFloorStrategyStr.c_str() ); } a_Prefab->SetExtendFloorStrategy(cPrefab::efsNone); @@ -592,8 +651,12 @@ bool cPrefabPiecePool::ReadPieceMetadataCubesetVer1( { if (!a_Prefab->SetVerticalLimitFromString(VerticalLimit, a_LogWarnings)) { - CONDWARNING(a_LogWarnings, "Unknown VerticalLimit (\"%s\") specified for piece %s in file %s. Using no limit instead.", - VerticalLimit.c_str(), a_PieceName.c_str(), a_FileName.c_str() + CONDWARNING( + a_LogWarnings, + "Unknown VerticalLimit (\"%s\") specified for piece %s in file %s. Using no limit instead.", + VerticalLimit.c_str(), + a_PieceName.c_str(), + a_FileName.c_str() ); } } @@ -612,10 +675,7 @@ bool cPrefabPiecePool::ReadPieceMetadataCubesetVer1( -void cPrefabPiecePool::ApplyBaseMetadataCubesetVer1( - const AString & a_FileName, - bool a_LogWarnings -) +void cPrefabPiecePool::ApplyBaseMetadataCubesetVer1(const AString & a_FileName, bool a_LogWarnings) { // Set the metadata values to defaults: m_MinDensity = 100; @@ -627,10 +687,10 @@ void cPrefabPiecePool::ApplyBaseMetadataCubesetVer1( // Read the metadata values: m_IntendedUse = GetMetadata("IntendedUse"); - GetStringMapInteger(m_Metadata, "MaxDensity", m_MaxDensity); - GetStringMapInteger(m_Metadata, "MinDensity", m_MinDensity); - GetStringMapInteger(m_Metadata, "VillageRoadBlockType", m_VillageRoadBlockType); - GetStringMapInteger(m_Metadata, "VillageRoadBlockMeta", m_VillageRoadBlockMeta); + GetStringMapInteger(m_Metadata, "MaxDensity", m_MaxDensity); + GetStringMapInteger(m_Metadata, "MinDensity", m_MinDensity); + GetStringMapInteger(m_Metadata, "VillageRoadBlockType", m_VillageRoadBlockType); + GetStringMapInteger(m_Metadata, "VillageRoadBlockMeta", m_VillageRoadBlockMeta); GetStringMapInteger(m_Metadata, "VillageWaterRoadBlockType", m_VillageWaterRoadBlockType); GetStringMapInteger(m_Metadata, "VillageWaterRoadBlockMeta", m_VillageWaterRoadBlockMeta); @@ -651,13 +711,16 @@ void cPrefabPiecePool::ApplyBaseMetadataCubesetVer1( else { auto biomes = StringSplitAndTrim(allowedBiomes, ","); - for (const auto & biome: biomes) + for (const auto & biome : biomes) { EMCSBiome b = StringToBiome(biome); if (b == biInvalidBiome) { - CONDWARNING(a_LogWarnings, "Invalid biome (\"%s\") specified in AllowedBiomes in cubeset file %s. Skipping the biome.", - biome.c_str(), a_FileName.c_str() + CONDWARNING( + a_LogWarnings, + "Invalid biome (\"%s\") specified in AllowedBiomes in cubeset file %s. Skipping the biome.", + biome.c_str(), + a_FileName.c_str() ); continue; } @@ -717,7 +780,7 @@ AString cPrefabPiecePool::GetMetadata(const AString & a_ParamName) const void cPrefabPiecePool::AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel) { // Assign the generator linkage to all starting pieces' VerticalStrategies: - for (auto & piece: m_StartingPieces) + for (auto & piece : m_StartingPieces) { auto verticalStrategy = piece->GetVerticalStrategy(); if (verticalStrategy != nullptr) @@ -727,7 +790,7 @@ void cPrefabPiecePool::AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHe } // for piece - m_StartingPieces[] // Assign the generator linkage to all pieces' VerticalLimits: - for (auto & piece: m_AllPieces) + for (auto & piece : m_AllPieces) { auto verticalLimit = piece->GetVerticalLimit(); if (verticalLimit != nullptr) @@ -774,7 +837,11 @@ cPieces cPrefabPiecePool::GetStartingPieces(void) -int cPrefabPiecePool::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece) +int cPrefabPiecePool::GetPieceWeight( + const cPlacedPiece & a_PlacedPiece, + const cPiece::cConnector & a_ExistingConnector, + const cPiece & a_NewPiece +) { return (static_cast<const cPrefab &>(a_NewPiece)).GetPieceWeight(a_PlacedPiece, a_ExistingConnector); } diff --git a/src/Generating/PrefabPiecePool.h b/src/Generating/PrefabPiecePool.h index 708b9be57..7e6e33fc8 100644 --- a/src/Generating/PrefabPiecePool.h +++ b/src/Generating/PrefabPiecePool.h @@ -23,10 +23,9 @@ class cLuaState; -class cPrefabPiecePool : - public cPiecePool +class cPrefabPiecePool : public cPiecePool { -public: + public: /** Creates an empty instance. Prefabs can be added by calling AddPieceDefs() and AddStartingPieceDefs(). */ cPrefabPiecePool(void); @@ -39,8 +38,10 @@ public: If a_DefaultStartingPieceHeight is non-negative, it is applied to each starting piece as its fixed height (for the GetStartingPieceHeight() call). */ cPrefabPiecePool( - const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs, - const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs, + const cPrefab::sDef * a_PieceDefs, + size_t a_NumPieceDefs, + const cPrefab::sDef * a_StartingPieceDefs, + size_t a_NumStartingPieceDefs, int a_DefaultStartingPieceHeight = -1 ); @@ -92,9 +93,9 @@ public: const AString & GetIntendedUse(void) const { return m_IntendedUse; } int GetMinDensity(void) const { return m_MinDensity; } int GetMaxDensity(void) const { return m_MaxDensity; } - BLOCKTYPE GetVillageRoadBlockType (void) const { return m_VillageRoadBlockType; } - NIBBLETYPE GetVillageRoadBlockMeta (void) const { return m_VillageRoadBlockMeta; } - BLOCKTYPE GetVillageWaterRoadBlockType(void) const { return m_VillageWaterRoadBlockType; } + BLOCKTYPE GetVillageRoadBlockType(void) const { return m_VillageRoadBlockType; } + NIBBLETYPE GetVillageRoadBlockMeta(void) const { return m_VillageRoadBlockMeta; } + BLOCKTYPE GetVillageWaterRoadBlockType(void) const { return m_VillageWaterRoadBlockType; } NIBBLETYPE GetVillageWaterRoadBlockMeta(void) const { return m_VillageWaterRoadBlockMeta; } /** Returns true if a_Biome is among the accepted biomes in the m_AcceptedBiomes metadata member. */ @@ -113,13 +114,16 @@ public: // cPiecePool overrides: virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override; virtual cPieces GetStartingPieces(void) override; - virtual int GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece) override; + virtual int GetPieceWeight( + const cPlacedPiece & a_PlacedPiece, + const cPiece::cConnector & a_ExistingConnector, + const cPiece & a_NewPiece + ) override; virtual int GetStartingPieceWeight(const cPiece & a_NewPiece) override; virtual void PiecePlaced(const cPiece & a_Piece) override; virtual void Reset(void) override; -protected: - + protected: /** The type used to map a connector type to the list of pieces with that connector */ typedef std::map<int, cPieces> cPiecesMap; @@ -197,9 +201,9 @@ protected: Returns true on success, false on failure. The connectors are added into the a_Prefab object. No Connectors table is considered a failure, empty Connectors table is considered a success. - If any of the connectors are malformed, it is considered a failure, although the rest of the connectors will still load. - a_PieceName is the identification of the piece, used for logging only. - If a_LogWarnings is true, logs a warning to console when loading fails. */ + If any of the connectors are malformed, it is considered a failure, although the rest of the connectors will still + load. a_PieceName is the identification of the piece, used for logging only. If a_LogWarnings is true, logs a + warning to console when loading fails. */ bool ReadConnectorsCubesetVer1( const AString & a_FileName, cLuaState & a_LuaState, @@ -225,20 +229,9 @@ protected: /** Reads the metadata for the entire pool from the cubeset file, stores it in the m_Metadata map. Returns true on success, false on failure. If a_LogWarnings is true, logs a warning to console when loading fails. */ - bool ReadPoolMetadataCubesetVer1( - const AString & a_FileName, - cLuaState & a_LuaState, - bool a_LogWarnings - ); + bool ReadPoolMetadataCubesetVer1(const AString & a_FileName, cLuaState & a_LuaState, bool a_LogWarnings); /** Applies the base known metadata from the m_Metadata map into this pool. If a_LogWarnings is true, logs a warning to console when loading fails. */ - void ApplyBaseMetadataCubesetVer1( - const AString & a_FileName, - bool a_LogWarnings - ); -} ; - - - - + void ApplyBaseMetadataCubesetVer1(const AString & a_FileName, bool a_LogWarnings); +}; diff --git a/src/Generating/PrefabStructure.cpp b/src/Generating/PrefabStructure.cpp index 9814610b4..c83f768d4 100644 --- a/src/Generating/PrefabStructure.cpp +++ b/src/Generating/PrefabStructure.cpp @@ -1,7 +1,8 @@ // PrefabStructure.cpp -// Implements the cPrefabStructure class representing a cGridStructGen::cStructure descendant based on placed cPrefab instances +// Implements the cPrefabStructure class representing a cGridStructGen::cStructure descendant based on placed cPrefab +// instances #include "Globals.h" #include "PrefabStructure.h" @@ -12,14 +13,14 @@ cPrefabStructure::cPrefabStructure( - int a_GridX, int a_GridZ, - int a_OriginX, int a_OriginZ, + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ, cPlacedPieces && a_Pieces, cTerrainHeightGen & a_HeightGen -): - Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), - m_Pieces(std::move(a_Pieces)), - m_HeightGen(a_HeightGen) +) : + Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Pieces(std::move(a_Pieces)), m_HeightGen(a_HeightGen) { } diff --git a/src/Generating/PrefabStructure.h b/src/Generating/PrefabStructure.h index 8b489d866..1b781c4e1 100644 --- a/src/Generating/PrefabStructure.h +++ b/src/Generating/PrefabStructure.h @@ -1,7 +1,8 @@ // PrefabStructure.h -// Declares the cPrefabStructure class representing a cGridStructGen::cStructure descendant based on placed cPrefab instances +// Declares the cPrefabStructure class representing a cGridStructGen::cStructure descendant based on placed cPrefab +// instances @@ -16,21 +17,21 @@ -class cPrefabStructure: - public cGridStructGen::cStructure +class cPrefabStructure : public cGridStructGen::cStructure { using Super = cGridStructGen::cStructure; -public: - + public: cPrefabStructure( - int a_GridX, int a_GridZ, - int a_OriginX, int a_OriginZ, + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ, cPlacedPieces && a_Pieces, cTerrainHeightGen & a_HeightGen ); -protected: + protected: /** The pieces placed by the generator. */ cPlacedPieces m_Pieces; diff --git a/src/Generating/ProtIntGen.h b/src/Generating/ProtIntGen.h index 290998075..1ab1b8096 100644 --- a/src/Generating/ProtIntGen.h +++ b/src/Generating/ProtIntGen.h @@ -33,7 +33,7 @@ This value is used only if there isn't an override in place. To adjust the actual buffer size, just do a "#define PROT_INT_BUFFER_SIZE 9000" before including this header. Note, however, that you should use a consistent value throughout a single project. */ #ifndef PROT_INT_BUFFER_SIZE - #define PROT_INT_BUFFER_SIZE 900 +#define PROT_INT_BUFFER_SIZE 900 #endif @@ -43,13 +43,12 @@ Note, however, that you should use a consistent value throughout a single projec /** Interface that all the generator classes provide. */ class cProtIntGen { -protected: + protected: /** Maximum size of the generated area. Adjust the constant if you need larger areas, these are just so that we can use fixed-size buffers. */ static const int m_BufferSize = PROT_INT_BUFFER_SIZE; -public: - + public: /** Type of the generic interface used for storing links to the underlying generators. */ using Underlying = std::shared_ptr<cProtIntGen>; @@ -59,7 +58,7 @@ public: virtual ~cProtIntGen() {} /** Generates the array of specified size into a_Values, based on given min coords. */ - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) = 0; + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) = 0; }; @@ -67,19 +66,17 @@ public: /** Provides additional cNoise member and its helper functions. */ -class cProtIntGenWithNoise: - public cProtIntGen +class cProtIntGenWithNoise : public cProtIntGen { using Super = cProtIntGen; -public: - - cProtIntGenWithNoise(int a_Seed): + public: + cProtIntGenWithNoise(int a_Seed) : m_Noise(a_Seed) { } -protected: + protected: cNoise m_Noise; /** Chooses one of a_Val1 or a_Val2, based on m_Noise and the coordinates for querying the noise. */ @@ -108,33 +105,31 @@ protected: /** Generates a 2D array of random integers in the specified range [0 .. Range). */ -class cProtIntGenChoice: - public cProtIntGenWithNoise +class cProtIntGenChoice : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenChoice(int a_Seed, int a_Range): - Super(a_Seed), - m_Range(a_Range) + public: + cProtIntGenChoice(int a_Seed, int a_Range) : + Super(a_Seed), m_Range(a_Range) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { for (size_t z = 0; z < a_SizeZ; z++) { int BaseZ = a_MinZ + static_cast<int>(z); for (size_t x = 0; x < a_SizeX; x++) { - a_Values[x + a_SizeX * z] = (Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), BaseZ) / 7) % m_Range; + a_Values[x + a_SizeX * z] = + (Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), BaseZ) / 7) % m_Range; } } // for z } -protected: + protected: int m_Range; }; @@ -145,21 +140,18 @@ protected: /** Decides between the ocean and landmass biomes. Has a threshold (in percent) of how much land, the larger the threshold, the more land. Generates 0 for ocean, biome group ID for landmass. */ -class cProtIntGenLandOcean: - public cProtIntGenWithNoise +class cProtIntGenLandOcean : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenLandOcean(int a_Seed, int a_Threshold): - Super(a_Seed), - m_Threshold(a_Threshold) + public: + cProtIntGenLandOcean(int a_Seed, int a_Threshold) : + Super(a_Seed), m_Threshold(a_Threshold) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { for (size_t z = 0; z < a_SizeZ; z++) { @@ -172,13 +164,14 @@ public: } // If the centerpoint of the world is within the area, set it to bgTemperate, always: - if ((a_MinX <= 0) && (a_MinZ <= 0) && (a_MinX + static_cast<int>(a_SizeX) > 0) && (a_MinZ + static_cast<int>(a_SizeZ) > 0)) + if ((a_MinX <= 0) && (a_MinZ <= 0) && (a_MinX + static_cast<int>(a_SizeX) > 0) && + (a_MinZ + static_cast<int>(a_SizeZ) > 0)) { a_Values[static_cast<size_t>(-a_MinX) - static_cast<size_t>(a_MinZ) * a_SizeX] = bgTemperate; } } -protected: + protected: int m_Threshold; }; @@ -189,21 +182,18 @@ protected: /** Zooms the underlying value array to twice the size. Uses random-neighbor for the pixels in-between. This means that the zoome out image is randomly distorted. Applying zoom several times provides all the distortion that the generators need. */ -class cProtIntGenZoom: - public cProtIntGenWithNoise +class cProtIntGenZoom : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenZoom(int a_Seed, Underlying a_UnderlyingGen): - Super(a_Seed), - m_UnderlyingGen(std::move(a_UnderlyingGen)) + public: + cProtIntGenZoom(int a_Seed, Underlying a_UnderlyingGen) : + Super(a_Seed), m_UnderlyingGen(std::move(a_UnderlyingGen)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Get the coords for the lower generator: int lowerMinX = a_MinX >> 1; @@ -235,7 +225,7 @@ public: int RndZ = (static_cast<int>(z) + lowerMinZ) * 2; cache[idx] = PrevZ0; cache[idx + lowStepX] = Super::chooseRandomOne(RndX, RndZ + 1, PrevZ0, PrevZ1); - cache[idx + 1] = Super::chooseRandomOne(RndX, RndZ - 1, PrevZ0, ValX1Z0); + cache[idx + 1] = Super::chooseRandomOne(RndX, RndZ - 1, PrevZ0, ValX1Z0); cache[idx + 1 + lowStepX] = Super::chooseRandomOne(RndX, RndZ, PrevZ0, ValX1Z0, PrevZ1, ValX1Z1); idx += 2; PrevZ0 = ValX1Z0; @@ -250,7 +240,7 @@ public: } } -protected: + protected: Underlying m_UnderlyingGen; }; @@ -260,21 +250,18 @@ protected: /** Smoothes out some artifacts generated by the zooming - mostly single-pixel values. Compares each pixel to its neighbors and if the neighbors are equal, changes the pixel to their value. */ -class cProtIntGenSmooth: - public cProtIntGenWithNoise +class cProtIntGenSmooth : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenSmooth(int a_Seed, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenSmooth(int a_Seed, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 2; @@ -290,10 +277,10 @@ public: int NoiseZ = a_MinZ + static_cast<int>(z); for (size_t x = 0; x < a_SizeX; x++) { - int val = lowerData[x + 1 + (z + 1) * lowerSizeX]; - int above = lowerData[x + 1 + z * lowerSizeX]; + int val = lowerData[x + 1 + (z + 1) * lowerSizeX]; + int above = lowerData[x + 1 + z * lowerSizeX]; int below = lowerData[x + 1 + (z + 2) * lowerSizeX]; - int left = lowerData[x + (z + 1) * lowerSizeX]; + int left = lowerData[x + (z + 1) * lowerSizeX]; int right = lowerData[x + 2 + (z + 1) * lowerSizeX]; if ((left == right) && (above == below)) @@ -325,7 +312,7 @@ public: } } -protected: + protected: Underlying m_Underlying; }; @@ -334,20 +321,18 @@ protected: /** Averages the values of the underlying 2 * 2 neighbors. */ -class cProtIntGenAvgValues: - public cProtIntGen +class cProtIntGenAvgValues : public cProtIntGen { using Super = cProtIntGen; -public: - - cProtIntGenAvgValues(Underlying a_Underlying): + public: + cProtIntGenAvgValues(Underlying a_Underlying) : m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 1; @@ -362,15 +347,14 @@ public: for (size_t x = 0; x < a_SizeX; x++) { size_t idxLower = x + lowerSizeX * z; - a_Values[x + a_SizeX * z] = ( - lowerData[idxLower] + lowerData[idxLower + 1] + - lowerData[idxLower + lowerSizeX] + lowerData[idxLower + lowerSizeX + 1] - ) / 4; + a_Values[x + a_SizeX * z] = (lowerData[idxLower] + lowerData[idxLower + 1] + + lowerData[idxLower + lowerSizeX] + lowerData[idxLower + lowerSizeX + 1]) / + 4; } } } -protected: + protected: Underlying m_Underlying; }; @@ -379,20 +363,18 @@ protected: /** Averages the values of the underlying 4 * 4 neighbors. */ -class cProtIntGenAvg4Values: - public cProtIntGen +class cProtIntGenAvg4Values : public cProtIntGen { using Super = cProtIntGen; -public: - - cProtIntGenAvg4Values(Underlying a_Underlying): + public: + cProtIntGenAvg4Values(Underlying a_Underlying) : m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 4; @@ -410,17 +392,19 @@ public: size_t idxLower2 = idxLower1 + lowerSizeX; size_t idxLower3 = idxLower1 + 2 * lowerSizeX; size_t idxLower4 = idxLower1 + 3 * lowerSizeX; - a_Values[x + a_SizeX * z] = ( - 1 * lowerData[idxLower1] + 2 * lowerData[idxLower1 + 1] + 2 * lowerData[idxLower1 + 2] + 1 * lowerData[idxLower1 + 3] + - 2 * lowerData[idxLower2] + 32 * lowerData[idxLower2 + 1] + 32 * lowerData[idxLower2 + 2] + 2 * lowerData[idxLower2 + 3] + - 2 * lowerData[idxLower3] + 32 * lowerData[idxLower3 + 1] + 32 * lowerData[idxLower3 + 2] + 2 * lowerData[idxLower3 + 3] + - 1 * lowerData[idxLower4] + 2 * lowerData[idxLower4 + 1] + 2 * lowerData[idxLower4 + 2] + 1 * lowerData[idxLower4 + 3] - ) / 148; + a_Values[x + a_SizeX * z] = + (1 * lowerData[idxLower1] + 2 * lowerData[idxLower1 + 1] + 2 * lowerData[idxLower1 + 2] + + 1 * lowerData[idxLower1 + 3] + 2 * lowerData[idxLower2] + 32 * lowerData[idxLower2 + 1] + + 32 * lowerData[idxLower2 + 2] + 2 * lowerData[idxLower2 + 3] + 2 * lowerData[idxLower3] + + 32 * lowerData[idxLower3 + 1] + 32 * lowerData[idxLower3 + 2] + 2 * lowerData[idxLower3 + 3] + + 1 * lowerData[idxLower4] + 2 * lowerData[idxLower4 + 1] + 2 * lowerData[idxLower4 + 2] + + 1 * lowerData[idxLower4 + 3]) / + 148; } } } -protected: + protected: Underlying m_Underlying; }; @@ -429,21 +413,18 @@ protected: /** Averages the values of the underlying 3 * 3 neighbors with custom weight. */ -template <int WeightCenter, int WeightCardinal, int WeightDiagonal> -class cProtIntGenWeightAvg: - public cProtIntGen +template <int WeightCenter, int WeightCardinal, int WeightDiagonal> class cProtIntGenWeightAvg : public cProtIntGen { using Super = cProtIntGen; -public: - - cProtIntGenWeightAvg(Underlying a_Underlying): + public: + cProtIntGenWeightAvg(Underlying a_Underlying) : m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 3; @@ -460,16 +441,18 @@ public: size_t idxLower1 = x + lowerSizeX * z; size_t idxLower2 = idxLower1 + lowerSizeX; size_t idxLower3 = idxLower1 + 2 * lowerSizeX; - a_Values[x + a_SizeX * z] = ( - WeightDiagonal * lowerData[idxLower1] + WeightCardinal * lowerData[idxLower1 + 1] + WeightDiagonal * lowerData[idxLower1 + 2] + - WeightCardinal * lowerData[idxLower2] + WeightCenter * lowerData[idxLower2 + 1] + WeightCardinal * lowerData[idxLower2 + 2] + - WeightDiagonal * lowerData[idxLower3] + WeightCardinal * lowerData[idxLower3 + 1] + WeightDiagonal * lowerData[idxLower3 + 2] - ) / (4 * WeightDiagonal + 4 * WeightCardinal + WeightCenter); + a_Values[x + a_SizeX * z] = + (WeightDiagonal * lowerData[idxLower1] + WeightCardinal * lowerData[idxLower1 + 1] + + WeightDiagonal * lowerData[idxLower1 + 2] + WeightCardinal * lowerData[idxLower2] + + WeightCenter * lowerData[idxLower2 + 1] + WeightCardinal * lowerData[idxLower2 + 2] + + WeightDiagonal * lowerData[idxLower3] + WeightCardinal * lowerData[idxLower3 + 1] + + WeightDiagonal * lowerData[idxLower3 + 2]) / + (4 * WeightDiagonal + 4 * WeightCardinal + WeightCenter); } } } -protected: + protected: Underlying m_Underlying; }; @@ -478,24 +461,18 @@ protected: /** Replaces random values of the underlying data with random integers in the specified range [Min .. Min + Range). */ -class cProtIntGenRndChoice: - public cProtIntGenWithNoise +class cProtIntGenRndChoice : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenRndChoice(int a_Seed, int a_ChancePct, int a_Min, int a_Range, Underlying a_Underlying): - Super(a_Seed), - m_ChancePct(a_ChancePct), - m_Min(a_Min), - m_Range(a_Range), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenRndChoice(int a_Seed, int a_ChancePct, int a_Min, int a_Range, Underlying a_Underlying) : + Super(a_Seed), m_ChancePct(a_ChancePct), m_Min(a_Min), m_Range(a_Range), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -508,13 +485,14 @@ public: { if (((Super::m_Noise.IntNoise2DInt(BaseZ, a_MinX + static_cast<int>(x)) / 13) % 101) < m_ChancePct) { - a_Values[x + a_SizeX * z] = m_Min + (Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), BaseZ) / 7) % m_Range; + a_Values[x + a_SizeX * z] = + m_Min + (Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), BaseZ) / 7) % m_Range; } } // for x } // for z } -protected: + protected: int m_ChancePct; int m_Min; int m_Range; @@ -526,23 +504,18 @@ protected: /** Adds a random value in range [-a_HalfRange, +a_HalfRange] to each of the underlying values. */ -class cProtIntGenAddRnd: - public cProtIntGenWithNoise +class cProtIntGenAddRnd : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenAddRnd(int a_Seed, int a_HalfRange, Underlying a_Underlying): - Super(a_Seed), - m_Range(a_HalfRange * 2 + 1), - m_HalfRange(a_HalfRange), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenAddRnd(int a_Seed, int a_HalfRange, Underlying a_Underlying) : + Super(a_Seed), m_Range(a_HalfRange * 2 + 1), m_HalfRange(a_HalfRange), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -553,13 +526,14 @@ public: int NoiseZ = a_MinZ + static_cast<int>(z); for (size_t x = 0; x < a_SizeX; x++) { - int noiseVal = ((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), NoiseZ) / 7) % m_Range) - m_HalfRange; + int noiseVal = + ((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), NoiseZ) / 7) % m_Range) - m_HalfRange; a_Values[x + z * a_SizeX] += noiseVal; } } } -protected: + protected: int m_Range; int m_HalfRange; Underlying m_Underlying; @@ -570,22 +544,18 @@ protected: /** Replaces random underlying values with the average of the neighbors. */ -class cProtIntGenRndAvg: - public cProtIntGenWithNoise +class cProtIntGenRndAvg : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenRndAvg(int a_Seed, int a_AvgChancePct, Underlying a_Underlying): - Super(a_Seed), - m_AvgChancePct(a_AvgChancePct), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenRndAvg(int a_Seed, int a_AvgChancePct, Underlying a_Underlying) : + Super(a_Seed), m_AvgChancePct(a_AvgChancePct), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 2; @@ -604,10 +574,9 @@ public: if (((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), NoiseZ) / 7) % 100) > m_AvgChancePct) { // Average the 4 neighbors: - a_Values[x + z * a_SizeX] = ( - lowerData[idxLower - 1] + lowerData[idxLower + 1] + - lowerData[idxLower - lowerSizeX] + lowerData[idxLower + lowerSizeX] - ) / 4; + a_Values[x + z * a_SizeX] = (lowerData[idxLower - 1] + lowerData[idxLower + 1] + + lowerData[idxLower - lowerSizeX] + lowerData[idxLower + lowerSizeX]) / + 4; } else { @@ -618,7 +587,7 @@ public: } } -protected: + protected: int m_AvgChancePct; Underlying m_Underlying; }; @@ -628,22 +597,18 @@ protected: /** Replaces random underlying values with a random value in between the max and min of the neighbors. */ -class cProtIntGenRndBetween: - public cProtIntGenWithNoise +class cProtIntGenRndBetween : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenRndBetween(int a_Seed, int a_AvgChancePct, Underlying a_Underlying): - Super(a_Seed), - m_AvgChancePct(a_AvgChancePct), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenRndBetween(int a_Seed, int a_AvgChancePct, Underlying a_Underlying) : + Super(a_Seed), m_AvgChancePct(a_AvgChancePct), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: size_t lowerSizeX = a_SizeX + 2; @@ -662,9 +627,17 @@ public: if (((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), NoiseZ) / 7) % 100) > m_AvgChancePct) { // Chose a value in between the min and max neighbor: - int min = std::min(std::min(lowerData[idxLower - 1], lowerData[idxLower + 1]), std::min(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX])); - int max = std::max(std::max(lowerData[idxLower - 1], lowerData[idxLower + 1]), std::max(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX])); - a_Values[x + z * a_SizeX] = min + ((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), NoiseZ + 10) / 7) % (max - min + 1)); + int min = std::min( + std::min(lowerData[idxLower - 1], lowerData[idxLower + 1]), + std::min(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX]) + ); + int max = std::max( + std::max(lowerData[idxLower - 1], lowerData[idxLower + 1]), + std::max(lowerData[idxLower - lowerSizeX], lowerData[idxLower + lowerSizeX]) + ); + a_Values[x + z * a_SizeX] = min + + ((Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), NoiseZ + 10) / 7) % (max - min + 1) + ); } else { @@ -675,7 +648,7 @@ public: } } -protected: + protected: int m_AvgChancePct; Underlying m_Underlying; }; @@ -685,24 +658,21 @@ protected: /** Converts land biomes at the edge of an ocean into the respective beach biome. */ -class cProtIntGenBeaches: - public cProtIntGen +class cProtIntGenBeaches : public cProtIntGen { using Super = cProtIntGen; -public: - - cProtIntGenBeaches(Underlying a_Underlying): + public: + cProtIntGenBeaches(Underlying a_Underlying) : m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Map for biome -> its beach: - static const int ToBeach[] = - { + static const int ToBeach[] = { /* biOcean */ biOcean, /* biPlains */ biBeach, /* biDesert */ biBeach, @@ -757,10 +727,10 @@ public: { for (size_t x = 0; x < a_SizeX; x++) { - int val = lowerValues[x + 1 + (z + 1) * lowerSizeX]; - int above = lowerValues[x + 1 + z * lowerSizeX]; + int val = lowerValues[x + 1 + (z + 1) * lowerSizeX]; + int above = lowerValues[x + 1 + z * lowerSizeX]; int below = lowerValues[x + 1 + (z + 2) * lowerSizeX]; - int left = lowerValues[x + (z + 1) * lowerSizeX]; + int left = lowerValues[x + (z + 1) * lowerSizeX]; int right = lowerValues[x + 2 + (z + 1) * lowerSizeX]; if (!IsBiomeOcean(val)) { @@ -775,7 +745,7 @@ public: } } -protected: + protected: Underlying m_Underlying; }; @@ -785,25 +755,21 @@ protected: /** Generates the underlying numbers and then randomly changes some ocean group pixels into random land biome group pixels, based on the predefined chance. */ -class cProtIntGenAddIslands: - public cProtIntGenWithNoise +class cProtIntGenAddIslands : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - + public: using Underlying = std::shared_ptr<cProtIntGen>; - cProtIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying): - Super(a_Seed), - m_Chance(a_Chance), - m_Underlying(std::move(a_Underlying)) + cProtIntGenAddIslands(int a_Seed, int a_Chance, Underlying a_Underlying) : + Super(a_Seed), m_Chance(a_Chance), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); for (size_t z = 0; z < a_SizeZ; z++) @@ -812,7 +778,8 @@ public: { if (a_Values[x + z * a_SizeX] == bgOcean) { - int rnd = Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), a_MinZ + static_cast<int>(z)) / 7; + int rnd = + Super::m_Noise.IntNoise2DInt(a_MinX + static_cast<int>(x), a_MinZ + static_cast<int>(z)) / 7; if (rnd % 1000 < m_Chance) { a_Values[x + z * a_SizeX] = (rnd / 1003) % bgLandOceanMax; @@ -822,7 +789,7 @@ public: } } -protected: + protected: /** Chance of each ocean pixel being converted, in permille. */ int m_Chance; @@ -834,14 +801,12 @@ protected: /** A filter that adds an edge biome group between two biome groups that need an edge between them. */ -class cProtIntGenBiomeGroupEdges: - public cProtIntGen +class cProtIntGenBiomeGroupEdges : public cProtIntGen { using Super = cProtIntGen; -public: - - cProtIntGenBiomeGroupEdges(Underlying a_Underlying): + public: + cProtIntGenBiomeGroupEdges(Underlying a_Underlying) : m_Underlying(std::move(a_Underlying)) { } @@ -861,22 +826,18 @@ public: { for (size_t x = 0; x < a_SizeX; x++) { - int val = lowerValues[x + 1 + (z + 1) * lowerSizeX]; - int Above = lowerValues[x + 1 + z * lowerSizeX]; + int val = lowerValues[x + 1 + (z + 1) * lowerSizeX]; + int Above = lowerValues[x + 1 + z * lowerSizeX]; int Below = lowerValues[x + 1 + (z + 2) * lowerSizeX]; - int Left = lowerValues[x + (z + 1) * lowerSizeX]; + int Left = lowerValues[x + (z + 1) * lowerSizeX]; int Right = lowerValues[x + 2 + (z + 1) * lowerSizeX]; switch (val) { // Desert should neighbor only oceans, desert and temperates; change to temperate when another: case bgDesert: { - if ( - !isDesertCompatible(Above) || - !isDesertCompatible(Below) || - !isDesertCompatible(Left) || - !isDesertCompatible(Right) - ) + if (!isDesertCompatible(Above) || !isDesertCompatible(Below) || !isDesertCompatible(Left) || + !isDesertCompatible(Right)) { val = bgTemperate; } @@ -886,12 +847,7 @@ public: // Ice should not neighbor deserts; change to temperate: case bgIce: { - if ( - (Above == bgDesert) || - (Below == bgDesert) || - (Left == bgDesert) || - (Right == bgDesert) - ) + if ((Above == bgDesert) || (Below == bgDesert) || (Left == bgDesert) || (Right == bgDesert)) { val = bgTemperate; } @@ -903,7 +859,7 @@ public: } // for z } -protected: + protected: Underlying m_Underlying; @@ -932,91 +888,102 @@ protected: /** Turns biome group indices into real biomes. For each pixel, takes its biome group and chooses a random biome from that group; replaces the value with that biome. */ -class cProtIntGenBiomes: - public cProtIntGenWithNoise +class cProtIntGenBiomes : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenBiomes(int a_Seed, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenBiomes(int a_Seed, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Define the per-biome-group biomes: - static const int oceanBiomes[] = - { + static const int oceanBiomes[] = { biOcean, // biDeepOcean, }; // Same as oceanBiomes, there are no rare oceanic biomes (mushroom islands are handled separately) - static const int rareOceanBiomes[] = - { + static const int rareOceanBiomes[] = { biOcean, }; - static const int desertBiomes[] = - { - biDesert, biDesert, biDesert, biDesert, biDesert, biDesert, biSavanna, biSavanna, biPlains, + static const int desertBiomes[] = { + biDesert, + biDesert, + biDesert, + biDesert, + biDesert, + biDesert, + biSavanna, + biSavanna, + biPlains, }; - static const int rareDesertBiomes[] = - { - biMesaPlateau, biMesaPlateauF, + static const int rareDesertBiomes[] = { + biMesaPlateau, + biMesaPlateauF, }; - static const int temperateBiomes[] = - { - biForest, biForest, biRoofedForest, biExtremeHills, biPlains, biBirchForest, biSwampland, + static const int temperateBiomes[] = { + biForest, + biForest, + biRoofedForest, + biExtremeHills, + biPlains, + biBirchForest, + biSwampland, }; - static const int rareTemperateBiomes[] = - { + static const int rareTemperateBiomes[] = { biJungle, // Jungle is not strictly temperate, but let's piggyback it here }; - static const int mountainBiomes[] = - { - biExtremeHills, biForest, biTaiga, biPlains, + static const int mountainBiomes[] = { + biExtremeHills, + biForest, + biTaiga, + biPlains, }; - static const int rareMountainBiomes[] = - { + static const int rareMountainBiomes[] = { biMegaTaiga, }; - static const int iceBiomes[] = - { - biIcePlains, biIcePlains, biIcePlains, biIcePlains, biColdTaiga, + static const int iceBiomes[] = { + biIcePlains, + biIcePlains, + biIcePlains, + biIcePlains, + biColdTaiga, }; // Same as iceBiomes, there's no rare ice biome - static const int rareIceBiomes[] = - { - biIcePlains, biIcePlains, biIcePlains, biIcePlains, biColdTaiga, + static const int rareIceBiomes[] = { + biIcePlains, + biIcePlains, + biIcePlains, + biIcePlains, + biColdTaiga, }; - static const cBiomesInGroups biomesInGroups[] = - { - /* bgOcean */ { static_cast<int>(ARRAYCOUNT(oceanBiomes)), oceanBiomes}, - /* bgDesert */ { static_cast<int>(ARRAYCOUNT(desertBiomes)), desertBiomes}, - /* bgTemperate */ { static_cast<int>(ARRAYCOUNT(temperateBiomes)), temperateBiomes}, - /* bgMountains */ { static_cast<int>(ARRAYCOUNT(mountainBiomes)), mountainBiomes}, - /* bgIce */ { static_cast<int>(ARRAYCOUNT(iceBiomes)), iceBiomes}, + static const cBiomesInGroups biomesInGroups[] = { + /* bgOcean */ {static_cast<int>(ARRAYCOUNT(oceanBiomes)), oceanBiomes}, + /* bgDesert */ {static_cast<int>(ARRAYCOUNT(desertBiomes)), desertBiomes}, + /* bgTemperate */ {static_cast<int>(ARRAYCOUNT(temperateBiomes)), temperateBiomes}, + /* bgMountains */ {static_cast<int>(ARRAYCOUNT(mountainBiomes)), mountainBiomes}, + /* bgIce */ {static_cast<int>(ARRAYCOUNT(iceBiomes)), iceBiomes}, }; - static const cBiomesInGroups rareBiomesInGroups[] = - { - /* bgOcean */ { static_cast<int>(ARRAYCOUNT(rareOceanBiomes)), rareOceanBiomes}, - /* bgDesert */ { static_cast<int>(ARRAYCOUNT(rareDesertBiomes)), rareDesertBiomes}, - /* bgTemperate */ { static_cast<int>(ARRAYCOUNT(rareTemperateBiomes)), rareTemperateBiomes}, - /* bgMountains */ { static_cast<int>(ARRAYCOUNT(rareMountainBiomes)), rareMountainBiomes}, - /* bgIce */ { static_cast<int>(ARRAYCOUNT(rareIceBiomes)), rareIceBiomes}, + static const cBiomesInGroups rareBiomesInGroups[] = { + /* bgOcean */ {static_cast<int>(ARRAYCOUNT(rareOceanBiomes)), rareOceanBiomes}, + /* bgDesert */ {static_cast<int>(ARRAYCOUNT(rareDesertBiomes)), rareDesertBiomes}, + /* bgTemperate */ {static_cast<int>(ARRAYCOUNT(rareTemperateBiomes)), rareTemperateBiomes}, + /* bgMountains */ {static_cast<int>(ARRAYCOUNT(rareMountainBiomes)), rareMountainBiomes}, + /* bgIce */ {static_cast<int>(ARRAYCOUNT(rareIceBiomes)), rareIceBiomes}, }; // Generate the underlying values, representing biome groups: @@ -1030,17 +997,17 @@ public: for (size_t x = 0; x < a_SizeX; x++) { int val = a_Values[x + IdxZ]; - const cBiomesInGroups & Biomes = (val > bgfRare) ? - rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] : - biomesInGroups[static_cast<size_t>(val) % ARRAYCOUNT(biomesInGroups)]; - int rnd = (Super::m_Noise.IntNoise2DInt(static_cast<int>(x) + a_MinX, static_cast<int>(z) + a_MinZ) / 7); + const cBiomesInGroups & Biomes = (val > bgfRare) + ? rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] + : biomesInGroups[static_cast<size_t>(val) % ARRAYCOUNT(biomesInGroups)]; + int rnd = + (Super::m_Noise.IntNoise2DInt(static_cast<int>(x) + a_MinX, static_cast<int>(z) + a_MinZ) / 7); a_Values[x + IdxZ] = Biomes.Biomes[rnd % Biomes.Count]; } } } -protected: - + protected: struct cBiomesInGroups { const int Count; @@ -1057,27 +1024,21 @@ protected: /** Randomly replaces pixels of one value to another value, using the given chance. */ -class cProtIntGenReplaceRandomly: - public cProtIntGenWithNoise +class cProtIntGenReplaceRandomly : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - + public: using Underlying = std::shared_ptr<cProtIntGen>; - cProtIntGenReplaceRandomly(int a_Seed, int a_From, int a_To, int a_Chance, Underlying a_Underlying): - Super(a_Seed), - m_From(a_From), - m_To(a_To), - m_Chance(a_Chance), - m_Underlying(std::move(a_Underlying)) + cProtIntGenReplaceRandomly(int a_Seed, int a_From, int a_To, int a_Chance, Underlying a_Underlying) : + Super(a_Seed), m_From(a_From), m_To(a_To), m_Chance(a_Chance), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying values: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1091,7 +1052,8 @@ public: size_t idx = x + idxZ; if (a_Values[idx] == m_From) { - int rnd = Super::m_Noise.IntNoise2DInt(static_cast<int>(x) + a_MinX, static_cast<int>(z) + a_MinZ) / 7; + int rnd = + Super::m_Noise.IntNoise2DInt(static_cast<int>(x) + a_MinX, static_cast<int>(z) + a_MinZ) / 7; if (rnd % 1000 < m_Chance) { a_Values[idx] = m_To; @@ -1102,7 +1064,7 @@ public: } -protected: + protected: /** The original value to be replaced. */ int m_From; @@ -1123,21 +1085,18 @@ protected: It first checks for oceans, if there is an ocean in the Biomes, it keeps the ocean. If there's no ocean, it checks Rivers for a river, if there is a river, it uses the Biomes to select either regular river or frozen river, based on the biome. */ -class cProtIntGenMixRivers: - public cProtIntGen +class cProtIntGenMixRivers : public cProtIntGen { using Super = cProtIntGen; -public: - - cProtIntGenMixRivers(Underlying a_Biomes, Underlying a_Rivers): - m_Biomes(std::move(a_Biomes)), - m_Rivers(std::move(a_Rivers)) + public: + cProtIntGenMixRivers(Underlying a_Biomes, Underlying a_Rivers) : + m_Biomes(std::move(a_Biomes)), m_Rivers(std::move(a_Rivers)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: ASSERT(a_SizeX * a_SizeZ <= m_BufferSize); @@ -1176,7 +1135,7 @@ public: } // for z } -protected: + protected: Underlying m_Biomes; Underlying m_Rivers; }; @@ -1188,21 +1147,18 @@ protected: /** Generates a river based on the underlying data. This is basically an edge detector over the underlying data. The rivers are the edges where the underlying data changes from one pixel to its neighbor. */ -class cProtIntGenRiver: - public cProtIntGenWithNoise +class cProtIntGenRiver : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenRiver(int a_Seed, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenRiver(int a_Seed, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: size_t lowerSizeX = a_SizeX + 2; @@ -1216,11 +1172,11 @@ public: { for (size_t x = 0; x < a_SizeX; x++) { - int Above = lowerValues[x + 1 + z * lowerSizeX]; + int Above = lowerValues[x + 1 + z * lowerSizeX]; int Below = lowerValues[x + 1 + (z + 2) * lowerSizeX]; - int Left = lowerValues[x + (z + 1) * lowerSizeX]; + int Left = lowerValues[x + (z + 1) * lowerSizeX]; int Right = lowerValues[x + 2 + (z + 1) * lowerSizeX]; - int val = lowerValues[x + 1 + (z + 1) * lowerSizeX]; + int val = lowerValues[x + 1 + (z + 1) * lowerSizeX]; if ((val == Above) && (val == Below) && (val == Left) && (val == Right)) { @@ -1235,7 +1191,7 @@ public: } // for z } -protected: + protected: Underlying m_Underlying; }; @@ -1245,23 +1201,18 @@ protected: /** Turns some of the oceans into the specified biome. Used for mushroom and deep ocean. The biome is only placed if at least 3 of its neighbors are ocean and only with the specified chance. */ -class cProtIntGenAddToOcean: - public cProtIntGenWithNoise +class cProtIntGenAddToOcean : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenAddToOcean(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying): - Super(a_Seed), - m_Chance(a_Chance), - m_ToValue(a_ToValue), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenAddToOcean(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying) : + Super(a_Seed), m_Chance(a_Chance), m_ToValue(a_ToValue), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: size_t lowerSizeX = a_SizeX + 2; @@ -1283,9 +1234,9 @@ public: } // Count the ocean neighbors: - int Above = lowerValues[x + 1 + z * lowerSizeX]; + int Above = lowerValues[x + 1 + z * lowerSizeX]; int Below = lowerValues[x + 1 + (z + 2) * lowerSizeX]; - int Left = lowerValues[x + (z + 1) * lowerSizeX]; + int Left = lowerValues[x + (z + 1) * lowerSizeX]; int Right = lowerValues[x + 2 + (z + 1) * lowerSizeX]; int NumOceanNeighbors = 0; if (IsBiomeOcean(Above)) @@ -1306,10 +1257,10 @@ public: } // If at least 3 ocean neighbors and the chance is right, change: - if ( - (NumOceanNeighbors >= 3) && - ((Super::m_Noise.IntNoise2DInt(static_cast<int>(x) + a_MinX, static_cast<int>(z) + a_MinZ) / 7) % 1000 < m_Chance) - ) + if ((NumOceanNeighbors >= 3) && + ((Super::m_Noise.IntNoise2DInt(static_cast<int>(x) + a_MinX, static_cast<int>(z) + a_MinZ) / 7) % + 1000 < + m_Chance)) { a_Values[x + z * a_SizeX] = m_ToValue; } @@ -1321,7 +1272,7 @@ public: } // for z } -protected: + protected: /** Chance, in permille, of changing the biome. */ int m_Chance; @@ -1336,23 +1287,18 @@ protected: /** Changes random pixels of the underlying data to the specified value. */ -class cProtIntGenSetRandomly: - public cProtIntGenWithNoise +class cProtIntGenSetRandomly : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenSetRandomly(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying): - Super(a_Seed), - m_Chance(a_Chance), - m_ToValue(a_ToValue), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenSetRandomly(int a_Seed, int a_Chance, int a_ToValue, Underlying a_Underlying) : + Super(a_Seed), m_Chance(a_Chance), m_ToValue(a_ToValue), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1371,7 +1317,7 @@ public: } } -protected: + protected: /** Chance, in permille, of changing each pixel. */ int m_Chance; @@ -1386,22 +1332,18 @@ protected: /** Adds a "rare" flag to random biome groups, based on the given chance. */ -class cProtIntGenRareBiomeGroups: - public cProtIntGenWithNoise +class cProtIntGenRareBiomeGroups : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenRareBiomeGroups(int a_Seed, int a_Chance, Underlying a_Underlying): - Super(a_Seed), - m_Chance(a_Chance), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenRareBiomeGroups(int a_Seed, int a_Chance, Underlying a_Underlying) : + Super(a_Seed), m_Chance(a_Chance), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying data: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1421,7 +1363,7 @@ public: } } -protected: + protected: /** Chance, in permille, of changing each pixel into the rare biome group. */ int m_Chance; @@ -1435,22 +1377,18 @@ protected: /** Changes biomes in the parent data into an alternate versions (usually "hill" variants), in such places that have their alterations set. */ -class cProtIntGenAlternateBiomes: - public cProtIntGenWithNoise +class cProtIntGenAlternateBiomes : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenAlternateBiomes(int a_Seed, Underlying a_Alterations, Underlying a_BaseBiomes): - Super(a_Seed), - m_Alterations(std::move(a_Alterations)), - m_BaseBiomes(std::move(a_BaseBiomes)) + public: + cProtIntGenAlternateBiomes(int a_Seed, Underlying a_Alterations, Underlying a_BaseBiomes) : + Super(a_Seed), m_Alterations(std::move(a_Alterations)), m_BaseBiomes(std::move(a_BaseBiomes)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the base biomes and the alterations: m_BaseBiomes->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1472,26 +1410,26 @@ public: switch (val) { case biBirchForest: val = biBirchForestHills; break; - case biDesert: val = biDesertHills; break; + case biDesert: val = biDesertHills; break; case biExtremeHills: val = biExtremeHillsPlus; break; - case biForest: val = biForestHills; break; - case biIcePlains: val = biIceMountains; break; - case biJungle: val = biJungleHills; break; - case biMegaTaiga: val = biMegaTaigaHills; break; - case biMesaPlateau: val = biMesa; break; - case biMesaPlateauF: val = biMesa; break; - case biMesaPlateauM: val = biMesa; break; - case biMesaPlateauFM: val = biMesa; break; - case biPlains: val = biForest; break; - case biRoofedForest: val = biPlains; break; - case biSavanna: val = biSavannaPlateau; break; - case biTaiga: val = biTaigaHills; break; + case biForest: val = biForestHills; break; + case biIcePlains: val = biIceMountains; break; + case biJungle: val = biJungleHills; break; + case biMegaTaiga: val = biMegaTaigaHills; break; + case biMesaPlateau: val = biMesa; break; + case biMesaPlateauF: val = biMesa; break; + case biMesaPlateauM: val = biMesa; break; + case biMesaPlateauFM: val = biMesa; break; + case biPlains: val = biForest; break; + case biRoofedForest: val = biPlains; break; + case biSavanna: val = biSavannaPlateau; break; + case biTaiga: val = biTaigaHills; break; } a_Values[idx] = val; } // for idx - a_Values[] } -protected: + protected: Underlying m_Alterations; Underlying m_BaseBiomes; }; @@ -1501,21 +1439,18 @@ protected: /** Adds an edge between two specifically incompatible biomes, such as mesa and forest. */ -class cProtIntGenBiomeEdges: - public cProtIntGenWithNoise +class cProtIntGenBiomeEdges : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenBiomeEdges(int a_Seed, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(std::move(a_Underlying)) + public: + cProtIntGenBiomeEdges(int a_Seed, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(std::move(a_Underlying)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying biomes: size_t lowerSizeX = a_SizeX + 2; @@ -1530,9 +1465,9 @@ public: for (size_t x = 0; x < a_SizeX; x++) { int biome = lowerValues[x + 1 + (z + 1) * lowerSizeX]; - int above = lowerValues[x + 1 + z * lowerSizeX]; + int above = lowerValues[x + 1 + z * lowerSizeX]; int below = lowerValues[x + 1 + (z + 2) * lowerSizeX]; - int left = lowerValues[x + (z + 1) * lowerSizeX]; + int left = lowerValues[x + (z + 1) * lowerSizeX]; int right = lowerValues[x + 2 + (z + 1) * lowerSizeX]; switch (biome) @@ -1541,12 +1476,10 @@ public: case biDesertM: case biDesertHills: { - if ( - IsBiomeVeryCold(static_cast<EMCSBiome>(above)) || + if (IsBiomeVeryCold(static_cast<EMCSBiome>(above)) || IsBiomeVeryCold(static_cast<EMCSBiome>(below)) || - IsBiomeVeryCold(static_cast<EMCSBiome>(left)) || - IsBiomeVeryCold(static_cast<EMCSBiome>(right)) - ) + IsBiomeVeryCold(static_cast<EMCSBiome>(left)) || + IsBiomeVeryCold(static_cast<EMCSBiome>(right))) { biome = biPlains; } @@ -1558,12 +1491,8 @@ public: case biMesaPlateauFM: case biMesaPlateauM: { - if ( - !isMesaCompatible(above) || - !isMesaCompatible(below) || - !isMesaCompatible(left) || - !isMesaCompatible(right) - ) + if (!isMesaCompatible(above) || !isMesaCompatible(below) || !isMesaCompatible(left) || + !isMesaCompatible(right)) { biome = biDesert; } @@ -1573,12 +1502,8 @@ public: case biJungle: case biJungleM: { - if ( - !isJungleCompatible(above) || - !isJungleCompatible(below) || - !isJungleCompatible(left) || - !isJungleCompatible(right) - ) + if (!isJungleCompatible(above) || !isJungleCompatible(below) || !isJungleCompatible(left) || + !isJungleCompatible(right)) { biome = (biome == biJungle) ? biJungleEdge : biJungleEdgeM; } @@ -1588,12 +1513,10 @@ public: case biSwampland: case biSwamplandM: { - if ( - IsBiomeNoDownfall(static_cast<EMCSBiome>(above)) || + if (IsBiomeNoDownfall(static_cast<EMCSBiome>(above)) || IsBiomeNoDownfall(static_cast<EMCSBiome>(below)) || - IsBiomeNoDownfall(static_cast<EMCSBiome>(left)) || - IsBiomeNoDownfall(static_cast<EMCSBiome>(right)) - ) + IsBiomeNoDownfall(static_cast<EMCSBiome>(left)) || + IsBiomeNoDownfall(static_cast<EMCSBiome>(right))) { biome = biPlains; } @@ -1607,7 +1530,7 @@ public: } -protected: + protected: Underlying m_Underlying; @@ -1661,22 +1584,18 @@ protected: /** Changes biomes in the parent data into their alternate versions ("M" variants), in such places that have their alterations set. */ -class cProtIntGenMBiomes: - public cProtIntGenWithNoise +class cProtIntGenMBiomes : public cProtIntGenWithNoise { using Super = cProtIntGenWithNoise; -public: - - cProtIntGenMBiomes(int a_Seed, Underlying a_Alteration, Underlying a_Underlying): - Super(a_Seed), - m_Underlying(std::move(a_Underlying)), - m_Alteration(std::move(a_Alteration)) + public: + cProtIntGenMBiomes(int a_Seed, Underlying a_Alteration, Underlying a_Underlying) : + Super(a_Seed), m_Underlying(std::move(a_Underlying)), m_Alteration(std::move(a_Alteration)) { } - virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int *a_Values) override + virtual void GetInts(int a_MinX, int a_MinZ, size_t a_SizeX, size_t a_SizeZ, int * a_Values) override { // Generate the underlying biomes and the alterations: m_Underlying->GetInts(a_MinX, a_MinZ, a_SizeX, a_SizeZ, a_Values); @@ -1695,35 +1614,31 @@ public: // Ice spikes biome was removed from here, because it was generated way too often switch (a_Values[idx]) { - case biPlains: a_Values[idx] = biSunflowerPlains; break; - case biDesert: a_Values[idx] = biDesertM; break; - case biExtremeHills: a_Values[idx] = biExtremeHillsM; break; - case biForest: a_Values[idx] = biFlowerForest; break; - case biTaiga: a_Values[idx] = biTaigaM; break; - case biSwampland: a_Values[idx] = biSwamplandM; break; - case biJungle: a_Values[idx] = biJungleM; break; - case biJungleEdge: a_Values[idx] = biJungleEdgeM; break; - case biBirchForest: a_Values[idx] = biBirchForestM; break; - case biBirchForestHills: a_Values[idx] = biBirchForestHillsM; break; - case biRoofedForest: a_Values[idx] = biRoofedForestM; break; - case biColdTaiga: a_Values[idx] = biColdTaigaM; break; - case biMegaSpruceTaiga: a_Values[idx] = biMegaSpruceTaiga; break; + case biPlains: a_Values[idx] = biSunflowerPlains; break; + case biDesert: a_Values[idx] = biDesertM; break; + case biExtremeHills: a_Values[idx] = biExtremeHillsM; break; + case biForest: a_Values[idx] = biFlowerForest; break; + case biTaiga: a_Values[idx] = biTaigaM; break; + case biSwampland: a_Values[idx] = biSwamplandM; break; + case biJungle: a_Values[idx] = biJungleM; break; + case biJungleEdge: a_Values[idx] = biJungleEdgeM; break; + case biBirchForest: a_Values[idx] = biBirchForestM; break; + case biBirchForestHills: a_Values[idx] = biBirchForestHillsM; break; + case biRoofedForest: a_Values[idx] = biRoofedForestM; break; + case biColdTaiga: a_Values[idx] = biColdTaigaM; break; + case biMegaSpruceTaiga: a_Values[idx] = biMegaSpruceTaiga; break; case biMegaSpruceTaigaHills: a_Values[idx] = biMegaSpruceTaigaHills; break; - case biExtremeHillsPlus: a_Values[idx] = biExtremeHillsPlusM; break; - case biSavanna: a_Values[idx] = biSavannaM; break; - case biSavannaPlateau: a_Values[idx] = biSavannaPlateauM; break; - case biMesa: a_Values[idx] = biMesaBryce; break; - case biMesaPlateauF: a_Values[idx] = biMesaPlateauFM; break; - case biMesaPlateau: a_Values[idx] = biMesaBryce; break; + case biExtremeHillsPlus: a_Values[idx] = biExtremeHillsPlusM; break; + case biSavanna: a_Values[idx] = biSavannaM; break; + case biSavannaPlateau: a_Values[idx] = biSavannaPlateauM; break; + case biMesa: a_Values[idx] = biMesaBryce; break; + case biMesaPlateauF: a_Values[idx] = biMesaPlateauFM; break; + case biMesaPlateau: a_Values[idx] = biMesaBryce; break; } } // for idx - a_Values[] / alterations[] } -protected: + protected: Underlying m_Underlying; Underlying m_Alteration; }; - - - - diff --git a/src/Generating/Ravines.cpp b/src/Generating/Ravines.cpp index 57c806ba5..37c09c2b8 100644 --- a/src/Generating/Ravines.cpp +++ b/src/Generating/Ravines.cpp @@ -24,14 +24,10 @@ struct cRavDefPoint int m_Bottom; cRavDefPoint(int a_BlockX, int a_BlockZ, int a_Radius, int a_Top, int a_Bottom) : - m_BlockX(a_BlockX), - m_BlockZ(a_BlockZ), - m_Radius(a_Radius), - m_Top (a_Top), - m_Bottom(a_Bottom) + m_BlockX(a_BlockX), m_BlockZ(a_BlockZ), m_Radius(a_Radius), m_Top(a_Top), m_Bottom(a_Bottom) { } -} ; +}; using cRavDefPoints = std::vector<cRavDefPoint>; @@ -39,8 +35,7 @@ using cRavDefPoints = std::vector<cRavDefPoint>; -class cStructGenRavines::cRavine: - public cGridStructGen::cStructure +class cStructGenRavines::cRavine : public cGridStructGen::cStructure { using Super = cGridStructGen::cStructure; @@ -59,19 +54,18 @@ class cStructGenRavines::cRavine: /** Linearly interpolates the points so that the maximum distance between two neighbors is max 1 block */ void FinishLinear(void); -public: - + public: cRavine(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_Size, cNoise & a_Noise); - #ifndef NDEBUG +#ifndef NDEBUG /** Exports itself as a SVG line definition */ AString ExportAsSVG(int a_Color, int a_OffsetX = 0, int a_OffsetZ = 0) const; - #endif // !NDEBUG +#endif // !NDEBUG -protected: + protected: // cGridStructGen::cStructure overrides: virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override; -} ; +}; @@ -81,8 +75,7 @@ protected: // cStructGenRavines: cStructGenRavines::cStructGenRavines(int a_Seed, int a_Size) : - Super(a_Seed, a_Size, a_Size, a_Size, a_Size, a_Size * 2, a_Size * 2, 100), - m_Size(a_Size) + Super(a_Seed, a_Size, a_Size, a_Size, a_Size, a_Size * 2, a_Size * 2, 100), m_Size(a_Size) { } @@ -102,7 +95,14 @@ cGridStructGen::cStructurePtr cStructGenRavines::CreateStructure(int a_GridX, in //////////////////////////////////////////////////////////////////////////////// // cStructGenRavines::cRavine -cStructGenRavines::cRavine::cRavine(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, int a_Size, cNoise & a_Noise) : +cStructGenRavines::cRavine::cRavine( + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ, + int a_Size, + cNoise & a_Noise +) : Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ) { // Calculate the ravine shape-defining points: @@ -123,23 +123,31 @@ cStructGenRavines::cRavine::cRavine(int a_GridX, int a_GridZ, int a_OriginX, int void cStructGenRavines::cRavine::GenerateBaseDefPoints(int a_BlockX, int a_BlockZ, int a_Size, cNoise & a_Noise) { // Modify the size slightly to have different-sized ravines (1 / 2 to 1 / 1 of a_Size): - a_Size = (512 + ((a_Noise.IntNoise3DInt(19 * a_BlockX, 11 * a_BlockZ, a_BlockX + a_BlockZ) / 17) % 512)) * a_Size / 1024; + a_Size = + (512 + ((a_Noise.IntNoise3DInt(19 * a_BlockX, 11 * a_BlockZ, a_BlockX + a_BlockZ) / 17) % 512)) * a_Size / 1024; // The complete offset of the ravine from its cellpoint, up to 2 * a_Size in each direction - int OffsetX = (((a_Noise.IntNoise3DInt(50 * a_BlockX, 30 * a_BlockZ, 0) / 9) % (2 * a_Size)) + ((a_Noise.IntNoise3DInt(30 * a_BlockX, 50 * a_BlockZ, 1000) / 7) % (2 * a_Size)) - 2 * a_Size) / 2; - int OffsetZ = (((a_Noise.IntNoise3DInt(50 * a_BlockX, 30 * a_BlockZ, 2000) / 7) % (2 * a_Size)) + ((a_Noise.IntNoise3DInt(30 * a_BlockX, 50 * a_BlockZ, 3000) / 9) % (2 * a_Size)) - 2 * a_Size) / 2; + int OffsetX = (((a_Noise.IntNoise3DInt(50 * a_BlockX, 30 * a_BlockZ, 0) / 9) % (2 * a_Size)) + + ((a_Noise.IntNoise3DInt(30 * a_BlockX, 50 * a_BlockZ, 1000) / 7) % (2 * a_Size)) - 2 * a_Size) / + 2; + int OffsetZ = (((a_Noise.IntNoise3DInt(50 * a_BlockX, 30 * a_BlockZ, 2000) / 7) % (2 * a_Size)) + + ((a_Noise.IntNoise3DInt(30 * a_BlockX, 50 * a_BlockZ, 3000) / 9) % (2 * a_Size)) - 2 * a_Size) / + 2; int CenterX = a_BlockX + OffsetX; int CenterZ = a_BlockZ + OffsetZ; // Get the base angle in which the ravine "axis" goes: - float Angle = static_cast<float>((static_cast<float>((a_Noise.IntNoise3DInt(20 * a_BlockX, 70 * a_BlockZ, 6000) / 9) % 16384)) / 16384.0 * M_PI); + float Angle = static_cast<float>( + (static_cast<float>((a_Noise.IntNoise3DInt(20 * a_BlockX, 70 * a_BlockZ, 6000) / 9) % 16384)) / 16384.0 * M_PI + ); float xc = sinf(Angle); float zc = cosf(Angle); // Calculate the definition points and radii: - int MaxRadius = static_cast<int>(sqrt(12.0 + ((a_Noise.IntNoise2DInt(61 * a_BlockX, 97 * a_BlockZ) / 13) % a_Size) / 16)); - int Top = 32 + ((a_Noise.IntNoise2DInt(13 * a_BlockX, 17 * a_BlockZ) / 23) % 32); - int Bottom = 5 + ((a_Noise.IntNoise2DInt(17 * a_BlockX, 29 * a_BlockZ) / 13) % 32); + int MaxRadius = + static_cast<int>(sqrt(12.0 + ((a_Noise.IntNoise2DInt(61 * a_BlockX, 97 * a_BlockZ) / 13) % a_Size) / 16)); + int Top = 32 + ((a_Noise.IntNoise2DInt(13 * a_BlockX, 17 * a_BlockZ) / 23) % 32); + int Bottom = 5 + ((a_Noise.IntNoise2DInt(17 * a_BlockX, 29 * a_BlockZ) / 13) % 32); int Mid = (Top + Bottom) / 2; int DefinitionPointX = CenterX - static_cast<int>(xc * a_Size / 2); int DefinitionPointZ = CenterZ - static_cast<int>(zc * a_Size / 2); @@ -154,8 +162,8 @@ void cStructGenRavines::cRavine::GenerateBaseDefPoints(int a_BlockX, int a_Block int PointX = LineX + static_cast<int>(zc * Amplitude); int PointZ = LineZ - static_cast<int>(xc * Amplitude); int Radius = MaxRadius - abs(i - NUM_RAVINE_POINTS / 2); // TODO: better radius function - int ThisTop = Top + ((a_Noise.IntNoise3DInt(7 * a_BlockX, 19 * a_BlockZ, i * 31) / 13) % 8) - 4; - int ThisBottom = Bottom + ((a_Noise.IntNoise3DInt(19 * a_BlockX, 7 * a_BlockZ, i * 31) / 13) % 8) - 4; + int ThisTop = Top + ((a_Noise.IntNoise3DInt(7 * a_BlockX, 19 * a_BlockZ, i * 31) / 13) % 8) - 4; + int ThisBottom = Bottom + ((a_Noise.IntNoise3DInt(19 * a_BlockX, 7 * a_BlockZ, i * 31) / 13) % 8) - 4; m_Points.emplace_back(PointX, PointZ, Radius, ThisTop, ThisBottom); } // for i - m_Points[] DefinitionPointX = CenterX + static_cast<int>(xc * a_Size / 2); @@ -197,7 +205,7 @@ void cStructGenRavines::cRavine::RefineDefPoints(const cRavDefPoints & a_Src, cR continue; } int dr = itr->m_Radius - PrevR; - int dt = itr->m_Top - PrevT; + int dt = itr->m_Top - PrevT; int db = itr->m_Bottom - PrevB; int Rad1 = std::max(PrevR + 1 * dr / 4, 1); int Rad2 = std::max(PrevR + 3 * dr / 4, 1); @@ -231,7 +239,8 @@ void cStructGenRavines::cRavine::FinishLinear(void) { // For each segment, use Bresenham's line algorithm to draw a "line" of defpoints // _X 2012_07_20: I tried modifying this algorithm to produce "thick" lines (only one coord change per point) - // But the results were about the same as the original, so I disposed of it again - no need to use twice the count of points + // But the results were about the same as the original, so I disposed of it again - no need to use twice the count + // of points cRavDefPoints Pts; std::swap(Pts, m_Points); @@ -290,29 +299,45 @@ AString cStructGenRavines::cRavine::ExportAsSVG(int a_Color, int a_OffsetX, int SVG.append("\"/>\n"); // Base point highlight: - SVG.append(fmt::format(FMT_STRING("<path style=\"fill:none;stroke:#ff0000;stroke-width:1px;\"\nd=\"M {}, {} L {}, {}\"/>\n"), - a_OffsetX + m_OriginX - 5, a_OffsetZ + m_OriginZ, a_OffsetX + m_OriginX + 5, a_OffsetZ + m_OriginZ + SVG.append(fmt::format( + FMT_STRING("<path style=\"fill:none;stroke:#ff0000;stroke-width:1px;\"\nd=\"M {}, {} L {}, {}\"/>\n"), + a_OffsetX + m_OriginX - 5, + a_OffsetZ + m_OriginZ, + a_OffsetX + m_OriginX + 5, + a_OffsetZ + m_OriginZ )); - SVG.append(fmt::format(FMT_STRING("<path style=\"fill:none;stroke:#ff0000;stroke-width:1px;\"\nd=\"M {}, {} L {}, {}\"/>\n"), - a_OffsetX + m_OriginX, a_OffsetZ + m_OriginZ - 5, a_OffsetX + m_OriginX, a_OffsetZ + m_OriginZ + 5 + SVG.append(fmt::format( + FMT_STRING("<path style=\"fill:none;stroke:#ff0000;stroke-width:1px;\"\nd=\"M {}, {} L {}, {}\"/>\n"), + a_OffsetX + m_OriginX, + a_OffsetZ + m_OriginZ - 5, + a_OffsetX + m_OriginX, + a_OffsetZ + m_OriginZ + 5 )); // A gray line from the base point to the first point of the ravine, for identification: - SVG.append(fmt::format(FMT_STRING("<path style=\"fill:none;stroke:#cfcfcf;stroke-width:1px;\"\nd=\"M {}, {} L {}, {}\"/>\n"), - a_OffsetX + m_OriginX, a_OffsetZ + m_OriginZ, a_OffsetX + m_Points.front().m_BlockX, a_OffsetZ + m_Points.front().m_BlockZ + SVG.append(fmt::format( + FMT_STRING("<path style=\"fill:none;stroke:#cfcfcf;stroke-width:1px;\"\nd=\"M {}, {} L {}, {}\"/>\n"), + a_OffsetX + m_OriginX, + a_OffsetZ + m_OriginZ, + a_OffsetX + m_Points.front().m_BlockX, + a_OffsetZ + m_Points.front().m_BlockZ )); // Offset guides: if (a_OffsetX > 0) { - SVG.append(fmt::format(FMT_STRING("<path style=\"fill:none;stroke:#0000ff;stroke-width:1px;\"\nd=\"M {}, 0 L {}, 1024\"/>\n"), - a_OffsetX, a_OffsetX + SVG.append(fmt::format( + FMT_STRING("<path style=\"fill:none;stroke:#0000ff;stroke-width:1px;\"\nd=\"M {}, 0 L {}, 1024\"/>\n"), + a_OffsetX, + a_OffsetX )); } if (a_OffsetZ > 0) { - SVG.append(fmt::format(FMT_STRING("<path style=\"fill:none;stroke:#0000ff;stroke-width:1px;\"\nd=\"M 0, {} L 1024, {}\"/>\n"), - a_OffsetZ, a_OffsetZ + SVG.append(fmt::format( + FMT_STRING("<path style=\"fill:none;stroke:#0000ff;stroke-width:1px;\"\nd=\"M 0, {} L 1024, {}\"/>\n"), + a_OffsetZ, + a_OffsetZ )); } return SVG; @@ -331,66 +356,61 @@ void cStructGenRavines::cRavine::DrawIntoChunk(cChunkDesc & a_ChunkDesc) int BlockEndZ = BlockStartZ + cChunkDef::Width; for (cRavDefPoints::const_iterator itr = m_Points.begin(), end = m_Points.end(); itr != end; ++itr) { - if ( - (itr->m_BlockX + itr->m_Radius < BlockStartX) || - (itr->m_BlockX - itr->m_Radius > BlockEndX) || - (itr->m_BlockZ + itr->m_Radius < BlockStartZ) || - (itr->m_BlockZ - itr->m_Radius > BlockEndZ) - ) + if ((itr->m_BlockX + itr->m_Radius < BlockStartX) || (itr->m_BlockX - itr->m_Radius > BlockEndX) || + (itr->m_BlockZ + itr->m_Radius < BlockStartZ) || (itr->m_BlockZ - itr->m_Radius > BlockEndZ)) { // Cannot intersect, bail out early continue; } // Carve out a cylinder around the xz point, m_Radius in diameter, from Bottom to Top: - int RadiusSq = itr->m_Radius * itr->m_Radius; // instead of doing sqrt for each distance, we do sqr of the radius + int RadiusSq = + itr->m_Radius * itr->m_Radius; // instead of doing sqrt for each distance, we do sqr of the radius int DifX = BlockStartX - itr->m_BlockX; // substitution for faster calc int DifZ = BlockStartZ - itr->m_BlockZ; // substitution for faster calc - for (int x = 0; x < cChunkDef::Width; x++) for (int z = 0; z < cChunkDef::Width; z++) - { - #ifndef NDEBUG - // DEBUG: Make the ravine shapepoints visible on a single layer (so that we can see with Minutor what's going on) - if ((DifX + x == 0) && (DifZ + z == 0)) + for (int x = 0; x < cChunkDef::Width; x++) + for (int z = 0; z < cChunkDef::Width; z++) { - a_ChunkDesc.SetBlockType(x, 4, z, E_BLOCK_LAPIS_ORE); - } - #endif // !NDEBUG +#ifndef NDEBUG + // DEBUG: Make the ravine shapepoints visible on a single layer (so that we can see with Minutor what's + // going on) + if ((DifX + x == 0) && (DifZ + z == 0)) + { + a_ChunkDesc.SetBlockType(x, 4, z, E_BLOCK_LAPIS_ORE); + } +#endif // !NDEBUG - int DistSq = (DifX + x) * (DifX + x) + (DifZ + z) * (DifZ + z); - if (DistSq <= RadiusSq) - { - int Top = std::min(itr->m_Top, static_cast<int>(cChunkDef::Height)); // Stupid gcc needs int cast - for (int y = std::max(itr->m_Bottom, 1); y <= Top; y++) + int DistSq = (DifX + x) * (DifX + x) + (DifZ + z) * (DifZ + z); + if (DistSq <= RadiusSq) { - switch (a_ChunkDesc.GetBlockType(x, y, z)) + int Top = std::min(itr->m_Top, static_cast<int>(cChunkDef::Height)); // Stupid gcc needs int cast + for (int y = std::max(itr->m_Bottom, 1); y <= Top; y++) { - // Only carve out these specific block types - case E_BLOCK_DIRT: - case E_BLOCK_GRASS: - case E_BLOCK_STONE: - case E_BLOCK_COBBLESTONE: - case E_BLOCK_GRAVEL: - case E_BLOCK_SAND: - case E_BLOCK_SANDSTONE: - case E_BLOCK_NETHERRACK: - case E_BLOCK_COAL_ORE: - case E_BLOCK_IRON_ORE: - case E_BLOCK_GOLD_ORE: - case E_BLOCK_DIAMOND_ORE: - case E_BLOCK_REDSTONE_ORE: - case E_BLOCK_REDSTONE_ORE_GLOWING: + switch (a_ChunkDesc.GetBlockType(x, y, z)) { - a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR); - break; + // Only carve out these specific block types + case E_BLOCK_DIRT: + case E_BLOCK_GRASS: + case E_BLOCK_STONE: + case E_BLOCK_COBBLESTONE: + case E_BLOCK_GRAVEL: + case E_BLOCK_SAND: + case E_BLOCK_SANDSTONE: + case E_BLOCK_NETHERRACK: + case E_BLOCK_COAL_ORE: + case E_BLOCK_IRON_ORE: + case E_BLOCK_GOLD_ORE: + case E_BLOCK_DIAMOND_ORE: + case E_BLOCK_REDSTONE_ORE: + case E_BLOCK_REDSTONE_ORE_GLOWING: + { + a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR); + break; + } + default: break; } - default: break; } } - } - } // for x, z - a_BlockTypes + } // for x, z - a_BlockTypes } // for itr - m_Points[] } - - - - diff --git a/src/Generating/Ravines.h b/src/Generating/Ravines.h index d1d0e0076..bb3206d4b 100644 --- a/src/Generating/Ravines.h +++ b/src/Generating/Ravines.h @@ -15,16 +15,14 @@ -class cStructGenRavines: - public cGridStructGen +class cStructGenRavines : public cGridStructGen { using Super = cGridStructGen; -public: - + public: cStructGenRavines(int a_Seed, int a_Size); -protected: + protected: class cRavine; // fwd: Ravines.cpp int m_Size; // Max size, in blocks, of the ravines generated @@ -32,7 +30,4 @@ protected: // cGridStructGen overrides: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; -} ; - - - +}; diff --git a/src/Generating/RoughRavines.cpp b/src/Generating/RoughRavines.cpp index a39f7922d..a98582771 100644 --- a/src/Generating/RoughRavines.cpp +++ b/src/Generating/RoughRavines.cpp @@ -15,20 +15,27 @@ //////////////////////////////////////////////////////////////////////////////// // cRoughRavine: -class cRoughRavine: - public cGridStructGen::cStructure +class cRoughRavine : public cGridStructGen::cStructure { using Super = cGridStructGen::cStructure; -public: - + public: cRoughRavine( - int a_Seed, size_t a_Size, - float a_CenterWidth, float a_Roughness, - float a_FloorHeightEdge1, float a_FloorHeightEdge2, float a_FloorHeightCenter, - float a_CeilingHeightEdge1, float a_CeilingHeightEdge2, float a_CeilingHeightCenter, - int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ - ): + int a_Seed, + size_t a_Size, + float a_CenterWidth, + float a_Roughness, + float a_FloorHeightEdge1, + float a_FloorHeightEdge2, + float a_FloorHeightCenter, + float a_CeilingHeightEdge1, + float a_CeilingHeightEdge2, + float a_CeilingHeightCenter, + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ + ) : Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Seed(a_Seed + 100), m_Noise(a_Seed + 100), @@ -40,12 +47,19 @@ public: m_DefPoints.resize(Max + 1); int rnd = m_Noise.IntNoise2DInt(a_OriginX, a_OriginZ) / 7; float Len = static_cast<float>(a_Size); - float Angle = static_cast<float>(rnd); // Angle is in radians, will be wrapped in the "sin" and "cos" operations + float Angle = + static_cast<float>(rnd); // Angle is in radians, will be wrapped in the "sin" and "cos" operations float OfsX = sinf(Angle) * Len; float OfsZ = cosf(Angle) * Len; - m_DefPoints[0].Set (a_OriginX - OfsX, a_OriginZ - OfsZ, 1, a_CeilingHeightEdge1, a_FloorHeightEdge1); - m_DefPoints[Half].Set(static_cast<float>(a_OriginX), static_cast<float>(a_OriginZ), a_CenterWidth, a_CeilingHeightCenter, a_FloorHeightCenter); - m_DefPoints[Max].Set (a_OriginX + OfsX, a_OriginZ + OfsZ, 1, a_CeilingHeightEdge2, a_FloorHeightEdge2); + m_DefPoints[0].Set(a_OriginX - OfsX, a_OriginZ - OfsZ, 1, a_CeilingHeightEdge1, a_FloorHeightEdge1); + m_DefPoints[Half].Set( + static_cast<float>(a_OriginX), + static_cast<float>(a_OriginZ), + a_CenterWidth, + a_CeilingHeightCenter, + a_FloorHeightCenter + ); + m_DefPoints[Max].Set(a_OriginX + OfsX, a_OriginZ + OfsZ, 1, a_CeilingHeightEdge2, a_FloorHeightEdge2); // Calculate the points in between, recursively: SubdivideLine(0, Half); @@ -55,7 +69,7 @@ public: InitPerHeightRadius(a_GridX, a_GridZ); } -protected: + protected: struct sRavineDefPoint { float m_X; @@ -100,7 +114,7 @@ protected: float MidX = (p1.m_X + p2.m_X) / 2; float MidZ = (p1.m_Z + p2.m_Z) / 2; float MidR = (p1.m_Radius + p2.m_Radius) / 2 + 0.1f; - float MidT = (p1.m_Top + p2.m_Top) / 2; + float MidT = (p1.m_Top + p2.m_Top) / 2; float MidB = (p1.m_Bottom + p2.m_Bottom) / 2; // Adjust the midpoint by a small amount of perpendicular vector in a random one of its two directions: @@ -162,12 +176,10 @@ protected: int BlockEndZ = BlockStartZ + cChunkDef::Width; for (sRavineDefPoints::const_iterator itr = m_DefPoints.begin(), end = m_DefPoints.end(); itr != end; ++itr) { - if ( - (ceilf (itr->m_X + itr->m_Radius + 2) < BlockStartX) || + if ((ceilf(itr->m_X + itr->m_Radius + 2) < BlockStartX) || (floorf(itr->m_X - itr->m_Radius - 2) > BlockEndX) || - (ceilf (itr->m_Z + itr->m_Radius + 2) < BlockStartZ) || - (floorf(itr->m_Z - itr->m_Radius - 2) > BlockEndZ) - ) + (ceilf(itr->m_Z + itr->m_Radius + 2) < BlockStartZ) || + (floorf(itr->m_Z - itr->m_Radius - 2) > BlockEndZ)) { // Cannot intersect, bail out early continue; @@ -175,41 +187,44 @@ protected: // Carve out a cylinder around the xz point, up to (m_Radius + 2) in diameter, from Bottom to Top: // On each height level, use m_PerHeightRadius[] to modify the actual radius used - // EnlargedRadiusSq is the square of the radius enlarged by the maximum m_PerHeightRadius offset - anything outside it will never be touched. + // EnlargedRadiusSq is the square of the radius enlarged by the maximum m_PerHeightRadius offset - anything + // outside it will never be touched. float RadiusSq = (itr->m_Radius + 2) * (itr->m_Radius + 2); float DifX = BlockStartX - itr->m_X; // substitution for faster calc float DifZ = BlockStartZ - itr->m_Z; // substitution for faster calc - for (int x = 0; x < cChunkDef::Width; x++) for (int z = 0; z < cChunkDef::Width; z++) - { - #ifndef NDEBUG - // DEBUG: Make the roughravine shapepoints visible on a single layer (so that we can see with Minutor what's going on) - if ((FloorC(DifX + x) == 0) && (FloorC(DifZ + z) == 0)) - { - a_ChunkDesc.SetBlockType(x, 4, z, E_BLOCK_LAPIS_ORE); - } - #endif // !NDEBUG - - // If the column is outside the enlarged radius, bail out completely - float DistSq = (DifX + x) * (DifX + x) + (DifZ + z) * (DifZ + z); - if (DistSq > RadiusSq) + for (int x = 0; x < cChunkDef::Width; x++) + for (int z = 0; z < cChunkDef::Width; z++) { - continue; - } +#ifndef NDEBUG + // DEBUG: Make the roughravine shapepoints visible on a single layer (so that we can see with + // Minutor what's going on) + if ((FloorC(DifX + x) == 0) && (FloorC(DifZ + z) == 0)) + { + a_ChunkDesc.SetBlockType(x, 4, z, E_BLOCK_LAPIS_ORE); + } +#endif // !NDEBUG - int Top = std::min(CeilC(itr->m_Top), +cChunkDef::Height); - for (int y = std::max(FloorC(itr->m_Bottom), 1); y <= Top; y++) - { - if ((itr->m_Radius + m_PerHeightRadius[y]) * (itr->m_Radius + m_PerHeightRadius[y]) < DistSq) + // If the column is outside the enlarged radius, bail out completely + float DistSq = (DifX + x) * (DifX + x) + (DifZ + z) * (DifZ + z); + if (DistSq > RadiusSq) { continue; } - if (cBlockInfo::CanBeTerraformed(a_ChunkDesc.GetBlockType(x, y, z))) + int Top = std::min(CeilC(itr->m_Top), +cChunkDef::Height); + for (int y = std::max(FloorC(itr->m_Bottom), 1); y <= Top; y++) { - a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR); - } - } // for y - } // for x, z - a_BlockTypes + if ((itr->m_Radius + m_PerHeightRadius[y]) * (itr->m_Radius + m_PerHeightRadius[y]) < DistSq) + { + continue; + } + + if (cBlockInfo::CanBeTerraformed(a_ChunkDesc.GetBlockType(x, y, z))) + { + a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_AIR); + } + } // for y + } // for x, z - a_BlockTypes } // for itr - m_Points[] } }; @@ -223,14 +238,22 @@ protected: cRoughRavines::cRoughRavines( int a_Seed, - int a_MaxSize, int a_MinSize, - float a_MaxCenterWidth, float a_MinCenterWidth, - float a_MaxRoughness, float a_MinRoughness, - float a_MaxFloorHeightEdge, float a_MinFloorHeightEdge, - float a_MaxFloorHeightCenter, float a_MinFloorHeightCenter, - float a_MaxCeilingHeightEdge, float a_MinCeilingHeightEdge, - float a_MaxCeilingHeightCenter, float a_MinCeilingHeightCenter, - int a_GridSize, int a_MaxOffset + int a_MaxSize, + int a_MinSize, + float a_MaxCenterWidth, + float a_MinCenterWidth, + float a_MaxRoughness, + float a_MinRoughness, + float a_MaxFloorHeightEdge, + float a_MinFloorHeightEdge, + float a_MaxFloorHeightCenter, + float a_MinFloorHeightCenter, + float a_MaxCeilingHeightEdge, + float a_MinCeilingHeightEdge, + float a_MaxCeilingHeightCenter, + float a_MinCeilingHeightCenter, + int a_GridSize, + int a_MaxOffset ) : Super(a_Seed, a_GridSize, a_GridSize, a_MaxOffset, a_MaxOffset, a_MaxSize, a_MaxSize, 64), m_MaxSize(a_MaxSize), @@ -276,26 +299,39 @@ cRoughRavines::cRoughRavines( cGridStructGen::cStructurePtr cRoughRavines::CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) { // Pick a random value for each of the ravine's parameters: - size_t Size = static_cast<size_t>(m_MinSize + (m_Noise.IntNoise2DInt(a_GridX, a_GridZ) / 7) % (m_MaxSize - m_MinSize)); // Random int from m_MinSize to m_MaxSize - float CenterWidth = m_Noise.IntNoise2DInRange(a_GridX + 10, a_GridZ, m_MinCenterWidth, m_MaxCenterWidth); - float Roughness = m_Noise.IntNoise2DInRange(a_GridX + 20, a_GridZ, m_MinRoughness, m_MaxRoughness); - float FloorHeightEdge1 = m_Noise.IntNoise2DInRange(a_GridX + 30, a_GridZ, m_MinFloorHeightEdge, m_MaxFloorHeightEdge); - float FloorHeightEdge2 = m_Noise.IntNoise2DInRange(a_GridX + 40, a_GridZ, m_MinFloorHeightEdge, m_MaxFloorHeightEdge); - float FloorHeightCenter = m_Noise.IntNoise2DInRange(a_GridX + 50, a_GridZ, m_MinFloorHeightCenter, m_MaxFloorHeightCenter); - float CeilingHeightEdge1 = m_Noise.IntNoise2DInRange(a_GridX + 60, a_GridZ, m_MinCeilingHeightEdge, m_MaxCeilingHeightEdge); - float CeilingHeightEdge2 = m_Noise.IntNoise2DInRange(a_GridX + 70, a_GridZ, m_MinCeilingHeightEdge, m_MaxCeilingHeightEdge); - float CeilingHeightCenter = m_Noise.IntNoise2DInRange(a_GridX + 80, a_GridZ, m_MinCeilingHeightCenter, m_MaxCeilingHeightCenter); + size_t Size = static_cast<size_t>( + m_MinSize + (m_Noise.IntNoise2DInt(a_GridX, a_GridZ) / 7) % (m_MaxSize - m_MinSize) + ); // Random int from m_MinSize to m_MaxSize + float CenterWidth = m_Noise.IntNoise2DInRange(a_GridX + 10, a_GridZ, m_MinCenterWidth, m_MaxCenterWidth); + float Roughness = m_Noise.IntNoise2DInRange(a_GridX + 20, a_GridZ, m_MinRoughness, m_MaxRoughness); + float FloorHeightEdge1 = + m_Noise.IntNoise2DInRange(a_GridX + 30, a_GridZ, m_MinFloorHeightEdge, m_MaxFloorHeightEdge); + float FloorHeightEdge2 = + m_Noise.IntNoise2DInRange(a_GridX + 40, a_GridZ, m_MinFloorHeightEdge, m_MaxFloorHeightEdge); + float FloorHeightCenter = + m_Noise.IntNoise2DInRange(a_GridX + 50, a_GridZ, m_MinFloorHeightCenter, m_MaxFloorHeightCenter); + float CeilingHeightEdge1 = + m_Noise.IntNoise2DInRange(a_GridX + 60, a_GridZ, m_MinCeilingHeightEdge, m_MaxCeilingHeightEdge); + float CeilingHeightEdge2 = + m_Noise.IntNoise2DInRange(a_GridX + 70, a_GridZ, m_MinCeilingHeightEdge, m_MaxCeilingHeightEdge); + float CeilingHeightCenter = + m_Noise.IntNoise2DInRange(a_GridX + 80, a_GridZ, m_MinCeilingHeightCenter, m_MaxCeilingHeightCenter); // Create a ravine: return cStructurePtr(new cRoughRavine( m_Seed, - Size, CenterWidth, Roughness, - FloorHeightEdge1, FloorHeightEdge2, FloorHeightCenter, - CeilingHeightEdge1, CeilingHeightEdge2, CeilingHeightCenter, - a_GridX, a_GridZ, a_OriginX, a_OriginZ + Size, + CenterWidth, + Roughness, + FloorHeightEdge1, + FloorHeightEdge2, + FloorHeightCenter, + CeilingHeightEdge1, + CeilingHeightEdge2, + CeilingHeightCenter, + a_GridX, + a_GridZ, + a_OriginX, + a_OriginZ )); } - - - - diff --git a/src/Generating/RoughRavines.h b/src/Generating/RoughRavines.h index 88b2f2e6d..4636d6e2f 100644 --- a/src/Generating/RoughRavines.h +++ b/src/Generating/RoughRavines.h @@ -14,26 +14,32 @@ -class cRoughRavines: - public cGridStructGen +class cRoughRavines : public cGridStructGen { using Super = cGridStructGen; -public: - + public: cRoughRavines( int a_Seed, - int a_MaxSize, int a_MinSize, - float a_MaxCenterWidth, float a_MinCenterWidth, - float a_MaxRoughness, float a_MinRoughness, - float a_MaxFloorHeightEdge, float a_MinFloorHeightEdge, - float a_MaxFloorHeightCenter, float a_MinFloorHeightCenter, - float a_MaxCeilingHeightEdge, float a_MinCeilingHeightEdge, - float a_MaxCeilingHeightCenter, float a_MinCeilingHeightCenter, - int a_GridSize, int a_MaxOffset + int a_MaxSize, + int a_MinSize, + float a_MaxCenterWidth, + float a_MinCenterWidth, + float a_MaxRoughness, + float a_MinRoughness, + float a_MaxFloorHeightEdge, + float a_MinFloorHeightEdge, + float a_MaxFloorHeightCenter, + float a_MinFloorHeightCenter, + float a_MaxCeilingHeightEdge, + float a_MinCeilingHeightEdge, + float a_MaxCeilingHeightCenter, + float a_MinCeilingHeightCenter, + int a_GridSize, + int a_MaxOffset ); -protected: + protected: /** Maximum size of the ravine, in each of the X / Z axis */ int m_MaxSize; @@ -79,7 +85,3 @@ protected: // cGridStructGen overrides: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; }; - - - - diff --git a/src/Generating/ShapeGen.cpp b/src/Generating/ShapeGen.cpp index f46c0c8e9..8d2f22c8b 100644 --- a/src/Generating/ShapeGen.cpp +++ b/src/Generating/ShapeGen.cpp @@ -19,11 +19,10 @@ // cTerrainHeightToShapeGen: /** Converts old-style height-generators into new-style shape-generators. */ -class cTerrainHeightToShapeGen: - public cTerrainShapeGen +class cTerrainHeightToShapeGen : public cTerrainShapeGen { -public: - cTerrainHeightToShapeGen(std::unique_ptr<cTerrainHeightGen> a_HeightGen): + public: + cTerrainHeightToShapeGen(std::unique_ptr<cTerrainHeightGen> a_HeightGen) : m_HeightGen(std::move(a_HeightGen)) { } @@ -56,12 +55,9 @@ public: } - virtual void InitializeShapeGen(cIniFile & a_IniFile) override - { - m_HeightGen->InitializeHeightGen(a_IniFile); - } + virtual void InitializeShapeGen(cIniFile & a_IniFile) override { m_HeightGen->InitializeHeightGen(a_IniFile); } -protected: + protected: /** The height generator being converted. */ std::unique_ptr<cTerrainHeightGen> m_HeightGen; }; diff --git a/src/Generating/SinglePieceStructuresGen.cpp b/src/Generating/SinglePieceStructuresGen.cpp index 375e87fdf..165c60c3a 100644 --- a/src/Generating/SinglePieceStructuresGen.cpp +++ b/src/Generating/SinglePieceStructuresGen.cpp @@ -9,17 +9,13 @@ //////////////////////////////////////////////////////////////////////////////// // cSinglePieceStructuresGen::cGen -class cSinglePieceStructuresGen::cGen : - public cGridStructGen +class cSinglePieceStructuresGen::cGen : public cGridStructGen { using Super = cGridStructGen; -public: - cGen(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel, const AString & a_Name): - Super(a_Seed), - m_BiomeGen(a_BiomeGen), - m_HeightGen(a_HeightGen), - m_SeaLevel(a_SeaLevel), - m_Name(a_Name) + + public: + cGen(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel, const AString & a_Name) : + Super(a_Seed), m_BiomeGen(a_BiomeGen), m_HeightGen(a_HeightGen), m_SeaLevel(a_SeaLevel), m_Name(a_Name) { } @@ -38,8 +34,11 @@ public: } if (NoCaseCompare(m_PiecePool.GetIntendedUse(), "SinglePieceStructures") != 0) { - LOGWARNING("SinglePieceStructures generator: File %s is intended for use in \"%s\", rather than single piece structures. Loading the file, but the generator may behave unexpectedly.", - a_FileName.c_str(), m_PiecePool.GetIntendedUse().c_str() + LOGWARNING( + "SinglePieceStructures generator: File %s is intended for use in \"%s\", rather than single piece " + "structures. Loading the file, but the generator may behave unexpectedly.", + a_FileName.c_str(), + m_PiecePool.GetIntendedUse().c_str() ); } m_PiecePool.AssignGens(m_Seed, m_BiomeGen, m_HeightGen, m_SeaLevel); @@ -71,7 +70,14 @@ public: } cPlacedPieces OutPiece; OutPiece.push_back(GetPiece(a_OriginX, a_OriginZ)); - return std::make_shared<cPrefabStructure>(a_GridX, a_GridZ, a_OriginX, a_OriginZ, std::move(OutPiece), m_HeightGen); + return std::make_shared<cPrefabStructure>( + a_GridX, + a_GridZ, + a_OriginX, + a_OriginZ, + std::move(OutPiece), + m_HeightGen + ); } @@ -126,15 +132,17 @@ public: int BlockY = StartingPiece->GetStartingPieceHeight(a_BlockX, a_BlockZ); ASSERT(BlockY >= 0); // The vertical strategy should have been provided and should give valid coords - cPlacedPiece * Piece = new cPlacedPiece(nullptr, *StartingPiece, Vector3i(a_BlockX, BlockY, a_BlockZ), Rotation); + cPlacedPiece * Piece = + new cPlacedPiece(nullptr, *StartingPiece, Vector3i(a_BlockX, BlockY, a_BlockZ), Rotation); return cPlacedPiecePtr(Piece); } -protected: + protected: /** The underlying biome generator that defines whether the structure is created or not */ cBiomeGen & m_BiomeGen; - /** The underlying height generator, used to position the prefabs crossing chunk borders if they are set to FitGround. */ + /** The underlying height generator, used to position the prefabs crossing chunk borders if they are set to + * FitGround. */ cTerrainHeightGen & m_HeightGen; /** The world's sea level, if available. Used for some cVerticalStrategy descendants. */ @@ -160,13 +168,19 @@ cSinglePieceStructuresGen::cSinglePieceStructuresGen(int a_Seed) : -bool cSinglePieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen) +bool cSinglePieceStructuresGen::Initialize( + const AString & a_Prefabs, + int a_SeaLevel, + cBiomeGen & a_BiomeGen, + cTerrainHeightGen & a_HeightGen +) { // Load each piecepool: auto Structures = StringSplitAndTrim(a_Prefabs, "|"); - for (const auto & S: Structures) + for (const auto & S : Structures) { - auto FileName = fmt::format(FMT_STRING("Prefabs{0}SinglePieceStructures{0}{1}.cubeset"), cFile::PathSeparator(), S); + auto FileName = + fmt::format(FMT_STRING("Prefabs{0}SinglePieceStructures{0}{1}.cubeset"), cFile::PathSeparator(), S); if (!cFile::IsFile(FileName)) { FileName.append(".gz"); @@ -187,7 +201,10 @@ bool cSinglePieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaL // Report a warning if no generators available: if (m_Gens.empty()) { - LOGWARNING("The PieceStructures generator was asked to generate \"%s\", but none of the prefabs are valid.", a_Prefabs); + LOGWARNING( + "The PieceStructures generator was asked to generate \"%s\", but none of the prefabs are valid.", + a_Prefabs + ); return false; } return true; @@ -199,7 +216,7 @@ bool cSinglePieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaL void cSinglePieceStructuresGen::GenFinish(cChunkDesc & a_Chunk) { - for (auto & Gen: m_Gens) + for (auto & Gen : m_Gens) { Gen->GenFinish(a_Chunk); } diff --git a/src/Generating/SinglePieceStructuresGen.h b/src/Generating/SinglePieceStructuresGen.h index 386d0f9ae..3edde2f4a 100644 --- a/src/Generating/SinglePieceStructuresGen.h +++ b/src/Generating/SinglePieceStructuresGen.h @@ -18,12 +18,11 @@ This uses the cGridStructGen to generate the structures on the map This is similar to the Piece Structure Generator but only placing one possible structure The Exported cubeset MUST have all possible structures as start structures or the server crashes on generation else it isn't accessible from the m_Piecepool. */ -class cSinglePieceStructuresGen : - public cFinishGen +class cSinglePieceStructuresGen : public cFinishGen { -using Super = cFinishGen; + using Super = cFinishGen; -public: + public: cSinglePieceStructuresGen(int a_Seed); /** Initializes the generator based on the specified prefab sets. @@ -36,7 +35,7 @@ public: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -protected: + protected: /** The generator doing the work for a single prefab set. Forward-declared so that its implementation changes don't affect the header. */ class cGen; diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index 2b497e9a5..3e6a70996 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -37,12 +37,13 @@ void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc) Dest = &WorkerDesc; WorkerDesc.SetChunkCoords({BaseX, BaseZ}); - // TODO: This may cause a lot of wasted calculations, instead of pulling data out of a single (cChunkDesc) cache + // TODO: This may cause a lot of wasted calculations, instead of pulling data out of a single + // (cChunkDesc) cache cChunkDesc::Shape workerShape; - m_BiomeGen.GenBiomes ({BaseX, BaseZ}, WorkerDesc.GetBiomeMap()); - m_ShapeGen.GenShape ({BaseX, BaseZ}, workerShape); - WorkerDesc.SetHeightFromShape (workerShape); + m_BiomeGen.GenBiomes({BaseX, BaseZ}, WorkerDesc.GetBiomeMap()); + m_ShapeGen.GenShape({BaseX, BaseZ}, workerShape); + WorkerDesc.SetHeightFromShape(workerShape); m_CompositionGen.ComposeTerrain(WorkerDesc, workerShape); } else @@ -60,7 +61,9 @@ void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc) Pos.z = (m_Noise.IntNoise3DInt(BaseX - BaseZ, 0, BaseZ) / 19) % cChunkDef::Width; Pos.y = Dest->GetHeight(Pos.x, Pos.z); - if (std::abs(m_Noise.IntNoise3D(BaseX * cChunkDef::Width + Pos.x, Pos.y, BaseZ * cChunkDef::Width + Pos.z)) <= NumTrees) + if (std::abs( + m_Noise.IntNoise3D(BaseX * cChunkDef::Width + Pos.x, Pos.y, BaseZ * cChunkDef::Width + Pos.z) + ) <= NumTrees) { GenerateSingleTree(BaseX, BaseZ, 0, Pos, *Dest, OutsideLogs, OutsideOther); } @@ -94,7 +97,9 @@ void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc) void cStructGenTrees::GenerateSingleTree( - int a_ChunkX, int a_ChunkZ, int a_Seq, + int a_ChunkX, + int a_ChunkZ, + int a_Seq, Vector3i a_Pos, cChunkDesc & a_ChunkDesc, sSetBlockVector & a_OutsideLogs, @@ -108,17 +113,20 @@ void cStructGenTrees::GenerateSingleTree( // Check the block underneath the tree: BLOCKTYPE TopBlock = a_ChunkDesc.GetBlockType(a_Pos.x, a_Pos.y, a_Pos.z); - if ((TopBlock != E_BLOCK_DIRT) && (TopBlock != E_BLOCK_GRASS) && (TopBlock != E_BLOCK_FARMLAND) && (TopBlock != E_BLOCK_MYCELIUM)) + if ((TopBlock != E_BLOCK_DIRT) && (TopBlock != E_BLOCK_GRASS) && (TopBlock != E_BLOCK_FARMLAND) && + (TopBlock != E_BLOCK_MYCELIUM)) { return; } sSetBlockVector TreeLogs, TreeOther; GetTreeImageByBiome( - { a_ChunkX * cChunkDef::Width + a_Pos.x, a_Pos.y + 1, a_ChunkZ * cChunkDef::Width + a_Pos.z }, - m_Noise, a_Seq, + {a_ChunkX * cChunkDef::Width + a_Pos.x, a_Pos.y + 1, a_ChunkZ * cChunkDef::Width + a_Pos.z}, + m_Noise, + a_Seq, a_ChunkDesc.GetBiome(a_Pos.x, a_Pos.z), - TreeLogs, TreeOther + TreeLogs, + TreeOther ); // Check if the generated image fits the terrain. Only the logs are checked: @@ -138,20 +146,20 @@ void cStructGenTrees::GenerateSingleTree( BLOCKTYPE Block = a_ChunkDesc.GetBlockType(itr->m_RelX, itr->m_RelY, itr->m_RelZ); switch (Block) { - CASE_TREE_ALLOWED_BLOCKS: - { - break; - } - default: - { - // There's something in the way, abort this tree altogether - return; - } + CASE_TREE_ALLOWED_BLOCKS: + { + break; + } + default: + { + // There's something in the way, abort this tree altogether + return; + } } } ApplyTreeImage(a_ChunkX, a_ChunkZ, a_ChunkDesc, TreeOther, a_OutsideOther); - ApplyTreeImage(a_ChunkX, a_ChunkZ, a_ChunkDesc, TreeLogs, a_OutsideLogs); + ApplyTreeImage(a_ChunkX, a_ChunkZ, a_ChunkDesc, TreeLogs, a_OutsideLogs); } @@ -159,7 +167,8 @@ void cStructGenTrees::GenerateSingleTree( void cStructGenTrees::ApplyTreeImage( - int a_ChunkX, int a_ChunkZ, + int a_ChunkX, + int a_ChunkZ, cChunkDesc & a_ChunkDesc, const sSetBlockVector & a_Image, sSetBlockVector & a_Overflow @@ -186,12 +195,11 @@ void cStructGenTrees::ApplyTreeImage( } CASE_TREE_OVERWRITTEN_BLOCKS: { - a_ChunkDesc.SetBlockTypeMeta(itr->m_RelX, itr->m_RelY, itr->m_RelZ, itr->m_BlockType, itr->m_BlockMeta); + a_ChunkDesc + .SetBlockTypeMeta(itr->m_RelX, itr->m_RelY, itr->m_RelZ, itr->m_BlockType, itr->m_BlockMeta); // If grass is below our tree, turn it to dirt - if ( - (cBlockInfo::IsSolid(itr->m_BlockType)) && - (a_ChunkDesc.GetBlockType(itr->m_RelX, itr->m_RelY - 1, itr->m_RelZ) == E_BLOCK_GRASS) - ) + if ((cBlockInfo::IsSolid(itr->m_BlockType)) && + (a_ChunkDesc.GetBlockType(itr->m_RelX, itr->m_RelY - 1, itr->m_RelZ) == E_BLOCK_GRASS)) { a_ChunkDesc.SetBlockType(itr->m_RelX, itr->m_RelY - 1, itr->m_RelZ, E_BLOCK_DIRT); } @@ -212,10 +220,7 @@ void cStructGenTrees::ApplyTreeImage( -double cStructGenTrees::GetNumTrees( - int a_ChunkX, int a_ChunkZ, - const cChunkDef::BiomeMap & a_Biomes -) +double cStructGenTrees::GetNumTrees(int a_ChunkX, int a_ChunkZ, const cChunkDef::BiomeMap & a_Biomes) { auto BiomeTrees = [](EMCSBiome a_Biome) { @@ -316,22 +321,23 @@ void cStructGenLakes::GenFinish(cChunkDesc & a_ChunkDesc) int ChunkX = a_ChunkDesc.GetChunkX(); int ChunkZ = a_ChunkDesc.GetChunkZ(); - for (int z = -1; z < 2; z++) for (int x = -1; x < 2; x++) - { - if (((m_Noise.IntNoise2DInt(ChunkX + x, ChunkZ + z) / 17) % 100) > m_Probability) + for (int z = -1; z < 2; z++) + for (int x = -1; x < 2; x++) { - continue; - } + if (((m_Noise.IntNoise2DInt(ChunkX + x, ChunkZ + z) / 17) % 100) > m_Probability) + { + continue; + } - cBlockArea Lake; - CreateLakeImage(ChunkX + x, ChunkZ + z, a_ChunkDesc.GetMinHeight(), Lake); + cBlockArea Lake; + CreateLakeImage(ChunkX + x, ChunkZ + z, a_ChunkDesc.GetMinHeight(), Lake); - int OfsX = Lake.GetOriginX() + x * cChunkDef::Width; - int OfsZ = Lake.GetOriginZ() + z * cChunkDef::Width; + int OfsX = Lake.GetOriginX() + x * cChunkDef::Width; + int OfsZ = Lake.GetOriginZ() + z * cChunkDef::Width; - // Merge the lake into the current data - a_ChunkDesc.WriteBlockArea(Lake, OfsX, Lake.GetOriginY(), OfsZ, cBlockArea::msLake); - } // for x, z - neighbor chunks + // Merge the lake into the current data + a_ChunkDesc.WriteBlockArea(Lake, OfsX, Lake.GetOriginY(), OfsZ, cBlockArea::msLake); + } // for x, z - neighbor chunks } @@ -343,13 +349,16 @@ void cStructGenLakes::CreateLakeImage(int a_ChunkX, int a_ChunkZ, int a_MaxLakeH a_Lake.Create(16, 8, 16); a_Lake.Fill(cBlockArea::baTypes, E_BLOCK_SPONGE); // Sponge is the NOP blocktype for lake merging strategy - // Make a random position in the chunk by using a random 16 block XZ offset and random height up to chunk's max height minus 6 + // Make a random position in the chunk by using a random 16 block XZ offset and random height up to chunk's max + // height minus 6 int MinHeight = std::max(a_MaxLakeHeight - 6, 2); int Rnd = m_Noise.IntNoise3DInt(a_ChunkX, 128, a_ChunkZ) / 11; - // Random offset [-8 .. 8], with higher probability around 0; add up four three-bit-wide randoms [0 .. 28], divide and subtract to get range + // Random offset [-8 .. 8], with higher probability around 0; add up four three-bit-wide randoms [0 .. 28], divide + // and subtract to get range int OffsetX = 4 * ((Rnd & 0x07) + ((Rnd & 0x38) >> 3) + ((Rnd & 0x1c0) >> 6) + ((Rnd & 0xe00) >> 9)) / 7 - 8; Rnd >>= 12; - // Random offset [-8 .. 8], with higher probability around 0; add up four three-bit-wide randoms [0 .. 28], divide and subtract to get range + // Random offset [-8 .. 8], with higher probability around 0; add up four three-bit-wide randoms [0 .. 28], divide + // and subtract to get range int OffsetZ = 4 * ((Rnd & 0x07) + ((Rnd & 0x38) >> 3) + ((Rnd & 0x1c0) >> 6) + ((Rnd & 0xe00) >> 9)) / 7 - 8; Rnd = m_Noise.IntNoise3DInt(a_ChunkX, 512, a_ChunkZ) / 13; // Random height [1 .. MinHeight] with preference to center heights @@ -399,13 +408,14 @@ void cStructGenLakes::CreateLakeImage(int a_ChunkX, int a_ChunkZ, int a_MaxLakeH // Turn air in the bottom half into liquid: for (int y = 0; y < 4; y++) { - for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) - { - if (BlockTypes[x + z * 16 + y * 16 * 16] == E_BLOCK_AIR) + for (int z = 0; z < 16; z++) + for (int x = 0; x < 16; x++) { - BlockTypes[x + z * 16 + y * 16 * 16] = m_Fluid; - } - } // for z, x + if (BlockTypes[x + z * 16 + y * 16 * 16] == E_BLOCK_AIR) + { + BlockTypes[x + z * 16 + y * 16 * 16] = m_Fluid; + } + } // for z, x } // for y // TODO: Turn sponge next to lava into stone @@ -421,8 +431,7 @@ void cStructGenLakes::CreateLakeImage(int a_ChunkX, int a_ChunkZ, int a_MaxLakeH // cStructGenDirectOverhangs: cStructGenDirectOverhangs::cStructGenDirectOverhangs(int a_Seed) : - m_Noise1(a_Seed), - m_Noise2(a_Seed + 1000) + m_Noise1(a_Seed), m_Noise2(a_Seed + 1000) { } @@ -443,9 +452,10 @@ void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) const int SEGMENT_HEIGHT = 8; const int INTERPOL_X = 16; // Must be a divisor of 16 const int INTERPOL_Z = 16; // Must be a divisor of 16 - // Interpolate the chunk in 16 * SEGMENT_HEIGHT * 16 "segments", each SEGMENT_HEIGHT blocks high and each linearly interpolated separately. - // Have two buffers, one for the lowest floor and one for the highest floor, so that Y-interpolation can be done between them - // Then swap the buffers and use the previously-top one as the current-bottom, without recalculating it. + // Interpolate the chunk in 16 * SEGMENT_HEIGHT * 16 "segments", each SEGMENT_HEIGHT blocks high and each linearly + // interpolated separately. Have two buffers, one for the lowest floor and one for the highest floor, so that + // Y-interpolation can be done between them Then swap the buffers and use the previously-top one as the + // current-bottom, without recalculating it. int FloorBuf1[17 * 17]; int FloorBuf2[17 * 17]; @@ -456,48 +466,50 @@ void cStructGenDirectOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) int BaseY = 63; // Interpolate the lowest floor: - for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++) - { - FloorLo[INTERPOL_X * x + 17 * INTERPOL_Z * z] = - m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, BaseY, BaseZ + INTERPOL_Z * z) * - m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, BaseY, BaseZ + INTERPOL_Z * z) / - 256; - } // for x, z - FloorLo[] + for (int z = 0; z <= 16 / INTERPOL_Z; z++) + for (int x = 0; x <= 16 / INTERPOL_X; x++) + { + FloorLo[INTERPOL_X * x + 17 * INTERPOL_Z * z] = + m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, BaseY, BaseZ + INTERPOL_Z * z) * + m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, BaseY, BaseZ + INTERPOL_Z * z) / 256; + } // for x, z - FloorLo[] LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorLo); // Interpolate segments: for (int Segment = BaseY; Segment < MaxHeight; Segment += SEGMENT_HEIGHT) { // First update the high floor: - for (int z = 0; z <= 16 / INTERPOL_Z; z++) for (int x = 0; x <= 16 / INTERPOL_X; x++) - { - FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] = ( - m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) * - m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256 - ); - } // for x, z - FloorLo[] + for (int z = 0; z <= 16 / INTERPOL_Z; z++) + for (int x = 0; x <= 16 / INTERPOL_X; x++) + { + FloorHi[INTERPOL_X * x + 17 * INTERPOL_Z * z] = + (m_Noise1.IntNoise3DInt(BaseX + INTERPOL_X * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) * + m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / + 256); + } // for x, z - FloorLo[] LinearUpscale2DArrayInPlace<17, 17, INTERPOL_X, INTERPOL_Z>(FloorHi); // Interpolate between FloorLo and FloorHi: - for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) - { - EMCSBiome biome = a_ChunkDesc.GetBiome(x, z); - - if ((biome == biExtremeHills) || (biome == biExtremeHillsEdge)) + for (int z = 0; z < 16; z++) + for (int x = 0; x < 16; x++) { - int Lo = FloorLo[x + 17 * z] / 256; - int Hi = FloorHi[x + 17 * z] / 256; - for (int y = 0; y < SEGMENT_HEIGHT; y++) + EMCSBiome biome = a_ChunkDesc.GetBiome(x, z); + + if ((biome == biExtremeHills) || (biome == biExtremeHillsEdge)) { - int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; - if (Val < 0) + int Lo = FloorLo[x + 17 * z] / 256; + int Hi = FloorHi[x + 17 * z] / 256; + for (int y = 0; y < SEGMENT_HEIGHT; y++) { - a_ChunkDesc.SetBlockType(x, y + Segment, z, E_BLOCK_AIR); - } - } // for y - break; - } // if (biome) - } // for z, x + int Val = Lo + (Hi - Lo) * y / SEGMENT_HEIGHT; + if (Val < 0) + { + a_ChunkDesc.SetBlockType(x, y + Segment, z, E_BLOCK_AIR); + } + } // for y + break; + } // if (biome) + } // for z, x // Swap the floors: std::swap(FloorLo, FloorHi); @@ -537,10 +549,7 @@ bool cStructGenDirectOverhangs::HasWantedBiome(cChunkDesc & a_ChunkDesc) const // cStructGenDistortedMembraneOverhangs: cStructGenDistortedMembraneOverhangs::cStructGenDistortedMembraneOverhangs(int a_Seed) : - m_NoiseX(a_Seed + 1000), - m_NoiseY(a_Seed + 2000), - m_NoiseZ(a_Seed + 3000), - m_NoiseH(a_Seed + 4000) + m_NoiseX(a_Seed + 1000), m_NoiseY(a_Seed + 2000), m_NoiseZ(a_Seed + 3000), m_NoiseH(a_Seed + 4000) { } @@ -559,14 +568,17 @@ void cStructGenDistortedMembraneOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) BLOCKTYPE ReplacementBlock = (y > 62) ? E_BLOCK_AIR : E_BLOCK_STATIONARY_WATER; for (int z = 0; z < cChunkDef::Width; z++) { - NOISE_DATATYPE NoiseZ = static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z) / Frequency; + NOISE_DATATYPE NoiseZ = + static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z) / Frequency; for (int x = 0; x < cChunkDef::Width; x++) { - NOISE_DATATYPE NoiseX = static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + x) / Frequency; + NOISE_DATATYPE NoiseX = + static_cast<NOISE_DATATYPE>(a_ChunkDesc.GetChunkX() * cChunkDef::Width + x) / Frequency; NOISE_DATATYPE DistortX = m_NoiseX.CubicNoise3D(NoiseX, NoiseY, NoiseZ) * Amount; NOISE_DATATYPE DistortY = m_NoiseY.CubicNoise3D(NoiseX, NoiseY, NoiseZ) * Amount; NOISE_DATATYPE DistortZ = m_NoiseZ.CubicNoise3D(NoiseX, NoiseY, NoiseZ) * Amount; - int MembraneHeight = 96 - static_cast<int>((DistortY + m_NoiseH.CubicNoise2D(NoiseX + DistortX, NoiseZ + DistortZ)) * 30); + int MembraneHeight = 96 - + static_cast<int>((DistortY + m_NoiseH.CubicNoise2D(NoiseX + DistortX, NoiseZ + DistortZ)) * 30); if (MembraneHeight < y) { a_ChunkDesc.SetBlockType(x, y, z, ReplacementBlock); diff --git a/src/Generating/StructGen.h b/src/Generating/StructGen.h index ec3ed89f6..0e6c5da82 100644 --- a/src/Generating/StructGen.h +++ b/src/Generating/StructGen.h @@ -18,24 +18,28 @@ -class cStructGenTrees : - public cFinishGen +class cStructGenTrees : public cFinishGen { -public: - cStructGenTrees(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainShapeGen & a_ShapeGen, cTerrainCompositionGen & a_CompositionGen) : + public: + cStructGenTrees( + int a_Seed, + cBiomeGen & a_BiomeGen, + cTerrainShapeGen & a_ShapeGen, + cTerrainCompositionGen & a_CompositionGen + ) : m_Seed(a_Seed), m_Noise(a_Seed), m_BiomeGen(a_BiomeGen), m_ShapeGen(a_ShapeGen), m_CompositionGen(a_CompositionGen) - {} - -protected: + { + } + protected: int m_Seed; cNoise m_Noise; - cBiomeGen & m_BiomeGen; - cTerrainShapeGen & m_ShapeGen; + cBiomeGen & m_BiomeGen; + cTerrainShapeGen & m_ShapeGen; cTerrainCompositionGen & m_CompositionGen; /** Generates and applies an image of a single tree. @@ -43,16 +47,19 @@ protected: Parts of the tree outside the chunk are stored in a_OutsideXYZ */ void GenerateSingleTree( - int a_ChunkX, int a_ChunkZ, int a_Seq, + int a_ChunkX, + int a_ChunkZ, + int a_Seq, Vector3i a_Pos, cChunkDesc & a_ChunkDesc, sSetBlockVector & a_OutsideLogs, sSetBlockVector & a_OutsideOther - ) ; + ); /** Applies an image into chunk blockdata; all blocks outside the chunk will be appended to a_Overflow. */ void ApplyTreeImage( - int a_ChunkX, int a_ChunkZ, + int a_ChunkX, + int a_ChunkZ, cChunkDesc & a_ChunkDesc, const sSetBlockVector & a_Image, sSetBlockVector & a_Overflow @@ -61,36 +68,28 @@ protected: /** Get the the number of trees to generate in a_Chunk If the value is between 0 and 1, it should be interpreted as the probability that a tree should be generated. */ - double GetNumTrees( - int a_ChunkX, int a_ChunkZ, - const cChunkDef::BiomeMap & a_Biomes - ); + double GetNumTrees(int a_ChunkX, int a_ChunkZ, const cChunkDef::BiomeMap & a_Biomes); // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; -class cStructGenLakes : - public cFinishGen +class cStructGenLakes : public cFinishGen { -public: + public: cStructGenLakes(int a_Seed, BLOCKTYPE a_Fluid, cTerrainShapeGen & a_ShapeGen, int a_Probability) : - m_Noise(a_Seed), - m_Seed(a_Seed), - m_Fluid(a_Fluid), - m_ShapeGen(a_ShapeGen), - m_Probability(a_Probability) + m_Noise(a_Seed), m_Seed(a_Seed), m_Fluid(a_Fluid), m_ShapeGen(a_ShapeGen), m_Probability(a_Probability) { } -protected: - cNoise m_Noise; - int m_Seed; - BLOCKTYPE m_Fluid; + protected: + cNoise m_Noise; + int m_Seed; + BLOCKTYPE m_Fluid; cTerrainShapeGen & m_ShapeGen; /** Chance, [0 .. 100], of a chunk having the lake. */ @@ -102,39 +101,37 @@ protected: /** Creates a lake image for the specified chunk into a_Lake. */ void CreateLakeImage(int a_ChunkX, int a_ChunkZ, int a_MaxLakeHeight, cBlockArea & a_Lake); -} ; +}; -class cStructGenDirectOverhangs : - public cFinishGen +class cStructGenDirectOverhangs : public cFinishGen { -public: + public: cStructGenDirectOverhangs(int a_Seed); -protected: - cNoise m_Noise1; - cNoise m_Noise2; + protected: + cNoise m_Noise1; + cNoise m_Noise2; // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; bool HasWantedBiome(cChunkDesc & a_ChunkDesc) const; -} ; +}; -class cStructGenDistortedMembraneOverhangs : - public cFinishGen +class cStructGenDistortedMembraneOverhangs : public cFinishGen { -public: + public: cStructGenDistortedMembraneOverhangs(int a_Seed); -protected: + protected: cNoise m_NoiseX; cNoise m_NoiseY; cNoise m_NoiseZ; @@ -142,4 +139,4 @@ protected: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; -} ; +}; diff --git a/src/Generating/Trees.cpp b/src/Generating/Trees.cpp index 385bafb2e..fd9f48e7d 100644 --- a/src/Generating/Trees.cpp +++ b/src/Generating/Trees.cpp @@ -23,41 +23,29 @@ typedef struct NIBBLETYPE Meta; } sMetaCoords; -static const sCoords Corners[] = -{ +static const sCoords Corners[] = { {-1, -1}, {-1, 1}, {1, -1}, {1, 1}, -} ; +}; /** Chooses a direction for a branch to go to based on the start position (a_BlockPos) and a_Seq. */ static const Vector3d & pickBranchDirection(const cNoise a_Noise, Vector3i a_BlockPos, int a_Seq) { - static const std::array<Vector3d, 32> directions = - { - { - { -1, 0, 0 }, { 0, 0, -1 }, - { -1, 0, 1 }, { -1, 0, -1 }, - { 1, 0, 1 }, { 1, 0, -1 }, - { 1, 0, 0 }, { 0, 0, 1 }, - - { -0.5, 0, 0 }, { 0, 0, -0.5 }, - { -0.5, 0, 0.5 }, { -0.5, 0, -0.5 }, - { 0.5, 0, 0.5 }, { 0.5, 0, -0.5 }, - { 0.5, 0, 0 }, { 0, 0, 0.5 }, - - { -1, 0.5, 0 }, { 0, 0.5, -1 }, - { -1, 0.5, 1 }, { -1, 0.5, -1 }, - { 1, 0.5, 1 }, { 1, 0.5, -1 }, - { 1, 0.5, 0 }, { 0, 0.5, 1 }, - - { -0.5, 0.5, 0 }, { 0, 0.5, -0.5 }, - { -0.5, 0.5, 0.5 }, { -0.5, 0.5, -0.5 }, - { 0.5, 0.5, 0.5 }, { 0.5, 0.5, -0.5 }, - { 0.5, 0.5, 0 }, { 0, 0.5, 0.5 }, - } - }; + static const std::array<Vector3d, 32> directions = {{ + {-1, 0, 0}, {0, 0, -1}, {-1, 0, 1}, {-1, 0, -1}, + {1, 0, 1}, {1, 0, -1}, {1, 0, 0}, {0, 0, 1}, + + {-0.5, 0, 0}, {0, 0, -0.5}, {-0.5, 0, 0.5}, {-0.5, 0, -0.5}, + {0.5, 0, 0.5}, {0.5, 0, -0.5}, {0.5, 0, 0}, {0, 0, 0.5}, + + {-1, 0.5, 0}, {0, 0.5, -1}, {-1, 0.5, 1}, {-1, 0.5, -1}, + {1, 0.5, 1}, {1, 0.5, -1}, {1, 0.5, 0}, {0, 0.5, 1}, + + {-0.5, 0.5, 0}, {0, 0.5, -0.5}, {-0.5, 0.5, 0.5}, {-0.5, 0.5, -0.5}, + {0.5, 0.5, 0.5}, {0.5, 0.5, -0.5}, {0.5, 0.5, 0}, {0, 0.5, 0.5}, + }}; size_t index = static_cast<size_t>(a_Noise.IntNoise3DInt(a_BlockPos * a_Seq)) % directions.size(); return directions[index]; @@ -65,190 +53,186 @@ static const Vector3d & pickBranchDirection(const cNoise a_Noise, Vector3i a_Blo // BigO = a big ring of blocks, used for generating horz slices of treetops, the number indicates the radius -static const sCoords BigO1[] = -{ - /* -1 */ {0, -1}, - /* 0 */ {-1, 0}, {1, 0}, - /* 1 */ {0, 1}, -} ; +static const sCoords BigO1[] = { + /* -1 */ {0, -1}, + /* 0 */ {-1, 0}, + {1, 0}, + /* 1 */ {0, 1}, +}; -static const sCoords BigO2[] = -{ - /* -2 */ {-1, -2}, {0, -2}, {1, -2}, +static const sCoords BigO2[] = { + /* -2 */ {-1, -2}, {0, -2}, {1, -2}, /* -1 */ {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, - /* 0 */ {-2, 0}, {-1, 0}, {1, 0}, {2, 0}, - /* 1 */ {-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1}, - /* 2 */ {-1, 2}, {0, 2}, {1, 2}, -} ; + /* 0 */ {-2, 0}, {-1, 0}, {1, 0}, {2, 0}, + /* 1 */ {-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1}, + /* 2 */ {-1, 2}, {0, 2}, {1, 2}, +}; -static const sCoords BigO3[] = -{ - /* -3 */ {-2, -3}, {-1, -3}, {0, -3}, {1, -3}, {2, -3}, +static const sCoords BigO3[] = { + /* -3 */ {-2, -3}, {-1, -3}, {0, -3}, {1, -3}, {2, -3}, /* -2 */ {-3, -2}, {-2, -2}, {-1, -2}, {0, -2}, {1, -2}, {2, -2}, {3, -2}, /* -1 */ {-3, -1}, {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, - /* 0 */ {-3, 0}, {-2, 0}, {-1, 0}, {1, 0}, {2, 0}, {3, 0}, - /* 1 */ {-3, 1}, {-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, - /* 2 */ {-3, 2}, {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, - /* 3 */ {-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}, -} ; + /* 0 */ {-3, 0}, {-2, 0}, {-1, 0}, {1, 0}, {2, 0}, {3, 0}, + /* 1 */ {-3, 1}, {-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, + /* 2 */ {-3, 2}, {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, + /* 3 */ {-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}, +}; static const sCoords BigO4[] = // Part of dark oak tree -{ - /* -4 */ {-2, -4}, {-1, -4}, {0, -4}, {1, -4}, {2, -4}, - /* -3 */ {-3, -3}, {-2, -3}, {-1, -3}, {0, -3}, {1, -3}, {2, -3}, {3, -3}, - /* -2 */ {-4, -2}, {-3, -2}, {-2, -2}, {-1, -2}, {0, -2}, {1, -2}, {2, -2}, {3, -2}, {4, -2}, - /* -1 */ {-4, -1}, {-3, -1}, {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, {4, -1}, - /* 0 */ {-4, 0}, {-3, 0}, {-2, 0}, {-1, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, - /* 1 */ {-4, 1}, {-3, 1}, {-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, - /* 2 */ {-4, 2}, {-3, 2}, {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, - /* 3 */ {-3, 3}, {-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}, {3, 3}, - /* 4 */ {-2, 4}, {-1, 4}, {0, 4}, {1, 4}, {2, 4}, + { + /* -4 */ {-2, -4}, {-1, -4}, {0, -4}, {1, -4}, {2, -4}, + /* -3 */ {-3, -3}, {-2, -3}, {-1, -3}, {0, -3}, {1, -3}, {2, -3}, {3, -3}, + /* -2 */ {-4, -2}, {-3, -2}, {-2, -2}, {-1, -2}, {0, -2}, {1, -2}, {2, -2}, {3, -2}, {4, -2}, + /* -1 */ {-4, -1}, {-3, -1}, {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, {4, -1}, + /* 0 */ {-4, 0}, {-3, 0}, {-2, 0}, {-1, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, + /* 1 */ {-4, 1}, {-3, 1}, {-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, + /* 2 */ {-4, 2}, {-3, 2}, {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, + /* 3 */ {-3, 3}, {-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}, {3, 3}, + /* 4 */ {-2, 4}, {-1, 4}, {0, 4}, {1, 4}, {2, 4}, }; -static const sCoords BigO3Jungle[] = -{ - /* -3 */ {0, -3}, {1, -3}, - /* -2 */ {-1, -2}, {0, -2}, {1, -2}, {2, -2}, - /* -1 */ {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, - /* 0 */ {-3, 0}, {-2, 0}, {-1, 0}, {0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, - /* 1 */ {-3, 1}, {-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, - /* 2 */ {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, - /* 3 */ {-1, 3}, {0, 3}, {1, 3}, {2, 3}, - /* 4 */ {0, 4}, {1, 4}, +static const sCoords BigO3Jungle[] = { + /* -3 */ {0, -3}, {1, -3}, + /* -2 */ {-1, -2}, {0, -2}, {1, -2}, {2, -2}, + /* -1 */ {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, + /* 0 */ {-3, 0}, {-2, 0}, {-1, 0}, {0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, + /* 1 */ {-3, 1}, {-2, 1}, {-1, 1}, {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, + /* 2 */ {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, + /* 3 */ {-1, 3}, {0, 3}, {1, 3}, {2, 3}, + /* 4 */ {0, 4}, {1, 4}, }; -static const sCoords BigO4Jungle[] = -{ - /* -4 */ {0, -4}, {1, -4}, - /* -3 */ {-2, -3}, {-1, -3}, {0, -3}, {1, -3}, {2, -3}, {3, -3}, - /* -2 */ {-3, -2}, {-2, -2}, {-1, -2}, {0, -2}, {1, -2}, {2, -2}, {3, -2}, {4, -2}, - /* -1 */ {-3, -1}, {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, {4, -1}, - /* 0 */ {-4, 0}, {-3, 0}, {-2, 0}, {-1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, - /* 1 */ {-4, 1}, {-3, 1}, {-2, 1}, {-1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, - /* 2 */ {-3, 2}, {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, - /* 3 */ {-3, 3}, {-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, - /* 4 */ {-2, 4}, {-1, 4}, {0, 4}, {1, 4}, {2, 4}, {3, 4}, - /* 5 */ {0, 5}, {1, 5}, +static const sCoords BigO4Jungle[] = { + /* -4 */ {0, -4}, {1, -4}, + /* -3 */ {-2, -3}, {-1, -3}, {0, -3}, {1, -3}, {2, -3}, {3, -3}, + /* -2 */ {-3, -2}, {-2, -2}, {-1, -2}, {0, -2}, {1, -2}, {2, -2}, {3, -2}, {4, -2}, + /* -1 */ {-3, -1}, {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, {4, -1}, + /* 0 */ {-4, 0}, {-3, 0}, {-2, 0}, {-1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, + /* 1 */ {-4, 1}, {-3, 1}, {-2, 1}, {-1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, + /* 2 */ {-3, 2}, {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, + /* 3 */ {-3, 3}, {-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, + /* 4 */ {-2, 4}, {-1, 4}, {0, 4}, {1, 4}, {2, 4}, {3, 4}, + /* 5 */ {0, 5}, {1, 5}, }; -static const sCoords BigO5Jungle[] = -{ - /* -5 */ {0, -5}, {1, -5}, - /* -4 */ {-2, -4}, {-1, -4}, {0, -4}, {1, -4}, {2, -4}, {3, -4}, - /* -3 */ {-3, -3}, {-2, -3}, {-1, -3}, {0, -3}, {1, -3}, {2, -3}, {3, -3}, {4, -3}, - /* -2 */ {-4, -2}, {-3, -2}, {-2, -2}, {-1, -2}, {0, -2}, {1, -2}, {2, -2}, {3, -2}, {4, -2}, {5, -2}, - /* -1 */ {-4, -1}, {-3, -1}, {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, {4, -1}, {5, -1}, - /* 0 */ {-5, 0}, {-4, 0}, {-3, 0}, {-2, 0}, {-1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, - /* 1 */ {-5, 1}, {-4, 1}, {-3, 1}, {-2, 1}, {-1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, - /* 2 */ {-4, 2}, {-3, 2}, {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, - /* 3 */ {-4, 3}, {-3, 3}, {-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, - /* 4 */ {-3, 4}, {-2, 4}, {-1, 4}, {0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, - /* 5 */ {-2, 5}, {-1, 5}, {0, 5}, {1, 5}, {2, 5}, {3, 5}, - /* 6 */ {0, 6}, {1, 6}, -} ; - -static const sCoords TopLargePine[] = -{ - /* 0 */ {0, 0}, {1, 0}, - /* 1 */ {0, 1}, {1, 1}, -} ; +static const sCoords BigO5Jungle[] = { + /* -5 */ {0, -5}, {1, -5}, + /* -4 */ {-2, -4}, {-1, -4}, {0, -4}, {1, -4}, {2, -4}, {3, -4}, + /* -3 */ {-3, -3}, {-2, -3}, {-1, -3}, {0, -3}, {1, -3}, {2, -3}, {3, -3}, {4, -3}, + /* -2 */ {-4, -2}, {-3, -2}, {-2, -2}, {-1, -2}, {0, -2}, {1, -2}, {2, -2}, {3, -2}, {4, -2}, {5, -2}, + /* -1 */ {-4, -1}, {-3, -1}, {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, {4, -1}, {5, -1}, + /* 0 */ {-5, 0}, {-4, 0}, {-3, 0}, {-2, 0}, {-1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, + /* 1 */ {-5, 1}, {-4, 1}, {-3, 1}, {-2, 1}, {-1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, + /* 2 */ {-4, 2}, {-3, 2}, {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, + /* 3 */ {-4, 3}, {-3, 3}, {-2, 3}, {-1, 3}, {0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}, + /* 4 */ {-3, 4}, {-2, 4}, {-1, 4}, {0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, + /* 5 */ {-2, 5}, {-1, 5}, {0, 5}, {1, 5}, {2, 5}, {3, 5}, + /* 6 */ {0, 6}, {1, 6}, +}; -static const sCoords BigOF2Pine[] = -{ - /* -1 */ {0, -1}, {1, -1}, - /* 0 */ {-1, 0}, {0, 0}, {1, 0}, {2, 0}, - /* 1 */ {-1, 1}, {0, 1}, {1, 1}, {2, 1}, - /* 2 */ {0, 2}, {1, 2}, -} ; +static const sCoords TopLargePine[] = { + /* 0 */ {0, 0}, + {1, 0}, + /* 1 */ {0, 1}, + {1, 1}, +}; -static const sCoords BigO2Pine[] = -{ - /* -2 */ {0, -2}, {1, -2}, - /* -1 */ {-1, -1}, {0, -1}, {1, -1}, {2, -1}, - /* 0 */ {-2, 0}, {-1, 0}, {2, 0}, {3, 0}, - /* 1 */ {-2, 1}, {-1, 1}, {2, 1}, {3, 1}, - /* 2 */ {-1, 2}, {0, 2}, {1, 2}, {2, 2}, - /* 3 */ {0, 3}, {1, 3}, -} ; - -static const sCoords BigO3Pine[] = -{ - /* -3 */ {0, -3}, {1, -3}, - /* -2 */ {-1, -2}, {0, -2}, {1, -2}, {2, -2}, - /* -1 */ {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, - /* 0 */ {-3, 0}, {-2, 0}, {-1, 0}, {2, 0}, {3, 0}, {4, 0}, - /* 1 */ {-3, 1}, {-2, 1}, {-1, 1}, {2, 1}, {3, 1}, {4, 1}, - /* 2 */ {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, - /* 3 */ {-1, 3}, {0, 3}, {1, 3}, {2, 3}, - /* 4 */ {0, 4}, {1, 4}, +static const sCoords BigOF2Pine[] = { + /* -1 */ {0, -1}, + {1, -1}, + /* 0 */ {-1, 0}, + {0, 0}, + {1, 0}, + {2, 0}, + /* 1 */ {-1, 1}, + {0, 1}, + {1, 1}, + {2, 1}, + /* 2 */ {0, 2}, + {1, 2}, }; -static const sCoords BigO1Spruce[] = -{ - /* -1 */ {0, -1}, {1, -1}, - /* 0 */ {-1, 0}, {2, 0}, - /* 1 */ {-1, 1}, {2, 1}, - /* 2 */ {0, 2}, {1, 2}, -} ; +static const sCoords BigO2Pine[] = { + /* -2 */ {0, -2}, {1, -2}, + /* -1 */ {-1, -1}, {0, -1}, {1, -1}, {2, -1}, + /* 0 */ {-2, 0}, {-1, 0}, {2, 0}, {3, 0}, + /* 1 */ {-2, 1}, {-1, 1}, {2, 1}, {3, 1}, + /* 2 */ {-1, 2}, {0, 2}, {1, 2}, {2, 2}, + /* 3 */ {0, 3}, {1, 3}, +}; + +static const sCoords BigO3Pine[] = { + /* -3 */ {0, -3}, {1, -3}, + /* -2 */ {-1, -2}, {0, -2}, {1, -2}, {2, -2}, + /* -1 */ {-2, -1}, {-1, -1}, {0, -1}, {1, -1}, {2, -1}, {3, -1}, + /* 0 */ {-3, 0}, {-2, 0}, {-1, 0}, {2, 0}, {3, 0}, {4, 0}, + /* 1 */ {-3, 1}, {-2, 1}, {-1, 1}, {2, 1}, {3, 1}, {4, 1}, + /* 2 */ {-2, 2}, {-1, 2}, {0, 2}, {1, 2}, {2, 2}, {3, 2}, + /* 3 */ {-1, 3}, {0, 3}, {1, 3}, {2, 3}, + /* 4 */ {0, 4}, {1, 4}, +}; + +static const sCoords BigO1Spruce[] = { + /* -1 */ {0, -1}, + {1, -1}, + /* 0 */ {-1, 0}, + {2, 0}, + /* 1 */ {-1, 1}, + {2, 1}, + /* 2 */ {0, 2}, + {1, 2}, +}; typedef struct { const sCoords * Coords; - size_t Count; + size_t Count; } sCoordsArr; -static const sCoordsArr BigOLayers[] = -{ +static const sCoordsArr BigOLayers[] = { {BigO1, ARRAYCOUNT(BigO1)}, {BigO2, ARRAYCOUNT(BigO2)}, {BigO3, ARRAYCOUNT(BigO3)}, {BigO4, ARRAYCOUNT(BigO4)}, -} ; +}; -static const sCoordsArr BigOJungleLayers[] = -{ +static const sCoordsArr BigOJungleLayers[] = { {BigO5Jungle, ARRAYCOUNT(BigO5Jungle)}, {BigO4Jungle, ARRAYCOUNT(BigO4Jungle)}, {BigO3Jungle, ARRAYCOUNT(BigO3Jungle)}, }; -static const sCoordsArr BigOPineLayers[] = -{ +static const sCoordsArr BigOPineLayers[] = { {BigO3Pine, ARRAYCOUNT(BigO3Pine)}, {BigO2Pine, ARRAYCOUNT(BigO2Pine)}, {BigOF2Pine, ARRAYCOUNT(BigOF2Pine)}, {TopLargePine, ARRAYCOUNT(TopLargePine)}, }; -static const sCoordsArr BigOSpruceLayersV1[] = -{ +static const sCoordsArr BigOSpruceLayersV1[] = { {BigO1Spruce, ARRAYCOUNT(BigO1Spruce)}, {nullptr, 0}, }; -static const sCoordsArr BigOSpruceLayersV2[] = -{ +static const sCoordsArr BigOSpruceLayersV2[] = { {BigO2Pine, ARRAYCOUNT(BigO2Pine)}, {BigO1Spruce, ARRAYCOUNT(BigO1Spruce)}, }; -static const sCoordsArr BigOSpruceLayersV3[] = -{ +static const sCoordsArr BigOSpruceLayersV3[] = { {BigO3Pine, ARRAYCOUNT(BigO3Pine)}, {BigO2Pine, ARRAYCOUNT(BigO2Pine)}, }; -static const sCoordsArr BigOSpruceLayersV4[] = -{ +static const sCoordsArr BigOSpruceLayersV4[] = { {BigO4Jungle, ARRAYCOUNT(BigO4Jungle)}, {BigO3Pine, ARRAYCOUNT(BigO3Pine)}, }; -static const sCoordsArr BigOSpruceTop[] = -{ +static const sCoordsArr BigOSpruceTop[] = { {BigO1Spruce, ARRAYCOUNT(BigO1Spruce)}, {TopLargePine, ARRAYCOUNT(TopLargePine)}, }; @@ -258,7 +242,16 @@ static const sCoordsArr BigOSpruceTop[] = /** Pushes a specified layer of blocks of the same type around (x, h, z) into a_Blocks */ -inline void PushCoordBlocks(int a_BlockX, int a_Height, int a_BlockZ, sSetBlockVector & a_Blocks, const sCoords * a_Coords, size_t a_NumCoords, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +inline void PushCoordBlocks( + int a_BlockX, + int a_Height, + int a_BlockZ, + sSetBlockVector & a_Blocks, + const sCoords * a_Coords, + size_t a_NumCoords, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_Meta +) { for (size_t i = 0; i < a_NumCoords; i++) { @@ -270,7 +263,18 @@ inline void PushCoordBlocks(int a_BlockX, int a_Height, int a_BlockZ, sSetBlockV -inline void PushCornerBlocks(int a_BlockX, int a_Height, int a_BlockZ, int a_Seq, cNoise & a_Noise, int a_Chance, sSetBlockVector & a_Blocks, int a_CornersDist, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta) +inline void PushCornerBlocks( + int a_BlockX, + int a_Height, + int a_BlockZ, + int a_Seq, + cNoise & a_Noise, + int a_Chance, + sSetBlockVector & a_Blocks, + int a_CornersDist, + BLOCKTYPE a_BlockType, + NIBBLETYPE a_Meta +) { for (size_t i = 0; i < ARRAYCOUNT(Corners); i++) { @@ -287,7 +291,19 @@ inline void PushCornerBlocks(int a_BlockX, int a_Height, int a_BlockZ, int a_Seq -inline void PushSomeColumns(int a_BlockX, int a_Height, int a_BlockZ, int a_ColumnHeight, int a_Seq, cNoise & a_Noise, int a_Chance, sSetBlockVector & a_Blocks, const sMetaCoords * a_Coords, size_t a_NumCoords, BLOCKTYPE a_BlockType) +inline void PushSomeColumns( + int a_BlockX, + int a_Height, + int a_BlockZ, + int a_ColumnHeight, + int a_Seq, + cNoise & a_Noise, + int a_Chance, + sSetBlockVector & a_Blocks, + const sMetaCoords * a_Coords, + size_t a_NumCoords, + BLOCKTYPE a_BlockType +) { for (size_t i = 0; i < a_NumCoords; i++) { @@ -307,7 +323,14 @@ inline void PushSomeColumns(int a_BlockX, int a_Height, int a_BlockZ, int a_Colu -void GetTreeImageByBiome(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, EMCSBiome a_Biome, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetTreeImageByBiome( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + EMCSBiome a_Biome, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { switch (a_Biome) { @@ -519,7 +542,13 @@ void GetTreeImageByBiome(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, EMCSB -void GetAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetAppleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { if (a_Noise.IntNoise3DInt(a_BlockPos.addedX(32 * a_Seq).addedY(32 * a_Seq)) < 0x73333333) { @@ -535,7 +564,13 @@ void GetAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlo -void GetSmallAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetSmallAppleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { /* Small apple tree has: - a top plus (no log) @@ -545,7 +580,7 @@ void GetSmallAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sS */ int Random = a_Noise.IntNoise3DInt(a_BlockPos.addedX(64 * a_Seq)) >> 3; - HEIGHTTYPE Heights[] = {1, 2, 2, 3} ; + HEIGHTTYPE Heights[] = {1, 2, 2, 3}; HEIGHTTYPE Height = 1 + Heights[Random & 3]; Random >>= 2; @@ -563,8 +598,28 @@ void GetSmallAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sS // 2 BigO2 + corners layers: for (int i = 0; i < 2; i++) { - PushCoordBlocks (a_BlockPos.x, Hei, a_BlockPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); - PushCornerBlocks(a_BlockPos.x, Hei, a_BlockPos.z, a_Seq, a_Noise, 0x5000000 - i * 0x10000000, a_OtherBlocks, 2, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + a_BlockPos.x, + Hei, + a_BlockPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); + PushCornerBlocks( + a_BlockPos.x, + Hei, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x5000000 - i * 0x10000000, + a_OtherBlocks, + 2, + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); a_LogBlocks.emplace_back(a_BlockPos.x, Hei, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_APPLE); Hei++; } // for i - 2* @@ -572,14 +627,43 @@ void GetSmallAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sS // Optional BigO1 + corners layer: if ((Random & 1) == 0) { - PushCoordBlocks (a_BlockPos.x, Hei, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); - PushCornerBlocks(a_BlockPos.x, Hei, a_BlockPos.z, a_Seq, a_Noise, 0x6000000, a_OtherBlocks, 1, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + a_BlockPos.x, + Hei, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); + PushCornerBlocks( + a_BlockPos.x, + Hei, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x6000000, + a_OtherBlocks, + 1, + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); a_LogBlocks.emplace_back(a_BlockPos.x, Hei, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_APPLE); Hei++; } // Top plus: - PushCoordBlocks(a_BlockPos.x, Hei, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + a_BlockPos.x, + Hei, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); a_OtherBlocks.emplace_back(a_BlockPos.x, Hei, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); } @@ -587,7 +671,13 @@ void GetSmallAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sS -void GetLargeAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetLargeAppleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { int Height = 7 + a_Noise.IntNoise3DInt(a_BlockPos) % 4; @@ -599,7 +689,15 @@ void GetLargeAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sS Vector3d BranchDirection = pickBranchDirection(a_Noise, a_BlockPos.addedY(i * a_Seq), a_Seq) / 3; int BranchLength = 2 + a_Noise.IntNoise3DInt(a_BlockPos * a_Seq) % 3; - GetTreeBranch(E_BLOCK_LOG, E_META_LOG_APPLE, a_BlockPos.addedY(i), BranchLength, BranchStartDirection, BranchDirection, a_LogBlocks); + GetTreeBranch( + E_BLOCK_LOG, + E_META_LOG_APPLE, + a_BlockPos.addedY(i), + BranchLength, + BranchStartDirection, + BranchDirection, + a_LogBlocks + ); } // Place leaves around each log block @@ -610,12 +708,39 @@ void GetLargeAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sS int Z = itr.GetZ(); a_OtherBlocks.emplace_back(X, itr.m_RelY - 2, Z, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); - PushCoordBlocks(X, itr.m_RelY - 2, Z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + X, + itr.m_RelY - 2, + Z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); for (int y = -1; y <= 1; y++) { - PushCoordBlocks (X, itr.m_RelY + y, Z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + X, + itr.m_RelY + y, + Z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); } - PushCoordBlocks(X, itr.m_RelY + 2, Z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + X, + itr.m_RelY + 2, + Z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); a_OtherBlocks.emplace_back(X, itr.m_RelY + 2, Z, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); } @@ -630,10 +755,18 @@ void GetLargeAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sS -Vector3d GetTreeBranch(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_BlockPos, int a_BranchLength, Vector3d a_StartDirection, Vector3d a_Direction, sSetBlockVector & a_LogBlocks) +Vector3d GetTreeBranch( + BLOCKTYPE a_BlockType, + NIBBLETYPE a_BlockMeta, + Vector3i a_BlockPos, + int a_BranchLength, + Vector3d a_StartDirection, + Vector3d a_Direction, + sSetBlockVector & a_LogBlocks +) { Vector3d CurrentPos = Vector3d(a_BlockPos); - Vector3d Direction = a_StartDirection; + Vector3d Direction = a_StartDirection; for (int i = 0; i < a_BranchLength; i++) { CurrentPos += Direction; @@ -670,7 +803,13 @@ NIBBLETYPE GetLogMetaFromDirection(NIBBLETYPE a_BlockMeta, Vector3d a_Direction) -void GetBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetBirchTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { HEIGHTTYPE Height = 5 + static_cast<HEIGHTTYPE>(a_Noise.IntNoise3DInt(a_BlockPos.addedX(64 * a_Seq)) % 3); @@ -686,20 +825,75 @@ void GetBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlo int h = a_BlockPos.y + Height; // Top layer - just the Plus: - PushCoordBlocks(a_BlockPos.x, h, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); - a_OtherBlocks.emplace_back(a_BlockPos.x, h, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); // There's no log at this layer + PushCoordBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); + a_OtherBlocks.emplace_back( + a_BlockPos.x, + h, + a_BlockPos.z, + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); // There's no log at this layer h--; // Second layer - log, Plus and maybe Corners: - PushCoordBlocks (a_BlockPos.x, h, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); - PushCornerBlocks(a_BlockPos.x, h, a_BlockPos.z, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 1, E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); + PushCoordBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); + PushCornerBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x5fffffff, + a_OtherBlocks, + 1, + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); h--; // Third and fourth layers - BigO2 and maybe 2 * Corners: for (int Row = 0; Row < 2; Row++) { - PushCoordBlocks (a_BlockPos.x, h, a_BlockPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); - PushCornerBlocks(a_BlockPos.x, h, a_BlockPos.z, a_Seq, a_Noise, 0x3fffffff + Row * 0x10000000, a_OtherBlocks, 2, E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); + PushCoordBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); + PushCornerBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x3fffffff + Row * 0x10000000, + a_OtherBlocks, + 2, + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); h--; } // for Row - 2* } @@ -708,7 +902,13 @@ void GetBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlo -void GetAcaciaTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetAcaciaTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { // Calculate a base height int Height = 2 + (a_Noise.IntNoise3DInt(a_BlockPos) / 11 % 3); @@ -720,12 +920,15 @@ void GetAcaciaTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBl } // Array with possible directions for a branch to go to. - const Vector3i AvailableDirections[] = - { - { -1, 1, 0 }, { 0, 1, -1 }, - { -1, 1, 1 }, { -1, 1, -1 }, - { 1, 1, 1 }, { 1, 1, -1 }, - { 1, 1, 0 }, { 0, 1, 1 }, + const Vector3i AvailableDirections[] = { + {-1, 1, 0}, + {0, 1, -1}, + {-1, 1, 1}, + {-1, 1, -1}, + {1, 1, 1}, + {1, 1, -1}, + {1, 1, 0}, + {0, 1, 1}, }; // Get a direction for the trunk to go to. @@ -734,11 +937,38 @@ void GetAcaciaTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBl // Calculate a height for the branch between 1 and 3 int BranchHeight = a_Noise.IntNoise3DInt(a_BlockPos) % 3 + 1; - Vector3i BranchPos = GetTreeBranch(E_BLOCK_NEW_LOG, E_META_NEW_LOG_ACACIA_WOOD, a_BlockPos.addedY(Height - 1), BranchHeight, Vector3i(BranchDirection), Vector3i(BranchDirection), a_LogBlocks).Floor(); + Vector3i BranchPos = GetTreeBranch( + E_BLOCK_NEW_LOG, + E_META_NEW_LOG_ACACIA_WOOD, + a_BlockPos.addedY(Height - 1), + BranchHeight, + Vector3i(BranchDirection), + Vector3i(BranchDirection), + a_LogBlocks + ) + .Floor(); // Add the leaves to the top of the branch - PushCoordBlocks(BranchPos.x, BranchPos.y, BranchPos.z, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_ACACIA); - PushCoordBlocks(BranchPos.x, BranchPos.y + 1, BranchPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_ACACIA); + PushCoordBlocks( + BranchPos.x, + BranchPos.y, + BranchPos.z, + a_OtherBlocks, + BigO3, + ARRAYCOUNT(BigO3), + E_BLOCK_NEW_LEAVES, + E_META_NEWLEAVES_ACACIA + ); + PushCoordBlocks( + BranchPos.x, + BranchPos.y + 1, + BranchPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_NEW_LEAVES, + E_META_NEWLEAVES_ACACIA + ); a_OtherBlocks.emplace_back(BranchPos.x, BranchPos.y + 1, BranchPos.z, E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_ACACIA); // Choose if we have to add another branch @@ -754,11 +984,38 @@ void GetAcaciaTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBl // Calculate a new height for the second branch BranchHeight = a_Noise.IntNoise3DInt(a_BlockPos * a_Seq) % 3 + 1; - BranchPos = GetTreeBranch(E_BLOCK_NEW_LOG, E_META_NEW_LOG_ACACIA_WOOD, a_BlockPos.addedY(Height - 1), BranchHeight, BranchDirection, BranchDirection, a_LogBlocks).Floor(); + BranchPos = GetTreeBranch( + E_BLOCK_NEW_LOG, + E_META_NEW_LOG_ACACIA_WOOD, + a_BlockPos.addedY(Height - 1), + BranchHeight, + BranchDirection, + BranchDirection, + a_LogBlocks + ) + .Floor(); // And add the leaves ontop of the second branch - PushCoordBlocks(BranchPos.x, BranchPos.y, BranchPos.z, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_ACACIA); - PushCoordBlocks(BranchPos.x, BranchPos.y + 1, BranchPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_ACACIA); + PushCoordBlocks( + BranchPos.x, + BranchPos.y, + BranchPos.z, + a_OtherBlocks, + BigO3, + ARRAYCOUNT(BigO3), + E_BLOCK_NEW_LEAVES, + E_META_NEWLEAVES_ACACIA + ); + PushCoordBlocks( + BranchPos.x, + BranchPos.y + 1, + BranchPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_NEW_LEAVES, + E_META_NEWLEAVES_ACACIA + ); a_OtherBlocks.emplace_back(BranchPos.x, BranchPos.y + 1, BranchPos.z, E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_ACACIA); } @@ -766,7 +1023,13 @@ void GetAcaciaTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBl -void GetDarkoakTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetDarkoakTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { // Pick a height int Height = 5 + (a_Noise.IntNoise3DInt(a_BlockPos.addedX(32 * a_Seq).addedZ(32 * a_Seq)) / 11) % 4; @@ -777,7 +1040,8 @@ void GetDarkoakTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetB a_LogBlocks.emplace_back(a_BlockPos.addedY(i), E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD); a_LogBlocks.emplace_back(a_BlockPos.addedX(1).addedY(i), E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD); a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedZ(1), E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD); - a_LogBlocks.emplace_back(a_BlockPos.addedX(1).addedY(i).addedZ(1), E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD); + a_LogBlocks + .emplace_back(a_BlockPos.addedX(1).addedY(i).addedZ(1), E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD); } // Prevent floating trees by placing dirt under them @@ -809,11 +1073,13 @@ void GetDarkoakTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetB } } - int y = Height - (a_Noise.IntNoise3DInt(a_BlockPos.addedX(x).addedZ(z).addedY(i * a_Seq)) % (Height - (Height / 4))); + int y = Height - + (a_Noise.IntNoise3DInt(a_BlockPos.addedX(x).addedZ(z).addedY(i * a_Seq)) % (Height - (Height / 4))); for (int Y = y; Y < Height; Y++) { - a_LogBlocks.emplace_back(a_BlockPos.addedX(x).addedY(Y).addedZ(z), E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD); + a_LogBlocks + .emplace_back(a_BlockPos.addedX(x).addedY(Y).addedZ(z), E_BLOCK_NEW_LOG, E_META_NEW_LOG_DARK_OAK_WOOD); } } @@ -822,14 +1088,54 @@ void GetDarkoakTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetB // The lower two leaves layers are BigO4 with log in the middle and possibly corners: for (int i = 0; i < 2; i++) { - PushCoordBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_OtherBlocks, BigO4, ARRAYCOUNT(BigO4), E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_DARK_OAK); - PushCornerBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_DARK_OAK); + PushCoordBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_OtherBlocks, + BigO4, + ARRAYCOUNT(BigO4), + E_BLOCK_NEW_LEAVES, + E_META_NEWLEAVES_DARK_OAK + ); + PushCornerBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x5fffffff, + a_OtherBlocks, + 3, + E_BLOCK_NEW_LEAVES, + E_META_NEWLEAVES_DARK_OAK + ); hei++; } // for i < 2 // The top leaves layer is a BigO3 with leaves in the middle and possibly corners: - PushCoordBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_DARK_OAK); - PushCornerBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_DARK_OAK); + PushCoordBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_OtherBlocks, + BigO3, + ARRAYCOUNT(BigO3), + E_BLOCK_NEW_LEAVES, + E_META_NEWLEAVES_DARK_OAK + ); + PushCornerBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x5fffffff, + a_OtherBlocks, + 3, + E_BLOCK_NEW_LEAVES, + E_META_NEWLEAVES_DARK_OAK + ); a_OtherBlocks.emplace_back(a_BlockPos.x, hei, a_BlockPos.z, E_BLOCK_NEW_LEAVES, E_META_NEWLEAVES_DARK_OAK); } @@ -837,7 +1143,13 @@ void GetDarkoakTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetB -void GetTallBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetTallBirchTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { HEIGHTTYPE Height = 9 + static_cast<HEIGHTTYPE>(a_Noise.IntNoise3DInt(a_BlockPos.addedX(64 * a_Seq)) % 3); @@ -853,20 +1165,75 @@ void GetTallBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSe int h = a_BlockPos.y + Height; // Top layer - just the Plus: - PushCoordBlocks(a_BlockPos.x, h, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); - a_OtherBlocks.emplace_back(a_BlockPos.x, h, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); // There's no log at this layer + PushCoordBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); + a_OtherBlocks.emplace_back( + a_BlockPos.x, + h, + a_BlockPos.z, + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); // There's no log at this layer h--; // Second layer - log, Plus and maybe Corners: - PushCoordBlocks (a_BlockPos.x, h, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); - PushCornerBlocks(a_BlockPos.x, h, a_BlockPos.z, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 1, E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); + PushCoordBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); + PushCornerBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x5fffffff, + a_OtherBlocks, + 1, + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); h--; // Third and fourth layers - BigO2 and maybe 2 * Corners: for (int Row = 0; Row < 2; Row++) { - PushCoordBlocks (a_BlockPos.x, h, a_BlockPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); - PushCornerBlocks(a_BlockPos.x, h, a_BlockPos.z, a_Seq, a_Noise, 0x3fffffff + Row * 0x10000000, a_OtherBlocks, 2, E_BLOCK_LEAVES, E_META_LEAVES_BIRCH); + PushCoordBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); + PushCornerBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x3fffffff + Row * 0x10000000, + a_OtherBlocks, + 2, + E_BLOCK_LEAVES, + E_META_LEAVES_BIRCH + ); h--; } // for Row - 2* } @@ -875,7 +1242,14 @@ void GetTallBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSe -void GetConiferTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks, bool a_Large) +void GetConiferTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks, + bool a_Large +) { // Half chance for a spruce, half for a pine and for the large ones 3 chances for a pine and one for spruce: if (a_Noise.IntNoise3DInt(a_BlockPos.addedX(64 * a_Seq).addedZ(32 * a_Seq)) < (a_Large ? 0x20000000 : 0x40000000)) @@ -892,7 +1266,14 @@ void GetConiferTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetB -void GetSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks, bool a_Large) +void GetSpruceTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks, + bool a_Large +) { if (a_Large) { @@ -902,14 +1283,20 @@ void GetSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBl { GetSmallSpruceTreeImage(a_BlockPos, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks); } - } -void GetPineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks, bool a_Large) +void GetPineTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks, + bool a_Large +) { if (a_Large) { @@ -919,14 +1306,19 @@ void GetPineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBloc { GetSmallPineTreeImage(a_BlockPos, a_Noise, a_Seq, a_LogBlocks, a_OtherBlocks); } - } -void GetSmallSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetSmallSpruceTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { // Spruces have a top section with layer sizes of (0, 1, 0) or only (1, 0), // then 1 - 3 sections of ascending sizes (1, 2) [most often], (1, 3) or (1, 2, 3) @@ -936,7 +1328,7 @@ void GetSmallSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s // (each of the mod8 remainders has a very different chance of occurrence) - that's why we divide by 8 int MyRandom = a_Noise.IntNoise3DInt(a_BlockPos.addedX(32 * a_Seq).addedY(32 * a_Seq)) / 8; - static const HEIGHTTYPE sHeights[] = {1, 2, 2, 3}; + static const HEIGHTTYPE sHeights[] = {1, 2, 2, 3}; HEIGHTTYPE Height = sHeights[MyRandom & 3]; MyRandom >>= 2; @@ -954,7 +1346,16 @@ void GetSmallSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s // Optional size-1 bottom leaves layer: if ((MyRandom & 1) == 0) { - PushCoordBlocks(a_BlockPos.x, Height, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); + PushCoordBlocks( + a_BlockPos.x, + Height, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); a_OtherBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); Height++; } @@ -971,28 +1372,91 @@ void GetSmallSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s case 0: case 1: { - PushCoordBlocks(a_BlockPos.x, Height, a_BlockPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); - PushCoordBlocks(a_BlockPos.x, Height + 1, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); - a_LogBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); + PushCoordBlocks( + a_BlockPos.x, + Height, + a_BlockPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); + PushCoordBlocks( + a_BlockPos.x, + Height + 1, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); + a_LogBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); a_LogBlocks.emplace_back(a_BlockPos.x, Height + 1, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); Height += 2; break; } case 2: { - PushCoordBlocks(a_BlockPos.x, Height, a_BlockPos.z, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); - PushCoordBlocks(a_BlockPos.x, Height + 1, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); - a_LogBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); + PushCoordBlocks( + a_BlockPos.x, + Height, + a_BlockPos.z, + a_OtherBlocks, + BigO3, + ARRAYCOUNT(BigO3), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); + PushCoordBlocks( + a_BlockPos.x, + Height + 1, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); + a_LogBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); a_LogBlocks.emplace_back(a_BlockPos.x, Height + 1, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); Height += 2; break; } case 3: { - PushCoordBlocks(a_BlockPos.x, Height, a_BlockPos.z, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); - PushCoordBlocks(a_BlockPos.x, Height + 1, a_BlockPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); - PushCoordBlocks(a_BlockPos.x, Height + 2, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); - a_LogBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); + PushCoordBlocks( + a_BlockPos.x, + Height, + a_BlockPos.z, + a_OtherBlocks, + BigO3, + ARRAYCOUNT(BigO3), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); + PushCoordBlocks( + a_BlockPos.x, + Height + 1, + a_BlockPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); + PushCoordBlocks( + a_BlockPos.x, + Height + 2, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); + a_LogBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); a_LogBlocks.emplace_back(a_BlockPos.x, Height + 1, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); a_LogBlocks.emplace_back(a_BlockPos.x, Height + 2, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); Height += 3; @@ -1005,16 +1469,34 @@ void GetSmallSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s if ((MyRandom & 1) == 0) { // (0, 1, 0) top: - a_LogBlocks.emplace_back (a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); - PushCoordBlocks (a_BlockPos.x, Height + 1, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); + a_LogBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_CONIFER); + PushCoordBlocks( + a_BlockPos.x, + Height + 1, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); a_OtherBlocks.emplace_back(a_BlockPos.x, Height + 1, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); a_OtherBlocks.emplace_back(a_BlockPos.x, Height + 2, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); } else { // (1, 0) top: - a_OtherBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); - PushCoordBlocks (a_BlockPos.x, Height + 1, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); + a_OtherBlocks.emplace_back(a_BlockPos.x, Height, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); + PushCoordBlocks( + a_BlockPos.x, + Height + 1, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); a_OtherBlocks.emplace_back(a_BlockPos.x, Height + 1, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); } } @@ -1023,11 +1505,26 @@ void GetSmallSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s -static void LargeSpruceAddRing(Vector3i a_BlockPos, int & a_Height, const sCoordsArr* const a_Ring, size_t a_RingCount, sSetBlockVector & a_OtherBlocks) +static void LargeSpruceAddRing( + Vector3i a_BlockPos, + int & a_Height, + const sCoordsArr * const a_Ring, + size_t a_RingCount, + sSetBlockVector & a_OtherBlocks +) { - for (size_t i = 0; i < a_RingCount ; i++) - { - PushCoordBlocks(a_BlockPos.x, a_Height--, a_BlockPos.z, a_OtherBlocks, a_Ring[a_RingCount - 1 - i].Coords, a_Ring[a_RingCount - 1 - i].Count, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); + for (size_t i = 0; i < a_RingCount; i++) + { + PushCoordBlocks( + a_BlockPos.x, + a_Height--, + a_BlockPos.z, + a_OtherBlocks, + a_Ring[a_RingCount - 1 - i].Coords, + a_Ring[a_RingCount - 1 - i].Count, + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); } } @@ -1037,24 +1534,32 @@ static void LargeSpruceAddRing(Vector3i a_BlockPos, int & a_Height, const sCoord const int MIN_LARGE_SPRUCE_TREE_RINGS = 3; const int MAX_LARGE_SPRUCE_TREE_RINGS = 11; -void GetLargeSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetLargeSpruceTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { int Height = 20 + (a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * a_Seq)) / 11) % 12; - int LeavesRingCount = - MIN_LARGE_SPRUCE_TREE_RINGS + - (a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * a_Seq)) / 13) % (1 + MAX_LARGE_SPRUCE_TREE_RINGS - MIN_LARGE_SPRUCE_TREE_RINGS); + int LeavesRingCount = MIN_LARGE_SPRUCE_TREE_RINGS + + (a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * a_Seq)) / 13) % + (1 + MAX_LARGE_SPRUCE_TREE_RINGS - MIN_LARGE_SPRUCE_TREE_RINGS); int RingRadius = 0; a_LogBlocks.reserve(static_cast<size_t>(Height) * 4); - a_OtherBlocks.reserve(ARRAYCOUNT(BigO1Spruce) + ARRAYCOUNT(TopLargePine) + - MAX_LARGE_SPRUCE_TREE_RINGS * (ARRAYCOUNT(BigO4Jungle) + ARRAYCOUNT(BigO3Pine) + ARRAYCOUNT(BigO2Pine))); + a_OtherBlocks.reserve( + ARRAYCOUNT(BigO1Spruce) + ARRAYCOUNT(TopLargePine) + + MAX_LARGE_SPRUCE_TREE_RINGS * (ARRAYCOUNT(BigO4Jungle) + ARRAYCOUNT(BigO3Pine) + ARRAYCOUNT(BigO2Pine)) + ); for (int i = 0; i < Height; i++) { - a_LogBlocks.emplace_back(a_BlockPos.addedY(i), E_BLOCK_LOG, E_META_LOG_CONIFER); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedX(1), E_BLOCK_LOG, E_META_LOG_CONIFER); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedZ(1), E_BLOCK_LOG, E_META_LOG_CONIFER); + a_LogBlocks.emplace_back(a_BlockPos.addedY(i), E_BLOCK_LOG, E_META_LOG_CONIFER); + a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedX(1), E_BLOCK_LOG, E_META_LOG_CONIFER); + a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedZ(1), E_BLOCK_LOG, E_META_LOG_CONIFER); a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(1, 1), E_BLOCK_LOG, E_META_LOG_CONIFER); } int hei = a_BlockPos.y + Height - 1; @@ -1062,23 +1567,33 @@ void GetLargeSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s // Prevent floating trees by placing dirt under them for (int i = 1; i < 5; i++) { - a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i), E_BLOCK_DIRT, E_META_DIRT_NORMAL); - a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedX(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); - a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedZ(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); + a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i), E_BLOCK_DIRT, E_META_DIRT_NORMAL); + a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedX(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); + a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedZ(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedXZ(1, 1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); } // Place the top. for (size_t i = 0; i < ARRAYCOUNT(BigOSpruceTop); i++) { - PushCoordBlocks(a_BlockPos.x, hei++, a_BlockPos.z, a_OtherBlocks, BigOSpruceTop[i].Coords, BigOSpruceTop[i].Count, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); + PushCoordBlocks( + a_BlockPos.x, + hei++, + a_BlockPos.z, + a_OtherBlocks, + BigOSpruceTop[i].Coords, + BigOSpruceTop[i].Count, + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); } hei = a_BlockPos.y + Height - 2; for (int i = 0; i < LeavesRingCount; i++) { - unsigned int Val = static_cast<unsigned int>(a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * i)) / 23) % 8; + unsigned int Val = + static_cast<unsigned int>(a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * i)) / 23) % 8; if ((Val < 4) && RingRadius < 3) { RingRadius++; @@ -1120,7 +1635,6 @@ void GetLargeSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s { break; } - } } @@ -1128,7 +1642,13 @@ void GetLargeSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s -void GetSmallPineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetSmallPineTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { // Tall, little leaves on top. The top leaves are arranged in a shape of two cones joined by their bases. // There can be one or two layers representing the cone bases (SameSizeMax) @@ -1172,7 +1692,16 @@ void GetSmallPineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSe break; } ASSERT(static_cast<size_t>(LayerSize) < ARRAYCOUNT(BigOLayers)); - PushCoordBlocks(a_BlockPos.x, h, a_BlockPos.z, a_OtherBlocks, BigOLayers[LayerSize].Coords, BigOLayers[LayerSize].Count, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); + PushCoordBlocks( + a_BlockPos.x, + h, + a_BlockPos.z, + a_OtherBlocks, + BigOLayers[LayerSize].Coords, + BigOLayers[LayerSize].Count, + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); h--; } } @@ -1181,18 +1710,26 @@ void GetSmallPineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSe -void GetLargePineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetLargePineTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { int Height = 20 + (a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * a_Seq)) / 11) % 12; a_LogBlocks.reserve(static_cast<size_t>(Height) * 4); - a_OtherBlocks.reserve(ARRAYCOUNT(BigO3Pine) + ARRAYCOUNT(BigO2Pine) + ARRAYCOUNT(BigOF2Pine) + ARRAYCOUNT(TopLargePine)); + a_OtherBlocks.reserve( + ARRAYCOUNT(BigO3Pine) + ARRAYCOUNT(BigO2Pine) + ARRAYCOUNT(BigOF2Pine) + ARRAYCOUNT(TopLargePine) + ); for (int i = 0; i < Height; i++) { - a_LogBlocks.emplace_back(a_BlockPos.addedY(i), E_BLOCK_LOG, E_META_LOG_CONIFER); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedX(1), E_BLOCK_LOG, E_META_LOG_CONIFER); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedZ(1), E_BLOCK_LOG, E_META_LOG_CONIFER); + a_LogBlocks.emplace_back(a_BlockPos.addedY(i), E_BLOCK_LOG, E_META_LOG_CONIFER); + a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedX(1), E_BLOCK_LOG, E_META_LOG_CONIFER); + a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedZ(1), E_BLOCK_LOG, E_META_LOG_CONIFER); a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(1, 1), E_BLOCK_LOG, E_META_LOG_CONIFER); } int hei = a_BlockPos.y + Height - 2; @@ -1200,16 +1737,25 @@ void GetLargePineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSe // Prevent floating trees by placing dirt under them for (int i = 1; i < 5; i++) { - a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i), E_BLOCK_DIRT, E_META_DIRT_NORMAL); - a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedX(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); - a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedZ(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); + a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i), E_BLOCK_DIRT, E_META_DIRT_NORMAL); + a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedX(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); + a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedZ(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedXZ(1, 1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); } // Place the canopy. for (size_t i = 0; i < ARRAYCOUNT(BigOPineLayers); i++) { - PushCoordBlocks(a_BlockPos.x, hei++, a_BlockPos.z, a_OtherBlocks, BigOPineLayers[i].Coords, BigOPineLayers[i].Count, E_BLOCK_LEAVES, E_META_LEAVES_CONIFER); + PushCoordBlocks( + a_BlockPos.x, + hei++, + a_BlockPos.z, + a_OtherBlocks, + BigOPineLayers[i].Coords, + BigOPineLayers[i].Count, + E_BLOCK_LEAVES, + E_META_LEAVES_CONIFER + ); } } @@ -1217,21 +1763,28 @@ void GetLargePineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSe -void GetSwampTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetSwampTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { // Vines are around the BigO3, but not in the corners; need proper meta for direction - static const sMetaCoords Vines[] = - { + static const sMetaCoords Vines[] = { {-2, -4, 1}, {-1, -4, 1}, {0, -4, 1}, {1, -4, 1}, {2, -4, 1}, // North face - {-2, 4, 4}, {-1, 4, 4}, {0, 4, 4}, {1, 4, 4}, {2, 4, 4}, // South face - {4, -2, 2}, {4, -1, 2}, {4, 0, 2}, {4, 1, 2}, {4, 2, 2}, // East face + {-2, 4, 4}, {-1, 4, 4}, {0, 4, 4}, {1, 4, 4}, {2, 4, 4}, // South face + {4, -2, 2}, {4, -1, 2}, {4, 0, 2}, {4, 1, 2}, {4, 2, 2}, // East face {-4, -2, 8}, {-4, -1, 8}, {-4, 0, 8}, {-4, 1, 8}, {-4, 2, 8}, // West face - } ; + }; int Height = 3 + (a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * a_Seq)) / 8) % 3; a_LogBlocks.reserve(static_cast<size_t>(Height)); - a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO2) + 2 * ARRAYCOUNT(BigO3) + static_cast<size_t>(Height) * ARRAYCOUNT(Vines) + 20); + a_OtherBlocks.reserve( + 2 * ARRAYCOUNT(BigO2) + 2 * ARRAYCOUNT(BigO3) + static_cast<size_t>(Height) * ARRAYCOUNT(Vines) + 20 + ); for (int i = 0; i < Height; i++) { @@ -1240,21 +1793,73 @@ void GetSwampTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlo int hei = a_BlockPos.y + Height - 2; // Put vines around the lowermost leaves layer: - PushSomeColumns(a_BlockPos.x, hei, a_BlockPos.z, Height, a_Seq, a_Noise, 0x3fffffff, a_OtherBlocks, Vines, ARRAYCOUNT(Vines), E_BLOCK_VINES); + PushSomeColumns( + a_BlockPos.x, + hei, + a_BlockPos.z, + Height, + a_Seq, + a_Noise, + 0x3fffffff, + a_OtherBlocks, + Vines, + ARRAYCOUNT(Vines), + E_BLOCK_VINES + ); // The lower two leaves layers are BigO3 with log in the middle and possibly corners: for (int i = 0; i < 2; i++) { - PushCoordBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); - PushCornerBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_OtherBlocks, + BigO3, + ARRAYCOUNT(BigO3), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); + PushCornerBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x5fffffff, + a_OtherBlocks, + 3, + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); hei++; } // for i - 2* // The upper two leaves layers are BigO2 with leaves in the middle and possibly corners: for (int i = 0; i < 2; i++) { - PushCoordBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); - PushCornerBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); + PushCornerBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x5fffffff, + a_OtherBlocks, + 3, + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); a_OtherBlocks.emplace_back(a_BlockPos.x, hei, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); hei++; } // for i - 2* @@ -1264,17 +1869,41 @@ void GetSwampTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlo -void GetAppleBushImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetAppleBushImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { a_OtherBlocks.reserve(3 + ARRAYCOUNT(BigO2) + ARRAYCOUNT(BigO1)); int hei = a_BlockPos.y; a_LogBlocks.emplace_back(a_BlockPos.x, hei, a_BlockPos.z, E_BLOCK_LOG, E_META_LOG_JUNGLE); - PushCoordBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); hei++; a_OtherBlocks.emplace_back(a_BlockPos.x, hei, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); - PushCoordBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_APPLE); + PushCoordBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_APPLE + ); hei++; a_OtherBlocks.emplace_back(a_BlockPos.x, hei, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_APPLE); @@ -1284,7 +1913,14 @@ void GetAppleBushImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlo -void GetJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks, bool a_Large) +void GetJungleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks, + bool a_Large +) { if (!a_Large) { @@ -1300,27 +1936,40 @@ void GetJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBl -void GetLargeJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetLargeJungleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { - static const sMetaCoords VinesTrunk[] = - { - {0, -1, 1}, {1, -1, 1}, // North face - {0, 2, 4}, {1, 2, 4}, // South face - {-1, 1, 8}, {-1, 0, 8}, // West face - {2, 1, 2}, {2, 0, 2}, // East face + static const sMetaCoords VinesTrunk[] = { + {0, -1, 1}, + {1, -1, 1}, // North face + {0, 2, 4}, + {1, 2, 4}, // South face + {-1, 1, 8}, + {-1, 0, 8}, // West face + {2, 1, 2}, + {2, 0, 2}, // East face }; - int Height = 10 + ((a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * a_Seq)) / 11) % 20); // 10 < Height < 29 + int Height = + 10 + ((a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * a_Seq)) / 11) % 20); // 10 < Height < 29 a_LogBlocks.reserve(static_cast<size_t>(Height) * 4); - a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO5Jungle) + ARRAYCOUNT(BigO4Jungle) + ARRAYCOUNT(BigO3Jungle) + static_cast<size_t>(Height) * 4 + 50); + a_OtherBlocks.reserve( + 2 * ARRAYCOUNT(BigO5Jungle) + ARRAYCOUNT(BigO4Jungle) + ARRAYCOUNT(BigO3Jungle) + + static_cast<size_t>(Height) * 4 + 50 + ); // Generates the main trunk for (int i = 0; i < Height; i++) { - a_LogBlocks.emplace_back(a_BlockPos.addedY(i), E_BLOCK_LOG, E_META_LOG_JUNGLE); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedX(1), E_BLOCK_LOG, E_META_LOG_JUNGLE); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedZ(1), E_BLOCK_LOG, E_META_LOG_JUNGLE); + a_LogBlocks.emplace_back(a_BlockPos.addedY(i), E_BLOCK_LOG, E_META_LOG_JUNGLE); + a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedX(1), E_BLOCK_LOG, E_META_LOG_JUNGLE); + a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedZ(1), E_BLOCK_LOG, E_META_LOG_JUNGLE); a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(1, 1), E_BLOCK_LOG, E_META_LOG_JUNGLE); // Randomly place vines around the trunk @@ -1330,46 +1979,117 @@ void GetLargeJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s { continue; } - a_OtherBlocks.emplace_back(a_BlockPos.addedXZ(VinesTrunk[j].x, VinesTrunk[j].z).addedY(i), E_BLOCK_VINES, VinesTrunk[j].Meta); + a_OtherBlocks.emplace_back( + a_BlockPos.addedXZ(VinesTrunk[j].x, VinesTrunk[j].z).addedY(i), + E_BLOCK_VINES, + VinesTrunk[j].Meta + ); } } // Prevent floating trees by placing dirt under them for (int i = 1; i < 5; i++) { - a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i), E_BLOCK_DIRT, E_META_DIRT_NORMAL); - a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedX(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); - a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedZ(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); + a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i), E_BLOCK_DIRT, E_META_DIRT_NORMAL); + a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedX(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); + a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedZ(1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); a_OtherBlocks.emplace_back(a_BlockPos.addedY(-i).addedXZ(1, 1), E_BLOCK_DIRT, E_META_DIRT_NORMAL); } int NumBranches = std::max( (a_Noise.IntNoise2DInt(a_BlockPos.x * a_Seq, a_BlockPos.z * a_Seq) / 10) % 4, // The Original Calculation - FloorC(Height / 10.0f) // Just to assure that no massive trees spawn with just one branch - ); - int BranchStartHeight = 6 + Height % 5; // 6 < BranchStartHeight < 10 + FloorC(Height / 10.0f) // Just to assure that no massive trees spawn with just one branch + ); + int BranchStartHeight = 6 + Height % 5; // 6 < BranchStartHeight < 10 int BranchInterval = (Height - 6 - BranchStartHeight) / NumBranches; - for (int i = BranchStartHeight; i < (Height - 6); i += BranchInterval) // Stop 6 blocks before reaching the top + for (int i = BranchStartHeight; i < (Height - 6); i += BranchInterval) // Stop 6 blocks before reaching the top { // Get a direction for the trunk to go to. Vector3d BranchStartDirection = pickBranchDirection(a_Noise, a_BlockPos.addedY(i), a_Seq); Vector3d BranchDirection = pickBranchDirection(a_Noise, a_BlockPos.addedY(i * a_Seq), a_Seq) / 3; int BranchLength = 2 + a_Noise.IntNoise3DInt(a_BlockPos * a_Seq) % 2; - Vector3i BranchEndPosition = GetTreeBranch(E_BLOCK_LOG, E_META_LOG_JUNGLE, a_BlockPos.addedY(i), BranchLength, BranchStartDirection, BranchDirection, a_LogBlocks).Floor(); + Vector3i BranchEndPosition = GetTreeBranch( + E_BLOCK_LOG, + E_META_LOG_JUNGLE, + a_BlockPos.addedY(i), + BranchLength, + BranchStartDirection, + BranchDirection, + a_LogBlocks + ) + .Floor(); // There's a chance that there is a third leaf level on a branch - if ((a_Noise.IntNoise3DInt(a_BlockPos.x * a_Seq, a_BlockPos.y * a_Seq, a_BlockPos.z * a_Seq) % 4) == 0) // A quarter chance + if ((a_Noise.IntNoise3DInt(a_BlockPos.x * a_Seq, a_BlockPos.y * a_Seq, a_BlockPos.z * a_Seq) % 4) == + 0) // A quarter chance { - PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y, BranchEndPosition.z, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); - PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y + 1, BranchEndPosition.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); - PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y + 2, BranchEndPosition.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); - a_OtherBlocks.emplace_back(BranchEndPosition.x, BranchEndPosition.y + 2, BranchEndPosition.z, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); + PushCoordBlocks( + BranchEndPosition.x, + BranchEndPosition.y, + BranchEndPosition.z, + a_OtherBlocks, + BigO3, + ARRAYCOUNT(BigO3), + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); + PushCoordBlocks( + BranchEndPosition.x, + BranchEndPosition.y + 1, + BranchEndPosition.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); + PushCoordBlocks( + BranchEndPosition.x, + BranchEndPosition.y + 2, + BranchEndPosition.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); + a_OtherBlocks.emplace_back( + BranchEndPosition.x, + BranchEndPosition.y + 2, + BranchEndPosition.z, + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); } else { - PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y, BranchEndPosition.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); - PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y + 1, BranchEndPosition.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); - a_OtherBlocks.emplace_back(BranchEndPosition.x, BranchEndPosition.y + 1, BranchEndPosition.z, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); + PushCoordBlocks( + BranchEndPosition.x, + BranchEndPosition.y, + BranchEndPosition.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); + PushCoordBlocks( + BranchEndPosition.x, + BranchEndPosition.y + 1, + BranchEndPosition.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); + a_OtherBlocks.emplace_back( + BranchEndPosition.x, + BranchEndPosition.y + 1, + BranchEndPosition.z, + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); } } @@ -1377,7 +2097,16 @@ void GetLargeJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s int CanopyHeight = a_BlockPos.y + Height - 2; for (size_t i = 0; i < ARRAYCOUNT(BigOJungleLayers); i++) { - PushCoordBlocks(a_BlockPos.x, CanopyHeight++, a_BlockPos.z, a_OtherBlocks, BigOJungleLayers[i].Coords, BigOJungleLayers[i].Count, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); + PushCoordBlocks( + a_BlockPos.x, + CanopyHeight++, + a_BlockPos.z, + a_OtherBlocks, + BigOJungleLayers[i].Coords, + BigOJungleLayers[i].Count, + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); } } @@ -1385,25 +2114,30 @@ void GetLargeJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s -void GetSmallJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetSmallJungleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { // Vines are around the BigO3, but not in the corners; need proper meta for direction - static const sMetaCoords Vines[] = - { + static const sMetaCoords Vines[] = { {-2, -4, 1}, {-1, -4, 1}, {0, -4, 1}, {1, -4, 1}, {2, -4, 1}, // North face - {-2, 4, 4}, {-1, 4, 4}, {0, 4, 4}, {1, 4, 4}, {2, 4, 4}, // South face - {4, -2, 2}, {4, -1, 2}, {4, 0, 2}, {4, 1, 2}, {4, 2, 2}, // East face - {-4, -2, 8}, {-4, -1, 8}, {-4, 0, 8}, {-4, 1, 8}, // West face + {-2, 4, 4}, {-1, 4, 4}, {0, 4, 4}, {1, 4, 4}, {2, 4, 4}, // South face + {4, -2, 2}, {4, -1, 2}, {4, 0, 2}, {4, 1, 2}, {4, 2, 2}, // East face + {-4, -2, 8}, {-4, -1, 8}, {-4, 0, 8}, {-4, 1, 8}, // West face // TODO: proper metas and height: {0, 1, 1}, {0, -1, 4}, {-1, 0, 2}, {1, 1, 8}, // Around the tunk - } ; + }; int Height = 7 + (a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(5 * a_Seq, 5 * a_Seq)) / 5) % 3; a_LogBlocks.reserve(static_cast<size_t>(Height)); a_OtherBlocks.reserve( - 2 * ARRAYCOUNT(BigO3) + // O3 layer, 2x - 2 * ARRAYCOUNT(BigO2) + // O2 layer, 2x - ARRAYCOUNT(BigO1) + 1 + // Plus on the top + 2 * ARRAYCOUNT(BigO3) + // O3 layer, 2x + 2 * ARRAYCOUNT(BigO2) + // O2 layer, 2x + ARRAYCOUNT(BigO1) + 1 + // Plus on the top static_cast<size_t>(Height) * ARRAYCOUNT(Vines) + // Vines 50 // some safety ); @@ -1415,26 +2149,87 @@ void GetSmallJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s int hei = a_BlockPos.y + Height - 3; // Put vines around the lowermost leaves layer: - PushSomeColumns(a_BlockPos.x, hei, a_BlockPos.z, Height, a_Seq, a_Noise, 0x3fffffff, a_OtherBlocks, Vines, ARRAYCOUNT(Vines), E_BLOCK_VINES); + PushSomeColumns( + a_BlockPos.x, + hei, + a_BlockPos.z, + Height, + a_Seq, + a_Noise, + 0x3fffffff, + a_OtherBlocks, + Vines, + ARRAYCOUNT(Vines), + E_BLOCK_VINES + ); // The lower two leaves layers are BigO3 with log in the middle and possibly corners: for (int i = 0; i < 2; i++) { - PushCoordBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); - PushCornerBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 3, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); + PushCoordBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_OtherBlocks, + BigO3, + ARRAYCOUNT(BigO3), + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); + PushCornerBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x5fffffff, + a_OtherBlocks, + 3, + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); hei++; } // for i - 2* // Two layers of BigO2 leaves, possibly with corners: for (int i = 0; i < 1; i++) { - PushCoordBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); - PushCornerBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_Seq, a_Noise, 0x5fffffff, a_OtherBlocks, 2, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); + PushCoordBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_OtherBlocks, + BigO2, + ARRAYCOUNT(BigO2), + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); + PushCornerBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_Seq, + a_Noise, + 0x5fffffff, + a_OtherBlocks, + 2, + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); hei++; } // for i - 2* // Top plus, all leaves: - PushCoordBlocks(a_BlockPos.x, hei, a_BlockPos.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); + PushCoordBlocks( + a_BlockPos.x, + hei, + a_BlockPos.z, + a_OtherBlocks, + BigO1, + ARRAYCOUNT(BigO1), + E_BLOCK_LEAVES, + E_META_LEAVES_JUNGLE + ); a_OtherBlocks.emplace_back(a_BlockPos.x, hei, a_BlockPos.z, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); } @@ -1442,7 +2237,13 @@ void GetSmallJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s -void GetRedMushroomTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetRedMushroomTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { static constexpr int Height = 4; @@ -1453,43 +2254,89 @@ void GetRedMushroomTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s if (i != 0) { // NORTH SIDE - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(-1, -2), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH_WEST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(0, -2), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(1, -2), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH_EAST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(i).addedXZ(-1, -2), + E_BLOCK_HUGE_RED_MUSHROOM, + E_META_MUSHROOM_NORTH_WEST + ); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(i).addedXZ(0, -2), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(i).addedXZ(1, -2), + E_BLOCK_HUGE_RED_MUSHROOM, + E_META_MUSHROOM_NORTH_EAST + ); // WEST SIDE - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(-2, -1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH_WEST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(-2, 0), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_WEST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(-2, 1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH_WEST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(i).addedXZ(-2, -1), + E_BLOCK_HUGE_RED_MUSHROOM, + E_META_MUSHROOM_NORTH_WEST + ); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(i).addedXZ(-2, 0), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_WEST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(i).addedXZ(-2, 1), + E_BLOCK_HUGE_RED_MUSHROOM, + E_META_MUSHROOM_SOUTH_WEST + ); // SOUTH SIDE - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(-1, 2), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH_WEST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(0, 2), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(1, 2), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH_EAST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(i).addedXZ(-1, 2), + E_BLOCK_HUGE_RED_MUSHROOM, + E_META_MUSHROOM_SOUTH_WEST + ); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(i).addedXZ(0, 2), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(i).addedXZ(1, 2), + E_BLOCK_HUGE_RED_MUSHROOM, + E_META_MUSHROOM_SOUTH_EAST + ); // EAST SIDE - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(2, -1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH_EAST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(2, 0), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_EAST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(i).addedXZ(2, 1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH_EAST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(i).addedXZ(2, -1), + E_BLOCK_HUGE_RED_MUSHROOM, + E_META_MUSHROOM_NORTH_EAST + ); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(i).addedXZ(2, 0), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_EAST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(i).addedXZ(2, 1), + E_BLOCK_HUGE_RED_MUSHROOM, + E_META_MUSHROOM_SOUTH_EAST + ); } } // Top Layer - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(-1, -1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH_WEST); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(Height).addedXZ(-1, -1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH_WEST); a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedX(-1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_WEST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(-1, 1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH_WEST); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(Height).addedXZ(-1, 1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH_WEST); a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedZ(-1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH); a_LogBlocks.emplace_back(a_BlockPos.addedY(Height), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_CENTER); a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedZ(1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH); - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(1, -1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH_EAST); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(Height).addedXZ(1, -1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_NORTH_EAST); a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedX(1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_EAST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(1, 1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH_EAST); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(Height).addedXZ(1, 1), E_BLOCK_HUGE_RED_MUSHROOM, E_META_MUSHROOM_SOUTH_EAST); } -void GetBrownMushroomTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks) +void GetBrownMushroomTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +) { static constexpr int Height = 4; static constexpr int Radius = 2; @@ -1504,32 +2351,78 @@ void GetBrownMushroomTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, { for (int z = -Radius; z <= Radius; z++) { - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(x, z), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_CENTER); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(x, z), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_CENTER + ); } } for (int i = 0; i < Border; i++) { // NORTH SIDE - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(-1, -3).addedX(i), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_NORTH); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(-1, -3).addedX(i), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_NORTH + ); // WEST SIDE - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(-3, -1).addedZ(i), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_WEST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(-3, -1).addedZ(i), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_WEST + ); // SOUTH SIDE - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(-1, 3).addedX(i), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_SOUTH); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(-1, 3).addedX(i), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_SOUTH + ); // EAST SIDE - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(3, -1).addedZ(i), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_EAST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(3, -1).addedZ(i), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_EAST + ); } // Corners - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(3, 2), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_SOUTH_EAST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(2, 3), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_SOUTH_EAST); - - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(-2, 3), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_SOUTH_WEST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(-3, 2), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_SOUTH_WEST); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(Height).addedXZ(3, 2), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_SOUTH_EAST); + a_LogBlocks + .emplace_back(a_BlockPos.addedY(Height).addedXZ(2, 3), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_SOUTH_EAST); + + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(-2, 3), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_SOUTH_WEST + ); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(-3, 2), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_SOUTH_WEST + ); - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(-2, -3), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_NORTH_WEST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(-3, -2), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_NORTH_WEST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(-2, -3), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_NORTH_WEST + ); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(-3, -2), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_NORTH_WEST + ); - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(2, -3), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_NORTH_EAST); - a_LogBlocks.emplace_back(a_BlockPos.addedY(Height).addedXZ(3, -2), E_BLOCK_HUGE_BROWN_MUSHROOM, E_META_MUSHROOM_NORTH_EAST); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(2, -3), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_NORTH_EAST + ); + a_LogBlocks.emplace_back( + a_BlockPos.addedY(Height).addedXZ(3, -2), + E_BLOCK_HUGE_BROWN_MUSHROOM, + E_META_MUSHROOM_NORTH_EAST + ); } diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h index 0ffeed30c..82c33cf53 100644 --- a/src/Generating/Trees.h +++ b/src/Generating/Trees.h @@ -25,101 +25,258 @@ logs can overwrite others(leaves), but others shouldn't overwrite logs. This is // Blocks that don't block tree growth: #define CASE_TREE_ALLOWED_BLOCKS \ - case E_BLOCK_AIR: \ - case E_BLOCK_LEAVES: \ - case E_BLOCK_NEW_LEAVES: \ - case E_BLOCK_SNOW: \ - case E_BLOCK_TALL_GRASS: \ - case E_BLOCK_DEAD_BUSH: \ - case E_BLOCK_SAPLING: \ + case E_BLOCK_AIR: \ + case E_BLOCK_LEAVES: \ + case E_BLOCK_NEW_LEAVES: \ + case E_BLOCK_SNOW: \ + case E_BLOCK_TALL_GRASS: \ + case E_BLOCK_DEAD_BUSH: \ + case E_BLOCK_SAPLING: \ case E_BLOCK_VINES // Blocks that a tree may overwrite when growing: -#define CASE_TREE_OVERWRITTEN_BLOCKS \ - case E_BLOCK_AIR: \ - /* case E_BLOCK_LEAVES: LEAVES are a special case, they can be overwritten only by log. Handled in cChunkMap::ReplaceTreeBlocks(). */ \ - case E_BLOCK_SNOW: \ - case E_BLOCK_TALL_GRASS: \ - case E_BLOCK_BIG_FLOWER: \ - case E_BLOCK_DEAD_BUSH: \ - case E_BLOCK_SAPLING: \ +#define CASE_TREE_OVERWRITTEN_BLOCKS \ + case E_BLOCK_AIR: \ + /* case E_BLOCK_LEAVES: LEAVES are a special case, they can be overwritten only by log. Handled in \ + * cChunkMap::ReplaceTreeBlocks(). */ \ + case E_BLOCK_SNOW: \ + case E_BLOCK_TALL_GRASS: \ + case E_BLOCK_BIG_FLOWER: \ + case E_BLOCK_DEAD_BUSH: \ + case E_BLOCK_SAPLING: \ case E_BLOCK_VINES -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a tree at the specified coords (lowest trunk block) in the specified biome */ -void GetTreeImageByBiome(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, EMCSBiome a_Biome, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a tree at the specified coords + * (lowest trunk block) in the specified biome */ +void GetTreeImageByBiome( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + EMCSBiome a_Biome, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); /** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random apple tree */ -void GetAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a small (nonbranching) apple tree */ -void GetSmallAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a large (branching) apple tree */ -void GetLargeAppleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +void GetAppleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a small (nonbranching) apple + * tree */ +void GetSmallAppleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a large (branching) apple tree + */ +void GetLargeAppleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); /** Fills a_LogBlocks with the logs of a tree branch of the provided log type. The length of the branch can be changed with the a_BranchLength. The initial direction is a_StartDirection. The direction can be manipulated with a_Direction to create a curve. Returns the position of the last log block placed. */ -Vector3d GetTreeBranch(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_BlockPos, int a_BranchLength, Vector3d a_StartDirection, Vector3d a_Direction, sSetBlockVector & a_LogBlocks); +Vector3d GetTreeBranch( + BLOCKTYPE a_BlockType, + NIBBLETYPE a_BlockMeta, + Vector3i a_BlockPos, + int a_BranchLength, + Vector3d a_StartDirection, + Vector3d a_Direction, + sSetBlockVector & a_LogBlocks +); /** Returns the meta for a log from the given direction */ NIBBLETYPE GetLogMetaFromDirection(NIBBLETYPE a_BlockMeta, Vector3d a_Direction); /** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random birch tree */ -void GetBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +void GetBirchTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); /** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random acacia tree */ -void GetAcaciaTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +void GetAcaciaTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); /** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random darkoak tree */ -void GetDarkoakTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +void GetDarkoakTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); /** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random large birch tree */ -void GetTallBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random conifer tree. The probability to get a large pine is higher than a spruce tree */ -void GetConiferTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks, bool a_Large = false); +void GetTallBirchTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random conifer tree. The + * probability to get a large pine is higher than a spruce tree */ +void GetConiferTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks, + bool a_Large = false +); /** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random spruce */ -void GetSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks, bool a_Large = false); +void GetSpruceTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks, + bool a_Large = false +); /** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random pine */ -void GetPineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks, bool a_Large = false); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random small spruce (short conifer, two layers of leaves) */ -void GetSmallSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random small pine (tall conifer, little leaves at top) */ -void GetSmallPineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random large spruce (short conifer, multiple layers of leaves) */ -void GetLargeSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random large pine (tall conifer, little leaves at top) */ -void GetLargePineTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +void GetPineTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks, + bool a_Large = false +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random small spruce (short + * conifer, two layers of leaves) */ +void GetSmallSpruceTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random small pine (tall + * conifer, little leaves at top) */ +void GetSmallPineTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random large spruce (short + * conifer, multiple layers of leaves) */ +void GetLargeSpruceTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random large pine (tall + * conifer, little leaves at top) */ +void GetLargePineTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); /** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random swampland tree */ -void GetSwampTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random apple bush (for jungles) */ -void GetAppleBushImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +void GetSwampTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random apple bush (for + * jungles) */ +void GetAppleBushImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); /** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a random jungle tree */ -void GetJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks, bool a_Large); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a large jungle tree (2x2 trunk) */ -void GetLargeJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); - -/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a small jungle tree (1x1 trunk) */ -void GetSmallJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +void GetJungleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks, + bool a_Large +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a large jungle tree (2x2 trunk) + */ +void GetLargeJungleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); + +/** Fills a_LogBlocks and a_OtherBlocks (dirt & leaves) with the blocks required to form a small jungle tree (1x1 trunk) + */ +void GetSmallJungleTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); /** Fills a_LogBlocks and a_OtherBlocks with the blocks required to form the red mushroom */ -void GetRedMushroomTreeImage(Vector3i vector3, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +void GetRedMushroomTreeImage( + Vector3i vector3, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); /** Fills a_LogBlocks and a_OtherBlocks with the blocks required to form the brown mushroom */ -void GetBrownMushroomTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks); +void GetBrownMushroomTreeImage( + Vector3i a_BlockPos, + cNoise & a_Noise, + int a_Seq, + sSetBlockVector & a_LogBlocks, + sSetBlockVector & a_OtherBlocks +); diff --git a/src/Generating/TwoHeights.cpp b/src/Generating/TwoHeights.cpp index 91c67608c..bdea22441 100644 --- a/src/Generating/TwoHeights.cpp +++ b/src/Generating/TwoHeights.cpp @@ -14,18 +14,13 @@ -class cTwoHeights: - public cTerrainShapeGen +class cTwoHeights : public cTerrainShapeGen { using Super = cTerrainShapeGen; -public: - - cTwoHeights(int a_Seed, cBiomeGen & a_BiomeGen): - m_Seed(a_Seed), - m_Choice(a_Seed), - m_HeightA(a_Seed + 1, a_BiomeGen), - m_HeightB(a_Seed + 2, a_BiomeGen) + public: + cTwoHeights(int a_Seed, cBiomeGen & a_BiomeGen) : + m_Seed(a_Seed), m_Choice(a_Seed), m_HeightA(a_Seed + 1, a_BiomeGen), m_HeightB(a_Seed + 2, a_BiomeGen) { } @@ -44,10 +39,10 @@ public: NOISE_DATATYPE workspace[33 * 5 * 5]; NOISE_DATATYPE startX = 0; NOISE_DATATYPE endX = 256 * m_FrequencyY; - NOISE_DATATYPE startY = a_ChunkCoords.m_ChunkX * cChunkDef::Width * m_FrequencyX; - NOISE_DATATYPE endY = (a_ChunkCoords.m_ChunkX * cChunkDef::Width + cChunkDef::Width + 1) * m_FrequencyX; - NOISE_DATATYPE startZ = a_ChunkCoords.m_ChunkZ * cChunkDef::Width * m_FrequencyZ; - NOISE_DATATYPE endZ = (a_ChunkCoords.m_ChunkZ * cChunkDef::Width + cChunkDef::Width + 1) * m_FrequencyZ; + NOISE_DATATYPE startY = a_ChunkCoords.m_ChunkX * cChunkDef::Width * m_FrequencyX; + NOISE_DATATYPE endY = (a_ChunkCoords.m_ChunkX * cChunkDef::Width + cChunkDef::Width + 1) * m_FrequencyX; + NOISE_DATATYPE startZ = a_ChunkCoords.m_ChunkZ * cChunkDef::Width * m_FrequencyZ; + NOISE_DATATYPE endZ = (a_ChunkCoords.m_ChunkZ * cChunkDef::Width + cChunkDef::Width + 1) * m_FrequencyZ; m_Choice.Generate3D(smallChoice, 33, 5, 5, startX, endX, startY, endY, startZ, endZ, workspace); NOISE_DATATYPE choice[257 * 17 * 17]; LinearUpscale3DArray(smallChoice, 33, 5, 5, choice, 8, 4, 4); @@ -93,7 +88,7 @@ public: } } -protected: + protected: int m_Seed; /** The noise used to decide between the two heightmaps. */ diff --git a/src/Generating/VerticalLimit.cpp b/src/Generating/VerticalLimit.cpp index 8ae8c4d9b..49548a3e3 100644 --- a/src/Generating/VerticalLimit.cpp +++ b/src/Generating/VerticalLimit.cpp @@ -16,38 +16,38 @@ If no value is in the string, both values are left unchanged. If only the minimum is in the string, it is assigned to both a_Min and a_Max. */ namespace VerticalLimit { - static bool ParseRange(const AString & a_Params, int & a_Min, int & a_Max, bool a_LogWarnings) +static bool ParseRange(const AString & a_Params, int & a_Min, int & a_Max, bool a_LogWarnings) +{ + auto params = StringSplitAndTrim(a_Params, "|"); + if (params.size() == 0) { - auto params = StringSplitAndTrim(a_Params, "|"); - if (params.size() == 0) - { - // No params, generate directly on top: - return true; - } - if (!StringToInteger(params[0], a_Min)) - { - // Failed to parse the min rel height: - CONDWARNING(a_LogWarnings, "Cannot parse minimum height from string \"%s\"!", params[0].c_str()); - return false; - } - if (params.size() == 1) - { - // Only one param was given, there's no range - a_Max = a_Min; - return true; - } - if (!StringToInteger(params[1], a_Max)) - { - CONDWARNING(a_LogWarnings, "Cannot parse maximum height from string \"%s\"!", params[1].c_str()); - return false; - } - if (a_Max < a_Min) - { - std::swap(a_Max, a_Min); - } + // No params, generate directly on top: return true; } + if (!StringToInteger(params[0], a_Min)) + { + // Failed to parse the min rel height: + CONDWARNING(a_LogWarnings, "Cannot parse minimum height from string \"%s\"!", params[0].c_str()); + return false; + } + if (params.size() == 1) + { + // Only one param was given, there's no range + a_Max = a_Min; + return true; + } + if (!StringToInteger(params[1], a_Max)) + { + CONDWARNING(a_LogWarnings, "Cannot parse maximum height from string \"%s\"!", params[1].c_str()); + return false; + } + if (a_Max < a_Min) + { + std::swap(a_Max, a_Min); + } + return true; } +} // namespace VerticalLimit @@ -55,22 +55,21 @@ namespace VerticalLimit //////////////////////////////////////////////////////////////////////////////// /** Limit that accepts any height. The default for all pieces. */ -class cVerticalLimitNone: - public cPiece::cVerticalLimit +class cVerticalLimitNone : public cPiece::cVerticalLimit { -public: - virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override - { - // Any height is okay - return true; - } + public: + virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override + { + // Any height is okay + return true; + } - virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) override - { - // No parameters to read, no checks being done - return true; - } + virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) override + { + // No parameters to read, no checks being done + return true; + } }; @@ -79,14 +78,10 @@ public: //////////////////////////////////////////////////////////////////////////////// /** Limit that accepts heights above the specified minimum fixed height. */ -class cVerticalLimitAbove: - public cPiece::cVerticalLimit +class cVerticalLimitAbove : public cPiece::cVerticalLimit { -public: - virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override - { - return (a_Height >= m_MinHeight); - } + public: + virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override { return (a_Height >= m_MinHeight); } virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) override @@ -100,7 +95,7 @@ public: return true; } -protected: + protected: /** The minimum accepted height. */ int m_MinHeight; }; @@ -111,10 +106,9 @@ protected: //////////////////////////////////////////////////////////////////////////////// /** Limit that accepts heights that are a specified number of blocks above terrain. */ -class cVerticalLimitAboveTerrain: - public cPiece::cVerticalLimit +class cVerticalLimitAboveTerrain : public cPiece::cVerticalLimit { -public: + public: virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override { ASSERT(m_TerrainHeightGen != nullptr); @@ -122,7 +116,7 @@ public: int compareHeight = a_Height - terrainHeight; return ( (compareHeight >= m_MinBlocksAbove) && // Above the minimum - (compareHeight <= m_MaxBlocksAbove) // and below the maximum + (compareHeight <= m_MaxBlocksAbove) // and below the maximum ); } @@ -136,12 +130,13 @@ public: } - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override + virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) + override { m_TerrainHeightGen = &a_TerrainHeightGen; } -protected: + protected: /** The underlying height generator. */ cTerrainHeightGen * m_TerrainHeightGen; @@ -158,10 +153,9 @@ protected: //////////////////////////////////////////////////////////////////////////////// /** Limit that accepts heights that are a specified number of blocks above terrain and sealevel, whichever is higher. */ -class cVerticalLimitAboveTerrainAndOcean: - public cPiece::cVerticalLimit +class cVerticalLimitAboveTerrainAndOcean : public cPiece::cVerticalLimit { -public: + public: virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override { ASSERT(m_TerrainHeightGen != nullptr); @@ -169,7 +163,7 @@ public: int compareHeight = a_Height - std::max(terrainHeight, m_SeaLevel); return ( (compareHeight >= m_MinBlocksAbove) && // Above the minimum - (compareHeight <= m_MaxBlocksAbove) // and below the maximum + (compareHeight <= m_MaxBlocksAbove) // and below the maximum ); } @@ -183,13 +177,14 @@ public: } - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override + virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) + override { m_TerrainHeightGen = &a_TerrainHeightGen; m_SeaLevel = a_SeaLevel; } -protected: + protected: /** The underlying height generator. */ cTerrainHeightGen * m_TerrainHeightGen; @@ -210,14 +205,10 @@ protected: //////////////////////////////////////////////////////////////////////////////// /** Limit that accepts heights below the specified fixed height. NOTE that the query height is the BOTTOM of the piece. */ -class cVerticalLimitBelow: - public cPiece::cVerticalLimit +class cVerticalLimitBelow : public cPiece::cVerticalLimit { -public: - virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override - { - return (a_Height <= m_MaxHeight); - } + public: + virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override { return (a_Height <= m_MaxHeight); } virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) override @@ -231,7 +222,7 @@ public: return true; } -protected: + protected: /** The maximum accepted height. */ int m_MaxHeight; }; @@ -243,18 +234,14 @@ protected: //////////////////////////////////////////////////////////////////////////////// /** Limit that accepts heights that are within a specified range below terrain. NOTE that the query height is the BOTTOM of the piece. */ -class cVerticalLimitBelowTerrain: - public cPiece::cVerticalLimit +class cVerticalLimitBelowTerrain : public cPiece::cVerticalLimit { -public: + public: virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override { auto terrainHeight = m_TerrainHeightGen->GetHeightAt(a_BlockX, a_BlockZ); auto compareHeight = terrainHeight - a_Height; - return ( - (compareHeight >= m_MinBlocksBelow) && - (compareHeight <= m_MaxBlocksBelow) - ); + return ((compareHeight >= m_MinBlocksBelow) && (compareHeight <= m_MaxBlocksBelow)); } @@ -267,12 +254,13 @@ public: } - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override + virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) + override { m_TerrainHeightGen = &a_TerrainHeightGen; } -protected: + protected: /** The underlying height generator. */ cTerrainHeightGen * m_TerrainHeightGen; @@ -289,18 +277,14 @@ protected: //////////////////////////////////////////////////////////////////////////////// /** Limit that accepts heights that are a specified number of blocks below terrain or sealevel, whichever is higher. */ -class cVerticalLimitBelowTerrainOrOcean: - public cPiece::cVerticalLimit +class cVerticalLimitBelowTerrainOrOcean : public cPiece::cVerticalLimit { -public: + public: virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override { int terrainHeight = m_TerrainHeightGen->GetHeightAt(a_BlockX, a_BlockZ); auto compareHeight = std::max(terrainHeight, m_SeaLevel) - a_Height; - return ( - (compareHeight >= m_MinBlocksBelow) && - (compareHeight <= m_MaxBlocksBelow) - ); + return ((compareHeight >= m_MinBlocksBelow) && (compareHeight <= m_MaxBlocksBelow)); } @@ -313,13 +297,14 @@ public: } - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override + virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) + override { m_TerrainHeightGen = &a_TerrainHeightGen; m_SeaLevel = a_SeaLevel; } -protected: + protected: /** The underlying height generator. */ cTerrainHeightGen * m_TerrainHeightGen; diff --git a/src/Generating/VerticalLimit.h b/src/Generating/VerticalLimit.h index aeb41c1e8..8c11d2ea1 100644 --- a/src/Generating/VerticalLimit.h +++ b/src/Generating/VerticalLimit.h @@ -20,7 +20,3 @@ a_LimitDesc is in the format "<LimitClass>|<Params>". The params and the pipe ma If an unknown class is requested or the param parsing fails, nullptr is returned. If a_LogWarnings is true, any problem is reported into the server console. */ cPiece::cVerticalLimitPtr CreateVerticalLimitFromString(const AString & a_LimitDesc, bool a_LogWarnings); - - - - diff --git a/src/Generating/VerticalStrategy.cpp b/src/Generating/VerticalStrategy.cpp index 3b0307167..6b8ba2983 100644 --- a/src/Generating/VerticalStrategy.cpp +++ b/src/Generating/VerticalStrategy.cpp @@ -25,39 +25,39 @@ If a_LogWarnings is true, outputs failure reasons to console. The range is returned in a_Min and a_Range, they are left unchanged if the range value is not present in the string. */ namespace VerticalStrategy { - static bool ParseRange(const AString & a_Params, int & a_Min, int & a_Range, bool a_LogWarnings) +static bool ParseRange(const AString & a_Params, int & a_Min, int & a_Range, bool a_LogWarnings) +{ + auto params = StringSplitAndTrim(a_Params, "|"); + if (params.size() == 0) { - auto params = StringSplitAndTrim(a_Params, "|"); - if (params.size() == 0) - { - // No params, generate directly on top: - return true; - } - if (!StringToInteger(params[0], a_Min)) - { - // Failed to parse the min rel height: - CONDWARNING(a_LogWarnings, "Cannot parse minimum height from string \"%s\"!", params[0].c_str()); - return false; - } - if (params.size() == 1) - { - // Only one param was given, there's no range - return true; - } - int maxHeight = a_Min; - if (!StringToInteger(params[1], maxHeight)) - { - CONDWARNING(a_LogWarnings, "Cannot parse maximum height from string \"%s\"!", params[1].c_str()); - return false; - } - if (maxHeight < a_Min) - { - std::swap(maxHeight, a_Min); - } - a_Range = maxHeight - a_Min + 1; + // No params, generate directly on top: return true; } + if (!StringToInteger(params[0], a_Min)) + { + // Failed to parse the min rel height: + CONDWARNING(a_LogWarnings, "Cannot parse minimum height from string \"%s\"!", params[0].c_str()); + return false; + } + if (params.size() == 1) + { + // Only one param was given, there's no range + return true; + } + int maxHeight = a_Min; + if (!StringToInteger(params[1], maxHeight)) + { + CONDWARNING(a_LogWarnings, "Cannot parse maximum height from string \"%s\"!", params[1].c_str()); + return false; + } + if (maxHeight < a_Min) + { + std::swap(maxHeight, a_Min); + } + a_Range = maxHeight - a_Min + 1; + return true; } +} // namespace VerticalStrategy @@ -65,20 +65,16 @@ namespace VerticalStrategy //////////////////////////////////////////////////////////////////////////////// /** A vertical strategy that places the piece at a predefined height. */ -class cVerticalStrategyFixed: - public cPiece::cVerticalStrategy +class cVerticalStrategyFixed : public cPiece::cVerticalStrategy { -public: - cVerticalStrategyFixed(void): + public: + cVerticalStrategyFixed(void) : m_Height(-1000) // Default to "unassigned" height { } - virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) override - { - return m_Height; - } + virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) override { return m_Height; } virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) override @@ -92,7 +88,7 @@ public: return true; } -protected: + protected: /** Height at which the pieces are placed. Note that this height may be outside the world, so that only a part of the piece is generated. */ int m_Height; @@ -104,11 +100,10 @@ protected: //////////////////////////////////////////////////////////////////////////////// /** A vertical strategy that places the piece in a random height between two heights. */ -class cVerticalStrategyRange: - public cPiece::cVerticalStrategy +class cVerticalStrategyRange : public cPiece::cVerticalStrategy { -public: - cVerticalStrategyRange(void): + public: + cVerticalStrategyRange(void) : m_Seed(0), m_Min(-1), // Default to "unassigned" height m_Range(1) @@ -135,7 +130,11 @@ public: int Max = 0; if (!StringToInteger(params[0], m_Min) || !StringToInteger(params[1], Max)) { - CONDWARNING(a_LogWarnings, "Cannot parse the minimum or maximum height from string \"%s\"!", a_Params.c_str()); + CONDWARNING( + a_LogWarnings, + "Cannot parse the minimum or maximum height from string \"%s\"!", + a_Params.c_str() + ); return false; } if (m_Min > Max) @@ -147,12 +146,13 @@ public: } - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override + virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) + override { m_Seed = a_Seed + SEED_OFFSET; } -protected: + protected: /** Seed for the random generator. Received in AssignGens(). */ int m_Seed; @@ -166,11 +166,9 @@ protected: //////////////////////////////////////////////////////////////////////////////// /** A vertical strategy that places the piece in a specified range relative to the top of the terrain. */ -class cVerticalStrategyTerrainTop: - public cPiece::cVerticalStrategy +class cVerticalStrategyTerrainTop : public cPiece::cVerticalStrategy { -public: - + public: virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) override { ASSERT(m_HeightGen != nullptr); @@ -181,7 +179,12 @@ public: m_HeightGen->GenHeightMap({ChunkX, ChunkZ}, HeightMap); cNoise noise(m_Seed); int rel = m_MinRelHeight + (noise.IntNoise2DInt(a_BlockX, a_BlockZ) / 7) % m_RelHeightRange + 1; - return cChunkDef::GetHeight(HeightMap, a_BlockX - ChunkX * cChunkDef::Width, a_BlockZ - ChunkZ * cChunkDef::Width) + rel; + return cChunkDef::GetHeight( + HeightMap, + a_BlockX - ChunkX * cChunkDef::Width, + a_BlockZ - ChunkZ * cChunkDef::Width + ) + + rel; } @@ -194,13 +197,14 @@ public: } - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel) override + virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel) + override { m_Seed = a_Seed + SEED_OFFSET; m_HeightGen = &a_HeightGen; } -protected: + protected: /** Seed for the random generator. */ int m_Seed; @@ -220,11 +224,9 @@ protected: //////////////////////////////////////////////////////////////////////////////// /** A vertical strategy that places the piece within a range on top of the terrain or ocean, whichever's higher. */ -class cVerticalStrategyTerrainOrOceanTop: - public cPiece::cVerticalStrategy +class cVerticalStrategyTerrainOrOceanTop : public cPiece::cVerticalStrategy { -public: - + public: virtual int GetVerticalPlacement(int a_BlockX, int a_BlockZ) override { ASSERT(m_HeightGen != nullptr); @@ -233,7 +235,9 @@ public: cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::HeightMap HeightMap; m_HeightGen->GenHeightMap({ChunkX, ChunkZ}, HeightMap); - int terrainHeight = static_cast<int>(cChunkDef::GetHeight(HeightMap, a_BlockX - ChunkX * cChunkDef::Width, a_BlockZ - ChunkZ * cChunkDef::Width)); + int terrainHeight = static_cast<int>( + cChunkDef::GetHeight(HeightMap, a_BlockX - ChunkX * cChunkDef::Width, a_BlockZ - ChunkZ * cChunkDef::Width) + ); terrainHeight = std::max(1 + terrainHeight, m_SeaLevel); cNoise noise(m_Seed); int rel = m_MinRelHeight + (noise.IntNoise2DInt(a_BlockX, a_BlockZ) / 7) % m_RelHeightRange + 1; @@ -250,14 +254,15 @@ public: } - virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel) override + virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel) + override { m_Seed = a_Seed + SEED_OFFSET; m_HeightGen = &a_HeightGen; m_SeaLevel = a_SeaLevel; } -protected: + protected: /** Seed for the random generator. */ int m_Seed; diff --git a/src/Generating/VerticalStrategy.h b/src/Generating/VerticalStrategy.h index d42f85d4b..535b4feab 100644 --- a/src/Generating/VerticalStrategy.h +++ b/src/Generating/VerticalStrategy.h @@ -19,7 +19,3 @@ a_StrategyDesc is in the format "<StrategyClass>|<Params>". The params and the pipe may be omitted. If an unknown class is requested or the param parsing fails, nullptr is returned. */ cPiece::cVerticalStrategyPtr CreateVerticalStrategyFromString(const AString & a_StrategyDesc, bool a_LogWarnings); - - - - diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp index d7edf688d..395c1911c 100644 --- a/src/Generating/VillageGen.cpp +++ b/src/Generating/VillageGen.cpp @@ -37,26 +37,23 @@ per-village density setting, the cVillage class itself implements the cPiecePool calls to the underlying cVillagePiecePool, after processing the density check. */ -class cVillagePiecePool: - public cPrefabPiecePool +class cVillagePiecePool : public cPrefabPiecePool { using Super = cPrefabPiecePool; -public: - + public: cVillagePiecePool( - const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs, - const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs - ): + const cPrefab::sDef * a_PieceDefs, + size_t a_NumPieceDefs, + const cPrefab::sDef * a_StartingPieceDefs, + size_t a_NumStartingPieceDefs + ) : Super(a_PieceDefs, a_NumPieceDefs, a_StartingPieceDefs, a_NumStartingPieceDefs) { AddRoadPieces(); } - cVillagePiecePool(void) - { - AddRoadPieces(); - } + cVillagePiecePool(void) { AddRoadPieces(); } void AddRoadPieces(void) { @@ -67,7 +64,7 @@ public: BA.Create(len, 1, 3, cBlockArea::baTypes | cBlockArea::baMetas); BA.Fill(cBlockArea::baTypes | cBlockArea::baMetas, E_BLOCK_GRAVEL, 0); cPrefab * RoadPiece = new cPrefab(BA, 1); - RoadPiece->AddConnector(0, 0, 1, cPiece::cConnector::dirXM, -2); + RoadPiece->AddConnector(0, 0, 1, cPiece::cConnector::dirXM, -2); RoadPiece->AddConnector(len - 1, 0, 1, cPiece::cConnector::dirXP, -2); RoadPiece->SetDefaultWeight(100); @@ -93,10 +90,15 @@ public: // cPrefabPiecePool overrides: - virtual int GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece) override + virtual int GetPieceWeight( + const cPlacedPiece & a_PlacedPiece, + const cPiece::cConnector & a_ExistingConnector, + const cPiece & a_NewPiece + ) override { // Roads cannot branch T-wise (appending -2 connector to a +2 connector on a 1-high piece): - if ((a_ExistingConnector.m_Type == 2) && (a_PlacedPiece.GetDepth() > 0) && (a_PlacedPiece.GetPiece().GetSize().y == 1)) + if ((a_ExistingConnector.m_Type == 2) && (a_PlacedPiece.GetDepth() > 0) && + (a_PlacedPiece.GetPiece().GetSize().y == 1)) { return 0; } @@ -109,24 +111,24 @@ public: -class cVillageGen::cVillage: - public cGridStructGen::cStructure, - protected cPiecePool +class cVillageGen::cVillage : public cGridStructGen::cStructure, + protected cPiecePool { using Super = cGridStructGen::cStructure; -public: - + public: cVillage( int a_Seed, - int a_GridX, int a_GridZ, - int a_OriginX, int a_OriginZ, + int a_GridX, + int a_GridZ, + int a_OriginX, + int a_OriginZ, int a_MaxRoadDepth, int a_MaxSize, int a_Density, cVillagePiecePool & a_Prefabs, cTerrainHeightGen & a_HeightGen - ): + ) : Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Seed(a_Seed), m_Noise(a_Seed), @@ -149,7 +151,7 @@ public: } -protected: + protected: /** Seed for the random functions */ int m_Seed; @@ -258,10 +260,7 @@ protected: } - virtual cPieces GetStartingPieces(void) override - { - return m_Prefabs.GetStartingPieces(); - } + virtual cPieces GetStartingPieces(void) override { return m_Prefabs.GetStartingPieces(); } virtual int GetPieceWeight( @@ -292,16 +291,10 @@ protected: } - virtual void PiecePlaced(const cPiece & a_Piece) override - { - m_Prefabs.PiecePlaced(a_Piece); - } + virtual void PiecePlaced(const cPiece & a_Piece) override { m_Prefabs.PiecePlaced(a_Piece); } - virtual void Reset(void) override - { - m_Prefabs.Reset(); - } + virtual void Reset(void) override { m_Prefabs.Reset(); } void MoveAllDescendants(cPlacedPieces & a_PlacedPieces, size_t a_Pivot, int a_HeightDifference) @@ -310,9 +303,9 @@ protected: auto & Pivot = a_PlacedPieces[a_Pivot]; for (size_t i = a_Pivot + 1; i < num; i++) { - if ( - (a_PlacedPieces[i]->GetParent() == Pivot.get()) && // It is a direct dependant of the pivot - !(static_cast<const cPrefab &>(a_PlacedPieces[i]->GetPiece())).ShouldMoveToGround() // It attaches strictly by connectors + if ((a_PlacedPieces[i]->GetParent() == Pivot.get()) && // It is a direct dependant of the pivot + !(static_cast<const cPrefab &>(a_PlacedPieces[i]->GetPiece())) + .ShouldMoveToGround() // It attaches strictly by connectors ) { a_PlacedPieces[i]->MoveToGroundBy(a_HeightDifference); @@ -320,7 +313,7 @@ protected: } } // for i - a_PlacedPieces[] } -} ; +}; @@ -351,7 +344,7 @@ cVillageGen::cVillageGen( m_BiomeGen(a_BiomeGen), m_HeightGen(a_HeightGen) { - for (const auto & toLoad: a_PrefabsToLoad) + for (const auto & toLoad : a_PrefabsToLoad) { auto prefabs = std::make_shared<cVillagePiecePool>(); auto fileName = fmt::format(FMT_STRING("Prefabs{0}Villages{0}{1}.cubeset"), cFile::GetPathSeparator(), toLoad); @@ -359,8 +352,11 @@ cVillageGen::cVillageGen( { if (NoCaseCompare(prefabs->GetIntendedUse(), "village") != 0) { - LOGWARNING("Village generator: File %s is intended for use in \"%s\", rather than villages. Loading the file, but the generator may behave unexpectedly.", - fileName, prefabs->GetIntendedUse() + LOGWARNING( + "Village generator: File %s is intended for use in \"%s\", rather than villages. Loading the file, " + "but the generator may behave unexpectedly.", + fileName, + prefabs->GetIntendedUse() ); } prefabs->AssignGens(a_Seed, m_BiomeGen, m_HeightGen, a_SeaLevel); @@ -382,16 +378,18 @@ cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_GridX, int a_Gr m_BiomeGen.GenBiomes({ChunkX, ChunkZ}, Biomes); // Get a list of pools that support each biome within the chunk: - // If just one column's biome is not allowed, the pool is not used because it's likely that an unfriendly biome is too close + // If just one column's biome is not allowed, the pool is not used because it's likely that an unfriendly biome is + // too close auto availablePools = m_Pools; for (size_t i = 0; i < ARRAYCOUNT(Biomes); i++) { auto biome = Biomes[i]; - availablePools.erase(std::remove_if(availablePools.begin(), availablePools.end(), - [biome](std::shared_ptr<cVillagePiecePool> & a_Pool) - { - return !a_Pool->IsBiomeAllowed(biome); - }), + availablePools.erase( + std::remove_if( + availablePools.begin(), + availablePools.end(), + [biome](std::shared_ptr<cVillagePiecePool> & a_Pool) { return !a_Pool->IsBiomeAllowed(biome); } + ), availablePools.end() ); // Bail out if no compatible pools left: @@ -422,5 +420,16 @@ cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_GridX, int a_Gr } // Create a village based on the chosen prefabs: - return cStructurePtr(new cVillage(m_Seed, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize, Density, *pool.get(), m_HeightGen)); + return cStructurePtr(new cVillage( + m_Seed, + a_GridX, + a_GridZ, + a_OriginX, + a_OriginZ, + m_MaxDepth, + m_MaxSize, + Density, + *pool.get(), + m_HeightGen + )); } diff --git a/src/Generating/VillageGen.h b/src/Generating/VillageGen.h index c59c089d3..b2e8b1f18 100644 --- a/src/Generating/VillageGen.h +++ b/src/Generating/VillageGen.h @@ -23,13 +23,11 @@ class cVillagePiecePool; -class cVillageGen: - public cGridStructGen +class cVillageGen : public cGridStructGen { using Super = cGridStructGen; -public: - + public: /** Creates a new instance of the generator with the specified parameters. */ cVillageGen( int a_Seed, @@ -37,14 +35,15 @@ public: int a_MaxOffset, int a_MaxDepth, int a_MaxSize, - int a_MinDensity, int a_MaxDensity, + int a_MinDensity, + int a_MaxDensity, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel, const AStringVector & a_PrefabsToLoad ); -protected: + protected: class cVillage; // fwd: VillageGen.cpp typedef std::vector<std::shared_ptr<cVillagePiecePool>> cVillagePiecePools; @@ -75,4 +74,4 @@ protected: // cGridStructGen overrides: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; -} ; +}; |