From 5856500be7440f56ab60be53b610ab49ee9b41ba Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 2 Feb 2013 18:17:46 +0000 Subject: Moved BioGen parameter reading from cComposableGenrator into each BioGen itself git-svn-id: http://mc-server.googlecode.com/svn/trunk@1190 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Generating/BioGen.cpp | 63 ++++++++++++++++++++++++++++++- source/Generating/BioGen.h | 55 +++++++++++++-------------- source/Generating/ComposableGenerator.cpp | 23 +++-------- source/Generating/ComposableGenerator.h | 3 ++ 4 files changed, 96 insertions(+), 48 deletions(-) (limited to 'source/Generating') diff --git a/source/Generating/BioGen.cpp b/source/Generating/BioGen.cpp index bee0eda87..e5c863d75 100644 --- a/source/Generating/BioGen.cpp +++ b/source/Generating/BioGen.cpp @@ -26,6 +26,21 @@ void cBioGenConstant::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap +void cBioGenConstant::Initialize(cIniFile & a_IniFile) +{ + AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", "Plains"); + m_Biome = StringToBiome(Biome); + if (m_Biome == -1) + { + LOGWARN("[Generator]::ConstantBiome value \"%s\" not recognized, using \"Plains\".", Biome.c_str()); + m_Biome = biPlains; + } +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cBioGenCache: @@ -116,6 +131,16 @@ void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a +void cBioGenCache::Initialize(cIniFile & a_IniFile) +{ + super::Initialize(a_IniFile); + m_BioGenToCache->Initialize(a_IniFile); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cBiomeGenList: @@ -217,6 +242,19 @@ void cBioGenCheckerboard::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome +void cBioGenCheckerboard::Initialize(cIniFile & a_IniFile) +{ + super::Initialize(a_IniFile); + AString Biomes = a_IniFile.GetValueSet ("Generator", "CheckerBoardBiomes", ""); + m_BiomeSize = a_IniFile.GetValueSetI("Generator", "CheckerboardBiomeSize", 64); + m_BiomeSize = (m_BiomeSize < 8) ? 8 : m_BiomeSize; + InitializeBiomes(Biomes); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cBioGenVoronoi : @@ -238,6 +276,18 @@ void cBioGenVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & +void cBioGenVoronoi::Initialize(cIniFile & a_IniFile) +{ + super::Initialize(a_IniFile); + m_CellSize = a_IniFile.GetValueSetI("Generator", "VoronoiCellSize", 64); + AString Biomes = a_IniFile.GetValueSet ("Generator", "VoronoiBiomes", ""); + InitializeBiomes(Biomes); +} + + + + + EMCSBiome cBioGenVoronoi::VoronoiBiome(int a_BlockX, int a_BlockZ) { int CellX = a_BlockX / m_CellSize; @@ -308,6 +358,17 @@ void cBioGenDistortedVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::B +void cBioGenDistortedVoronoi::Initialize(cIniFile & a_IniFile) +{ + // Do NOT call super::Initialize(), as it would try to read Voronoi params instead of DistortedVoronoi params + m_CellSize = a_IniFile.GetValueSetI("Generator", "DistortedVoronoiCellSize", 96); + AString Biomes = a_IniFile.GetValueSet ("Generator", "DistortedVoronoiBiomes", ""); + InitializeBiomes(Biomes); +} + + + + void cBioGenDistortedVoronoi::Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ) { double NoiseX = m_Noise.CubicNoise3D((float)a_BlockX / m_CellSize, (float)a_BlockZ / m_CellSize, 1000); @@ -343,7 +404,7 @@ cBioGenMultiStepMap::cBioGenMultiStepMap(int a_Seed) : -void cBioGenMultiStepMap::Init(cIniFile & a_IniFile) +void cBioGenMultiStepMap::Initialize(cIniFile & a_IniFile) { m_OceanCellSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapOceanCellSize", m_OceanCellSize); m_MushroomIslandSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapMushroomIslandSize", m_MushroomIslandSize); diff --git a/source/Generating/BioGen.h b/source/Generating/BioGen.h index 5979ade8b..0df80967f 100644 --- a/source/Generating/BioGen.h +++ b/source/Generating/BioGen.h @@ -25,14 +25,15 @@ class cBioGenConstant : public cBiomeGen { public: - cBioGenConstant(EMCSBiome a_Biome) : m_Biome(a_Biome) {} + cBioGenConstant(void) : m_Biome(biPlains) {} protected: EMCSBiome m_Biome; - // cBiomeGen override: + // cBiomeGen overrides: virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; + virtual void Initialize(cIniFile & a_IniFile) override; } ; @@ -43,6 +44,8 @@ protected: class cBioGenCache : public cBiomeGen { + typedef cBiomeGen super; + public: cBioGenCache(cBiomeGen * a_BioGenToCache, int a_CacheSize); // Takes ownership of a_BioGenToCache ~cBioGenCache(); @@ -69,6 +72,7 @@ protected: int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits) virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; + virtual void Initialize(cIniFile & a_IniFile) override; } ; @@ -79,12 +83,9 @@ protected: class cBiomeGenList : public cBiomeGen { -protected: - cBiomeGenList(const AString & a_Biomes) - { - InitializeBiomes(a_Biomes); - } + typedef cBiomeGen super; +protected: // List of biomes that the generator is allowed to generate: typedef std::vector EMCSBiomes; EMCSBiomes m_Biomes; @@ -92,7 +93,6 @@ protected: /// Parses the INI file setting string into m_Biomes. void InitializeBiomes(const AString & a_Biomes); - } ; @@ -102,19 +102,14 @@ protected: class cBioGenCheckerboard : public cBiomeGenList { -public: - cBioGenCheckerboard(int a_BiomeSize, const AString & a_Biomes) : - cBiomeGenList(a_Biomes), - m_BiomeSize((a_BiomeSize < 8) ? 8 : a_BiomeSize) - { - } + typedef cBiomeGenList super; protected: - int m_BiomeSize; - // cBiomeGen override: + // cBiomeGen overrides: virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; + virtual void Initialize(cIniFile & a_IniFile) override; } ; @@ -124,22 +119,22 @@ protected: class cBioGenVoronoi : public cBiomeGenList { + typedef cBiomeGenList super; + public: - cBioGenVoronoi(int a_Seed, int a_CellSize, const AString & a_Biomes) : - cBiomeGenList(a_Biomes), - m_CellSize((a_CellSize > 4) ? a_CellSize : 4), + cBioGenVoronoi(int a_Seed) : m_Noise(a_Seed) { } protected: - int m_CellSize; cNoise m_Noise; - // cBiomeGen override: + // cBiomeGen overrides: virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; + virtual void Initialize(cIniFile & a_IniFile) override; EMCSBiome VoronoiBiome(int a_BlockX, int a_BlockZ); } ; @@ -151,16 +146,17 @@ protected: class cBioGenDistortedVoronoi : public cBioGenVoronoi { + typedef cBioGenVoronoi super; public: - cBioGenDistortedVoronoi(int a_Seed, int a_CellSize, const AString & a_Biomes) : - cBioGenVoronoi(a_Seed, a_CellSize, a_Biomes) + cBioGenDistortedVoronoi(int a_Seed) : + cBioGenVoronoi(a_Seed) { } protected: - - // cBiomeGen override: + // cBiomeGen overrides: virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; + virtual void Initialize(cIniFile & a_IniFile) override; /// Distorts the coords using a Perlin-like noise void Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ); @@ -173,11 +169,11 @@ protected: class cBioGenMultiStepMap : public cBiomeGen { + typedef cBiomeGen super; + public: cBioGenMultiStepMap(int a_Seed); - void Init(cIniFile & a_IniFile); - protected: cNoise m_Noise; int m_Seed; @@ -189,8 +185,9 @@ protected: typedef int IntMap[256]; // x + 16 * z, expected trimmed into [0..255] range - // cBiomeGen override: + // cBiomeGen overrides: virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override; + virtual void Initialize(cIniFile & a_IniFile) override; /** Step 1: Decides between ocean, land and mushroom, using a DistVoronoi with special conditions and post-processing for mushroom islands Sets biomes to biOcean, -1 (i.e. land), biMushroomIsland or biMushroomShore @@ -202,7 +199,7 @@ protected: */ void AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap); - /** Step 3: Decide land biomes, using Distorted Voronoi and a temperature / humidity map and freezes ocean / river in low temperatures. + /** Step 3: Decide land biomes using a temperature / humidity map; freeze ocean / river in low temperatures. Flips all remaining "-1" biomes into land biomes. Also flips some biOcean and biRiver into biFrozenOcean, biFrozenRiver, based on temp map. */ void ApplyTemperatureHumidity(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap); diff --git a/source/Generating/ComposableGenerator.cpp b/source/Generating/ComposableGenerator.cpp index 680c2e204..a758d5049 100644 --- a/source/Generating/ComposableGenerator.cpp +++ b/source/Generating/ComposableGenerator.cpp @@ -146,33 +146,21 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) bool CacheOffByDefault = false; if (NoCaseCompare(BiomeGenName, "constant") == 0) { - AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", "Plains"); - EMCSBiome b = StringToBiome(Biome); - if (b == -1) - { - LOGWARN("[Generator]::ConstantBiome value \"%s\" not recognized, using \"Plains\".", Biome.c_str()); - b = biPlains; - } - m_BiomeGen = new cBioGenConstant(b); + m_BiomeGen = new cBioGenConstant; CacheOffByDefault = true; // we're generating faster than a cache would retrieve data :) } else if (NoCaseCompare(BiomeGenName, "checkerboard") == 0) { - int BiomeSize = a_IniFile.GetValueSetI("Generator", "CheckerboardBiomeSize", 64); - AString Biomes = a_IniFile.GetValueSet ("Generator", "CheckerBoardBiomes", ""); - m_BiomeGen = new cBioGenCheckerboard(BiomeSize, Biomes); + m_BiomeGen = new cBioGenCheckerboard; CacheOffByDefault = true; // we're (probably) generating faster than a cache would retrieve data } else if (NoCaseCompare(BiomeGenName, "voronoi") == 0) { - int CellSize = a_IniFile.GetValueSetI("Generator", "VoronoiCellSize", 64); - AString Biomes = a_IniFile.GetValueSet ("Generator", "VoronoiBiomes", ""); - m_BiomeGen = new cBioGenVoronoi(Seed, CellSize, Biomes); + m_BiomeGen = new cBioGenVoronoi(Seed); } else if (NoCaseCompare(BiomeGenName, "multistepmap") == 0) { m_BiomeGen = new cBioGenMultiStepMap(Seed); - ((cBioGenMultiStepMap *)m_BiomeGen)->Init(a_IniFile); } else { @@ -180,9 +168,7 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) { LOGWARNING("Unknown BiomeGen \"%s\", using \"DistortedVoronoi\" instead.", BiomeGenName.c_str()); } - int CellSize = a_IniFile.GetValueSetI("Generator", "DistortedVoronoiCellSize", 96); - AString Biomes = a_IniFile.GetValueSet ("Generator", "DistortedVoronoiBiomes", ""); - m_BiomeGen = new cBioGenDistortedVoronoi(Seed, CellSize, Biomes); + m_BiomeGen = new cBioGenDistortedVoronoi(Seed); } // Add a cache, if requested: @@ -199,6 +185,7 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) LOGINFO("Using a cache for biomegen of size %d.", CacheSize); m_BiomeGen = new cBioGenCache(m_BiomeGen, CacheSize); } + m_BiomeGen->Initialize(a_IniFile); } diff --git a/source/Generating/ComposableGenerator.h b/source/Generating/ComposableGenerator.h index e3a37d57c..327074436 100644 --- a/source/Generating/ComposableGenerator.h +++ b/source/Generating/ComposableGenerator.h @@ -34,6 +34,9 @@ public: /// Generates biomes for the given chunk virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) = 0; + + /// Reads parameters from the ini file, prepares generator for use. + virtual void Initialize(cIniFile & a_IniFile) {} } ; -- cgit v1.2.3