Moved BiomeGen creation from INI file data to BioGen.cpp.
This way it can be shared between MCServer and BiomeVisualiser.
This commit is contained in:
parent
012840360e
commit
c0a6c2b533
@ -12,6 +12,72 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// cBiomeGen:
|
||||||
|
|
||||||
|
cBiomeGen * cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault)
|
||||||
|
{
|
||||||
|
AString BiomeGenName = a_IniFile.GetValueSet("Generator", "BiomeGen", "");
|
||||||
|
if (BiomeGenName.empty())
|
||||||
|
{
|
||||||
|
LOGWARN("[Generator] BiomeGen value not set in world.ini, using \"MultiStepMap\".");
|
||||||
|
BiomeGenName = "MultiStepMap";
|
||||||
|
}
|
||||||
|
|
||||||
|
cBiomeGen * res = NULL;
|
||||||
|
a_CacheOffByDefault = false;
|
||||||
|
if (NoCaseCompare(BiomeGenName, "constant") == 0)
|
||||||
|
{
|
||||||
|
res = new cBioGenConstant;
|
||||||
|
a_CacheOffByDefault = true; // we're generating faster than a cache would retrieve data :)
|
||||||
|
}
|
||||||
|
else if (NoCaseCompare(BiomeGenName, "checkerboard") == 0)
|
||||||
|
{
|
||||||
|
res = new cBioGenCheckerboard;
|
||||||
|
a_CacheOffByDefault = true; // we're (probably) generating faster than a cache would retrieve data
|
||||||
|
}
|
||||||
|
else if (NoCaseCompare(BiomeGenName, "voronoi") == 0)
|
||||||
|
{
|
||||||
|
res = new cBioGenVoronoi(a_Seed);
|
||||||
|
}
|
||||||
|
else if (NoCaseCompare(BiomeGenName, "distortedvoronoi") == 0)
|
||||||
|
{
|
||||||
|
res = new cBioGenDistortedVoronoi(a_Seed);
|
||||||
|
}
|
||||||
|
else if (NoCaseCompare(BiomeGenName, "twolevel") == 0)
|
||||||
|
{
|
||||||
|
res = new cBioGenTwoLevel(a_Seed);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (NoCaseCompare(BiomeGenName, "multistepmap") != 0)
|
||||||
|
{
|
||||||
|
LOGWARNING("Unknown BiomeGen \"%s\", using \"MultiStepMap\" instead.", BiomeGenName.c_str());
|
||||||
|
}
|
||||||
|
res = new cBioGenMultiStepMap(a_Seed);
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Performance-testing:
|
||||||
|
LOGINFO("Measuring performance of cBioGenMultiStepMap...");
|
||||||
|
clock_t BeginTick = clock();
|
||||||
|
for (int x = 0; x < 5000; x++)
|
||||||
|
{
|
||||||
|
cChunkDef::BiomeMap Biomes;
|
||||||
|
res->GenBiomes(x * 5, x * 5, Biomes);
|
||||||
|
}
|
||||||
|
clock_t Duration = clock() - BeginTick;
|
||||||
|
LOGINFO("cBioGenMultiStepMap for 5000 chunks took %d ticks (%.02f sec)", Duration, (double)Duration / CLOCKS_PER_SEC);
|
||||||
|
//*/
|
||||||
|
}
|
||||||
|
res->InitializeBiomeGen(a_IniFile);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// cBioGenConstant:
|
// cBioGenConstant:
|
||||||
|
|
||||||
|
@ -147,54 +147,8 @@ void cComposableGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a
|
|||||||
|
|
||||||
void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
|
void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
|
||||||
{
|
{
|
||||||
AString BiomeGenName = a_IniFile.GetValueSet("Generator", "BiomeGen", "");
|
|
||||||
if (BiomeGenName.empty())
|
|
||||||
{
|
|
||||||
LOGWARN("[Generator] BiomeGen value not set in world.ini, using \"MultiStepMap\".");
|
|
||||||
BiomeGenName = "MultiStepMap";
|
|
||||||
}
|
|
||||||
|
|
||||||
int Seed = m_ChunkGenerator.GetSeed();
|
|
||||||
bool CacheOffByDefault = false;
|
bool CacheOffByDefault = false;
|
||||||
if (NoCaseCompare(BiomeGenName, "constant") == 0)
|
m_BiomeGen = cBiomeGen::CreateBiomeGen(a_IniFile, m_ChunkGenerator.GetSeed(), CacheOffByDefault);
|
||||||
{
|
|
||||||
m_BiomeGen = new cBioGenConstant;
|
|
||||||
CacheOffByDefault = true; // we're generating faster than a cache would retrieve data :)
|
|
||||||
}
|
|
||||||
else if (NoCaseCompare(BiomeGenName, "checkerboard") == 0)
|
|
||||||
{
|
|
||||||
m_BiomeGen = new cBioGenCheckerboard;
|
|
||||||
CacheOffByDefault = true; // we're (probably) generating faster than a cache would retrieve data
|
|
||||||
}
|
|
||||||
else if (NoCaseCompare(BiomeGenName, "voronoi") == 0)
|
|
||||||
{
|
|
||||||
m_BiomeGen = new cBioGenVoronoi(Seed);
|
|
||||||
}
|
|
||||||
else if (NoCaseCompare(BiomeGenName, "distortedvoronoi") == 0)
|
|
||||||
{
|
|
||||||
m_BiomeGen = new cBioGenDistortedVoronoi(Seed);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (NoCaseCompare(BiomeGenName, "multistepmap") != 0)
|
|
||||||
{
|
|
||||||
LOGWARNING("Unknown BiomeGen \"%s\", using \"MultiStepMap\" instead.", BiomeGenName.c_str());
|
|
||||||
}
|
|
||||||
m_BiomeGen = new cBioGenMultiStepMap(Seed);
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Performance-testing:
|
|
||||||
LOGINFO("Measuring performance of cBioGenMultiStepMap...");
|
|
||||||
clock_t BeginTick = clock();
|
|
||||||
for (int x = 0; x < 5000; x++)
|
|
||||||
{
|
|
||||||
cChunkDef::BiomeMap Biomes;
|
|
||||||
m_BiomeGen->GenBiomes(x * 5, x * 5, Biomes);
|
|
||||||
}
|
|
||||||
clock_t Duration = clock() - BeginTick;
|
|
||||||
LOGINFO("cBioGenMultiStepMap for 5000 chunks took %d ticks (%.02f sec)", Duration, (double)Duration / CLOCKS_PER_SEC);
|
|
||||||
//*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a cache, if requested:
|
// Add a cache, if requested:
|
||||||
int CacheSize = a_IniFile.GetValueSetI("Generator", "BiomeGenCacheSize", CacheOffByDefault ? 0 : 64);
|
int CacheSize = a_IniFile.GetValueSetI("Generator", "BiomeGenCacheSize", CacheOffByDefault ? 0 : 64);
|
||||||
@ -211,7 +165,6 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
|
|||||||
m_UnderlyingBiomeGen = m_BiomeGen;
|
m_UnderlyingBiomeGen = m_BiomeGen;
|
||||||
m_BiomeGen = new cBioGenCache(m_UnderlyingBiomeGen, CacheSize);
|
m_BiomeGen = new cBioGenCache(m_UnderlyingBiomeGen, CacheSize);
|
||||||
}
|
}
|
||||||
m_BiomeGen->InitializeBiomeGen(a_IniFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,13 @@ public:
|
|||||||
|
|
||||||
/// Reads parameters from the ini file, prepares generator for use.
|
/// Reads parameters from the ini file, prepares generator for use.
|
||||||
virtual void InitializeBiomeGen(cIniFile & a_IniFile) {}
|
virtual void InitializeBiomeGen(cIniFile & a_IniFile) {}
|
||||||
|
|
||||||
|
/// 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 enabled by default
|
||||||
|
/// Used in BiomeVisualiser, too.
|
||||||
|
/// Implemented in BioGen.cpp!
|
||||||
|
static cBiomeGen * CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault);
|
||||||
|
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user