2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
// ComposableGenerator.h
|
|
|
|
|
|
|
|
// Declares the cComposableGenerator class representing the chunk generator that takes the composition approach to generating chunks
|
|
|
|
|
|
|
|
/*
|
|
|
|
Generating works by composing several algorithms:
|
|
|
|
Biome, TerrainHeight, TerrainComposition, Ores, Structures and SmallFoliage
|
|
|
|
Each algorithm may be chosen from a pool of available algorithms in the same class and combined with others,
|
|
|
|
based on user's preferences in the world.ini.
|
|
|
|
See http://forum.mc-server.org/showthread.php?tid=409 for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ChunkGenerator.h"
|
|
|
|
#include "ChunkDesc.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-19 08:01:59 -04:00
|
|
|
// Forward-declare the shared pointers to subgenerator classes:
|
|
|
|
class cBiomeGen;
|
2014-11-12 15:24:26 -05:00
|
|
|
class cTerrainShapeGen;
|
2014-10-19 08:01:59 -04:00
|
|
|
class cTerrainHeightGen;
|
|
|
|
class cTerrainCompositionGen;
|
|
|
|
class cFinishGen;
|
|
|
|
typedef SharedPtr<cBiomeGen> cBiomeGenPtr;
|
2014-11-12 15:24:26 -05:00
|
|
|
typedef SharedPtr<cTerrainShapeGen> cTerrainShapeGenPtr;
|
2014-10-19 08:01:59 -04:00
|
|
|
typedef SharedPtr<cTerrainHeightGen> cTerrainHeightGenPtr;
|
|
|
|
typedef SharedPtr<cTerrainCompositionGen> cTerrainCompositionGenPtr;
|
|
|
|
typedef SharedPtr<cFinishGen> cFinishGenPtr;
|
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** The interface that a biome generator must implement
|
|
|
|
A biome generator takes chunk coords on input and outputs an array of biome indices for that chunk on output.
|
|
|
|
The output array is sequenced in the same way as the MapChunk packet's biome data.
|
|
|
|
*/
|
|
|
|
class cBiomeGen
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~cBiomeGen() {} // Force a virtual destructor in descendants
|
|
|
|
|
2014-03-01 14:56:09 -05:00
|
|
|
/** Generates biomes for the given chunk */
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) = 0;
|
|
|
|
|
2014-03-01 14:56:09 -05:00
|
|
|
/** Reads parameters from the ini file, prepares generator for use. */
|
2013-10-10 09:49:24 -04:00
|
|
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) {}
|
2013-11-28 14:15:52 -05:00
|
|
|
|
2014-03-01 14:56:09 -05:00
|
|
|
/** Creates the correct BiomeGen descendant based on the ini file settings and the seed provided.
|
|
|
|
a_CacheOffByDefault gets set to whether the cache should be disabled by default.
|
|
|
|
Used in BiomeVisualiser, too.
|
|
|
|
Implemented in BioGen.cpp! */
|
2014-10-19 08:01:59 -04:00
|
|
|
static cBiomeGenPtr CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault);
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-11-12 15:24:26 -05:00
|
|
|
/** The interface that a terrain shape generator must implement
|
|
|
|
A terrain shape generator takes chunk coords on input and outputs a 3D array of "shape" for that chunk. The shape here
|
|
|
|
represents the distinction between air and solid; there's no representation of Water since that is added by the
|
|
|
|
composition geenrator.
|
|
|
|
The output array is indexed [y + 256 * z + 16 * 256 * x], so that it's fast to later compose a single column of the terrain,
|
|
|
|
which is the dominant operation following the shape generation.
|
2013-07-29 07:13:03 -04:00
|
|
|
The generator may request biome information from the underlying BiomeGen, it may even request information for
|
2014-11-12 15:24:26 -05:00
|
|
|
other chunks than the one it's currently generating (neighbors - for averaging)
|
2013-07-29 07:13:03 -04:00
|
|
|
*/
|
2014-11-12 15:24:26 -05:00
|
|
|
class cTerrainShapeGen
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
public:
|
2014-11-12 15:24:26 -05:00
|
|
|
virtual ~cTerrainShapeGen() {} // Force a virtual destructor in descendants
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2014-11-12 15:24:26 -05:00
|
|
|
/** Generates the shape for the given chunk */
|
|
|
|
virtual void GenShape(int a_ChunkX, int a_ChunkZ, cChunkDesc::Shape & a_Shape) = 0;
|
2013-10-11 04:18:01 -04:00
|
|
|
|
2014-03-01 14:56:09 -05:00
|
|
|
/** Reads parameters from the ini file, prepares generator for use. */
|
2014-11-12 15:24:26 -05:00
|
|
|
virtual void InitializeShapeGen(cIniFile & a_IniFile) {}
|
2014-01-09 04:21:26 -05:00
|
|
|
|
2014-11-12 15:24:26 -05:00
|
|
|
/** Creates the correct TerrainShapeGen descendant based on the ini file settings and the seed provided.
|
|
|
|
a_BiomeGen is the underlying biome generator, some shape generators may depend on it providing additional biomes data around the chunk
|
2014-01-09 04:21:26 -05:00
|
|
|
a_CacheOffByDefault gets set to whether the cache should be disabled by default
|
2014-11-12 15:24:26 -05:00
|
|
|
Implemented in ShapeGen.cpp!
|
2014-01-09 04:21:26 -05:00
|
|
|
*/
|
2014-11-12 15:24:26 -05:00
|
|
|
static cTerrainShapeGenPtr CreateShapeGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** The interface that is used to query terrain height from the shape generator.
|
|
|
|
Usually the structure generators require only the final heightmap, and generating the whole shape only to
|
|
|
|
consume the heightmap is wasteful, so this interface is used instead; it has a cache implemented over it so
|
|
|
|
that data is retained. */
|
|
|
|
class cTerrainHeightGen
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~cTerrainHeightGen() {} // Force a virtual destructor in descendants
|
|
|
|
|
|
|
|
/** Retrieves the heightmap for the specified chunk. */
|
|
|
|
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) = 0;
|
|
|
|
|
|
|
|
/** Initializes the generator, reading its parameters from the INI file. */
|
|
|
|
virtual void InitializeHeightGen(cIniFile & a_IniFile) {}
|
|
|
|
|
|
|
|
/** Creates a cTerrainHeightGen descendant based on the INI file settings. */
|
2014-10-19 08:01:59 -04:00
|
|
|
static cTerrainHeightGenPtr CreateHeightGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault);
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** The interface that a terrain composition generator must implement
|
|
|
|
Terrain composition takes chunk coords on input and outputs the blockdata for that entire chunk, along with
|
|
|
|
the list of entities. It is supposed to make use of the underlying TerrainHeightGen and BiomeGen for that purpose,
|
|
|
|
but it may request information for other chunks than the one it's currently generating from them.
|
|
|
|
*/
|
|
|
|
class cTerrainCompositionGen
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~cTerrainCompositionGen() {} // Force a virtual destructor in descendants
|
|
|
|
|
2014-11-12 15:24:26 -05:00
|
|
|
/** Generates the chunk's composition into a_ChunkDesc, using the terrain shape provided in a_Shape.
|
|
|
|
Is expected to fill a_ChunkDesc's heightmap with the data from a_Shape. */
|
|
|
|
virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc, const cChunkDesc::Shape & a_Shape) = 0;
|
2013-10-11 04:18:01 -04:00
|
|
|
|
2014-03-01 14:56:09 -05:00
|
|
|
/** Reads parameters from the ini file, prepares generator for use. */
|
2013-10-11 04:18:01 -04:00
|
|
|
virtual void InitializeCompoGen(cIniFile & a_IniFile) {}
|
2014-01-09 04:35:51 -05:00
|
|
|
|
|
|
|
/** Creates the correct TerrainCompositionGen descendant based on the ini file settings and the seed provided.
|
2014-11-12 15:24:26 -05:00
|
|
|
a_BiomeGen is the underlying biome generator, some composition generators may depend on it providing additional biomes around the chunk
|
|
|
|
a_ShapeGen is the underlying shape generator, some composition generators may depend on it providing additional shape around the chunk
|
2014-01-09 04:35:51 -05:00
|
|
|
*/
|
2014-11-12 15:24:26 -05:00
|
|
|
static cTerrainCompositionGenPtr CreateCompositionGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, cTerrainShapeGenPtr a_ShapeGen, int a_Seed);
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** The interface that a finisher must implement
|
2014-03-01 14:56:09 -05:00
|
|
|
Finisher implements changes to the chunk after the rough terrain has been generated.
|
|
|
|
Examples of finishers are trees, snow, ore, lilypads and others.
|
2014-11-12 15:24:26 -05:00
|
|
|
Note that a worldgenerator may contain multiple finishers, chained one after another.
|
2014-03-01 14:56:09 -05:00
|
|
|
Also note that previously we used to distinguish between a structuregen and a finisher; this distinction is
|
|
|
|
no longer relevant, all structure generators are considered finishers now (#398)
|
2013-07-29 07:13:03 -04:00
|
|
|
*/
|
|
|
|
class cFinishGen
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~cFinishGen() {} // Force a virtual destructor in descendants
|
|
|
|
|
|
|
|
virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0;
|
|
|
|
} ;
|
|
|
|
|
2014-10-19 08:01:59 -04:00
|
|
|
typedef std::list<cFinishGenPtr> cFinishGenList;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cComposableGenerator :
|
|
|
|
public cChunkGenerator::cGenerator
|
|
|
|
{
|
|
|
|
typedef cChunkGenerator::cGenerator super;
|
|
|
|
|
|
|
|
public:
|
|
|
|
cComposableGenerator(cChunkGenerator & a_ChunkGenerator);
|
|
|
|
|
2014-11-12 15:24:26 -05:00
|
|
|
// cChunkGenerator::cGenerator overrides:
|
2014-01-10 16:22:54 -05:00
|
|
|
virtual void Initialize(cIniFile & a_IniFile) override;
|
2013-07-29 07:13:03 -04:00
|
|
|
virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
|
|
|
virtual void DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc) override;
|
|
|
|
|
|
|
|
protected:
|
2014-11-12 15:24:26 -05:00
|
|
|
// The generator's composition:
|
|
|
|
/** The biome generator. */
|
|
|
|
cBiomeGenPtr m_BiomeGen;
|
|
|
|
|
|
|
|
/** The terrain shape generator. */
|
|
|
|
cTerrainShapeGenPtr m_ShapeGen;
|
|
|
|
|
|
|
|
/** The terrain composition generator. */
|
2014-10-19 08:01:59 -04:00
|
|
|
cTerrainCompositionGenPtr m_CompositionGen;
|
2014-11-12 15:24:26 -05:00
|
|
|
|
|
|
|
/** The cache for the heights of the composited terrain. */
|
|
|
|
cTerrainHeightGenPtr m_CompositedHeightCache;
|
|
|
|
|
|
|
|
/** The finisher generators, in the order in which they are applied. */
|
|
|
|
cFinishGenList m_FinishGens;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
2014-11-12 15:24:26 -05:00
|
|
|
/** Reads the BiomeGen settings from the ini and initializes m_BiomeGen accordingly */
|
2013-07-29 07:13:03 -04:00
|
|
|
void InitBiomeGen(cIniFile & a_IniFile);
|
|
|
|
|
2014-11-12 15:24:26 -05:00
|
|
|
/** Reads the ShapeGen settings from the ini and initializes m_ShapeGen accordingly */
|
|
|
|
void InitShapeGen(cIniFile & a_IniFile);
|
2013-07-29 07:13:03 -04:00
|
|
|
|
2014-03-01 14:56:09 -05:00
|
|
|
/** Reads the CompositionGen settings from the ini and initializes m_CompositionGen accordingly */
|
2013-07-29 07:13:03 -04:00
|
|
|
void InitCompositionGen(cIniFile & a_IniFile);
|
|
|
|
|
2014-03-01 14:56:09 -05:00
|
|
|
/** Reads the finishers from the ini and initializes m_FinishGens accordingly */
|
2013-07-29 07:13:03 -04:00
|
|
|
void InitFinishGens(cIniFile & a_IniFile);
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|