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:
30  virtual ~cNoise3DGenerator() override;
31 
32  virtual void Initialize(cIniFile & a_IniFile) override;
33  virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
34  virtual void Generate(cChunkDesc & a_ChunkDesc) override;
35 
36 protected:
37  // Linear interpolation step sizes, must be divisors of cChunkDef::Width and cChunkDef::Height, respectively:
38  static const int UPSCALE_X = 4;
39  static const int UPSCALE_Y = 8;
40  static const int UPSCALE_Z = 4;
41 
42  // Linear interpolation buffer dimensions, calculated from the step sizes:
43  static const int DIM_X = 1 + cChunkDef::Width / UPSCALE_X;
44  static const int DIM_Y = 1 + cChunkDef::Height / UPSCALE_Y;
45  static const int DIM_Z = 1 + cChunkDef::Width / UPSCALE_Z;
46 
49 
52 
55  NOISE_DATATYPE m_MidPoint; // Where the vertical "center" of the noise should be
60 
62  void GenerateNoiseArray(cChunkCoords a_ChunkCoords, NOISE_DATATYPE * a_Noise);
63 
65  void ComposeTerrain(cChunkDesc & a_ChunkDesc);
66 } ;
67 
68 
69 
70 
71 
73  public cTerrainShapeGen
74 {
75 public:
76  cNoise3DComposable(int a_Seed);
77 
78  void Initialize(cIniFile & a_IniFile);
79 
80 protected:
83 
86 
89 
92 
96 
99 
100  // Frequency of the 3D noise's first octave:
104 
105  // Frequency of the base terrain noise:
108 
109  // Frequency of the choice noise:
113 
114  // Threshold for when the values are considered air:
116 
117  // Cache for the last calculated chunk (reused between heightmap and composition queries):
119  NOISE_DATATYPE m_NoiseArray[17 * 17 * 257]; // x + 17 * z + 17 * 17 * y
120 
121 
123  void GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords);
124 
125  // cTerrainHeightGen overrides:
126  virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override;
127  virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); }
128 } ;
129 
130 
131 
132 
133 
135  public cTerrainShapeGen
136 {
137 public:
138  cBiomalNoise3DComposable(int a_Seed, cBiomeGenPtr a_BiomeGen);
139 
140  void Initialize(cIniFile & a_IniFile);
141 
142 protected:
144  static const int AVERAGING_SIZE = 9;
145 
147  typedef NOISE_DATATYPE ChunkParam[5 * 5];
148 
149 
152 
155 
158 
161 
164 
167 
168  // Frequency of the 3D noise's first octave:
172 
173  // Frequency of the base terrain noise:
176 
177  // Frequency of the choice noise:
181 
182  // Threshold for when the values are considered air:
184 
185  // Cache for the last calculated chunk (reused between heightmap and composition queries):
187  NOISE_DATATYPE m_NoiseArray[17 * 17 * 257]; // 257 * x + y + 257 * 17 * z
188 
190  NOISE_DATATYPE m_Weight[AVERAGING_SIZE * 2 + 1][AVERAGING_SIZE * 2 + 1];
191 
194 
195 
197  void GenerateNoiseArrayIfNeeded(cChunkCoords a_ChunkCoords);
198 
200  void CalcBiomeParamArrays(cChunkCoords a_ChunkCoords, ChunkParam & a_HeightAmp, ChunkParam & a_MidPoint);
201 
203  void GetBiomeParams(EMCSBiome a_Biome, NOISE_DATATYPE & a_HeightAmp, NOISE_DATATYPE & a_MidPoint);
204 
205  // cTerrainShapeGen overrides:
206  virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override;
207  virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); }
208 } ;
209 
210 
211 
212 
Byte Shape[256 *16 *16]
The datatype used to represent the entire chunk worth of shape.
Definition: ChunkDesc.h:36
NOISE_DATATYPE m_HeightAmplification
The main parameter of the generator, specifies the slope of the vertical linear gradient.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_BaseNoise
Heightmap-like noise used to provide variance for low-amplitude biomes.
NOISE_DATATYPE m_AirThreshold
NOISE_DATATYPE m_BaseFrequencyX
NOISE_DATATYPE m_BaseFrequencyX
NOISE_DATATYPE m_ChoiceFrequencyZ
static const int Width
Definition: ChunkDef.h:134
NOISE_DATATYPE m_FrequencyZ
cOctavedNoise< cInterp5DegNoise > m_Cubic
The noise used for heightmap directing.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_DensityNoiseB
Density 3D noise, variant B.
static const int UPSCALE_X
int m_SeaLevel
Block height of the sealevel, used for composing the terrain.
NOISE_DATATYPE m_HeightAmplification
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:21
NOISE_DATATYPE m_ChoiceFrequencyY
static const int UPSCALE_Y
void ComposeTerrain(cChunkDesc &a_ChunkDesc)
Composes terrain - adds dirt, grass and sand.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_ChoiceNoise
The noise that is used to choose between density noise A and B.
static const int DIM_Z
static const int Height
Definition: ChunkDef.h:135
virtual void Generate(cChunkDesc &a_ChunkDesc) override
Does the actual chunk generation.
virtual ~cNoise3DGenerator() override
NOISE_DATATYPE m_BaseFrequencyZ
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...
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_DensityNoiseA
Density 3D noise, variant A.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_DensityNoiseB
Density 3D noise, variant B.
NOISE_DATATYPE m_MidPoint
Where the vertical "center" of the noise should be, as block height.
NOISE_DATATYPE m_FrequencyY
NOISE_DATATYPE m_ChoiceFrequencyZ
float NOISE_DATATYPE
The datatype used by all the noise generators.
Definition: Noise.h:9
virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates the biomes for the specified chunk.
NOISE_DATATYPE m_FrequencyY
cChunkCoords m_LastChunkCoords
NOISE_DATATYPE m_ChoiceFrequencyX
NOISE_DATATYPE m_WeightSum
The sum of m_Weight[].
The interface that a terrain shape generator must implement A terrain shape generator takes chunk coo...
NOISE_DATATYPE m_ChoiceFrequencyX
NOISE_DATATYPE m_BaseFrequencyZ
cChunkGenerator Super
NOISE_DATATYPE m_MidPoint
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_DensityNoiseA
Density 3D noise, variant A.
cBiomeGenPtr m_BiomeGen
The underlying biome generator.
virtual void InitializeShapeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_ChoiceNoise
The 3D noise that is used to choose between density noise A and B.
NOISE_DATATYPE m_FrequencyZ
cOctavedNoise< cInterp5DegNoise > m_Perlin
The base 3D noise source for the actual composition.
virtual void Initialize(cIniFile &a_IniFile) override
Called to initialize the generator on server startup.
virtual void InitializeShapeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
static const int UPSCALE_Z
NOISE_DATATYPE m_AirThreshold
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:147
NOISE_DATATYPE m_FrequencyX
cOctavedNoise< cInterpolNoise< Interp5Deg > > m_BaseNoise
Heightmap-like noise used to provide variance for low-amplitude biomes.
static const int DIM_Y
NOISE_DATATYPE m_ChoiceFrequencyY
NOISE_DATATYPE m_FrequencyX
The interface that all chunk generators must implement to provide the generated chunks.
static const int DIM_X
std::shared_ptr< cBiomeGen > cBiomeGenPtr