Cuberite
A lightweight, fast and extensible game server for Minecraft
Noise3DGenerator.h
Go to the documentation of this file.
1 
2 // Noise3DGenerator.h
3 
4 // Declares cNoise3DGenerator and cNoise3DComposable classes, representing 3D-noise-based generators.
5 // They generate terrain shape by combining a lerp of two 3D noises with a vertical linear gradient
6 // cNoise3DGenerator is obsolete and unmaintained.
7 // cNoise3DComposable is used to test parameter combinations for single-biome worlds.
8 
9 
10 
11 
12 
13 #pragma once
14 
15 #include "ComposableGenerator.h"
16 #include "../Noise/Noise.h"
17 #include "../Noise/InterpolNoise.h"
18 
19 
20 
21 
22 
24  public cChunkGenerator
25 {
27 
28 public:
29 
31  virtual ~cNoise3DGenerator() override;
32 
33  virtual void Initialize(cIniFile & a_IniFile) override;
34  virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
35  virtual void Generate(cChunkDesc & a_ChunkDesc) override;
36 
37 protected:
38  // Linear interpolation step sizes, must be divisors of cChunkDef::Width and cChunkDef::Height, respectively:
39  static const int UPSCALE_X = 4;
40  static const int UPSCALE_Y = 8;
41  static const int UPSCALE_Z = 4;
42 
43  // Linear interpolation buffer dimensions, calculated from the step sizes:
44  static const int DIM_X = 1 + cChunkDef::Width / UPSCALE_X;
45  static const int DIM_Y = 1 + cChunkDef::Height / UPSCALE_Y;
46  static const int DIM_Z = 1 + cChunkDef::Width / UPSCALE_Z;
47 
50 
53 
56  NOISE_DATATYPE m_MidPoint; // Where the vertical "center" of the noise should be
61 
63  void GenerateNoiseArray(cChunkCoords a_ChunkCoords, NOISE_DATATYPE * a_Noise);
64 
66  void ComposeTerrain(cChunkDesc & a_ChunkDesc);
67 } ;
68 
69 
70 
71 
72 
74  public cTerrainShapeGen
75 {
76 public:
77  cNoise3DComposable(int a_Seed);
78 
79  void Initialize(cIniFile & a_IniFile);
80 
81 protected:
84 
87 
90 
93 
97 
100 
101  // Frequency of the 3D noise's first octave:
105 
106  // Frequency of the base terrain noise:
109 
110  // Frequency of the choice noise:
114 
115  // Threshold for when the values are considered air:
117 
118  // Cache for the last calculated chunk (reused between heightmap and composition queries):
120  NOISE_DATATYPE m_NoiseArray[17 * 17 * 257]; // x + 17 * z + 17 * 17 * y
121 
122 
124  void GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords);
125 
126  // cTerrainHeightGen overrides:
127  virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override;
128  virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); }
129 } ;
130 
131 
132 
133 
134 
136  public cTerrainShapeGen
137 {
138 public:
139  cBiomalNoise3DComposable(int a_Seed, cBiomeGen & a_BiomeGen);
140 
141  void Initialize(cIniFile & a_IniFile);
142 
143 protected:
145  static const int AVERAGING_SIZE = 9;
146 
148  typedef NOISE_DATATYPE ChunkParam[5 * 5];
149 
150 
153 
156 
159 
162 
165 
168 
169  // Frequency of the 3D noise's first octave:
173 
174  // Frequency of the base terrain noise:
177 
178  // Frequency of the choice noise:
182 
183  // Threshold for when the values are considered air:
185 
186  // Cache for the last calculated chunk (reused between heightmap and composition queries):
188  NOISE_DATATYPE m_NoiseArray[17 * 17 * 257]; // 257 * x + y + 257 * 17 * z
189 
192 
195 
196 
198  void GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords);
199 
201  void CalcBiomeParamArrays(cChunkCoords a_ChunkCoords, ChunkParam & a_HeightAmp, ChunkParam & a_MidPoint);
202 
204  void GetBiomeParams(EMCSBiome a_Biome, NOISE_DATATYPE & a_HeightAmp, NOISE_DATATYPE & a_MidPoint);
205 
206  // cTerrainShapeGen overrides:
207  virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override;
208  virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); }
209 } ;
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:18
float NOISE_DATATYPE
The datatype used by all the noise generators.
Definition: Noise.h:9
Wraps the chunk coords into a single structure.
Definition: ChunkDef.h:57
static const int Width
Definition: ChunkDef.h:124
static const int Height
Definition: ChunkDef.h:125
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:137
Byte Shape[256 *16 *16]
The datatype used to represent the entire chunk worth of shape.
Definition: ChunkDesc.h:36
The interface that all chunk generators must implement to provide the generated chunks.
The interface that a biome generator must implement A biome generator takes chunk coords on input and...
The interface that a terrain shape generator must implement A terrain shape generator takes chunk coo...
cOctavedNoise< cInterp5DegNoise > m_Perlin
The base 3D noise source for the actual composition.
void ComposeTerrain(cChunkDesc &a_ChunkDesc)
Composes terrain - adds dirt, grass and sand.
NOISE_DATATYPE m_FrequencyZ
void GenerateNoiseArray(cChunkCoords a_ChunkCoords, NOISE_DATATYPE *a_Noise)
Generates the 3D noise array used for terrain generation into a_Noise; a_Noise is of ChunkData-size.
static const int DIM_Z
cOctavedNoise< cInterp5DegNoise > m_Cubic
The noise used for heightmap directing.
NOISE_DATATYPE m_FrequencyY
virtual void Initialize(cIniFile &a_IniFile) override
Called to initialize the generator on server startup.
virtual void Generate(cChunkDesc &a_ChunkDesc) override
Does the actual chunk generation.
NOISE_DATATYPE m_MidPoint
static const int UPSCALE_X
virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates the biomes for the specified chunk.
NOISE_DATATYPE m_FrequencyX
virtual ~cNoise3DGenerator() override
NOISE_DATATYPE m_AirThreshold
static const int DIM_X
NOISE_DATATYPE m_HeightAmplification
static const int DIM_Y
static const int UPSCALE_Z
static const int UPSCALE_Y
NOISE_DATATYPE m_ChoiceFrequencyX
NOISE_DATATYPE m_FrequencyY
NOISE_DATATYPE m_ChoiceFrequencyY
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_DensityNoiseA
Density 3D noise, variant A.
NOISE_DATATYPE m_FrequencyZ
NOISE_DATATYPE m_BaseFrequencyX
virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape &a_Shape) override
Generates the shape for the given chunk.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_BaseNoise
Heightmap-like noise used to provide variance for low-amplitude biomes.
NOISE_DATATYPE m_MidPoint
Where the vertical "center" of the noise should be, as block height.
NOISE_DATATYPE m_NoiseArray[17 *17 *257]
cChunkCoords m_LastChunkCoords
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_DensityNoiseB
Density 3D noise, variant B.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_ChoiceNoise
The 3D noise that is used to choose between density noise A and B.
virtual void InitializeShapeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
NOISE_DATATYPE m_FrequencyX
NOISE_DATATYPE m_HeightAmplification
The main parameter of the generator, specifies the slope of the vertical linear gradient.
NOISE_DATATYPE m_BaseFrequencyZ
NOISE_DATATYPE m_AirThreshold
NOISE_DATATYPE m_ChoiceFrequencyZ
cNoise3DComposable(int a_Seed)
void GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords)
Generates the 3D noise array used for terrain generation (m_NoiseArray), unless the LastChunk coords ...
void Initialize(cIniFile &a_IniFile)
NOISE_DATATYPE m_ChoiceFrequencyY
NOISE_DATATYPE m_ChoiceFrequencyZ
NOISE_DATATYPE m_Weight[AVERAGING_SIZE *2+1][AVERAGING_SIZE *2+1]
Weights for summing up neighboring biomes.
NOISE_DATATYPE m_NoiseArray[17 *17 *257]
void CalcBiomeParamArrays(cChunkCoords a_ChunkCoords, ChunkParam &a_HeightAmp, ChunkParam &a_MidPoint)
Calculates the biome-related parameters for the chunk.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_BaseNoise
Heightmap-like noise used to provide variance for low-amplitude biomes.
NOISE_DATATYPE m_WeightSum
The sum of m_Weight[].
void GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords)
Generates the 3D noise array used for terrain generation (m_NoiseArray), unless the LastChunk coords ...
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_ChoiceNoise
The noise that is used to choose between density noise A and B.
cBiomeGen & m_BiomeGen
The underlying biome generator.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_DensityNoiseA
Density 3D noise, variant A.
void Initialize(cIniFile &a_IniFile)
cBiomalNoise3DComposable(int a_Seed, cBiomeGen &a_BiomeGen)
int m_SeaLevel
Block height of the sealevel, used for composing the terrain.
NOISE_DATATYPE m_ChoiceFrequencyX
static const int AVERAGING_SIZE
Number of columns around the pixel to query for biomes for averaging.
NOISE_DATATYPE ChunkParam[5 *5]
Type used for a single parameter across the entire (downscaled) chunk.
void GetBiomeParams(EMCSBiome a_Biome, NOISE_DATATYPE &a_HeightAmp, NOISE_DATATYPE &a_MidPoint)
Returns the parameters for the specified biome.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_DensityNoiseB
Density 3D noise, variant B.
virtual void InitializeShapeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
NOISE_DATATYPE m_BaseFrequencyZ
virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape &a_Shape) override
Generates the shape for the given chunk.
NOISE_DATATYPE m_BaseFrequencyX