diff options
author | mBornand <63592189+mBornand@users.noreply.github.com> | 2020-05-06 17:31:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-06 17:31:52 +0200 |
commit | b9f441294d0c45bf3e81a0573ad6fad68b1ba600 (patch) | |
tree | ef7dc48589a5c14d76bc602ea9851a34974816a8 /src/Generating/StructGen.cpp | |
parent | Fixed various MSVC warnings. (diff) | |
download | cuberite-b9f441294d0c45bf3e81a0573ad6fad68b1ba600.tar cuberite-b9f441294d0c45bf3e81a0573ad6fad68b1ba600.tar.gz cuberite-b9f441294d0c45bf3e81a0573ad6fad68b1ba600.tar.bz2 cuberite-b9f441294d0c45bf3e81a0573ad6fad68b1ba600.tar.lz cuberite-b9f441294d0c45bf3e81a0573ad6fad68b1ba600.tar.xz cuberite-b9f441294d0c45bf3e81a0573ad6fad68b1ba600.tar.zst cuberite-b9f441294d0c45bf3e81a0573ad6fad68b1ba600.zip |
Diffstat (limited to 'src/Generating/StructGen.cpp')
-rw-r--r-- | src/Generating/StructGen.cpp | 170 |
1 files changed, 93 insertions, 77 deletions
diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index 0b45502a6..ac937da78 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -50,14 +50,33 @@ void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc) Dest = &a_ChunkDesc; } - int NumTrees = GetNumTrees(BaseX, BaseZ, Dest->GetBiomeMap()); + double NumTrees = GetNumTrees(BaseX, BaseZ, Dest->GetBiomeMap()); sSetBlockVector OutsideLogs, OutsideOther; - for (int i = 0; i < NumTrees; i++) + if (NumTrees < 1) { - GenerateSingleTree(BaseX, BaseZ, i, *Dest, OutsideLogs, OutsideOther); + Vector3i Pos; + Pos.x = (m_Noise.IntNoise3DInt(BaseX + BaseZ, BaseZ, 0) / 19) % cChunkDef::Width; + 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) + { + GenerateSingleTree(BaseX, BaseZ, 0, Pos, *Dest, OutsideLogs, OutsideOther); + } } + else + { + for (int i = 0; i < NumTrees; i++) + { + Vector3i Pos; + Pos.x = (m_Noise.IntNoise3DInt(BaseX + BaseZ, BaseZ, i) / 19) % cChunkDef::Width; + Pos.z = (m_Noise.IntNoise3DInt(BaseX - BaseZ, i, BaseZ) / 19) % cChunkDef::Width; + Pos.y = Dest->GetHeight(Pos.x, Pos.z); + GenerateSingleTree(BaseX, BaseZ, i, Pos, *Dest, OutsideLogs, OutsideOther); + } + } sSetBlockVector IgnoredOverflow; IgnoredOverflow.reserve(OutsideOther.size()); ApplyTreeImage(ChunkX, ChunkZ, a_ChunkDesc, OutsideOther, IgnoredOverflow); @@ -76,23 +95,19 @@ void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc) void cStructGenTrees::GenerateSingleTree( int a_ChunkX, int a_ChunkZ, int a_Seq, + Vector3i a_Pos, cChunkDesc & a_ChunkDesc, sSetBlockVector & a_OutsideLogs, sSetBlockVector & a_OutsideOther ) { - int x = (m_Noise.IntNoise3DInt(a_ChunkX + a_ChunkZ, a_ChunkZ, a_Seq) / 19) % cChunkDef::Width; - int z = (m_Noise.IntNoise3DInt(a_ChunkX - a_ChunkZ, a_Seq, a_ChunkZ) / 19) % cChunkDef::Width; - - int Height = a_ChunkDesc.GetHeight(x, z); - - if ((Height <= 0) || (Height >= 230)) + if ((a_Pos.y <= 0) || (a_Pos.y >= 230)) { return; } // Check the block underneath the tree: - BLOCKTYPE TopBlock = a_ChunkDesc.GetBlockType(x, Height, z); + 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)) { return; @@ -100,9 +115,9 @@ void cStructGenTrees::GenerateSingleTree( sSetBlockVector TreeLogs, TreeOther; GetTreeImageByBiome( - { a_ChunkX * cChunkDef::Width + x, Height + 1, a_ChunkZ * cChunkDef::Width + z }, + { 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(x, z), + a_ChunkDesc.GetBiome(a_Pos.x, a_Pos.z), TreeLogs, TreeOther ); @@ -195,7 +210,7 @@ void cStructGenTrees::ApplyTreeImage( -int cStructGenTrees::GetNumTrees( +double cStructGenTrees::GetNumTrees( int a_ChunkX, int a_ChunkZ, const cChunkDef::BiomeMap & a_Biomes ) @@ -204,68 +219,68 @@ int cStructGenTrees::GetNumTrees( { switch (a_Biome) { - case biOcean: return 2; - case biPlains: return 1; - case biDesert: return 0; - case biExtremeHills: return 3; - case biForest: return 30; - case biTaiga: return 30; - case biSwampland: return 8; - case biRiver: return 0; - case biNether: return 0; - case biEnd: return 0; - case biFrozenOcean: return 0; - case biFrozenRiver: return 0; - case biIcePlains: return 1; - case biIceMountains: return 1; - case biMushroomIsland: return 3; - case biMushroomShore: return 3; - case biBeach: return 0; - case biDesertHills: return 0; - case biForestHills: return 20; - case biTaigaHills: return 20; - case biExtremeHillsEdge: return 5; - case biJungle: return 120; - case biJungleHills: return 90; - case biJungleEdge: return 90; - case biDeepOcean: return 0; - case biStoneBeach: return 0; - case biColdBeach: return 0; - case biBirchForest: return 30; - case biBirchForestHills: return 20; - case biRoofedForest: return 50; - case biColdTaiga: return 20; - case biColdTaigaHills: return 15; - case biMegaTaiga: return 30; - case biMegaTaigaHills: return 25; - case biExtremeHillsPlus: return 3; - case biSavanna: return 8; - case biSavannaPlateau: return 12; - case biMesa: return 2; - case biMesaPlateauF: return 8; - case biMesaPlateau: return 8; + case biOcean: return 2.0; + case biPlains: return 0.03125; + case biDesert: return 0.0; + case biExtremeHills: return 3.0; + case biForest: return 30.0; + case biTaiga: return 30.0; + case biSwampland: return 8.0; + case biRiver: return 0.0; + case biNether: return 0.0; + case biEnd: return 0.0; + case biFrozenOcean: return 0.0; + case biFrozenRiver: return 0.0; + case biIcePlains: return 0.03125; + case biIceMountains: return 0.125; + case biMushroomIsland: return 3.0; + case biMushroomShore: return 3.0; + case biBeach: return 0.0; + case biDesertHills: return 0.0; + case biForestHills: return 20.0; + case biTaigaHills: return 20.0; + case biExtremeHillsEdge: return 5.0; + case biJungle: return 120.0; + case biJungleHills: return 90.0; + case biJungleEdge: return 90.0; + case biDeepOcean: return 0.0; + case biStoneBeach: return 0.0; + case biColdBeach: return 0.0; + case biBirchForest: return 30.0; + case biBirchForestHills: return 20.0; + case biRoofedForest: return 50.0; + case biColdTaiga: return 20.0; + case biColdTaigaHills: return 15.0; + case biMegaTaiga: return 30.0; + case biMegaTaigaHills: return 25.0; + case biExtremeHillsPlus: return 3.0; + case biSavanna: return 8.0; + case biSavannaPlateau: return 12.0; + case biMesa: return 2.0; + case biMesaPlateauF: return 8.0; + case biMesaPlateau: return 8.0; // Biome variants - case biSunflowerPlains: return 1; - case biDesertM: return 0; - case biExtremeHillsM: return 4; - case biFlowerForest: return 30; - case biTaigaM: return 30; - case biSwamplandM: return 8; - case biIcePlainsSpikes: return 1; - case biJungleM: return 120; - case biJungleEdgeM: return 90; - case biBirchForestM: return 30; - case biBirchForestHillsM: return 20; - case biRoofedForestM: return 40; - case biColdTaigaM: return 30; - case biMegaSpruceTaiga: return 30; - case biMegaSpruceTaigaHills: return 30; - case biExtremeHillsPlusM: return 4; - case biSavannaM: return 8; - case biSavannaPlateauM: return 12; - case biMesaBryce: return 4; - case biMesaPlateauFM: return 12; - case biMesaPlateauM: return 12; + case biSunflowerPlains: return 0.03125; + case biDesertM: return 0.0; + case biExtremeHillsM: return 4.0; + case biFlowerForest: return 2.0; + case biTaigaM: return 30.0; + case biSwamplandM: return 8.0; + case biIcePlainsSpikes: return 0.0078125; + case biJungleM: return 120.0; + case biJungleEdgeM: return 90.0; + case biBirchForestM: return 30.0; + case biBirchForestHillsM: return 20.0; + case biRoofedForestM: return 40.0; + case biColdTaigaM: return 30.0; + case biMegaSpruceTaiga: return 30.0; + case biMegaSpruceTaigaHills: return 30.0; + case biExtremeHillsPlusM: return 4.0; + case biSavannaM: return 8.0; + case biSavannaPlateauM: return 12.0; + case biMesaBryce: return 4.0; + case biMesaPlateauFM: return 12.0; + case biMesaPlateauM: return 12.0; // Non-biomes case biInvalidBiome: case biNumBiomes: @@ -273,18 +288,19 @@ int cStructGenTrees::GetNumTrees( case biNumVariantBiomes: { ASSERT(!"Invalid biome in cStructGenTrees::GetNumTrees"); - return 0; + return 0.0; } } UNREACHABLE("Unsupported biome"); }; - int NumTrees = 0; + double NumTrees = 0.0; for (auto Biome : a_Biomes) { NumTrees += BiomeTrees(Biome); } - return NumTrees / 1024; + + return NumTrees / (cChunkDef::Width * cChunkDef::Width * 4); } |