diff options
author | Mattes D <github@xoft.cz> | 2014-10-30 16:24:35 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-10-30 16:24:35 +0100 |
commit | 8c04abf9aa749af3b15bc92f517b636c9593109e (patch) | |
tree | bb9af9b2d0d0c9760c937dd98b25c1738b075a13 /src/Generating/IntGen.h | |
parent | Merge remote-tracking branch 'origin/master' into GrownBiomes (diff) | |
download | cuberite-8c04abf9aa749af3b15bc92f517b636c9593109e.tar cuberite-8c04abf9aa749af3b15bc92f517b636c9593109e.tar.gz cuberite-8c04abf9aa749af3b15bc92f517b636c9593109e.tar.bz2 cuberite-8c04abf9aa749af3b15bc92f517b636c9593109e.tar.lz cuberite-8c04abf9aa749af3b15bc92f517b636c9593109e.tar.xz cuberite-8c04abf9aa749af3b15bc92f517b636c9593109e.tar.zst cuberite-8c04abf9aa749af3b15bc92f517b636c9593109e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Generating/IntGen.h | 173 |
1 files changed, 133 insertions, 40 deletions
diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index d7ed9275a..5f0394060 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -36,13 +36,14 @@ 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 bgJungle = 4; -const int bgIce = 5; -const int bgMax = 5; // Maximum biome group value +const int bgOcean = 0; +const int bgDesert = 1; +const int bgTemperate = 2; +const int bgMountains = 3; +const int bgJungle = 4; +const int bgIce = 5; +const int bgLandOceanMax = 5; // Maximum biome group value generated in the landOcean generator +const int bgMesa = 6; @@ -167,7 +168,7 @@ public: for (int x = 0; x < SizeX; x++) { int rnd = (super::m_Noise.IntNoise2DInt(a_MinX + x, BaseZ) / 7); - a_Values[x + SizeX * z] = ((rnd % 100) < m_Threshold) ? ((rnd / 128) % bgMax + 1) : 0; + a_Values[x + SizeX * z] = ((rnd % 100) < m_Threshold) ? ((rnd / 128) % bgLandOceanMax + 1) : 0; } } @@ -462,7 +463,7 @@ public: int rnd = super::m_Noise.IntNoise2DInt(a_MinX + x, a_MinZ + z) / 7; if (rnd % 100 < m_Threshold) { - a_Values[x + z * SizeX] = (rnd / 100) % bgMax; + a_Values[x + z * SizeX] = (rnd / 100) % bgLandOceanMax; } } } @@ -521,16 +522,16 @@ public: case bgDesert: { if ( - !IsDesertCompatible(Above) || - !IsDesertCompatible(Below) || - !IsDesertCompatible(Left) || - !IsDesertCompatible(Right) + !isDesertCompatible(Above) || + !isDesertCompatible(Below) || + !isDesertCompatible(Left) || + !isDesertCompatible(Right) ) { v = bgTemperate; } break; - } + } // case bgDesert // Ice should not neighbor deserts; change to temperate: case bgIce: @@ -545,21 +546,36 @@ public: v = bgTemperate; } break; - } + } // case bgIce // Jungle should not neighbor Desert or Ice; change to temperate: case bgJungle: { if ( - !IsJungleCompatible(Above) || - !IsJungleCompatible(Below) || - !IsJungleCompatible(Left) || - !IsJungleCompatible(Right) + !isJungleCompatible(Above) || + !isJungleCompatible(Below) || + !isJungleCompatible(Left) || + !isJungleCompatible(Right) ) { v = bgTemperate; } - } + } // case bgJungle + + // Mesa should neighbor only oceans and deserts; change to desert when another: + case bgMesa: + { + if ( + !isMesaCompatible(Above) || + !isMesaCompatible(Below) || + !isMesaCompatible(Left) || + !isMesaCompatible(Right) + ) + { + v = bgDesert; + } + break; + } // case bgDesert } a_Values[x + z * SizeX] = v; } // for x @@ -570,14 +586,32 @@ protected: Underlying m_Underlying; - inline bool IsDesertCompatible(int a_BiomeGroup) + inline bool isDesertCompatible(int a_BiomeGroup) + { + switch (a_BiomeGroup) + { + case bgOcean: + case bgDesert: + case bgTemperate: + case bgMesa: + { + return true; + } + default: + { + return false; + } + } + } + + inline bool isJungleCompatible(int a_BiomeGroup) { - return ((a_BiomeGroup == bgOcean) || (a_BiomeGroup == bgDesert) || (a_BiomeGroup == bgTemperate)); + return ((a_BiomeGroup != bgDesert) && (a_BiomeGroup != bgMesa) && (a_BiomeGroup != bgIce)); } - inline bool IsJungleCompatible(int a_BiomeGroup) + inline bool isMesaCompatible(int a_BiomeGroup) { - return ((a_BiomeGroup != bgDesert) && (a_BiomeGroup != bgIce)); + return ((a_BiomeGroup == bgOcean) || (a_BiomeGroup == bgDesert)); } }; @@ -605,44 +639,50 @@ 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, }; - static const int DesertBiomes[] = + static const int desertBiomes[] = { - biDesert, biDesert, biSavanna, biPlains, + biDesert, biDesert, biDesert, biDesert, biDesert, biDesert, biSavanna, biSavanna, biPlains, }; - static const int TemperateBiomes[] = + static const int temperateBiomes[] = { - biForest, biRoofedForest, biExtremeHills, biPlains, biBirchForest, biSwampland, + biForest, biForest, biRoofedForest, biExtremeHills, biPlains, biBirchForest, biSwampland, }; - static const int MountainBiomes[] = + static const int mountainBiomes[] = { biExtremeHills, biForest, biTaiga, biPlains, }; - static const int JungleBiomes[] = + static const int jungleBiomes[] = + { + biJungle, biJungle, biJungle, biForest, + }; + + static const int iceBiomes[] = { - biJungle, biJungle, biForest, + biIcePlains, biIcePlains, biIcePlains, biIcePlains, biColdTaiga, }; - static const int IceBiomes[] = + static const int mesaBiomes[] = { - biIcePlains, biIcePlains, biColdTaiga, + biMesa, biMesaPlateau, }; static const cBiomesInGroups BiomesInGroups[] = { - { static_cast<int>(ARRAYCOUNT(OceanBiomes)), OceanBiomes}, - { static_cast<int>(ARRAYCOUNT(DesertBiomes)), DesertBiomes}, - { static_cast<int>(ARRAYCOUNT(TemperateBiomes)), TemperateBiomes}, - { static_cast<int>(ARRAYCOUNT(MountainBiomes)), MountainBiomes}, - { static_cast<int>(ARRAYCOUNT(JungleBiomes)), JungleBiomes}, - { static_cast<int>(ARRAYCOUNT(IceBiomes)), IceBiomes}, + /* 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}, + /* bgJungle */ { static_cast<int>(ARRAYCOUNT(jungleBiomes)), jungleBiomes}, + /* bgIce */ { static_cast<int>(ARRAYCOUNT(iceBiomes)), iceBiomes}, + /* bgMesa */ { static_cast<int>(ARRAYCOUNT(mesaBiomes)), mesaBiomes}, }; // Generate the underlying values, representing biome groups: @@ -951,3 +991,56 @@ protected: + +/** Changes random pixels of the underlying data to the specified value. */ +template <int SizeX, int SizeZ = SizeX> +class cIntGenSetRandomly : + public cIntGenWithNoise<SizeX, SizeZ> +{ + typedef cIntGenWithNoise<SizeX, SizeZ> super; + +public: + typedef std::shared_ptr<cIntGen<SizeX, SizeZ>> 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) + { + } + + + virtual void GetInts(int a_MinX, int a_MinZ, typename super::Values & a_Values) override + { + // Generate the underlying data: + m_Underlying->GetInts(a_MinX, a_MinZ, a_Values); + + // Change random pixels to bgOcean: + for (int z = 0; z < SizeZ; z++) + { + for (int x = 0; x < SizeX; x++) + { + int rnd = super::m_Noise.IntNoise2DInt(x + a_MinX, z + a_MinZ) / 7; + if (rnd % 1000 < m_Chance) + { + a_Values[x + z * SizeX] = m_ToValue; + } + } + } + } + +protected: + /** Chance, in permille, of changing each pixel. */ + int m_Chance; + + /** The value to which to set the pixel. */ + int m_ToValue; + + Underlying m_Underlying; +}; + + + + + |