CompoGen and HeiGen read their settings in their respective Initialize() functions.
parent
47b64b63fa
commit
a9e70c84b5
|
@ -10,7 +10,9 @@
|
|||
#include "Globals.h"
|
||||
#include "CompoGen.h"
|
||||
#include "../BlockID.h"
|
||||
#include "../Item.h"
|
||||
#include "../LinearUpscale.h"
|
||||
#include "../../iniFile/iniFile.h"
|
||||
|
||||
|
||||
|
||||
|
@ -48,6 +50,16 @@ void cCompoGenSameBlock::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
|||
|
||||
|
||||
|
||||
void cCompoGenSameBlock::InitializeCompoGen(cIniFile & a_IniFile)
|
||||
{
|
||||
m_BlockType = (BLOCKTYPE)(GetIniItemSet(a_IniFile, "Generator", "SameBlockType", "stone").m_ItemType);
|
||||
m_IsBedrocked = (a_IniFile.GetValueSetI("Generator", "SameBlockBedrocked", 1) != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cCompoGenDebugBiomes:
|
||||
|
||||
|
@ -102,20 +114,16 @@ void cCompoGenDebugBiomes::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cCompoGenClassic:
|
||||
|
||||
cCompoGenClassic::cCompoGenClassic(
|
||||
int a_SeaLevel, int a_BeachHeight, int a_BeachDepth,
|
||||
BLOCKTYPE a_BlockTop, BLOCKTYPE a_BlockMiddle, BLOCKTYPE a_BlockBottom,
|
||||
BLOCKTYPE a_BlockBeach, BLOCKTYPE a_BlockBeachBottom, BLOCKTYPE a_BlockSea
|
||||
) :
|
||||
m_SeaLevel(a_SeaLevel),
|
||||
m_BeachHeight(a_BeachHeight),
|
||||
m_BeachDepth(a_BeachDepth),
|
||||
m_BlockTop(a_BlockTop),
|
||||
m_BlockMiddle(a_BlockMiddle),
|
||||
m_BlockBottom(a_BlockBottom),
|
||||
m_BlockBeach(a_BlockBeach),
|
||||
m_BlockBeachBottom(a_BlockBeachBottom),
|
||||
m_BlockSea(a_BlockSea)
|
||||
cCompoGenClassic::cCompoGenClassic(void) :
|
||||
m_SeaLevel(60),
|
||||
m_BeachHeight(2),
|
||||
m_BeachDepth(4),
|
||||
m_BlockTop(E_BLOCK_GRASS),
|
||||
m_BlockMiddle(E_BLOCK_DIRT),
|
||||
m_BlockBottom(E_BLOCK_STONE),
|
||||
m_BlockBeach(E_BLOCK_SAND),
|
||||
m_BlockBeachBottom(E_BLOCK_SANDSTONE),
|
||||
m_BlockSea(E_BLOCK_STATIONARY_WATER)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -184,6 +192,23 @@ void cCompoGenClassic::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
|||
|
||||
|
||||
|
||||
void cCompoGenClassic::InitializeCompoGen(cIniFile & a_IniFile)
|
||||
{
|
||||
m_SeaLevel = a_IniFile.GetValueSetI("Generator", "ClassicSeaLevel", m_SeaLevel);
|
||||
m_BeachHeight = a_IniFile.GetValueSetI("Generator", "ClassicBeachHeight", m_BeachHeight);
|
||||
m_BeachDepth = a_IniFile.GetValueSetI("Generator", "ClassicBeachDepth", m_BeachDepth);
|
||||
m_BlockTop = (BLOCKTYPE)(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockTop", "grass").m_ItemType);
|
||||
m_BlockMiddle = (BLOCKTYPE)(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockMiddle", "dirt").m_ItemType);
|
||||
m_BlockBottom = (BLOCKTYPE)(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockBottom", "stone").m_ItemType);
|
||||
m_BlockBeach = (BLOCKTYPE)(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockBeach", "sand").m_ItemType);
|
||||
m_BlockBeachBottom = (BLOCKTYPE)(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockBeachBottom", "sandstone").m_ItemType);
|
||||
m_BlockSea = (BLOCKTYPE)(GetIniItemSet(a_IniFile, "Generator", "ClassicBlockSea", "stationarywater").m_ItemType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cCompoGenBiomal:
|
||||
|
||||
|
@ -286,6 +311,15 @@ void cCompoGenBiomal::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
|||
|
||||
|
||||
|
||||
void cCompoGenBiomal::InitializeCompoGen(cIniFile & a_IniFile)
|
||||
{
|
||||
m_SeaLevel = a_IniFile.GetValueSetI("Generator", "BiomalSeaLevel", m_SeaLevel) - 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cCompoGenBiomal::FillColumnGrass(int a_RelX, int a_RelZ, int a_Height, cChunkDef::BlockTypes & a_BlockTypes)
|
||||
{
|
||||
BLOCKTYPE Pattern[] =
|
||||
|
@ -485,10 +519,19 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
|||
|
||||
|
||||
|
||||
void cCompoGenNether::InitializeCompoGen(cIniFile & a_IniFile)
|
||||
{
|
||||
m_Threshold = a_IniFile.GetValueSetI("Generator", "NetherThreshold", m_Threshold);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cCompoGenCache:
|
||||
|
||||
cCompoGenCache::cCompoGenCache(cTerrainCompositionGen * a_Underlying, int a_CacheSize) :
|
||||
cCompoGenCache::cCompoGenCache(cTerrainCompositionGen & a_Underlying, int a_CacheSize) :
|
||||
m_Underlying(a_Underlying),
|
||||
m_CacheSize(a_CacheSize),
|
||||
m_CacheOrder(new int[a_CacheSize]),
|
||||
|
@ -521,13 +564,13 @@ cCompoGenCache::~cCompoGenCache()
|
|||
|
||||
void cCompoGenCache::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
||||
{
|
||||
//*
|
||||
#ifdef _DEBUG
|
||||
if (((m_NumHits + m_NumMisses) % 1024) == 10)
|
||||
{
|
||||
LOGD("CompoGenCache: %d hits, %d misses, saved %.2f %%", m_NumHits, m_NumMisses, 100.0 * m_NumHits / (m_NumHits + m_NumMisses));
|
||||
LOGD("CompoGenCache: Avg cache chain length: %.2f", (float)m_TotalChain / m_NumHits);
|
||||
}
|
||||
//*/
|
||||
#endif // _DEBUG
|
||||
|
||||
int ChunkX = a_ChunkDesc.GetChunkX();
|
||||
int ChunkZ = a_ChunkDesc.GetChunkZ();
|
||||
|
@ -562,7 +605,7 @@ void cCompoGenCache::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
|||
|
||||
// Not in the cache:
|
||||
m_NumMisses++;
|
||||
m_Underlying->ComposeTerrain(a_ChunkDesc);
|
||||
m_Underlying.ComposeTerrain(a_ChunkDesc);
|
||||
|
||||
// Insert it as the first item in the MRU order:
|
||||
int Idx = m_CacheOrder[m_CacheSize - 1];
|
||||
|
@ -580,3 +623,12 @@ void cCompoGenCache::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
|||
|
||||
|
||||
|
||||
|
||||
void cCompoGenCache::InitializeCompoGen(cIniFile & a_IniFile)
|
||||
{
|
||||
m_Underlying.InitializeCompoGen(a_IniFile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -27,9 +27,9 @@ class cCompoGenSameBlock :
|
|||
public cTerrainCompositionGen
|
||||
{
|
||||
public:
|
||||
cCompoGenSameBlock(BLOCKTYPE a_BlockType, bool a_IsBedrocked) :
|
||||
m_BlockType(a_BlockType),
|
||||
m_IsBedrocked(a_IsBedrocked)
|
||||
cCompoGenSameBlock(void) :
|
||||
m_BlockType(E_BLOCK_STONE),
|
||||
m_IsBedrocked(true)
|
||||
{}
|
||||
|
||||
protected:
|
||||
|
@ -39,6 +39,7 @@ protected:
|
|||
|
||||
// cTerrainCompositionGen overrides:
|
||||
virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
|
||||
virtual void InitializeCompoGen(cIniFile & a_IniFile) override;
|
||||
} ;
|
||||
|
||||
|
||||
|
@ -65,11 +66,7 @@ class cCompoGenClassic :
|
|||
public cTerrainCompositionGen
|
||||
{
|
||||
public:
|
||||
cCompoGenClassic(
|
||||
int a_SeaLevel, int a_BeachHeight, int a_BeachDepth,
|
||||
BLOCKTYPE a_BlockTop, BLOCKTYPE a_BlockMiddle, BLOCKTYPE a_BlockBottom,
|
||||
BLOCKTYPE a_BlockBeach, BLOCKTYPE a_BlockBeachBottom, BLOCKTYPE a_BlockSea
|
||||
);
|
||||
cCompoGenClassic(void);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -85,6 +82,7 @@ protected:
|
|||
|
||||
// cTerrainCompositionGen overrides:
|
||||
virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
|
||||
virtual void InitializeCompoGen(cIniFile & a_IniFile) override;
|
||||
} ;
|
||||
|
||||
|
||||
|
@ -95,9 +93,9 @@ class cCompoGenBiomal :
|
|||
public cTerrainCompositionGen
|
||||
{
|
||||
public:
|
||||
cCompoGenBiomal(int a_Seed, int a_SeaLevel) :
|
||||
cCompoGenBiomal(int a_Seed) :
|
||||
m_Noise(a_Seed + 1000),
|
||||
m_SeaLevel(a_SeaLevel - 1) // we do an adjustment later in filling the terrain with water
|
||||
m_SeaLevel(62)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -108,6 +106,7 @@ protected:
|
|||
|
||||
// cTerrainCompositionGen overrides:
|
||||
virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
|
||||
virtual void InitializeCompoGen(cIniFile & a_IniFile) override;
|
||||
|
||||
void FillColumnGrass (int a_RelX, int a_RelZ, int a_Height, cChunkDef::BlockTypes & a_BlockTypes);
|
||||
void FillColumnSand (int a_RelX, int a_RelZ, int a_Height, cChunkDef::BlockTypes & a_BlockTypes);
|
||||
|
@ -136,6 +135,7 @@ protected:
|
|||
|
||||
// cTerrainCompositionGen overrides:
|
||||
virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
|
||||
virtual void InitializeCompoGen(cIniFile & a_IniFile) override;
|
||||
} ;
|
||||
|
||||
|
||||
|
@ -147,15 +147,16 @@ class cCompoGenCache :
|
|||
public cTerrainCompositionGen
|
||||
{
|
||||
public:
|
||||
cCompoGenCache(cTerrainCompositionGen * a_Underlying, int a_CacheSize); // Doesn't take ownership of a_Underlying
|
||||
cCompoGenCache(cTerrainCompositionGen & a_Underlying, int a_CacheSize); // Doesn't take ownership of a_Underlying
|
||||
~cCompoGenCache();
|
||||
|
||||
// cTerrainCompositionGen override:
|
||||
virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
|
||||
virtual void InitializeCompoGen(cIniFile & a_IniFile) override;
|
||||
|
||||
protected:
|
||||
|
||||
cTerrainCompositionGen * m_Underlying;
|
||||
cTerrainCompositionGen & m_Underlying;
|
||||
|
||||
struct sCacheData
|
||||
{
|
||||
|
|
|
@ -231,35 +231,24 @@ void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile)
|
|||
bool CacheOffByDefault = false;
|
||||
if (NoCaseCompare(HeightGenName, "flat") == 0)
|
||||
{
|
||||
int Height = a_IniFile.GetValueSetI("Generator", "FlatHeight", 5);
|
||||
m_HeightGen = new cHeiGenFlat(Height);
|
||||
m_HeightGen = new cHeiGenFlat;
|
||||
CacheOffByDefault = true; // We're generating faster than a cache would retrieve data
|
||||
}
|
||||
else if (NoCaseCompare(HeightGenName, "classic") == 0)
|
||||
{
|
||||
// These used to be in terrain.ini, but now they are in world.ini (so that multiple worlds can have different values):
|
||||
float HeightFreq1 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq1", 0.1);
|
||||
float HeightFreq2 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq2", 1.0);
|
||||
float HeightFreq3 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq3", 2.0);
|
||||
float HeightAmp1 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp1", 1.0);
|
||||
float HeightAmp2 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp2", 0.5);
|
||||
float HeightAmp3 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp3", 0.5);
|
||||
m_HeightGen = new cHeiGenClassic(Seed, HeightFreq1, HeightAmp1, HeightFreq2, HeightAmp2, HeightFreq3, HeightAmp3);
|
||||
m_HeightGen = new cHeiGenClassic(Seed);
|
||||
}
|
||||
else if (NoCaseCompare(HeightGenName, "DistortedHeightmap") == 0)
|
||||
{
|
||||
m_HeightGen = new cDistortedHeightmap(Seed, *m_BiomeGen);
|
||||
((cDistortedHeightmap *)m_HeightGen)->Initialize(a_IniFile);
|
||||
}
|
||||
else if (NoCaseCompare(HeightGenName, "End") == 0)
|
||||
{
|
||||
m_HeightGen = new cEndGen(Seed);
|
||||
((cEndGen *)m_HeightGen)->Initialize(a_IniFile);
|
||||
}
|
||||
else if (NoCaseCompare(HeightGenName, "Noise3D") == 0)
|
||||
{
|
||||
m_HeightGen = new cNoise3DComposable(Seed);
|
||||
((cNoise3DComposable *)m_HeightGen)->Initialize(a_IniFile);
|
||||
}
|
||||
else // "biomal" or <not found>
|
||||
{
|
||||
|
@ -283,6 +272,9 @@ void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile)
|
|||
//*/
|
||||
}
|
||||
|
||||
// Read the settings:
|
||||
m_HeightGen->InitializeHeightGen(a_IniFile);
|
||||
|
||||
// Add a cache, if requested:
|
||||
int CacheSize = a_IniFile.GetValueSetI("Generator", "HeightGenCacheSize", CacheOffByDefault ? 0 : 64);
|
||||
if (CacheSize > 0)
|
||||
|
@ -296,7 +288,7 @@ void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile)
|
|||
}
|
||||
LOGD("Using a cache for Heightgen of size %d.", CacheSize);
|
||||
m_UnderlyingHeightGen = m_HeightGen;
|
||||
m_HeightGen = new cHeiGenCache(m_UnderlyingHeightGen, CacheSize);
|
||||
m_HeightGen = new cHeiGenCache(*m_UnderlyingHeightGen, CacheSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,6 +298,7 @@ void cComposableGenerator::InitHeightGen(cIniFile & a_IniFile)
|
|||
|
||||
void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
|
||||
{
|
||||
int Seed = m_ChunkGenerator.GetSeed();
|
||||
AString CompoGenName = a_IniFile.GetValueSet("Generator", "CompositionGen", "");
|
||||
if (CompoGenName.empty())
|
||||
{
|
||||
|
@ -314,9 +307,7 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
|
|||
}
|
||||
if (NoCaseCompare(CompoGenName, "sameblock") == 0)
|
||||
{
|
||||
int Block = m_ChunkGenerator.GetIniBlock(a_IniFile, "Generator", "SameBlockType", "stone");
|
||||
bool Bedrocked = (a_IniFile.GetValueSetI("Generator", "SameBlockBedrocked", 1) != 0);
|
||||
m_CompositionGen = new cCompoGenSameBlock((BLOCKTYPE)Block, Bedrocked);
|
||||
m_CompositionGen = new cCompoGenSameBlock;
|
||||
}
|
||||
else if (NoCaseCompare(CompoGenName, "debugbiomes") == 0)
|
||||
{
|
||||
|
@ -324,38 +315,23 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
|
|||
}
|
||||
else if (NoCaseCompare(CompoGenName, "classic") == 0)
|
||||
{
|
||||
int SeaLevel = a_IniFile.GetValueSetI("Generator", "ClassicSeaLevel", 60);
|
||||
int BeachHeight = a_IniFile.GetValueSetI("Generator", "ClassicBeachHeight", 2);
|
||||
int BeachDepth = a_IniFile.GetValueSetI("Generator", "ClassicBeachDepth", 4);
|
||||
BLOCKTYPE BlockTop = m_ChunkGenerator.GetIniBlock(a_IniFile, "Generator", "ClassicBlockTop", "grass");
|
||||
BLOCKTYPE BlockMiddle = m_ChunkGenerator.GetIniBlock(a_IniFile, "Generator", "ClassicBlockMiddle", "dirt");
|
||||
BLOCKTYPE BlockBottom = m_ChunkGenerator.GetIniBlock(a_IniFile, "Generator", "ClassicBlockBottom", "stone");
|
||||
BLOCKTYPE BlockBeach = m_ChunkGenerator.GetIniBlock(a_IniFile, "Generator", "ClassicBlockBeach", "sand");
|
||||
BLOCKTYPE BlockBeachBottom = m_ChunkGenerator.GetIniBlock(a_IniFile, "Generator", "ClassicBlockBeachBottom", "sandstone");
|
||||
BLOCKTYPE BlockSea = m_ChunkGenerator.GetIniBlock(a_IniFile, "Generator", "ClassicBlockSea", "stationarywater");
|
||||
m_CompositionGen = new cCompoGenClassic(
|
||||
SeaLevel, BeachHeight, BeachDepth, BlockTop, BlockMiddle, BlockBottom, BlockBeach,
|
||||
BlockBeachBottom, BlockSea
|
||||
);
|
||||
m_CompositionGen = new cCompoGenClassic;
|
||||
}
|
||||
else if (NoCaseCompare(CompoGenName, "DistortedHeightmap") == 0)
|
||||
{
|
||||
m_CompositionGen = new cDistortedHeightmap(m_ChunkGenerator.GetSeed(), *m_BiomeGen);
|
||||
((cDistortedHeightmap *)m_CompositionGen)->Initialize(a_IniFile);
|
||||
m_CompositionGen = new cDistortedHeightmap(Seed, *m_BiomeGen);
|
||||
}
|
||||
else if (NoCaseCompare(CompoGenName, "end") == 0)
|
||||
{
|
||||
m_CompositionGen = new cEndGen(m_ChunkGenerator.GetSeed());
|
||||
((cEndGen *)m_CompositionGen)->Initialize(a_IniFile);
|
||||
m_CompositionGen = new cEndGen(Seed);
|
||||
}
|
||||
else if (NoCaseCompare(CompoGenName, "nether") == 0)
|
||||
{
|
||||
m_CompositionGen = new cCompoGenNether(m_ChunkGenerator.GetSeed());
|
||||
m_CompositionGen = new cCompoGenNether(Seed);
|
||||
}
|
||||
else if (NoCaseCompare(CompoGenName, "Noise3D") == 0)
|
||||
{
|
||||
m_CompositionGen = new cNoise3DComposable(m_ChunkGenerator.GetSeed());
|
||||
((cNoise3DComposable *)m_CompositionGen)->Initialize(a_IniFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -363,9 +339,7 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
|
|||
{
|
||||
LOGWARN("Unknown CompositionGen \"%s\", using \"biomal\" instead.", CompoGenName.c_str());
|
||||
}
|
||||
int SeaLevel = a_IniFile.GetValueSetI("Generator", "BiomalSeaLevel", 62);
|
||||
int Seed = m_ChunkGenerator.GetSeed();
|
||||
m_CompositionGen = new cCompoGenBiomal(Seed, SeaLevel);
|
||||
m_CompositionGen = new cCompoGenBiomal(Seed);
|
||||
|
||||
/*
|
||||
// Performance-testing:
|
||||
|
@ -383,11 +357,14 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
|
|||
//*/
|
||||
}
|
||||
|
||||
// Read the settings from the ini file:
|
||||
m_CompositionGen->InitializeCompoGen(a_IniFile);
|
||||
|
||||
int CompoGenCacheSize = a_IniFile.GetValueSetI("Generator", "CompositionGenCacheSize", 64);
|
||||
if (CompoGenCacheSize > 1)
|
||||
{
|
||||
m_UnderlyingCompositionGen = m_CompositionGen;
|
||||
m_CompositionGen = new cCompoGenCache(m_UnderlyingCompositionGen, 32);
|
||||
m_CompositionGen = new cCompoGenCache(*m_UnderlyingCompositionGen, 32);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,9 @@ public:
|
|||
|
||||
/// Generates heightmap for the given chunk
|
||||
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) = 0;
|
||||
|
||||
/// Reads parameters from the ini file, prepares generator for use.
|
||||
virtual void InitializeHeightGen(cIniFile & a_IniFile) {}
|
||||
} ;
|
||||
|
||||
|
||||
|
@ -84,6 +87,9 @@ public:
|
|||
virtual ~cTerrainCompositionGen() {} // Force a virtual destructor in descendants
|
||||
|
||||
virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) = 0;
|
||||
|
||||
/// Reads parameters from the ini file, prepares generator for use.
|
||||
virtual void InitializeCompoGen(cIniFile & a_IniFile) {}
|
||||
} ;
|
||||
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ cDistortedHeightmap::cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen) :
|
|||
m_OceanFloorSelect(a_Seed + 3000),
|
||||
m_BiomeGen(a_BiomeGen),
|
||||
m_UnderlyingHeiGen(a_Seed, a_BiomeGen),
|
||||
m_HeightGen(&m_UnderlyingHeiGen, 64)
|
||||
m_HeightGen(m_UnderlyingHeiGen, 64)
|
||||
{
|
||||
m_NoiseDistortX.AddOctave((NOISE_DATATYPE)1, (NOISE_DATATYPE)0.5);
|
||||
m_NoiseDistortX.AddOctave((NOISE_DATATYPE)0.5, (NOISE_DATATYPE)1);
|
||||
|
@ -77,11 +77,18 @@ cDistortedHeightmap::cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen) :
|
|||
|
||||
void cDistortedHeightmap::Initialize(cIniFile & a_IniFile)
|
||||
{
|
||||
if (m_IsInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Read the params from the INI file:
|
||||
m_SeaLevel = a_IniFile.GetValueSetI("Generator", "DistortedHeightmapSeaLevel", 62);
|
||||
m_FrequencyX = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "DistortedHeightmapFrequencyX", 10);
|
||||
m_FrequencyY = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "DistortedHeightmapFrequencyY", 10);
|
||||
m_FrequencyZ = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "DistortedHeightmapFrequencyZ", 10);
|
||||
|
||||
m_IsInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -184,6 +191,15 @@ void cDistortedHeightmap::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::He
|
|||
|
||||
|
||||
|
||||
void cDistortedHeightmap::InitializeHeightGen(cIniFile & a_IniFile)
|
||||
{
|
||||
Initialize(a_IniFile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cDistortedHeightmap::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
||||
{
|
||||
// Frequencies for the ocean floor selecting noise:
|
||||
|
@ -311,6 +327,15 @@ void cDistortedHeightmap::ComposeTerrain(cChunkDesc & a_ChunkDesc)
|
|||
|
||||
|
||||
|
||||
void cDistortedHeightmap::InitializeCompoGen(cIniFile & a_IniFile)
|
||||
{
|
||||
Initialize(a_IniFile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int cDistortedHeightmap::GetHeightmapAt(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Z)
|
||||
{
|
||||
int ChunkX = (int)floor(a_X / (NOISE_DATATYPE)16);
|
||||
|
|
|
@ -30,8 +30,6 @@ class cDistortedHeightmap :
|
|||
public:
|
||||
cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen);
|
||||
|
||||
void Initialize(cIniFile & a_IniFile);
|
||||
|
||||
protected:
|
||||
typedef cChunkDef::BiomeMap BiomeNeighbors[3][3];
|
||||
|
||||
|
@ -77,6 +75,9 @@ protected:
|
|||
NOISE_DATATYPE m_DistortAmpX[DIM_X * DIM_Z];
|
||||
NOISE_DATATYPE m_DistortAmpZ[DIM_X * DIM_Z];
|
||||
|
||||
/// True if Initialize() has been called. Used to initialize-once even with multiple init entrypoints (HeiGen / CompoGen)
|
||||
bool m_IsInitialized;
|
||||
|
||||
|
||||
/// Unless the LastChunk coords are equal to coords given, prepares the internal state (noise arrays, heightmap)
|
||||
void PrepareState(int a_ChunkX, int a_ChunkZ);
|
||||
|
@ -93,10 +94,15 @@ protected:
|
|||
/// Calculates the X and Z distortion amplitudes based on the neighbors' biomes
|
||||
void GetDistortAmpsAt(BiomeNeighbors & a_Neighbors, int a_RelX, int a_RelZ, NOISE_DATATYPE & a_DistortAmpX, NOISE_DATATYPE & a_DistortAmpZ);
|
||||
|
||||
/// Reads the settings from the ini file. Skips reading if already initialized
|
||||
void Initialize(cIniFile & a_IniFile);
|
||||
|
||||
|
||||
// cTerrainHeightGen overrides:
|
||||
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
|
||||
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
|
||||
|
||||
// cTerrainCompositionGen overrides:
|
||||
virtual void ComposeTerrain(cChunkDesc & a_ChunkDesc) override;
|
||||
virtual void InitializeCompoGen(cIniFile & a_IniFile) override;
|
||||
} ;
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "Globals.h"
|
||||
#include "HeiGen.h"
|
||||
#include "../LinearUpscale.h"
|
||||
#include "../../iniFile/iniFile.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -26,10 +28,19 @@ void cHeiGenFlat::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap
|
|||
|
||||
|
||||
|
||||
void cHeiGenFlat::InitializeHeightGen(cIniFile & a_IniFile)
|
||||
{
|
||||
m_Height = a_IniFile.GetValueSetI("Generator", "FlatHeight", m_Height);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cHeiGenCache:
|
||||
|
||||
cHeiGenCache::cHeiGenCache(cTerrainHeightGen * a_HeiGenToCache, int a_CacheSize) :
|
||||
cHeiGenCache::cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, int a_CacheSize) :
|
||||
m_HeiGenToCache(a_HeiGenToCache),
|
||||
m_CacheSize(a_CacheSize),
|
||||
m_CacheOrder(new int[a_CacheSize]),
|
||||
|
@ -99,7 +110,7 @@ void cHeiGenCache::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap
|
|||
|
||||
// Not in the cache:
|
||||
m_NumMisses++;
|
||||
m_HeiGenToCache->GenHeightMap(a_ChunkX, a_ChunkZ, a_HeightMap);
|
||||
m_HeiGenToCache.GenHeightMap(a_ChunkX, a_ChunkZ, a_HeightMap);
|
||||
|
||||
// Insert it as the first item in the MRU order:
|
||||
int Idx = m_CacheOrder[m_CacheSize - 1];
|
||||
|
@ -117,6 +128,15 @@ void cHeiGenCache::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap
|
|||
|
||||
|
||||
|
||||
void cHeiGenCache::InitializeHeightGen(cIniFile & a_IniFile)
|
||||
{
|
||||
m_HeiGenToCache.InitializeHeightGen(a_IniFile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cHeiGenCache::GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height)
|
||||
{
|
||||
for (int i = 0; i < m_CacheSize; i++)
|
||||
|
@ -137,17 +157,10 @@ bool cHeiGenCache::GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_Rel
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cHeiGenClassic:
|
||||
|
||||
cHeiGenClassic::cHeiGenClassic(int a_Seed, float a_HeightFreq1, float a_HeightAmp1, float a_HeightFreq2, float a_HeightAmp2, float a_HeightFreq3, float a_HeightAmp3) :
|
||||
cHeiGenClassic::cHeiGenClassic(int a_Seed) :
|
||||
m_Seed(a_Seed),
|
||||
m_Noise(a_Seed),
|
||||
m_HeightFreq1(a_HeightFreq1),
|
||||
m_HeightAmp1 (a_HeightAmp1),
|
||||
m_HeightFreq2(a_HeightFreq2),
|
||||
m_HeightAmp2 (a_HeightAmp2),
|
||||
m_HeightFreq3(a_HeightFreq3),
|
||||
m_HeightAmp3 (a_HeightAmp3)
|
||||
m_Noise(a_Seed)
|
||||
{
|
||||
// Nothing needed yet
|
||||
}
|
||||
|
||||
|
||||
|
@ -199,6 +212,20 @@ void cHeiGenClassic::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightM
|
|||
|
||||
|
||||
|
||||
void cHeiGenClassic::InitializeHeightGen(cIniFile & a_IniFile)
|
||||
{
|
||||
m_HeightFreq1 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq1", 0.1);
|
||||
m_HeightFreq2 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq2", 1.0);
|
||||
m_HeightFreq3 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightFreq3", 2.0);
|
||||
m_HeightAmp1 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp1", 1.0);
|
||||
m_HeightAmp2 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp2", 0.5);
|
||||
m_HeightAmp3 = (float)a_IniFile.GetValueSetF("Generator", "ClassicHeightAmp3", 0.5);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cHeiGenBiomal:
|
||||
|
||||
|
@ -294,6 +321,15 @@ void cHeiGenBiomal::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMa
|
|||
|
||||
|
||||
|
||||
void cHeiGenBiomal::InitializeHeightGen(cIniFile & a_IniFile)
|
||||
{
|
||||
// No user-settable params
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
NOISE_DATATYPE cHeiGenBiomal::GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const cHeiGenBiomal::BiomeNeighbors & a_BiomeNeighbors)
|
||||
{
|
||||
// Sum up how many biomes of each type there are in the neighborhood:
|
||||
|
|
|
@ -25,14 +25,15 @@ class cHeiGenFlat :
|
|||
public cTerrainHeightGen
|
||||
{
|
||||
public:
|
||||
cHeiGenFlat(int a_Height) : m_Height(a_Height) {}
|
||||
cHeiGenFlat(void) : m_Height(5) {}
|
||||
|
||||
protected:
|
||||
|
||||
int m_Height;
|
||||
|
||||
// cTerrainHeightGen override:
|
||||
// cTerrainHeightGen overrides:
|
||||
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
|
||||
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
|
||||
} ;
|
||||
|
||||
|
||||
|
@ -44,18 +45,19 @@ class cHeiGenCache :
|
|||
public cTerrainHeightGen
|
||||
{
|
||||
public:
|
||||
cHeiGenCache(cTerrainHeightGen * a_HeiGenToCache, int a_CacheSize); // Doesn't take ownership of a_HeiGenToCache
|
||||
cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, int a_CacheSize); // Doesn't take ownership of a_HeiGenToCache
|
||||
~cHeiGenCache();
|
||||
|
||||
// cTerrainHeightGen override:
|
||||
// cTerrainHeightGen overrides:
|
||||
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
|
||||
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
|
||||
|
||||
/// Retrieves height at the specified point in the cache, returns true if found, false if not found
|
||||
bool GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height);
|
||||
|
||||
protected:
|
||||
|
||||
cTerrainHeightGen * m_HeiGenToCache;
|
||||
cTerrainHeightGen & m_HeiGenToCache;
|
||||
|
||||
struct sCacheData
|
||||
{
|
||||
|
@ -83,7 +85,7 @@ class cHeiGenClassic :
|
|||
public cTerrainHeightGen
|
||||
{
|
||||
public:
|
||||
cHeiGenClassic(int a_Seed, float a_HeightFreq1, float a_HeightAmp1, float a_HeightFreq2, float a_HeightAmp2, float a_HeightFreq3, float a_HeightAmp3);
|
||||
cHeiGenClassic(int a_Seed);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -95,8 +97,9 @@ protected:
|
|||
|
||||
float GetNoise(float x, float y);
|
||||
|
||||
// cTerrainHeightGen override:
|
||||
// cTerrainHeightGen overrides:
|
||||
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
|
||||
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
|
||||
} ;
|
||||
|
||||
|
||||
|
@ -130,8 +133,9 @@ protected:
|
|||
} ;
|
||||
static const sGenParam m_GenParam[biNumBiomes];
|
||||
|
||||
// cTerrainHeightGen override:
|
||||
// cTerrainHeightGen overrides:
|
||||
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
|
||||
virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
|
||||
|
||||
NOISE_DATATYPE GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const BiomeNeighbors & a_BiomeNeighbors);
|
||||
} ;
|
||||
|
|
Loading…
Reference in New Issue