Cuberite
A lightweight, fast and extensible game server for Minecraft
BioGen.h
Go to the documentation of this file.
1 
2 // BioGen.h
3 
4 /*
5 Interfaces to the various biome generators:
6  - cBioGenConstant
7  - cBioGenCheckerboard
8  - cBioGenDistortedVoronoi
9 */
10 
11 
12 
13 
14 
15 #pragma once
16 
17 #include "ComposableGenerator.h"
18 #include "../Noise/Noise.h"
19 #include "../VoronoiMap.h"
20 
21 
22 
23 
24 
26  public cBiomeGen
27 {
28 public:
30 
31 protected:
32 
34 
35  // cBiomeGen overrides:
36  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
37  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
38 } ;
39 
40 
41 
42 
43 
45 class cBioGenCache :
46  public cBiomeGen
47 {
48  typedef cBiomeGen super;
49 
50 public:
51 
52  cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize);
53  virtual ~cBioGenCache() override = default;
54 
55 
56 protected:
57 
59 
60  struct sCacheData
61  {
64 
67  m_Coords(0x7fffffff, 0x7fffffff)
68  {
69  }
70  } ;
71 
72  // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data
73  size_t m_CacheSize;
74  std::vector<size_t> m_CacheOrder; // MRU-ized order, indices into m_CacheData array
75  std::vector<sCacheData> m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used
76 
77  // Cache statistics
78  size_t m_NumHits;
79  size_t m_NumMisses;
80  size_t m_TotalChain; // Number of cache items walked to get to a hit (only added for hits)
81 
82  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
83  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
84 } ;
85 
86 
87 
88 
89 
91  public cBiomeGen
92 {
93 
94  typedef cBiomeGen super;
95 
96 public:
97  /* Creates a new multicache - a cache that divides the caching into several sub-caches based on the chunk coords.
98  This allows us to use shorter cache depths with faster lookups for more covered area. (#381)
99  a_SubCacheSize defines the size of each sub-cache
100  a_NumSubCaches defines how many sub-caches are used for the multicache. */
101  cBioGenMulticache(cBiomeGenPtr a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches);
102 
103 protected:
104  typedef std::vector<cBiomeGenPtr> cBiomeGenPtrs;
105 
106 
109 
111  cBiomeGenPtrs m_Caches;
112 
113 
114  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
115  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
116 };
117 
118 
119 
120 
121 
124  public cBiomeGen
125 {
126  typedef cBiomeGen super;
127 
128 protected:
129  // List of biomes that the generator is allowed to generate:
130  typedef std::vector<EMCSBiome> EMCSBiomes;
131  EMCSBiomes m_Biomes;
132  int m_BiomesCount; // Pulled out of m_Biomes for faster access
133 
135  void InitializeBiomes(const AString & a_Biomes);
136 } ;
137 
138 
139 
140 
141 
143  public cBiomeGenList
144 {
146 
147 protected:
149 
150  // cBiomeGen overrides:
151  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
152  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
153 } ;
154 
155 
156 
157 
158 
160  public cBiomeGenList
161 {
163 
164 public:
165  cBioGenVoronoi(int a_Seed) :
166  m_Voronoi(a_Seed)
167  {
168  }
169 
170 protected:
172 
173  // cBiomeGen overrides:
174  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
175  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
176 
177  EMCSBiome VoronoiBiome(int a_BlockX, int a_BlockZ);
178 } ;
179 
180 
181 
182 
183 
185  public cBiomeGenList
186 {
188 
189 public:
191  m_Noise(a_Seed),
192  m_Voronoi(a_Seed),
193  m_CellSize(0)
194  {
195  }
196 
197 protected:
200 
203 
206 
207  // cBiomeGen overrides:
208  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
209  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
210 
212  void Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ);
213 } ;
214 
215 
216 
217 
218 
220  public cBiomeGen
221 {
222  typedef cBiomeGen super;
223 
224 public:
225  cBioGenMultiStepMap(int a_Seed);
226 
227 protected:
228  // Noises used for composing the perlin-noise:
235 
236  int m_Seed;
242 
243  typedef int IntMap[17 * 17]; // x + 17 * z, expected trimmed into [0..255] range
244  typedef double DblMap[17 * 17]; // x + 17 * z, expected trimmed into [0..1] range
245 
246  // cBiomeGen overrides:
247  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
248  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
249 
252  void DecideOceanLandMushroom(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap);
253 
256  void AddRivers(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap);
257 
260  void ApplyTemperatureHumidity(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap);
261 
263  void Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ, int a_CellSize);
264 
266  void BuildTemperatureHumidityMaps(cChunkCoords a_ChunkCoords, IntMap & a_TemperatureMap, IntMap & a_HumidityMap);
267 
269  void DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap, const IntMap & a_HumidityMap);
270 
272  void FreezeWaterBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap);
273 } ;
274 
275 
276 
277 
278 
280  public cBiomeGen
281 {
282  typedef cBiomeGen super;
283 
284 public:
285  cBioGenTwoLevel(int a_Seed);
286 
287 protected:
290 
293 
294  // The noises used for the distortion:
301 
302  // Frequencies and amplitudes for the distortion noises:
303  float m_FreqX1, m_AmpX1;
304  float m_FreqX2, m_AmpX2;
305  float m_FreqX3, m_AmpX3;
306  float m_FreqZ1, m_AmpZ1;
307  float m_FreqZ2, m_AmpZ2;
308  float m_FreqZ3, m_AmpZ3;
309 
310 
311  // cBiomeGen overrides:
312  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
313  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
314 
318  EMCSBiome SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel);
319 } ;
320 
321 
322 
323 
cBiomeGenList super
Definition: BioGen.h:162
float m_FreqZ1
Definition: BioGen.h:306
float m_FreqZ3
Definition: BioGen.h:308
cNoise m_Noise1
Definition: BioGen.h:295
cVoronoiMap m_VoronoiSmall
The Voronoi map that decides biomes inside individual biome groups.
Definition: BioGen.h:292
cBiomeGen super
Definition: BioGen.h:126
std::vector< sCacheData > m_CacheData
Definition: BioGen.h:75
size_t m_NumHits
Definition: BioGen.h:78
int m_CellSize
Size of the Voronoi cells, also used for distortion amplitude.
Definition: BioGen.h:205
cBiomeGenList super
Definition: BioGen.h:145
cVoronoiMap m_Voronoi
The underlying Voronoi map of the biomes.
Definition: BioGen.h:202
int m_BiomesCount
Definition: BioGen.h:132
size_t m_NumSubCaches
Number of sub-caches.
Definition: BioGen.h:108
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates biomes for the given chunk.
Definition: BioGen.cpp:21
size_t m_NumMisses
Definition: BioGen.h:79
cNoise m_Noise2
Definition: BioGen.h:296
cBiomeGen super
Definition: BioGen.h:222
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:21
cNoise m_Noise6
Definition: BioGen.h:300
std::vector< EMCSBiome > EMCSBiomes
Definition: BioGen.h:130
EMCSBiomes m_Biomes
Definition: BioGen.h:131
double m_RiverWidthThreshold
Definition: BioGen.h:240
size_t m_CacheSize
Definition: BioGen.h:73
sCacheData()
Default constructor: Fill in bogus coords so that the item is not used in the cache until properly ca...
Definition: BioGen.h:66
cChunkDef::BiomeMap m_BiomeMap
Definition: BioGen.h:63
cChunkCoords m_Coords
Definition: BioGen.h:62
cNoise m_Noise4
Definition: BioGen.h:298
float m_FreqZ2
Definition: BioGen.h:307
cNoise m_Noise
Noise used for the distortion.
Definition: BioGen.h:199
cBiomeGen super
Definition: BioGen.h:48
cBiomeGenPtrs m_Caches
Individual sub-caches.
Definition: BioGen.h:111
cBiomeGenPtr m_BioGenToCache
Definition: BioGen.h:58
float m_FreqX3
Definition: BioGen.h:305
cBiomeGen super
Definition: BioGen.h:94
Base class for generators that use a list of available biomes.
Definition: BioGen.h:123
A simple cache that stores N most recently generated chunks&#39; biomes; N being settable upon creation...
Definition: BioGen.h:45
Definition: Noise.h:19
std::vector< cBiomeGenPtr > cBiomeGenPtrs
Definition: BioGen.h:104
std::string AString
Definition: StringUtils.h:13
cBioGenVoronoi(int a_Seed)
Definition: BioGen.h:165
cNoise m_Noise5
Definition: BioGen.h:299
cBiomeGenList super
Definition: BioGen.h:187
cVoronoiMap m_Voronoi
Definition: BioGen.h:171
cBioGenConstant(void)
Definition: BioGen.h:29
virtual void InitializeBiomeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
Definition: BioGen.cpp:34
cBioGenDistortedVoronoi(int a_Seed)
Definition: BioGen.h:190
cNoise m_Noise3
Definition: BioGen.h:297
cVoronoiMap m_VoronoiLarge
The Voronoi map that decides the groups of biomes.
Definition: BioGen.h:289
EMCSBiome m_Biome
Definition: BioGen.h:33
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:147
float m_LandBiomesSize
Definition: BioGen.h:241
int m_MushroomIslandSize
Definition: BioGen.h:238
size_t m_TotalChain
Definition: BioGen.h:80
float m_FreqX1
Definition: BioGen.h:303
float m_FreqX2
Definition: BioGen.h:304
cBiomeGen super
Definition: BioGen.h:282
std::vector< size_t > m_CacheOrder
Definition: BioGen.h:74
The interface that a biome generator must implement A biome generator takes chunk coords on input and...
std::shared_ptr< cBiomeGen > cBiomeGenPtr