diff options
Diffstat (limited to 'src/Generating/Noise3DGenerator.cpp')
-rw-r--r-- | src/Generating/Noise3DGenerator.cpp | 605 |
1 files changed, 457 insertions, 148 deletions
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 |