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 
46  public cBiomeGen
47 {
48  using Super = cBiomeGen;
49 
50 public:
51 
52  cBioGenCache(cBiomeGen & a_BioGenToCache, size_t a_CacheSize);
53 
54 protected:
55 
56  friend class cBioGenMulticache;
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  using Super = cBiomeGen;
94 
95 public:
96  /* Creates a new multicache - a cache that divides the caching into several sub-caches based on the chunk coords.
97  This allows us to use shorter cache depths with faster lookups for more covered area. (#381)
98  a_SubCacheSize defines the size of each sub-cache
99  a_NumSubCaches defines how many sub-caches are used for the multicache. */
100  cBioGenMulticache(std::unique_ptr<cBiomeGen> a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches);
101 
102 protected:
103 
106 
108  std::vector<std::unique_ptr<cBioGenCache>> m_Caches;
109 
111  std::unique_ptr<cBiomeGen> m_Underlying;
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  using Super = cBiomeGen;
127 
128 protected:
129 
130  // List of biomes that the generator is allowed to generate:
131  typedef std::vector<EMCSBiome> EMCSBiomes;
133  int m_BiomesCount; // Pulled out of m_Biomes for faster access
134 
136  void InitializeBiomes(const AString & a_Biomes);
137 } ;
138 
139 
140 
141 
142 
144  public cBiomeGenList
145 {
147 
148 protected:
149 
151 
152  // cBiomeGen overrides:
153  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
154  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
155 } ;
156 
157 
158 
159 
160 
162  public cBiomeGenList
163 {
165 
166 public:
167 
168  cBioGenVoronoi(int a_Seed) :
169  m_Voronoi(a_Seed)
170  {
171  }
172 
173 protected:
174 
176 
177  // cBiomeGen overrides:
178  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
179  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
180 
181  EMCSBiome VoronoiBiome(int a_BlockX, int a_BlockZ);
182 } ;
183 
184 
185 
186 
187 
189  public cBiomeGenList
190 {
192 
193 public:
194 
196  m_Noise(a_Seed),
197  m_Voronoi(a_Seed),
198  m_CellSize(0)
199  {
200  }
201 
202 protected:
205 
208 
211 
212  // cBiomeGen overrides:
213  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
214  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
215 
217  void Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ);
218 } ;
219 
220 
221 
222 
223 
225  public cBiomeGen
226 {
227  using Super = cBiomeGen;
228 
229 public:
230 
231  cBioGenMultiStepMap(int a_Seed);
232 
233 protected:
234  // Noises used for composing the perlin-noise:
241 
242  int m_Seed;
248 
249  typedef int IntMap[17 * 17]; // x + 17 * z, expected trimmed into [0..255] range
250  typedef double DblMap[17 * 17]; // x + 17 * z, expected trimmed into [0..1] range
251 
252  // cBiomeGen overrides:
253  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
254  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
255 
258  void DecideOceanLandMushroom(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap);
259 
262  void AddRivers(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap);
263 
266  void ApplyTemperatureHumidity(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap);
267 
269  void Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ, int a_CellSize);
270 
272  void BuildTemperatureHumidityMaps(cChunkCoords a_ChunkCoords, IntMap & a_TemperatureMap, IntMap & a_HumidityMap);
273 
275  void DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap, const IntMap & a_HumidityMap);
276 
278  void FreezeWaterBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap);
279 } ;
280 
281 
282 
283 
284 
286  public cBiomeGen
287 {
288  using Super = cBiomeGen;
289 
290 public:
291 
292  cBioGenTwoLevel(int a_Seed);
293 
294 protected:
297 
300 
301  // The noises used for the distortion:
308 
309  // Frequencies and amplitudes for the distortion noises:
316 
317 
318  // cBiomeGen overrides:
319  virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
320  virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
321 
325  EMCSBiome SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel);
326 } ;
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:18
@ biPlains
Definition: BiomeDef.h:23
std::string AString
Definition: StringUtils.h:11
Wraps the chunk coords into a single structure.
Definition: ChunkDef.h:57
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:137
virtual void InitializeBiomeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
Definition: BioGen.cpp:33
EMCSBiome m_Biome
Definition: BioGen.h:33
cBioGenConstant(void)
Definition: BioGen.h:29
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates biomes for the given chunk.
Definition: BioGen.cpp:20
A simple cache that stores N most recently generated chunks' biomes; N being settable upon creation.
Definition: BioGen.h:47
std::vector< size_t > m_CacheOrder
Definition: BioGen.h:74
size_t m_NumHits
Definition: BioGen.h:78
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates biomes for the given chunk.
Definition: BioGen.cpp:78
virtual void InitializeBiomeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
Definition: BioGen.cpp:129
std::vector< sCacheData > m_CacheData
Definition: BioGen.h:75
size_t m_TotalChain
Definition: BioGen.h:80
size_t m_NumMisses
Definition: BioGen.h:79
cBiomeGen & m_BioGenToCache
Definition: BioGen.h:58
cBioGenCache(cBiomeGen &a_BioGenToCache, size_t a_CacheSize)
Definition: BioGen.cpp:59
size_t m_CacheSize
Definition: BioGen.h:73
cChunkDef::BiomeMap m_BiomeMap
Definition: BioGen.h:63
sCacheData()
Default constructor: Fill in bogus coords so that the item is not used in the cache until properly ca...
Definition: BioGen.h:66
cChunkCoords m_Coords
Definition: BioGen.h:62
std::vector< std::unique_ptr< cBioGenCache > > m_Caches
Individual sub-caches.
Definition: BioGen.h:108
std::unique_ptr< cBiomeGen > m_Underlying
The underlying biome generator.
Definition: BioGen.h:111
size_t m_NumSubCaches
Number of sub-caches.
Definition: BioGen.h:105
cBioGenMulticache(std::unique_ptr< cBiomeGen > a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches)
Definition: BioGen.cpp:141
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates biomes for the given chunk.
Definition: BioGen.cpp:156
virtual void InitializeBiomeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
Definition: BioGen.cpp:168
Base class for generators that use a list of available biomes.
Definition: BioGen.h:125
EMCSBiomes m_Biomes
Definition: BioGen.h:132
std::vector< EMCSBiome > EMCSBiomes
Definition: BioGen.h:131
void InitializeBiomes(const AString &a_Biomes)
Parses the INI file setting string into m_Biomes.
Definition: BioGen.cpp:183
int m_BiomesCount
Definition: BioGen.h:133
virtual void InitializeBiomeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
Definition: BioGen.cpp:281
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates biomes for the given chunk.
Definition: BioGen.cpp:263
cVoronoiMap m_Voronoi
Definition: BioGen.h:175
cBioGenVoronoi(int a_Seed)
Definition: BioGen.h:168
virtual void InitializeBiomeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
Definition: BioGen.cpp:316
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates biomes for the given chunk.
Definition: BioGen.cpp:297
EMCSBiome VoronoiBiome(int a_BlockX, int a_BlockZ)
virtual void InitializeBiomeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
Definition: BioGen.cpp:365
void Distort(int a_BlockX, int a_BlockZ, int &a_DistortedX, int &a_DistortedZ)
Distorts the coords using a Perlin-like noise.
Definition: BioGen.cpp:377
cVoronoiMap m_Voronoi
The underlying Voronoi map of the biomes.
Definition: BioGen.h:207
cBioGenDistortedVoronoi(int a_Seed)
Definition: BioGen.h:195
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates biomes for the given chunk.
Definition: BioGen.cpp:335
int m_CellSize
Size of the Voronoi cells, also used for distortion amplitude.
Definition: BioGen.h:210
cNoise m_Noise
Noise used for the distortion.
Definition: BioGen.h:204
void BuildTemperatureHumidityMaps(cChunkCoords a_ChunkCoords, IntMap &a_TemperatureMap, IntMap &a_HumidityMap)
Builds two Perlin-noise maps, one for temperature, the other for humidity.
Definition: BioGen.cpp:606
float m_LandBiomesSize
Definition: BioGen.h:247
void DecideOceanLandMushroom(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap)
Step 1: Decides between ocean, land and mushroom, using a DistVoronoi with special conditions and pos...
Definition: BioGen.cpp:441
double DblMap[17 *17]
Definition: BioGen.h:250
cBioGenMultiStepMap(int a_Seed)
Definition: BioGen.cpp:397
void Distort(int a_BlockX, int a_BlockZ, int &a_DistortedX, int &a_DistortedZ, int a_CellSize)
Distorts the coords using a Perlin-like noise, with a specified cell-size.
Definition: BioGen.cpp:589
int m_MushroomIslandSize
Definition: BioGen.h:244
double m_RiverWidthThreshold
Definition: BioGen.h:246
virtual void InitializeBiomeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
Definition: BioGen.cpp:417
void FreezeWaterBiomes(cChunkDef::BiomeMap &a_BiomeMap, const IntMap &a_TemperatureMap)
Flips biOcean and biRiver into biFrozenOcean and biFrozenRiver if the temperature is too low.
Definition: BioGen.cpp:688
void DecideLandBiomes(cChunkDef::BiomeMap &a_BiomeMap, const IntMap &a_TemperatureMap, const IntMap &a_HumidityMap)
Flips all remaining "-1" biomes into land biomes using the two maps.
Definition: BioGen.cpp:644
int IntMap[17 *17]
Definition: BioGen.h:249
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates biomes for the given chunk.
Definition: BioGen.cpp:430
void AddRivers(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap)
Step 2: Add rivers to the land Flips some "-1" biomes into biRiver.
Definition: BioGen.cpp:544
void ApplyTemperatureHumidity(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap)
Step 3: Decide land biomes using a temperature / humidity map; freeze ocean / river in low temperatur...
Definition: BioGen.cpp:575
float m_AmpZ1
Definition: BioGen.h:313
float m_AmpX2
Definition: BioGen.h:311
float m_AmpZ2
Definition: BioGen.h:314
cBioGenTwoLevel(int a_Seed)
Definition: BioGen.cpp:718
float m_FreqZ2
Definition: BioGen.h:314
cNoise m_Noise6
Definition: BioGen.h:307
cVoronoiMap m_VoronoiSmall
The Voronoi map that decides biomes inside individual biome groups.
Definition: BioGen.h:299
cNoise m_Noise5
Definition: BioGen.h:306
EMCSBiome SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel)
Selects biome from the specified biome group, based on the specified index.
Definition: BioGen.cpp:790
cNoise m_Noise1
Definition: BioGen.h:302
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap) override
Generates biomes for the given chunk.
Definition: BioGen.cpp:746
float m_AmpX3
Definition: BioGen.h:312
float m_AmpX1
Definition: BioGen.h:310
cNoise m_Noise2
Definition: BioGen.h:303
cNoise m_Noise4
Definition: BioGen.h:305
float m_FreqZ1
Definition: BioGen.h:313
float m_FreqX3
Definition: BioGen.h:312
float m_AmpZ3
Definition: BioGen.h:315
float m_FreqZ3
Definition: BioGen.h:315
cVoronoiMap m_VoronoiLarge
The Voronoi map that decides the groups of biomes.
Definition: BioGen.h:296
float m_FreqX1
Definition: BioGen.h:310
cNoise m_Noise3
Definition: BioGen.h:304
virtual void InitializeBiomeGen(cIniFile &a_IniFile) override
Reads parameters from the ini file, prepares generator for use.
Definition: BioGen.cpp:903
float m_FreqX2
Definition: BioGen.h:311
The interface that a biome generator must implement A biome generator takes chunk coords on input and...
Definition: Noise.h:20