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"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "../Noise.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) {}
|
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-02-02 13:17:46 -05:00
|
|
|
virtual void Initialize(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// A simple cache that stores N most recently generated chunks' biomes; N being settable upon creation
|
|
|
|
class cBioGenCache :
|
|
|
|
public cBiomeGen
|
|
|
|
{
|
2013-02-02 13:17:46 -05:00
|
|
|
typedef cBiomeGen super;
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
|
|
|
cBioGenCache(cBiomeGen * a_BioGenToCache, int a_CacheSize); // Takes ownership of a_BioGenToCache
|
|
|
|
~cBioGenCache();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
cBiomeGen * m_BioGenToCache;
|
|
|
|
|
|
|
|
struct sCacheData
|
|
|
|
{
|
|
|
|
int m_ChunkX;
|
|
|
|
int m_ChunkZ;
|
|
|
|
cChunkDef::BiomeMap m_BiomeMap;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
// To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data
|
|
|
|
int m_CacheSize;
|
|
|
|
int * m_CacheOrder; // MRU-ized order, indices into m_CacheData array
|
|
|
|
sCacheData * m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used
|
|
|
|
|
|
|
|
// Cache statistics
|
|
|
|
int m_NumHits;
|
|
|
|
int m_NumMisses;
|
|
|
|
int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits)
|
|
|
|
|
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
2013-02-02 13:17:46 -05:00
|
|
|
virtual void Initialize(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Base class for generators that use a list of available biomes. This class takes care of the list.
|
|
|
|
class cBiomeGenList :
|
|
|
|
public cBiomeGen
|
|
|
|
{
|
2013-02-02 13:17:46 -05:00
|
|
|
typedef cBiomeGen super;
|
2012-06-14 09:06:06 -04: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
|
|
|
|
|
2012-11-20 14:45:28 -05: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;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_BiomeSize;
|
|
|
|
|
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-02-02 13:17:46 -05:00
|
|
|
virtual void Initialize(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;
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
2013-02-02 13:17:46 -05:00
|
|
|
cBioGenVoronoi(int a_Seed) :
|
2012-06-14 09:06:06 -04:00
|
|
|
m_Noise(a_Seed)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_CellSize;
|
|
|
|
|
|
|
|
cNoise m_Noise;
|
|
|
|
|
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-02-02 13:17:46 -05:00
|
|
|
virtual void Initialize(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
EMCSBiome VoronoiBiome(int a_BlockX, int a_BlockZ);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBioGenDistortedVoronoi :
|
|
|
|
public cBioGenVoronoi
|
|
|
|
{
|
2013-02-02 13:17:46 -05:00
|
|
|
typedef cBioGenVoronoi super;
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
2013-02-02 13:17:46 -05:00
|
|
|
cBioGenDistortedVoronoi(int a_Seed) :
|
|
|
|
cBioGenVoronoi(a_Seed)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
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-02-02 13:17:46 -05:00
|
|
|
virtual void Initialize(cIniFile & a_IniFile) override;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
/// Distorts the coords using a Perlin-like noise
|
|
|
|
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;
|
|
|
|
|
2013-01-24 07:15:36 -05:00
|
|
|
public:
|
|
|
|
cBioGenMultiStepMap(int a_Seed);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
cNoise m_Noise;
|
|
|
|
int m_Seed;
|
|
|
|
int m_OceanCellSize;
|
|
|
|
int m_MushroomIslandSize;
|
|
|
|
int m_RiverCellSize;
|
|
|
|
float m_RiverWidthThreshold;
|
|
|
|
float m_LandBiomesSize;
|
|
|
|
|
|
|
|
typedef int IntMap[256]; // x + 16 * z, expected trimmed into [0..255] range
|
|
|
|
|
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-02-02 13:17:46 -05:00
|
|
|
virtual void Initialize(cIniFile & a_IniFile) override;
|
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
|
|
|
|
Sets biomes to biOcean, -1 (i.e. land), biMushroomIsland or biMushroomShore
|
|
|
|
*/
|
|
|
|
void DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap);
|
|
|
|
|
|
|
|
/** Step 2: Add rivers to the land
|
|
|
|
Flips some "-1" biomes into biRiver
|
|
|
|
*/
|
|
|
|
void AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap);
|
|
|
|
|
2013-02-02 13:17:46 -05:00
|
|
|
/** Step 3: Decide land biomes using a temperature / humidity map; freeze ocean / river in low temperatures.
|
2013-01-24 07:15:36 -05:00
|
|
|
Flips all remaining "-1" biomes into land biomes. Also flips some biOcean and biRiver into biFrozenOcean, biFrozenRiver, based on temp map.
|
|
|
|
*/
|
|
|
|
void ApplyTemperatureHumidity(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap);
|
|
|
|
|
|
|
|
/// Distorts the coords using a Perlin-like noise, with a specified cell-size
|
|
|
|
void Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ, int a_CellSize);
|
|
|
|
|
|
|
|
/// Builds two Perlin-noise maps, one for temperature, the other for humidity. Trims both into [0..255] range
|
|
|
|
void BuildTemperatureHumidityMaps(int a_ChunkX, int a_ChunkZ, IntMap & a_TemperatureMap, IntMap & a_HumidityMap);
|
|
|
|
|
|
|
|
/// Flips all remaining "-1" biomes into land biomes using the two maps
|
|
|
|
void DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap, const IntMap & a_HumidityMap);
|
|
|
|
|
|
|
|
/// Flips biOcean and biRiver into biFrozenOcean and biFrozenRiver if the temperature is too low
|
|
|
|
void FreezeWaterBiomes(cChunkDef::BiomeMap & a_BiomeMap, const IntMap & a_TemperatureMap);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|