1
0

Moved the generator defaults to ComposableGenerator.

This commit is contained in:
Mattes D 2019-09-01 21:47:03 +02:00
parent a2ffa432b3
commit 878393a03d
9 changed files with 177 additions and 98 deletions

View File

@ -32,7 +32,15 @@ void cBioGenConstant::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap
void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile)
{
AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", "");
AString defaultBiome;
switch (StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld")))
{
case dimOverworld: defaultBiome = "Plains"; break;
case dimNether: defaultBiome = "Nether"; break;
case dimEnd: defaultBiome = "End"; break;
case dimNotSet: defaultBiome = "Swampland"; break;
}
AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", defaultBiome);
m_Biome = StringToBiome(Biome);
if (m_Biome == biInvalidBiome)
{
@ -1144,11 +1152,11 @@ protected:
cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault)
{
AString BiomeGenName = a_IniFile.GetValueSet("Generator", "BiomeGen", "");
AString BiomeGenName = a_IniFile.GetValue("Generator", "BiomeGen");
if (BiomeGenName.empty())
{
LOGWARN("[Generator] BiomeGen value not set in world.ini, using \"MultiStepMap\".");
BiomeGenName = "MultiStepMap";
LOGWARN("[Generator] BiomeGen value not set in world.ini, using \"Grown\".");
BiomeGenName = "Grown";
}
cBiomeGen * res = nullptr;
@ -1175,9 +1183,9 @@ cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool &
{
res = new cBioGenTwoLevel(a_Seed);
}
else if (NoCaseCompare(BiomeGenName, "grown") == 0)
else if (NoCaseCompare(BiomeGenName, "multistepmap") == 0)
{
res = new cBioGenGrown(a_Seed);
res = new cBioGenMultiStepMap(a_Seed);
}
else if (NoCaseCompare(BiomeGenName, "grownprot") == 0)
{
@ -1185,24 +1193,11 @@ cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool &
}
else
{
if (NoCaseCompare(BiomeGenName, "multistepmap") != 0)
if (NoCaseCompare(BiomeGenName, "grown") != 0)
{
LOGWARNING("Unknown BiomeGen \"%s\", using \"MultiStepMap\" instead.", BiomeGenName.c_str());
LOGWARNING("Unknown BiomeGen \"%s\", using \"Grown\" 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 = new cBioGenGrown(a_Seed);
}
res->InitializeBiomeGen(a_IniFile);

View File

@ -25,6 +25,8 @@ void cChunkGenerator::Initialize(cIniFile & a_IniFile)
LOGINFO("Chosen a new random seed for world: %d", m_Seed);
a_IniFile.SetValueI("Seed", "Seed", m_Seed);
}
m_Dimension = StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld"));
}

View File

@ -50,6 +50,9 @@ protected:
/** The main seed, read from the INI file, used for the entire generator. */
int m_Seed;
/** The dimension, read from the INI file. */
eDimension m_Dimension;
};

View File

@ -413,13 +413,15 @@ protected:
return;
}
case biInvalidBiome:
case biHell:
case biSky:
case biNether:
case biEnd:
case biNumBiomes:
case biVariant:
case biNumVariantBiomes:
{
ASSERT(!"Unhandled biome");
// This generator is not supposed to be used for these biomes, but it has to produce *something*
// so let's produce stone:
FillColumnPattern(a_ChunkDesc, a_RelX, a_RelZ, patStone.Get(), a_ShapeColumn);
return;
}
} // switch (Biome)

View File

@ -37,9 +37,14 @@
////////////////////////////////////////////////////////////////////////////////
// cTerrainCompositionGen:
cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, cTerrainShapeGenPtr a_ShapeGen, int a_Seed)
cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen(
cIniFile & a_IniFile,
cBiomeGenPtr a_BiomeGen,
cTerrainShapeGenPtr a_ShapeGen,
int a_Seed
)
{
AString CompoGenName = a_IniFile.GetValueSet("Generator", "CompositionGen", "");
AString CompoGenName = a_IniFile.GetValue("Generator", "CompositionGen");
if (CompoGenName.empty())
{
LOGWARN("[Generator] CompositionGen value not set in world.ini, using \"Biomal\".");
@ -123,6 +128,9 @@ void cComposableGenerator::Initialize(cIniFile & a_IniFile)
{
Super::Initialize(a_IniFile);
// Add the defaults, if they're not overridden:
InitializeGeneratorDefaults(a_IniFile, m_Dimension);
InitBiomeGen(a_IniFile);
InitShapeGen(a_IniFile);
InitCompositionGen(a_IniFile);
@ -189,6 +197,84 @@ void cComposableGenerator::Generate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_C
void cComposableGenerator::InitializeGeneratorDefaults(cIniFile & a_IniFile, eDimension a_Dimension)
{
switch (a_Dimension)
{
case dimOverworld:
{
a_IniFile.GetValueSet("Generator", "BiomeGen", "Grown");
a_IniFile.GetValueSet("Generator", "ShapeGen", "BiomalNoise3D");
a_IniFile.GetValueSet("Generator", "CompositionGen", "Biomal");
a_IniFile.GetValueSet("Generator", "Finishers",
"RoughRavines, "
"WormNestCaves, "
"WaterLakes, "
"WaterSprings, "
"LavaLakes, "
"LavaSprings, "
"OreNests, "
"Mineshafts, "
"Trees, "
"Villages, "
"TallGrass, "
"SprinkleFoliage, "
"Ice, "
"Snow, "
"Lilypads, "
"BottomLava, "
"DeadBushes, "
"NaturalPatches, "
"PreSimulator, "
"Animals"
);
break;
} // dimOverworld
case dimNether:
{
a_IniFile.GetValueSet("Generator", "Generator", "Composable");
a_IniFile.GetValueSet("Generator", "BiomeGen", "Constant");
a_IniFile.GetValueSet("Generator", "ConstantBiome", "Nether");
a_IniFile.GetValueSet("Generator", "ShapeGen", "HeightMap");
a_IniFile.GetValueSet("Generator", "HeightGen", "Flat");
a_IniFile.GetValueSet("Generator", "FlatHeight", "128");
a_IniFile.GetValueSet("Generator", "CompositionGen", "Nether");
a_IniFile.GetValueSet("Generator", "Finishers",
"SoulsandRims, "
"WormNestCaves, "
"BottomLava, "
"LavaSprings, "
"NetherClumpFoliage, "
"NetherOreNests, "
"PieceStructures: NetherFort, "
"GlowStone, "
"PreSimulator");
break;
} // dimNether
case dimEnd:
{
a_IniFile.GetValueSet("Generator", "BiomeGen", "Constant");
a_IniFile.GetValueSet("Generator", "ConstantBiome", "End");
a_IniFile.GetValueSet("Generator", "ShapeGen", "End");
a_IniFile.GetValueSet("Generator", "CompositionGen", "End");
a_IniFile.GetValueSet("Generator", "Finishers", "");
break;
} // dimEnd
default:
{
ASSERT(!"Unhandled dimension");
break;
}
}
}
void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
{
bool CacheOffByDefault = false;
@ -228,7 +314,12 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
void cComposableGenerator::InitShapeGen(cIniFile & a_IniFile)
{
bool CacheOffByDefault = false;
m_ShapeGen = cTerrainShapeGen::CreateShapeGen(a_IniFile, m_BiomeGen, m_Seed, CacheOffByDefault);
m_ShapeGen = cTerrainShapeGen::CreateShapeGen(
a_IniFile,
m_BiomeGen,
m_Seed,
CacheOffByDefault
);
/*
// TODO
@ -255,7 +346,12 @@ void cComposableGenerator::InitShapeGen(cIniFile & a_IniFile)
void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
{
m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen(a_IniFile, m_BiomeGen, m_ShapeGen, m_Seed);
m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen(
a_IniFile,
m_BiomeGen,
m_ShapeGen,
m_Seed
);
// Add a cache over the composition generator:
// Even a cache of size 1 is useful due to the CompositedHeiGen cache after us doing re-composition on its misses
@ -276,10 +372,9 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
{
eDimension Dimension = StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld"));
auto seaLevel = a_IniFile.GetValueI("Generator", "SeaLevel");
AString Finishers = a_IniFile.GetValueSet("Generator", "Finishers", "");
AString Finishers = a_IniFile.GetValue("Generator", "Finishers");
// Create all requested finishers:
AStringVector Str = StringSplitAndTrim(Finishers, ",");
@ -294,11 +389,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
// Finishers, alpha-sorted:
if (NoCaseCompare(finisher, "Animals") == 0)
{
m_FinishGens.push_back(cFinishGenPtr(new cFinishGenPassiveMobs(m_Seed, a_IniFile, Dimension)));
m_FinishGens.push_back(cFinishGenPtr(new cFinishGenPassiveMobs(m_Seed, a_IniFile, m_Dimension)));
}
else if (NoCaseCompare(finisher, "BottomLava") == 0)
{
int DefaultBottomLavaLevel = (Dimension == dimNether) ? 30 : 10;
int DefaultBottomLavaLevel = (m_Dimension == dimNether) ? 30 : 10;
int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel);
m_FinishGens.push_back(cFinishGenPtr(new cFinishGenBottomLava(BottomLavaLevel)));
}
@ -369,7 +464,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
}
else if (NoCaseCompare(finisher, "LavaSprings") == 0)
{
m_FinishGens.push_back(cFinishGenPtr(new cFinishGenFluidSprings(m_Seed, E_BLOCK_LAVA, a_IniFile, Dimension)));
m_FinishGens.push_back(cFinishGenPtr(new cFinishGenFluidSprings(m_Seed, E_BLOCK_LAVA, a_IniFile, m_Dimension)));
}
else if (NoCaseCompare(finisher, "Lilypads") == 0)
{
@ -566,7 +661,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
}
else if (NoCaseCompare(finisher, "WaterSprings") == 0)
{
m_FinishGens.push_back(cFinishGenPtr(new cFinishGenFluidSprings(m_Seed, E_BLOCK_WATER, a_IniFile, Dimension)));
m_FinishGens.push_back(cFinishGenPtr(new cFinishGenFluidSprings(m_Seed, E_BLOCK_WATER, a_IniFile, m_Dimension)));
}
else if (NoCaseCompare(finisher, "WormNestCaves") == 0)
{

View File

@ -55,11 +55,16 @@ public:
/** Reads parameters from the ini file, prepares generator for use. */
virtual void InitializeBiomeGen(cIniFile & a_IniFile) {}
/** Creates the correct BiomeGen descendant based on the ini file settings and the seed provided.
/** Creates the correct BiomeGen descendant based on the ini file settings.
a_Seed is the seed read from the INI file.
a_CacheOffByDefault gets set to whether the cache should be disabled by default.
Used in BiomeVisualiser, too.
Implemented in BioGen.cpp! */
static cBiomeGenPtr CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault);
static cBiomeGenPtr CreateBiomeGen(
cIniFile & a_IniFile,
int a_Seed,
bool & a_CacheOffByDefault
);
} ;
@ -91,7 +96,12 @@ public:
a_CacheOffByDefault gets set to whether the cache should be disabled by default
Implemented in ShapeGen.cpp!
*/
static cTerrainShapeGenPtr CreateShapeGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault);
static cTerrainShapeGenPtr CreateShapeGen(
cIniFile & a_IniFile,
cBiomeGenPtr a_BiomeGen,
int a_Seed,
bool & a_CacheOffByDefault
);
} ;
@ -126,7 +136,12 @@ public:
}
/** Creates a cTerrainHeightGen descendant based on the INI file settings. */
static cTerrainHeightGenPtr CreateHeightGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault);
static cTerrainHeightGenPtr CreateHeightGen(
cIniFile & a_IniFile,
cBiomeGenPtr a_BiomeGen,
int a_Seed,
bool & a_CacheOffByDefault
);
} ;
@ -152,9 +167,13 @@ public:
/** Creates the correct TerrainCompositionGen descendant based on the ini file settings and the seed provided.
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
*/
static cTerrainCompositionGenPtr CreateCompositionGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, cTerrainShapeGenPtr a_ShapeGen, int a_Seed);
a_ShapeGen is the underlying shape generator, some composition generators may depend on it providing additional shape around the chunk. */
static cTerrainCompositionGenPtr CreateCompositionGen(
cIniFile & a_IniFile,
cBiomeGenPtr a_BiomeGen,
cTerrainShapeGenPtr a_ShapeGen,
int a_Seed
);
} ;
@ -195,7 +214,13 @@ public:
virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
virtual void Generate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc) override;
/** If there's no particular sub-generator set in the INI file,
adds the default one, based on the dimension. */
static void InitializeGeneratorDefaults(cIniFile & a_IniFile, eDimension a_Dimension);
protected:
// The generator's composition:
/** The biome generator. */
cBiomeGenPtr m_BiomeGen;

View File

@ -75,9 +75,14 @@ typedef std::shared_ptr<cTerrainHeightToShapeGen> cTerrainHeightToShapeGenPtr;
////////////////////////////////////////////////////////////////////////////////
// cTerrainShapeGen:
cTerrainShapeGenPtr cTerrainShapeGen::CreateShapeGen(cIniFile & a_IniFile, cBiomeGenPtr a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault)
cTerrainShapeGenPtr cTerrainShapeGen::CreateShapeGen(
cIniFile & a_IniFile,
cBiomeGenPtr a_BiomeGen,
int a_Seed,
bool & a_CacheOffByDefault
)
{
AString shapeGenName = a_IniFile.GetValueSet("Generator", "ShapeGen", "");
AString shapeGenName = a_IniFile.GetValue("Generator", "ShapeGen");
if (shapeGenName.empty())
{
LOGWARN("[Generator] ShapeGen value not set in world.ini, using \"BiomalNoise3D\".");

View File

@ -7,6 +7,7 @@
#include "Root.h"
#include "IniFile.h"
#include "Generating/ChunkDesc.h"
#include "Generating/ComposableGenerator.h"
#include "SetChunkData.h"
#include "DeadlockDetect.h"
#include "LineBlockTracer.h"
@ -400,8 +401,9 @@ cWorld::cWorld(
m_TNTShrapnelLevel = static_cast<eShrapnelLevel>(Clamp<int>(TNTShrapnelLevel, slNone, slAll));
m_Weather = static_cast<eWeather> (Clamp<int>(Weather, wSunny, wStorm));
InitialiseGeneratorDefaults(IniFile);
InitialiseAndLoadMobSpawningValues(IniFile);
cComposableGenerator::InitializeGeneratorDefaults(IniFile, m_Dimension);
InitializeAndLoadMobSpawningValues(IniFile);
SetTimeOfDay(IniFile.GetValueSetI("General", "TimeInTicks", GetTimeOfDay()));
m_ChunkMap = cpp14::make_unique<cChunkMap>(this);
@ -881,54 +883,7 @@ eWeather cWorld::ChooseNewWeather()
void cWorld::InitialiseGeneratorDefaults(cIniFile & a_IniFile)
{
switch (GetDimension())
{
case dimEnd:
{
a_IniFile.GetValueSet("Generator", "Generator", "Composable");
a_IniFile.GetValueSet("Generator", "BiomeGen", "Constant");
a_IniFile.GetValueSet("Generator", "ConstantBiome", "End");
a_IniFile.GetValueSet("Generator", "ShapeGen", "End");
a_IniFile.GetValueSet("Generator", "CompositionGen", "End");
break;
}
case dimOverworld:
{
a_IniFile.GetValueSet("Generator", "Generator", "Composable");
a_IniFile.GetValueSet("Generator", "BiomeGen", "Grown");
a_IniFile.GetValueSet("Generator", "ShapeGen", "BiomalNoise3D");
a_IniFile.GetValueSet("Generator", "CompositionGen", "Biomal");
a_IniFile.GetValueSet("Generator", "Finishers", "RoughRavines, WormNestCaves, WaterLakes, WaterSprings, LavaLakes, LavaSprings, OreNests, Mineshafts, Trees, Villages, TallGrass, SprinkleFoliage, Ice, Snow, Lilypads, BottomLava, DeadBushes, NaturalPatches, PreSimulator, Animals");
break;
}
case dimNether:
{
a_IniFile.GetValueSet("Generator", "Generator", "Composable");
a_IniFile.GetValueSet("Generator", "BiomeGen", "Constant");
a_IniFile.GetValueSet("Generator", "ConstantBiome", "Nether");
a_IniFile.GetValueSet("Generator", "ShapeGen", "HeightMap");
a_IniFile.GetValueSet("Generator", "HeightGen", "Flat");
a_IniFile.GetValueSet("Generator", "FlatHeight", "128");
a_IniFile.GetValueSet("Generator", "CompositionGen", "Nether");
a_IniFile.GetValueSet("Generator", "Finishers", "SoulsandRims, WormNestCaves, BottomLava, LavaSprings, NetherClumpFoliage, NetherOreNests, PieceStructures: NetherFort, GlowStone, PreSimulator");
a_IniFile.GetValueSet("Generator", "BottomLavaHeight", "30");
break;
}
case dimNotSet:
{
ASSERT(!"Dimension not set");
break;
}
}
}
void cWorld::InitialiseAndLoadMobSpawningValues(cIniFile & a_IniFile)
void cWorld::InitializeAndLoadMobSpawningValues(cIniFile & a_IniFile)
{
AString DefaultMonsters;
switch (m_Dimension)

View File

@ -1133,11 +1133,8 @@ private:
Assumes it is called from the Tick thread. */
void AddQueuedPlayers(void);
/** Sets generator values to dimension specific defaults, if those values do not exist */
void InitialiseGeneratorDefaults(cIniFile & a_IniFile);
/** Sets mob spawning values if nonexistant to their dimension specific defaults */
void InitialiseAndLoadMobSpawningValues(cIniFile & a_IniFile);
void InitializeAndLoadMobSpawningValues(cIniFile & a_IniFile);
/** Sets the specified chunk data into the chunkmap. Called in the tick thread.
Modifies the a_SetChunkData - moves the entities contained in it into the chunk. */