2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// BioGen.h
|
|
|
|
|
|
|
|
/*
|
|
|
|
Interfaces to the various biome generators:
|
|
|
|
- cBioGenConstant
|
|
|
|
- cBioGenCheckerboard
|
|
|
|
- cBioGenDistortedVoronoi
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-01-25 05:12:29 -05:00
|
|
|
#include "ComposableGenerator.h"
|
2014-11-18 06:07:08 -05:00
|
|
|
#include "../Noise/Noise.h"
|
2013-11-27 15:42:13 -05:00
|
|
|
#include "../VoronoiMap.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBioGenConstant :
|
|
|
|
public cBiomeGen
|
|
|
|
{
|
|
|
|
public:
|
2013-02-02 13:17:46 -05:00
|
|
|
cBioGenConstant(void) : m_Biome(biPlains) {}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
EMCSBiome m_Biome;
|
|
|
|
|
2013-02-02 13:17:46 -05:00
|
|
|
// cBiomeGen overrides:
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
2013-10-10 09:49:24 -04:00
|
|
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** A simple cache that stores N most recently generated chunks' biomes; N being settable upon creation */
|
2012-06-14 09:06:06 -04:00
|
|
|
class cBioGenCache :
|
|
|
|
public cBiomeGen
|
|
|
|
{
|
2013-02-02 13:17:46 -05:00
|
|
|
typedef cBiomeGen super;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
2015-05-19 06:50:59 -04:00
|
|
|
cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize);
|
2017-05-20 02:16:28 -04:00
|
|
|
virtual ~cBioGenCache() override;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
protected:
|
|
|
|
|
2014-10-19 08:01:59 -04:00
|
|
|
cBiomeGenPtr m_BioGenToCache;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
struct sCacheData
|
|
|
|
{
|
|
|
|
int m_ChunkX;
|
|
|
|
int m_ChunkZ;
|
|
|
|
cChunkDef::BiomeMap m_BiomeMap;
|
|
|
|
} ;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
// To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data
|
2015-05-19 06:50:59 -04:00
|
|
|
size_t m_CacheSize;
|
|
|
|
size_t * m_CacheOrder; // MRU-ized order, indices into m_CacheData array
|
2012-06-14 09:06:06 -04:00
|
|
|
sCacheData * m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
// Cache statistics
|
2015-07-07 05:50:06 -04:00
|
|
|
size_t m_NumHits;
|
|
|
|
size_t m_NumMisses;
|
|
|
|
size_t m_TotalChain; // Number of cache items walked to get to a hit (only added for hits)
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
2013-10-10 09:49:24 -04:00
|
|
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
2014-09-02 04:49:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-01 15:37:36 -04:00
|
|
|
class cBioGenMulticache :
|
|
|
|
public cBiomeGen
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef cBiomeGen super;
|
|
|
|
|
|
|
|
public:
|
2014-10-19 08:01:59 -04:00
|
|
|
/* Creates a new multicache - a cache that divides the caching into several sub-caches based on the chunk coords.
|
|
|
|
This allows us to use shorter cache depths with faster lookups for more covered area. (#381)
|
|
|
|
a_SubCacheSize defines the size of each sub-cache
|
|
|
|
a_NumSubCaches defines how many sub-caches are used for the multicache. */
|
|
|
|
cBioGenMulticache(cBiomeGenPtr a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches);
|
2014-09-01 15:37:36 -04:00
|
|
|
|
|
|
|
protected:
|
2014-10-19 08:01:59 -04:00
|
|
|
typedef std::vector<cBiomeGenPtr> cBiomeGenPtrs;
|
2014-09-05 16:07:13 -04:00
|
|
|
|
|
|
|
|
2014-10-19 08:01:59 -04:00
|
|
|
/** Number of sub-caches. Pulled out of m_Caches.size() for faster access. */
|
|
|
|
size_t m_NumSubCaches;
|
|
|
|
|
|
|
|
/** Individual sub-caches. */
|
|
|
|
cBiomeGenPtrs m_Caches;
|
2014-09-05 16:07:13 -04:00
|
|
|
|
2014-09-01 15:37:36 -04:00
|
|
|
|
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
|
|
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
|
|
|
};
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2014-09-02 04:49:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Base class for generators that use a list of available biomes. This class takes care of the list. */
|
2012-06-14 09:06:06 -04:00
|
|
|
class cBiomeGenList :
|
|
|
|
public cBiomeGen
|
|
|
|
{
|
2013-02-02 13:17:46 -05:00
|
|
|
typedef cBiomeGen super;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-02-02 13:17:46 -05:00
|
|
|
protected:
|
2012-06-14 09:06:06 -04:00
|
|
|
// List of biomes that the generator is allowed to generate:
|
|
|
|
typedef std::vector<EMCSBiome> EMCSBiomes;
|
|
|
|
EMCSBiomes m_Biomes;
|
|
|
|
int m_BiomesCount; // Pulled out of m_Biomes for faster access
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Parses the INI file setting string into m_Biomes. */
|
2012-06-14 09:06:06 -04:00
|
|
|
void InitializeBiomes(const AString & a_Biomes);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBioGenCheckerboard :
|
|
|
|
public cBiomeGenList
|
|
|
|
{
|
2013-02-02 13:17:46 -05:00
|
|
|
typedef cBiomeGenList super;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
protected:
|
|
|
|
int m_BiomeSize;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-02-02 13:17:46 -05:00
|
|
|
// cBiomeGen overrides:
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
2013-10-10 09:49:24 -04:00
|
|
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBioGenVoronoi :
|
|
|
|
public cBiomeGenList
|
|
|
|
{
|
2013-02-02 13:17:46 -05:00
|
|
|
typedef cBiomeGenList super;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
2013-02-02 13:17:46 -05:00
|
|
|
cBioGenVoronoi(int a_Seed) :
|
2013-11-27 15:42:13 -05:00
|
|
|
m_Voronoi(a_Seed)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
protected:
|
2013-11-27 15:42:13 -05:00
|
|
|
cVoronoiMap m_Voronoi;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-02-02 13:17:46 -05:00
|
|
|
// cBiomeGen overrides:
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
2013-10-10 09:49:24 -04:00
|
|
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
EMCSBiome VoronoiBiome(int a_BlockX, int a_BlockZ);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBioGenDistortedVoronoi :
|
2013-11-27 15:42:13 -05:00
|
|
|
public cBiomeGenList
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-11-27 15:42:13 -05:00
|
|
|
typedef cBiomeGenList super;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
2013-02-02 13:17:46 -05:00
|
|
|
cBioGenDistortedVoronoi(int a_Seed) :
|
2013-11-27 15:42:13 -05:00
|
|
|
m_Noise(a_Seed),
|
|
|
|
m_Voronoi(a_Seed),
|
|
|
|
m_CellSize(0)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Noise used for the distortion */
|
2013-11-27 15:42:13 -05:00
|
|
|
cNoise m_Noise;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The underlying Voronoi map of the biomes */
|
2013-11-27 15:42:13 -05:00
|
|
|
cVoronoiMap m_Voronoi;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Size of the Voronoi cells, also used for distortion amplitude */
|
2013-11-27 15:42:13 -05:00
|
|
|
int m_CellSize;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-02-02 13:17:46 -05:00
|
|
|
// cBiomeGen overrides:
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
2013-10-10 09:49:24 -04:00
|
|
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Distorts the coords using a Perlin-like noise */
|
2012-06-14 09:06:06 -04:00
|
|
|
void Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-24 07:15:36 -05:00
|
|
|
class cBioGenMultiStepMap :
|
|
|
|
public cBiomeGen
|
|
|
|
{
|
2013-02-02 13:17:46 -05:00
|
|
|
typedef cBiomeGen super;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-01-24 07:15:36 -05:00
|
|
|
public:
|
|
|
|
cBioGenMultiStepMap(int a_Seed);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-01-24 07:15:36 -05:00
|
|
|
protected:
|
2013-04-24 10:35:13 -04:00
|
|
|
// Noises used for composing the perlin-noise:
|
|
|
|
cNoise m_Noise1;
|
|
|
|
cNoise m_Noise2;
|
|
|
|
cNoise m_Noise3;
|
|
|
|
cNoise m_Noise4;
|
|
|
|
cNoise m_Noise5;
|
|
|
|
cNoise m_Noise6;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-01-24 07:15:36 -05:00
|
|
|
int m_Seed;
|
|
|
|
int m_OceanCellSize;
|
|
|
|
int m_MushroomIslandSize;
|
|
|
|
int m_RiverCellSize;
|
2013-03-24 12:07:51 -04:00
|
|
|
double m_RiverWidthThreshold;
|
|
|
|
float m_LandBiomesSize;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-03-24 12:07:51 -04:00
|
|
|
typedef int IntMap[17 * 17]; // x + 17 * z, expected trimmed into [0..255] range
|
|
|
|
typedef double DblMap[17 * 17]; // x + 17 * z, expected trimmed into [0..1] range
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-02-02 13:17:46 -05:00
|
|
|
// cBiomeGen overrides:
|
2013-01-24 07:15:36 -05:00
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
2013-10-10 09:49:24 -04:00
|
|
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-01-24 07:15:36 -05:00
|
|
|
/** Step 1: Decides between ocean, land and mushroom, using a DistVoronoi with special conditions and post-processing for mushroom islands
|
2015-07-31 10:49:10 -04:00
|
|
|
Sets biomes to biOcean, -1 (i.e. land), biMushroomIsland or biMushroomShore. */
|
2013-01-24 07:15:36 -05:00
|
|
|
void DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-01-24 07:15:36 -05:00
|
|
|
/** Step 2: Add rivers to the land
|
2015-07-31 10:49:10 -04:00
|
|
|
Flips some "-1" biomes into biRiver. */
|
2013-01-24 07:15:36 -05:00
|
|
|
void AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-02-02 13:17:46 -05:00
|
|
|
/** Step 3: Decide land biomes using a temperature / humidity map; freeze ocean / river in low temperatures.
|
2015-07-31 10:49:10 -04:00
|
|
|
Flips all remaining "-1" biomes into land biomes. Also flips some biOcean and biRiver into biFrozenOcean, biFrozenRiver, based on temp map. */
|
2013-01-24 07:15:36 -05:00
|
|
|
void ApplyTemperatureHumidity(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Distorts the coords using a Perlin-like noise, with a specified cell-size */
|
2013-01-24 07:15:36 -05:00
|
|
|
void Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ, int a_CellSize);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Builds two Perlin-noise maps, one for temperature, the other for humidity. Trims both into [0..255] range */
|
2013-01-24 07:15:36 -05:00
|
|
|
void BuildTemperatureHumidityMaps(int a_ChunkX, int a_ChunkZ, IntMap & a_TemperatureMap, IntMap & a_HumidityMap);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Flips all remaining "-1" biomes into land biomes using the two maps */
|
2013-01-24 07:15:36 -05:00
|
|
|
void DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap, const IntMap & a_HumidityMap);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Flips biOcean and biRiver into biFrozenOcean and biFrozenRiver if the temperature is too low */
|
2013-01-24 07:15:36 -05:00
|
|
|
void FreezeWaterBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-28 13:58:20 -05:00
|
|
|
|
|
|
|
class cBioGenTwoLevel :
|
|
|
|
public cBiomeGen
|
|
|
|
{
|
|
|
|
typedef cBiomeGen super;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-11-28 13:58:20 -05:00
|
|
|
public:
|
|
|
|
cBioGenTwoLevel(int a_Seed);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-11-28 13:58:20 -05:00
|
|
|
protected:
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The Voronoi map that decides the groups of biomes */
|
2013-11-28 13:58:20 -05:00
|
|
|
cVoronoiMap m_VoronoiLarge;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** The Voronoi map that decides biomes inside individual biome groups */
|
2013-11-28 13:58:20 -05:00
|
|
|
cVoronoiMap m_VoronoiSmall;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-09-27 16:01:47 -04:00
|
|
|
// The noises used for the distortion:
|
2014-06-20 11:10:18 -04:00
|
|
|
cNoise m_Noise1;
|
|
|
|
cNoise m_Noise2;
|
|
|
|
cNoise m_Noise3;
|
|
|
|
cNoise m_Noise4;
|
|
|
|
cNoise m_Noise5;
|
|
|
|
cNoise m_Noise6;
|
2013-11-28 13:58:20 -05:00
|
|
|
|
2014-09-27 16:01:47 -04:00
|
|
|
// Frequencies and amplitudes for the distortion noises:
|
|
|
|
float m_FreqX1, m_AmpX1;
|
|
|
|
float m_FreqX2, m_AmpX2;
|
|
|
|
float m_FreqX3, m_AmpX3;
|
|
|
|
float m_FreqZ1, m_AmpZ1;
|
|
|
|
float m_FreqZ2, m_AmpZ2;
|
|
|
|
float m_FreqZ3, m_AmpZ3;
|
|
|
|
|
2013-11-28 13:58:20 -05:00
|
|
|
|
|
|
|
// cBiomeGen overrides:
|
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
|
|
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) override;
|
|
|
|
|
2015-07-31 10:49:10 -04:00
|
|
|
/** Selects biome from the specified biome group, based on the specified index.
|
|
|
|
Note that both params may overflow
|
|
|
|
a_DistLevel is either 0 or 1; zero when it is at the edge of the small Voronoi cell, 1 near the center */
|
2015-05-19 06:50:59 -04:00
|
|
|
EMCSBiome SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel);
|
2013-11-28 13:58:20 -05:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|