summaryrefslogtreecommitdiffstats
path: root/src/Generating
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2019-09-01 21:47:03 +0200
committerMattes D <github@xoft.cz>2019-09-06 16:12:33 +0200
commit878393a03d201061064f8fe02fe6d16f9c2df052 (patch)
tree77d4e1a83898e3fd0e66a484aa07704632dd063e /src/Generating
parentSeparated chunk generator from world / plugin interfaces. (diff)
downloadcuberite-878393a03d201061064f8fe02fe6d16f9c2df052.tar
cuberite-878393a03d201061064f8fe02fe6d16f9c2df052.tar.gz
cuberite-878393a03d201061064f8fe02fe6d16f9c2df052.tar.bz2
cuberite-878393a03d201061064f8fe02fe6d16f9c2df052.tar.lz
cuberite-878393a03d201061064f8fe02fe6d16f9c2df052.tar.xz
cuberite-878393a03d201061064f8fe02fe6d16f9c2df052.tar.zst
cuberite-878393a03d201061064f8fe02fe6d16f9c2df052.zip
Diffstat (limited to 'src/Generating')
-rw-r--r--src/Generating/BioGen.cpp39
-rw-r--r--src/Generating/ChunkGenerator.cpp2
-rw-r--r--src/Generating/ChunkGenerator.h3
-rw-r--r--src/Generating/CompoGenBiomal.cpp8
-rw-r--r--src/Generating/ComposableGenerator.cpp115
-rw-r--r--src/Generating/ComposableGenerator.h39
-rw-r--r--src/Generating/ShapeGen.cpp9
7 files changed, 171 insertions, 44 deletions
diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp
index 09631d098..4439fd901 100644
--- a/src/Generating/BioGen.cpp
+++ b/src/Generating/BioGen.cpp
@@ -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);
diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp
index d426ca19c..7687eea72 100644
--- a/src/Generating/ChunkGenerator.cpp
+++ b/src/Generating/ChunkGenerator.cpp
@@ -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"));
}
diff --git a/src/Generating/ChunkGenerator.h b/src/Generating/ChunkGenerator.h
index d11e846dc..703372094 100644
--- a/src/Generating/ChunkGenerator.h
+++ b/src/Generating/ChunkGenerator.h
@@ -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;
};
diff --git a/src/Generating/CompoGenBiomal.cpp b/src/Generating/CompoGenBiomal.cpp
index 624885ede..6d2277819 100644
--- a/src/Generating/CompoGenBiomal.cpp
+++ b/src/Generating/CompoGenBiomal.cpp
@@ -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)
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp
index 1cb3ed7c9..3bf2c4339 100644
--- a/src/Generating/ComposableGenerator.cpp
+++ b/src/Generating/ComposableGenerator.cpp
@@ -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)
{
diff --git a/src/Generating/ComposableGenerator.h b/src/Generating/ComposableGenerator.h
index 2eed12b74..0bc5195e9 100644
--- a/src/Generating/ComposableGenerator.h
+++ b/src/Generating/ComposableGenerator.h
@@ -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;
diff --git a/src/Generating/ShapeGen.cpp b/src/Generating/ShapeGen.cpp
index 2e764a530..20c89e33e 100644
--- a/src/Generating/ShapeGen.cpp
+++ b/src/Generating/ShapeGen.cpp
@@ -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\".");