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 typedef std::shared_ptr<cBiomeGen> cBiomeGenPtr;
34 typedef std::shared_ptr<cTerrainShapeGen> cTerrainShapeGenPtr;
35 typedef std::shared_ptr<cTerrainHeightGen> cTerrainHeightGenPtr;
36 typedef std::shared_ptr<cTerrainCompositionGen> cTerrainCompositionGenPtr;
37 typedef std::shared_ptr<cFinishGen> cFinishGenPtr;
38 
39 
40 
41 
42 
47 class cBiomeGen
48 {
49 public:
50  virtual ~cBiomeGen() {} // Force a virtual destructor in descendants
51 
53  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) = 0;
54 
56  virtual void InitializeBiomeGen(cIniFile & a_IniFile) {}
57 
64  cIniFile & a_IniFile,
65  int a_Seed,
66  bool & a_CacheOffByDefault
67  );
68 } ;
69 
70 
71 
72 
73 
84 {
85 public:
86  virtual ~cTerrainShapeGen() {} // Force a virtual destructor in descendants
87 
89  virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) = 0;
90 
92  virtual void InitializeShapeGen(cIniFile & a_IniFile) {}
93 
99  static cTerrainShapeGenPtr CreateShapeGen(
100  cIniFile & a_IniFile,
101  cBiomeGenPtr a_BiomeGen,
102  int a_Seed,
103  bool & a_CacheOffByDefault
104  );
105 } ;
106 
107 
108 
109 
110 
116 {
117 public:
118  virtual ~cTerrainHeightGen() {} // Force a virtual destructor in descendants
119 
121  virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) = 0;
122 
124  virtual void InitializeHeightGen(cIniFile & a_IniFile) {}
125 
129  virtual HEIGHTTYPE GetHeightAt(int a_BlockX, int a_BlockZ)
130  {
131  auto chunkCoords = cChunkDef::BlockToChunk({a_BlockX, 0, a_BlockZ});
132  cChunkDef::HeightMap heightMap;
133  GenHeightMap(chunkCoords, heightMap);
134  return cChunkDef::GetHeight(heightMap, a_BlockX - chunkCoords.m_ChunkX * cChunkDef::Width, a_BlockZ - chunkCoords.m_ChunkZ * cChunkDef::Width);
135  }
136 
138  static cTerrainHeightGenPtr CreateHeightGen(
139  cIniFile & a_IniFile,
140  cBiomeGenPtr a_BiomeGen,
141  int a_Seed,
142  bool & a_CacheOffByDefault
143  );
144 } ;
145 
146 
147 
148 
149 
156 {
157 public:
158  virtual ~cTerrainCompositionGen() {} // Force a virtual destructor in descendants
159 
162  virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) = 0;
163 
165  virtual void InitializeCompoGen(cIniFile & a_IniFile) {}
166 
170  static cTerrainCompositionGenPtr CreateCompositionGen(
171  cIniFile & a_IniFile,
172  cBiomeGenPtr a_BiomeGen,
173  cTerrainShapeGenPtr a_ShapeGen,
174  int a_Seed
175  );
176 } ;
177 
178 
179 
180 
181 
190 {
191 public:
192  virtual ~cFinishGen() {} // Force a virtual destructor in descendants
193 
194  virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0;
195 } ;
196 
197 typedef std::list<cFinishGenPtr> cFinishGenList;
198 
199 
200 
201 
202 
204  public cChunkGenerator
205 {
207 
208 public:
210 
211  // cChunkGenerator::cGenerator overrides:
212  virtual void Initialize(cIniFile & a_IniFile) override;
213  virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
214  virtual void Generate(cChunkDesc & a_ChunkDesc) override;
215 
218  static void InitializeGeneratorDefaults(cIniFile & a_IniFile, eDimension a_Dimension);
219 
220 
221 protected:
222 
223  // The generator's composition:
226 
229 
232 
235 
238 
239 
241  void InitBiomeGen(cIniFile & a_IniFile);
242 
244  void InitShapeGen(cIniFile & a_IniFile);
245 
247  void InitCompositionGen(cIniFile & a_IniFile);
248 
250  void InitFinishGens(cIniFile & a_IniFile);
251 } ;
252 
253 
254 
255 
virtual ~cFinishGen()
Byte Shape[256 *16 *16]
The datatype used to represent the entire chunk worth of shape.
Definition: ChunkDesc.h:36
eDimension
Dimension of a world.
Definition: BlockID.h:1127
std::shared_ptr< cFinishGen > cFinishGenPtr
std::shared_ptr< cTerrainHeightGen > cTerrainHeightGenPtr
static const int Width
Definition: ChunkDef.h:134
The interface that is used to query terrain height from the shape generator.
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
Definition: ChunkDef.h:351
static cBiomeGenPtr 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
std::shared_ptr< cTerrainCompositionGen > cTerrainCompositionGenPtr
virtual void InitializeHeightGen(cIniFile &a_IniFile)
Initializes the generator, reading its parameters from the INI file.
cTerrainHeightGenPtr m_CompositedHeightCache
The cache for the heights of the composited terrain.
unsigned char HEIGHTTYPE
The type used by the heightmap.
Definition: ChunkDef.h:48
cBiomeGenPtr m_BiomeGen
The biome generator.
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:234
std::list< cFinishGenPtr > cFinishGenList
virtual void InitializeCompoGen(cIniFile &a_IniFile)
Reads parameters from the ini file, prepares generator for use.
std::shared_ptr< cTerrainShapeGen > cTerrainShapeGenPtr
The interface that a terrain composition generator must implement Terrain composition takes chunk coo...
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap)=0
Generates biomes for the given chunk.
cFinishGenList m_FinishGens
The finisher generators, in the order in which they are applied.
The interface that a terrain shape generator must implement A terrain shape generator takes chunk coo...
cTerrainShapeGenPtr m_ShapeGen
The terrain shape generator.
virtual void InitializeShapeGen(cIniFile &a_IniFile)
Reads parameters from the ini file, prepares generator for use.
virtual void InitializeBiomeGen(cIniFile &a_IniFile)
Reads parameters from the ini file, prepares generator for use.
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:142
cTerrainCompositionGenPtr m_CompositionGen
The terrain composition generator.
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:147
The interface that a finisher must implement Finisher implements changes to the chunk after the rough...
virtual HEIGHTTYPE GetHeightAt(int a_BlockX, int a_BlockZ)
Returns the height at the specified column.
virtual ~cBiomeGen()
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...
std::shared_ptr< cBiomeGen > cBiomeGenPtr