Cuberite
A lightweight, fast and extensible game server for Minecraft
ComposableGenerator.h
Go to the documentation of this file.
1 
2 // ComposableGenerator.h
3 
4 // Declares the cComposableGenerator class representing the chunk generator that takes the composition approach to generating chunks
5 
6 /*
7 Generating works by composing several algorithms:
8 Biome, TerrainHeight, TerrainComposition, Ores, Structures and SmallFoliage
9 Each algorithm may be chosen from a pool of available algorithms in the same class and combined with others,
10 based on user's preferences in the world.ini.
11 See https://forum.cuberite.org/thread-409.html for details.
12 */
13 
14 
15 
16 
17 
18 #pragma once
19 
20 #include "ChunkGenerator.h"
21 #include "ChunkDesc.h"
22 
23 
24 
25 
26 
27 // Forward-declare the shared pointers to subgenerator classes:
28 class cBiomeGen;
29 class cTerrainShapeGen;
30 class cTerrainHeightGen;
32 class cFinishGen;
33 
34 
35 
36 
37 
42 class cBiomeGen
43 {
44 public:
45  virtual ~cBiomeGen() {} // Force a virtual destructor in descendants
46 
48  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) = 0;
49 
51  virtual void InitializeBiomeGen(cIniFile & a_IniFile) {}
52 
58  static std::unique_ptr<cBiomeGen> CreateBiomeGen(
59  cIniFile & a_IniFile,
60  int a_Seed,
61  bool & a_CacheOffByDefault
62  );
63 } ;
64 
65 
66 
67 
68 
79 {
80 public:
81  virtual ~cTerrainShapeGen() {} // Force a virtual destructor in descendants
82 
84  virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) = 0;
85 
87  virtual void InitializeShapeGen(cIniFile & a_IniFile) {}
88 
94  static std::unique_ptr<cTerrainShapeGen> CreateShapeGen(
95  cIniFile & a_IniFile,
96  cBiomeGen & a_BiomeGen,
97  int a_Seed,
98  bool & a_CacheOffByDefault
99  );
100 } ;
101 
102 
103 
104 
105 
111 {
112 public:
113  virtual ~cTerrainHeightGen() {} // Force a virtual destructor in descendants
114 
116  virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) = 0;
117 
119  virtual void InitializeHeightGen(cIniFile & a_IniFile) {}
120 
124  virtual HEIGHTTYPE GetHeightAt(int a_BlockX, int a_BlockZ)
125  {
126  auto chunkCoords = cChunkDef::BlockToChunk({a_BlockX, 0, a_BlockZ});
127  cChunkDef::HeightMap heightMap;
128  GenHeightMap(chunkCoords, heightMap);
129  return cChunkDef::GetHeight(heightMap, a_BlockX - chunkCoords.m_ChunkX * cChunkDef::Width, a_BlockZ - chunkCoords.m_ChunkZ * cChunkDef::Width);
130  }
131 
133  static std::unique_ptr<cTerrainHeightGen> CreateHeightGen(
134  cIniFile & a_IniFile,
135  cBiomeGen & a_BiomeGen,
136  int a_Seed,
137  bool & a_CacheOffByDefault
138  );
139 } ;
140 
141 
142 
143 
144 
151 {
152 public:
153  virtual ~cTerrainCompositionGen() {} // Force a virtual destructor in descendants
154 
157  virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) = 0;
158 
160  virtual void InitializeCompoGen(cIniFile & a_IniFile) {}
161 
165  static std::unique_ptr<cTerrainCompositionGen> CreateCompositionGen(
166  cIniFile & a_IniFile,
167  cBiomeGen & a_BiomeGen,
168  cTerrainShapeGen & a_ShapeGen,
169  int a_Seed
170  );
171 } ;
172 
173 
174 
175 
176 
185 {
186 public:
187  virtual ~cFinishGen() {} // Force a virtual destructor in descendants
188 
189  virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0;
190 } ;
191 
192 
193 
194 
195 
197  public cChunkGenerator
198 {
200 
201 public:
202 
204 
205  // cChunkGenerator::cGenerator overrides:
206  virtual void Initialize(cIniFile & a_IniFile) override;
207  virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
208  virtual void Generate(cChunkDesc & a_ChunkDesc) override;
209 
212  static void InitializeGeneratorDefaults(cIniFile & a_IniFile, eDimension a_Dimension);
213 
214 
215 protected:
216 
217  // The generator's composition:
219  std::unique_ptr<cBiomeGen> m_BiomeGen;
220 
222  std::unique_ptr<cTerrainShapeGen> m_ShapeGen;
223 
225  std::unique_ptr<cTerrainCompositionGen> m_CompositionGen;
226 
228  std::unique_ptr<cTerrainHeightGen> m_CompositedHeightCache;
229 
231  std::vector<std::unique_ptr<cFinishGen>> m_FinishGens;
232 
233 
235  void InitBiomeGen(cIniFile & a_IniFile);
236 
238  void InitShapeGen(cIniFile & a_IniFile);
239 
241  void InitCompositionGen(cIniFile & a_IniFile);
242 
244  void InitFinishGens(cIniFile & a_IniFile);
245 } ;
cComposableGenerator::Generate
virtual void Generate(cChunkDesc &a_ChunkDesc) override
Does the actual chunk generation.
Definition: ComposableGenerator.cpp:158
cChunkDesc
Definition: ChunkDesc.h:27
cComposableGenerator::m_CompositedHeightCache
std::unique_ptr< cTerrainHeightGen > m_CompositedHeightCache
The cache for the heights of the composited terrain.
Definition: ComposableGenerator.h:228
cBiomeGen::~cBiomeGen
virtual ~cBiomeGen()
Definition: ComposableGenerator.h:45
cChunkDef::Width
static const int Width
Definition: ChunkDef.h:107
cTerrainCompositionGen::ComposeTerrain
virtual void ComposeTerrain(cChunkDesc &a_ChunkDesc, const cChunkDesc::Shape &a_Shape)=0
Generates the chunk's composition into a_ChunkDesc, using the terrain shape provided in a_Shape.
cComposableGenerator::InitShapeGen
void InitShapeGen(cIniFile &a_IniFile)
Reads the ShapeGen settings from the ini and initializes m_ShapeGen accordingly.
Definition: ComposableGenerator.cpp:319
cBiomeGen::InitializeBiomeGen
virtual void InitializeBiomeGen(cIniFile &a_IniFile)
Reads parameters from the ini file, prepares generator for use.
Definition: ComposableGenerator.h:51
cTerrainCompositionGen::CreateCompositionGen
static std::unique_ptr< cTerrainCompositionGen > CreateCompositionGen(cIniFile &a_IniFile, cBiomeGen &a_BiomeGen, cTerrainShapeGen &a_ShapeGen, int a_Seed)
Creates the correct TerrainCompositionGen descendant based on the ini file settings and the seed prov...
Definition: ComposableGenerator.cpp:42
cBiomeGen::CreateBiomeGen
static std::unique_ptr< cBiomeGen > CreateBiomeGen(cIniFile &a_IniFile, int a_Seed, bool &a_CacheOffByDefault)
Creates the correct BiomeGen descendant based on the ini file settings.
Definition: BioGen.cpp:1136
cTerrainHeightGen::GenHeightMap
virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap &a_HeightMap)=0
Retrieves the heightmap for the specified chunk.
cChunkDef::BiomeMap
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:120
cComposableGenerator::m_BiomeGen
std::unique_ptr< cBiomeGen > m_BiomeGen
The biome generator.
Definition: ComposableGenerator.h:219
cChunkDesc::Shape
Byte Shape[256 *16 *16]
The datatype used to represent the entire chunk worth of shape.
Definition: ChunkDesc.h:36
cTerrainCompositionGen::~cTerrainCompositionGen
virtual ~cTerrainCompositionGen()
Definition: ComposableGenerator.h:153
cTerrainShapeGen::CreateShapeGen
static std::unique_ptr< cTerrainShapeGen > CreateShapeGen(cIniFile &a_IniFile, cBiomeGen &a_BiomeGen, int a_Seed, bool &a_CacheOffByDefault)
Creates the correct TerrainShapeGen descendant based on the ini file settings and the seed provided.
Definition: ShapeGen.cpp:78
cTerrainCompositionGen
The interface that a terrain composition generator must implement Terrain composition takes chunk coo...
Definition: ComposableGenerator.h:150
cChunkDef::BlockToChunk
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
Definition: ChunkDef.h:193
cBiomeGen::GenBiomes
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap)=0
Generates biomes for the given chunk.
cTerrainHeightGen::GetHeightAt
virtual HEIGHTTYPE GetHeightAt(int a_BlockX, int a_BlockZ)
Returns the height at the specified column.
Definition: ComposableGenerator.h:124
cComposableGenerator::m_CompositionGen
std::unique_ptr< cTerrainCompositionGen > m_CompositionGen
The terrain composition generator.
Definition: ComposableGenerator.h:225
cComposableGenerator
Definition: ComposableGenerator.h:196
ChunkGenerator.h
cTerrainHeightGen
The interface that is used to query terrain height from the shape generator.
Definition: ComposableGenerator.h:110
cFinishGen::GenFinish
virtual void GenFinish(cChunkDesc &a_ChunkDesc)=0
cBiomeGen
The interface that a biome generator must implement A biome generator takes chunk coords on input and...
Definition: ComposableGenerator.h:42
cTerrainShapeGen::GenShape
virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape &a_Shape)=0
Generates the shape for the given chunk.
cChunkDef::GetHeight
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
Definition: ChunkDef.h:286
cComposableGenerator::m_ShapeGen
std::unique_ptr< cTerrainShapeGen > m_ShapeGen
The terrain shape generator.
Definition: ComposableGenerator.h:222
cTerrainHeightGen::CreateHeightGen
static std::unique_ptr< cTerrainHeightGen > CreateHeightGen(cIniFile &a_IniFile, cBiomeGen &a_BiomeGen, int a_Seed, bool &a_CacheOffByDefault)
Creates a cTerrainHeightGen descendant based on the INI file settings.
Definition: HeiGen.cpp:835
HEIGHTTYPE
unsigned char HEIGHTTYPE
The type used by the heightmap.
Definition: ChunkDef.h:47
cFinishGen
The interface that a finisher must implement Finisher implements changes to the chunk after the rough...
Definition: ComposableGenerator.h:184
cTerrainShapeGen::~cTerrainShapeGen
virtual ~cTerrainShapeGen()
Definition: ComposableGenerator.h:81
ChunkDesc.h
cComposableGenerator::Initialize
virtual void Initialize(cIniFile &a_IniFile) override
Called to initialize the generator on server startup.
Definition: ComposableGenerator.cpp:129
cComposableGenerator::InitBiomeGen
void InitBiomeGen(cIniFile &a_IniFile)
Reads the BiomeGen settings from the ini and initializes m_BiomeGen accordingly.
Definition: ComposableGenerator.cpp:283
cComposableGenerator::InitCompositionGen
void InitCompositionGen(cIniFile &a_IniFile)
Reads the CompositionGen settings from the ini and initializes m_CompositionGen accordingly.
Definition: ComposableGenerator.cpp:352
cComposableGenerator::InitializeGeneratorDefaults
static void InitializeGeneratorDefaults(cIniFile &a_IniFile, eDimension a_Dimension)
If there's no particular sub-generator set in the INI file, adds the default one, based on the dimens...
Definition: ComposableGenerator.cpp:202
cComposableGenerator::InitFinishGens
void InitFinishGens(cIniFile &a_IniFile)
Reads the finishers from the ini and initializes m_FinishGens accordingly.
Definition: ComposableGenerator.cpp:378
cChunkDef::HeightMap
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
Definition: ChunkDef.h:115
eDimension
eDimension
Dimension of a world.
Definition: Defines.h:230
cIniFile
Definition: IniFile.h:33
cFinishGen::~cFinishGen
virtual ~cFinishGen()
Definition: ComposableGenerator.h:187
cChunkCoords
Definition: ChunkDef.h:55
cTerrainShapeGen::InitializeShapeGen
virtual void InitializeShapeGen(cIniFile &a_IniFile)
Reads parameters from the ini file, prepares generator for use.
Definition: ComposableGenerator.h:87
cComposableGenerator::GenerateBiomes
virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates the biomes for the specified chunk.
Definition: ComposableGenerator.cpp:146
cTerrainHeightGen::InitializeHeightGen
virtual void InitializeHeightGen(cIniFile &a_IniFile)
Initializes the generator, reading its parameters from the INI file.
Definition: ComposableGenerator.h:119
cTerrainHeightGen::~cTerrainHeightGen
virtual ~cTerrainHeightGen()
Definition: ComposableGenerator.h:113
cComposableGenerator::cComposableGenerator
cComposableGenerator()
Definition: ComposableGenerator.cpp:118
cChunkGenerator
The interface that all chunk generators must implement to provide the generated chunks.
Definition: ChunkGenerator.h:20
cComposableGenerator::m_FinishGens
std::vector< std::unique_ptr< cFinishGen > > m_FinishGens
The finisher generators, in the order in which they are applied.
Definition: ComposableGenerator.h:231
cTerrainShapeGen
The interface that a terrain shape generator must implement A terrain shape generator takes chunk coo...
Definition: ComposableGenerator.h:78
cTerrainCompositionGen::InitializeCompoGen
virtual void InitializeCompoGen(cIniFile &a_IniFile)
Reads parameters from the ini file, prepares generator for use.
Definition: ComposableGenerator.h:160