2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// Noise3DGenerator.h
|
|
|
|
|
2014-11-09 08:33:37 -05:00
|
|
|
// Declares cNoise3DGenerator and cNoise3DComposable classes, representing 3D-noise-based generators.
|
|
|
|
// They generate terrain shape by combining a lerp of two 3D noises with a vertical linear gradient
|
|
|
|
// cNoise3DGenerator is obsolete and unmaintained.
|
|
|
|
// cNoise3DComposable is used to test parameter combinations for single-biome worlds.
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ComposableGenerator.h"
|
2014-11-18 06:07:08 -05:00
|
|
|
#include "../Noise/Noise.h"
|
2014-11-18 17:21:57 -05:00
|
|
|
#include "../Noise/InterpolNoise.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cNoise3DGenerator :
|
|
|
|
public cChunkGenerator::cGenerator
|
|
|
|
{
|
|
|
|
typedef cChunkGenerator::cGenerator super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
cNoise3DGenerator(cChunkGenerator & a_ChunkGenerator);
|
|
|
|
virtual ~cNoise3DGenerator();
|
|
|
|
|
2014-01-10 16:22:54 -05:00
|
|
|
virtual void Initialize(cIniFile & a_IniFile) override;
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
|
|
|
virtual void DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Linear interpolation step sizes, must be divisors of cChunkDef::Width and cChunkDef::Height, respectively:
|
2014-11-17 10:50:28 -05:00
|
|
|
static const int UPSCALE_X = 4;
|
|
|
|
static const int UPSCALE_Y = 8;
|
|
|
|
static const int UPSCALE_Z = 4;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// Linear interpolation buffer dimensions, calculated from the step sizes:
|
|
|
|
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;
|
|
|
|
|
2014-11-18 17:21:57 -05:00
|
|
|
/** The base 3D noise source for the actual composition */
|
|
|
|
cOctavedNoise<cInterp5DegNoise> m_Perlin;
|
|
|
|
|
2014-11-19 10:58:27 -05:00
|
|
|
/** The noise used for heightmap directing. */
|
|
|
|
cOctavedNoise<cInterp5DegNoise> m_Cubic;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
int m_SeaLevel;
|
|
|
|
NOISE_DATATYPE m_HeightAmplification;
|
|
|
|
NOISE_DATATYPE m_MidPoint; // Where the vertical "center" of the noise should be
|
|
|
|
NOISE_DATATYPE m_FrequencyX;
|
|
|
|
NOISE_DATATYPE m_FrequencyY;
|
|
|
|
NOISE_DATATYPE m_FrequencyZ;
|
|
|
|
NOISE_DATATYPE m_AirThreshold;
|
|
|
|
|
|
|
|
/// Generates the 3D noise array used for terrain generation; a_Noise is of ChunkData-size
|
|
|
|
void GenerateNoiseArray(int a_ChunkX, int a_ChunkZ, NOISE_DATATYPE * a_Noise);
|
|
|
|
|
|
|
|
/// Updates heightmap based on the chunk's contents
|
|
|
|
void UpdateHeightmap(cChunkDesc & a_ChunkDesc);
|
|
|
|
|
|
|
|
/// Composes terrain - adds dirt, grass and sand
|
|
|
|
void ComposeTerrain(cChunkDesc & a_ChunkDesc);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cNoise3DComposable :
|
2014-11-12 15:24:26 -05:00
|
|
|
public cTerrainShapeGen
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
cNoise3DComposable(int a_Seed);
|
|
|
|
|
|
|
|
void Initialize(cIniFile & a_IniFile);
|
|
|
|
|
|
|
|
protected:
|
2014-11-20 08:45:20 -05:00
|
|
|
/** The 3D noise that is used to choose between density noise A and B. */
|
|
|
|
cOctavedNoise<cInterpolNoise<Interp5Deg>> m_ChoiceNoise;
|
2014-11-09 08:33:37 -05:00
|
|
|
|
|
|
|
/** Density 3D noise, variant A. */
|
2014-11-20 08:45:20 -05:00
|
|
|
cOctavedNoise<cInterpolNoise<Interp5Deg>> m_DensityNoiseA;
|
2014-11-09 08:33:37 -05:00
|
|
|
|
|
|
|
/** Density 3D noise, variant B. */
|
2014-11-20 08:45:20 -05:00
|
|
|
cOctavedNoise<cInterpolNoise<Interp5Deg>> m_DensityNoiseB;
|
2014-11-09 08:33:37 -05:00
|
|
|
|
|
|
|
/** Heightmap-like noise used to provide variance for low-amplitude biomes. */
|
2014-11-20 08:45:20 -05:00
|
|
|
cOctavedNoise<cInterpolNoise<Interp5Deg>> m_BaseNoise;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2014-11-09 08:33:37 -05:00
|
|
|
/** The main parameter of the generator, specifies the slope of the vertical linear gradient.
|
|
|
|
A higher value means a steeper slope and a smaller total amplitude of the generated terrain. */
|
2013-07-29 07:13:03 -04:00
|
|
|
NOISE_DATATYPE m_HeightAmplification;
|
2014-11-09 08:33:37 -05:00
|
|
|
|
|
|
|
/** Where the vertical "center" of the noise should be, as block height. */
|
|
|
|
NOISE_DATATYPE m_MidPoint;
|
|
|
|
|
|
|
|
// Frequency of the 3D noise's first octave:
|
2013-07-29 07:13:03 -04:00
|
|
|
NOISE_DATATYPE m_FrequencyX;
|
|
|
|
NOISE_DATATYPE m_FrequencyY;
|
|
|
|
NOISE_DATATYPE m_FrequencyZ;
|
2014-11-09 08:33:37 -05:00
|
|
|
|
|
|
|
// Frequency of the base terrain noise:
|
|
|
|
NOISE_DATATYPE m_BaseFrequencyX;
|
|
|
|
NOISE_DATATYPE m_BaseFrequencyZ;
|
|
|
|
|
|
|
|
// Frequency of the choice noise:
|
|
|
|
NOISE_DATATYPE m_ChoiceFrequencyX;
|
|
|
|
NOISE_DATATYPE m_ChoiceFrequencyY;
|
|
|
|
NOISE_DATATYPE m_ChoiceFrequencyZ;
|
|
|
|
|
|
|
|
// Threshold for when the values are considered air:
|
2013-07-29 07:13:03 -04:00
|
|
|
NOISE_DATATYPE m_AirThreshold;
|
|
|
|
|
2014-11-09 08:33:37 -05:00
|
|
|
// Cache for the last calculated chunk (reused between heightmap and composition queries):
|
2013-07-29 07:13:03 -04:00
|
|
|
int m_LastChunkX;
|
|
|
|
int m_LastChunkZ;
|
|
|
|
NOISE_DATATYPE m_NoiseArray[17 * 17 * 257]; // x + 17 * z + 17 * 17 * y
|
|
|
|
|
|
|
|
|
2014-11-09 08:33:37 -05:00
|
|
|
/** Generates the 3D noise array used for terrain generation (m_NoiseArray), unless the LastChunk coords are equal to coords given */
|
2013-07-29 07:13:03 -04:00
|
|
|
void GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ);
|
|
|
|
|
|
|
|
// cTerrainHeightGen overrides:
|
2014-11-12 15:24:26 -05:00
|
|
|
virtual void GenShape(int a_ChunkX, int a_ChunkZ, cChunkDesc::Shape & a_Shape) override;
|
|
|
|
virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); }
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-10 11:00:14 -05:00
|
|
|
|
|
|
|
class cBiomalNoise3DComposable :
|
2014-11-12 15:24:26 -05:00
|
|
|
public cTerrainShapeGen
|
2014-11-10 11:00:14 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
cBiomalNoise3DComposable(int a_Seed, cBiomeGenPtr a_BiomeGen);
|
|
|
|
|
|
|
|
void Initialize(cIniFile & a_IniFile);
|
|
|
|
|
|
|
|
protected:
|
2014-11-23 09:10:55 -05:00
|
|
|
/** 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;
|
2014-11-10 11:00:14 -05:00
|
|
|
|
|
|
|
/** Type used for a single parameter across the entire (downscaled) chunk. */
|
|
|
|
typedef NOISE_DATATYPE ChunkParam[5 * 5];
|
|
|
|
|
|
|
|
|
|
|
|
/** The noise that is used to choose between density noise A and B. */
|
2014-11-20 08:45:20 -05:00
|
|
|
cOctavedNoise<cInterpolNoise<Interp5Deg>> m_ChoiceNoise;
|
2014-11-10 11:00:14 -05:00
|
|
|
|
|
|
|
/** Density 3D noise, variant A. */
|
2014-11-20 08:45:20 -05:00
|
|
|
cOctavedNoise<cInterpolNoise<Interp5Deg>> m_DensityNoiseA;
|
2014-11-10 11:00:14 -05:00
|
|
|
|
|
|
|
/** Density 3D noise, variant B. */
|
2014-11-20 08:45:20 -05:00
|
|
|
cOctavedNoise<cInterpolNoise<Interp5Deg>> m_DensityNoiseB;
|
2014-11-10 11:00:14 -05:00
|
|
|
|
|
|
|
/** Heightmap-like noise used to provide variance for low-amplitude biomes. */
|
2014-11-20 08:45:20 -05:00
|
|
|
cOctavedNoise<cInterpolNoise<Interp5Deg>> m_BaseNoise;
|
2014-11-10 11:00:14 -05:00
|
|
|
|
|
|
|
/** The underlying biome generator. */
|
|
|
|
cBiomeGenPtr m_BiomeGen;
|
|
|
|
|
|
|
|
/** Block height of the sealevel, used for composing the terrain. */
|
|
|
|
int m_SeaLevel;
|
|
|
|
|
|
|
|
// Frequency of the 3D noise's first octave:
|
|
|
|
NOISE_DATATYPE m_FrequencyX;
|
|
|
|
NOISE_DATATYPE m_FrequencyY;
|
|
|
|
NOISE_DATATYPE m_FrequencyZ;
|
|
|
|
|
|
|
|
// Frequency of the base terrain noise:
|
|
|
|
NOISE_DATATYPE m_BaseFrequencyX;
|
|
|
|
NOISE_DATATYPE m_BaseFrequencyZ;
|
|
|
|
|
|
|
|
// Frequency of the choice noise:
|
|
|
|
NOISE_DATATYPE m_ChoiceFrequencyX;
|
|
|
|
NOISE_DATATYPE m_ChoiceFrequencyY;
|
|
|
|
NOISE_DATATYPE m_ChoiceFrequencyZ;
|
|
|
|
|
|
|
|
// Threshold for when the values are considered air:
|
|
|
|
NOISE_DATATYPE m_AirThreshold;
|
|
|
|
|
|
|
|
// Cache for the last calculated chunk (reused between heightmap and composition queries):
|
|
|
|
int m_LastChunkX;
|
|
|
|
int m_LastChunkZ;
|
2014-11-12 15:24:26 -05:00
|
|
|
NOISE_DATATYPE m_NoiseArray[17 * 17 * 257]; // 257 * x + y + 257 * 17 * z
|
2014-11-10 11:00:14 -05:00
|
|
|
|
|
|
|
/** Weights for summing up neighboring biomes. */
|
|
|
|
NOISE_DATATYPE m_Weight[AVERAGING_SIZE * 2 + 1][AVERAGING_SIZE * 2 + 1];
|
|
|
|
|
|
|
|
/** The sum of m_Weight[]. */
|
|
|
|
NOISE_DATATYPE m_WeightSum;
|
|
|
|
|
|
|
|
|
|
|
|
/** Generates the 3D noise array used for terrain generation (m_NoiseArray), unless the LastChunk coords are equal to coords given */
|
|
|
|
void GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ);
|
|
|
|
|
|
|
|
/** Calculates the biome-related parameters for the chunk. */
|
|
|
|
void CalcBiomeParamArrays(int a_ChunkX, int a_ChunkZ, ChunkParam & a_HeightAmp, ChunkParam & a_MidPoint);
|
|
|
|
|
|
|
|
/** Returns the parameters for the specified biome. */
|
|
|
|
void GetBiomeParams(EMCSBiome a_Biome, NOISE_DATATYPE & a_HeightAmp, NOISE_DATATYPE & a_MidPoint);
|
|
|
|
|
2014-11-12 15:24:26 -05:00
|
|
|
// cTerrainShapeGen overrides:
|
|
|
|
virtual void GenShape(int a_ChunkX, int a_ChunkZ, cChunkDesc::Shape & a_Shape) override;
|
|
|
|
virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); }
|
2014-11-10 11:00:14 -05:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|