1
0

shared_ptr -> unique_ptr in generators

This commit is contained in:
Tiger Wang 2021-03-08 16:39:43 +00:00
parent 3e3c30496d
commit 5ca3a7c2e7
35 changed files with 263 additions and 385 deletions

View File

@ -57,8 +57,8 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cBioGenCache: // cBioGenCache:
cBioGenCache::cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize) : cBioGenCache::cBioGenCache(cBiomeGen & a_BioGenToCache, size_t a_CacheSize) :
m_BioGenToCache(std::move(a_BioGenToCache)), m_BioGenToCache(a_BioGenToCache),
m_CacheSize(a_CacheSize), m_CacheSize(a_CacheSize),
m_NumHits(0), m_NumHits(0),
m_NumMisses(0), m_NumMisses(0),
@ -110,7 +110,7 @@ void cBioGenCache::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a
// Not in the cache: // Not in the cache:
m_NumMisses++; m_NumMisses++;
m_BioGenToCache->GenBiomes(a_ChunkCoords, a_BiomeMap); m_BioGenToCache.GenBiomes(a_ChunkCoords, a_BiomeMap);
// Insert it as the first item in the MRU order: // Insert it as the first item in the MRU order:
size_t Idx = m_CacheOrder[m_CacheSize - 1]; size_t Idx = m_CacheOrder[m_CacheSize - 1];
@ -130,7 +130,7 @@ void cBioGenCache::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a
void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile) void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile)
{ {
Super::InitializeBiomeGen(a_IniFile); Super::InitializeBiomeGen(a_IniFile);
m_BioGenToCache->InitializeBiomeGen(a_IniFile); m_BioGenToCache.InitializeBiomeGen(a_IniFile);
} }
@ -139,13 +139,14 @@ void cBioGenCache::InitializeBiomeGen(cIniFile & a_IniFile)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cBioGenMulticache: // cBioGenMulticache:
cBioGenMulticache::cBioGenMulticache(const cBiomeGenPtr & a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches) : cBioGenMulticache::cBioGenMulticache(std::unique_ptr<cBiomeGen> a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches) :
m_NumSubCaches(a_NumSubCaches) m_NumSubCaches(a_NumSubCaches),
m_Underlying(std::move(a_BioGenToCache))
{ {
m_Caches.reserve(a_NumSubCaches); m_Caches.reserve(a_NumSubCaches);
for (size_t i = 0; i < a_NumSubCaches; i++) for (size_t i = 0; i < a_NumSubCaches; i++)
{ {
m_Caches.emplace_back(new cBioGenCache(a_BioGenToCache, a_SubCacheSize)); m_Caches.push_back(std::make_unique<cBioGenCache>(*m_Underlying, a_SubCacheSize));
} }
} }
@ -167,7 +168,7 @@ void cBioGenMulticache::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMa
void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile) void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile)
{ {
for (const auto & itr : m_Caches) for (auto & itr : m_Caches)
{ {
itr->InitializeBiomeGen(a_IniFile); itr->InitializeBiomeGen(a_IniFile);
} }
@ -1133,7 +1134,7 @@ protected:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cBiomeGen: // cBiomeGen:
cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault) std::unique_ptr<cBiomeGen> cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault)
{ {
AString BiomeGenName = a_IniFile.GetValue("Generator", "BiomeGen"); AString BiomeGenName = a_IniFile.GetValue("Generator", "BiomeGen");
if (BiomeGenName.empty()) if (BiomeGenName.empty())
@ -1142,37 +1143,37 @@ cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool &
BiomeGenName = "Grown"; BiomeGenName = "Grown";
} }
cBiomeGen * res = nullptr; std::unique_ptr<cBiomeGen> res;
a_CacheOffByDefault = false; a_CacheOffByDefault = false;
if (NoCaseCompare(BiomeGenName, "constant") == 0) if (NoCaseCompare(BiomeGenName, "constant") == 0)
{ {
res = new cBioGenConstant; res = std::make_unique<cBioGenConstant>();
a_CacheOffByDefault = true; // we're generating faster than a cache would retrieve data :) a_CacheOffByDefault = true; // we're generating faster than a cache would retrieve data :)
} }
else if (NoCaseCompare(BiomeGenName, "checkerboard") == 0) else if (NoCaseCompare(BiomeGenName, "checkerboard") == 0)
{ {
res = new cBioGenCheckerboard; res = std::make_unique<cBioGenCheckerboard>();
a_CacheOffByDefault = true; // we're (probably) generating faster than a cache would retrieve data a_CacheOffByDefault = true; // we're (probably) generating faster than a cache would retrieve data
} }
else if (NoCaseCompare(BiomeGenName, "voronoi") == 0) else if (NoCaseCompare(BiomeGenName, "voronoi") == 0)
{ {
res = new cBioGenVoronoi(a_Seed); res = std::make_unique<cBioGenVoronoi>(a_Seed);
} }
else if (NoCaseCompare(BiomeGenName, "distortedvoronoi") == 0) else if (NoCaseCompare(BiomeGenName, "distortedvoronoi") == 0)
{ {
res = new cBioGenDistortedVoronoi(a_Seed); res = std::make_unique<cBioGenDistortedVoronoi>(a_Seed);
} }
else if (NoCaseCompare(BiomeGenName, "twolevel") == 0) else if (NoCaseCompare(BiomeGenName, "twolevel") == 0)
{ {
res = new cBioGenTwoLevel(a_Seed); res = std::make_unique<cBioGenTwoLevel>(a_Seed);
} }
else if (NoCaseCompare(BiomeGenName, "multistepmap") == 0) else if (NoCaseCompare(BiomeGenName, "multistepmap") == 0)
{ {
res = new cBioGenMultiStepMap(a_Seed); res = std::make_unique<cBioGenMultiStepMap>(a_Seed);
} }
else if (NoCaseCompare(BiomeGenName, "grownprot") == 0) else if (NoCaseCompare(BiomeGenName, "grownprot") == 0)
{ {
res = new cBioGenProtGrown(a_Seed); res = std::make_unique<cBioGenProtGrown>(a_Seed);
} }
else else
{ {
@ -1180,11 +1181,11 @@ cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool &
{ {
LOGWARNING("Unknown BiomeGen \"%s\", using \"Grown\" instead.", BiomeGenName.c_str()); LOGWARNING("Unknown BiomeGen \"%s\", using \"Grown\" instead.", BiomeGenName.c_str());
} }
res = new cBioGenGrown(a_Seed); res = std::make_unique<cBioGenGrown>(a_Seed);
} }
res->InitializeBiomeGen(a_IniFile); res->InitializeBiomeGen(a_IniFile);
return cBiomeGenPtr(res); return res;
} }
@ -1234,7 +1235,3 @@ protected:
} g_BioGenPerfTest; } g_BioGenPerfTest;
#endif #endif

View File

@ -49,13 +49,13 @@ class cBioGenCache:
public: public:
cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize); cBioGenCache(cBiomeGen & a_BioGenToCache, size_t a_CacheSize);
virtual ~cBioGenCache() override = default;
protected: protected:
cBiomeGenPtr m_BioGenToCache; friend class cBioGenMulticache;
cBiomeGen & m_BioGenToCache;
struct sCacheData struct sCacheData
{ {
@ -97,17 +97,18 @@ public:
This allows us to use shorter cache depths with faster lookups for more covered area. (#381) This allows us to use shorter cache depths with faster lookups for more covered area. (#381)
a_SubCacheSize defines the size of each sub-cache a_SubCacheSize defines the size of each sub-cache
a_NumSubCaches defines how many sub-caches are used for the multicache. */ a_NumSubCaches defines how many sub-caches are used for the multicache. */
cBioGenMulticache(const cBiomeGenPtr & a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches); cBioGenMulticache(std::unique_ptr<cBiomeGen> a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches);
protected: protected:
typedef std::vector<cBiomeGenPtr> cBiomeGenPtrs;
/** Number of sub-caches. Pulled out of m_Caches.size() for faster access. */ /** Number of sub-caches. Pulled out of m_Caches.size() for faster access. */
size_t m_NumSubCaches; size_t m_NumSubCaches;
/** Individual sub-caches. */ /** Individual sub-caches. */
cBiomeGenPtrs m_Caches; std::vector<std::unique_ptr<cBioGenCache>> m_Caches;
/** The underlying biome generator. */
std::unique_ptr<cBiomeGen> m_Underlying;
virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override; virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
@ -323,7 +324,3 @@ protected:
a_DistLevel is either 0 or 1; zero when it is at the edge of the small Voronoi cell, 1 near the center */ a_DistLevel is either 0 or 1; zero when it is at the edge of the small Voronoi cell, 1 near the center */
EMCSBiome SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel); EMCSBiome SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel);
} ; } ;

View File

@ -329,7 +329,7 @@ void cCompoGenNether::InitializeCompoGen(cIniFile & a_IniFile)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cCompoGenCache: // cCompoGenCache:
cCompoGenCache::cCompoGenCache(cTerrainCompositionGenPtr a_Underlying, int a_CacheSize) : cCompoGenCache::cCompoGenCache(std::unique_ptr<cTerrainCompositionGen> a_Underlying, int a_CacheSize) :
m_Underlying(std::move(a_Underlying)), m_Underlying(std::move(a_Underlying)),
m_CacheSize(a_CacheSize), m_CacheSize(a_CacheSize),
m_CacheOrder(new int[ToUnsigned(a_CacheSize)]), m_CacheOrder(new int[ToUnsigned(a_CacheSize)]),
@ -430,7 +430,3 @@ void cCompoGenCache::InitializeCompoGen(cIniFile & a_IniFile)
{ {
m_Underlying->InitializeCompoGen(a_IniFile); m_Underlying->InitializeCompoGen(a_IniFile);
} }

View File

@ -115,7 +115,7 @@ class cCompoGenCache :
public cTerrainCompositionGen public cTerrainCompositionGen
{ {
public: public:
cCompoGenCache(cTerrainCompositionGenPtr a_Underlying, int a_CacheSize); // Doesn't take ownership of a_Underlying cCompoGenCache(std::unique_ptr<cTerrainCompositionGen> a_Underlying, int a_CacheSize);
virtual ~cCompoGenCache() override; virtual ~cCompoGenCache() override;
// cTerrainCompositionGen override: // cTerrainCompositionGen override:
@ -124,7 +124,7 @@ public:
protected: protected:
cTerrainCompositionGenPtr m_Underlying; std::unique_ptr<cTerrainCompositionGen> m_Underlying;
struct sCacheData struct sCacheData
{ {
@ -145,7 +145,3 @@ protected:
int m_NumMisses; int m_NumMisses;
int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits) int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits)
} ; } ;

View File

@ -582,10 +582,7 @@ protected:
cTerrainCompositionGenPtr CreateCompoGenBiomal(int a_Seed) std::unique_ptr<cTerrainCompositionGen> CreateCompoGenBiomal(int a_Seed)
{ {
return std::make_shared<cCompoGenBiomal>(a_Seed); return std::make_unique<cCompoGenBiomal>(a_Seed);
} }

View File

@ -14,8 +14,4 @@
/** Returns a new instance of the Biomal composition generator. */ /** Returns a new instance of the Biomal composition generator. */
cTerrainCompositionGenPtr CreateCompoGenBiomal(int a_Seed); std::unique_ptr<cTerrainCompositionGen> CreateCompoGenBiomal(int a_Seed);

View File

@ -38,10 +38,10 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cTerrainCompositionGen: // cTerrainCompositionGen:
cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen( std::unique_ptr<cTerrainCompositionGen> cTerrainCompositionGen::CreateCompositionGen(
cIniFile & a_IniFile, cIniFile & a_IniFile,
const cBiomeGenPtr & a_BiomeGen, cBiomeGen & a_BiomeGen,
const cTerrainShapeGenPtr & a_ShapeGen, cTerrainShapeGen & a_ShapeGen,
int a_Seed int a_Seed
) )
{ {
@ -53,7 +53,7 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen(
} }
// Compositor list is alpha-sorted // Compositor list is alpha-sorted
cTerrainCompositionGenPtr res; std::unique_ptr<cTerrainCompositionGen> res;
if (NoCaseCompare(CompoGenName, "Biomal") == 0) if (NoCaseCompare(CompoGenName, "Biomal") == 0)
{ {
res = CreateCompoGenBiomal(a_Seed); res = CreateCompoGenBiomal(a_Seed);
@ -65,11 +65,11 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen(
} }
else if (NoCaseCompare(CompoGenName, "Classic") == 0) else if (NoCaseCompare(CompoGenName, "Classic") == 0)
{ {
res = std::make_shared<cCompoGenClassic>(); res = std::make_unique<cCompoGenClassic>();
} }
else if (NoCaseCompare(CompoGenName, "DebugBiomes") == 0) else if (NoCaseCompare(CompoGenName, "DebugBiomes") == 0)
{ {
res = std::make_shared<cCompoGenDebugBiomes>(); res = std::make_unique<cCompoGenDebugBiomes>();
} }
else if (NoCaseCompare(CompoGenName, "DistortedHeightmap") == 0) else if (NoCaseCompare(CompoGenName, "DistortedHeightmap") == 0)
{ {
@ -78,11 +78,11 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen(
} }
else if (NoCaseCompare(CompoGenName, "End") == 0) else if (NoCaseCompare(CompoGenName, "End") == 0)
{ {
res = std::make_shared<cEndGen>(a_Seed); res = std::make_unique<cEndGen>(a_Seed);
} }
else if (NoCaseCompare(CompoGenName, "Nether") == 0) else if (NoCaseCompare(CompoGenName, "Nether") == 0)
{ {
res = std::make_shared<cCompoGenNether>(a_Seed); res = std::make_unique<cCompoGenNether>(a_Seed);
} }
else if (NoCaseCompare(CompoGenName, "Noise3D") == 0) else if (NoCaseCompare(CompoGenName, "Noise3D") == 0)
{ {
@ -91,7 +91,7 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen(
} }
else if (NoCaseCompare(CompoGenName, "SameBlock") == 0) else if (NoCaseCompare(CompoGenName, "SameBlock") == 0)
{ {
res = std::make_shared<cCompoGenSameBlock>(); res = std::make_unique<cCompoGenSameBlock>();
} }
else else
{ {
@ -104,7 +104,7 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen(
// Read the settings from the ini file: // Read the settings from the ini file:
res->InitializeCompoGen(a_IniFile); res->InitializeCompoGen(a_IniFile);
return cTerrainCompositionGenPtr(res); return res;
} }
@ -181,10 +181,10 @@ void cComposableGenerator::Generate(cChunkDesc & a_ChunkDesc)
if (a_ChunkDesc.IsUsingDefaultFinish()) if (a_ChunkDesc.IsUsingDefaultFinish())
{ {
for (cFinishGenList::iterator itr = m_FinishGens.begin(); itr != m_FinishGens.end(); ++itr) for (const auto & Finisher : m_FinishGens)
{ {
(*itr)->GenFinish(a_ChunkDesc); Finisher->GenFinish(a_ChunkDesc);
} // for itr - m_FinishGens[] }
ShouldUpdateHeightmap = true; ShouldUpdateHeightmap = true;
} }
@ -302,11 +302,11 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile)
if (MultiCacheLength > 0) if (MultiCacheLength > 0)
{ {
LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength); LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength);
m_BiomeGen = std::make_shared<cBioGenMulticache>(m_BiomeGen, static_cast<size_t>(CacheSize), static_cast<size_t>(MultiCacheLength)); m_BiomeGen = std::make_unique<cBioGenMulticache>(std::move(m_BiomeGen), static_cast<size_t>(CacheSize), static_cast<size_t>(MultiCacheLength));
} }
else else
{ {
m_BiomeGen = std::make_shared<cBioGenCache>(m_BiomeGen, static_cast<size_t>(CacheSize)); m_BiomeGen = std::make_unique<cBioGenMulticache>(std::move(m_BiomeGen), static_cast<size_t>(CacheSize), 1);
} }
} }
@ -319,7 +319,7 @@ void cComposableGenerator::InitShapeGen(cIniFile & a_IniFile)
bool CacheOffByDefault = false; bool CacheOffByDefault = false;
m_ShapeGen = cTerrainShapeGen::CreateShapeGen( m_ShapeGen = cTerrainShapeGen::CreateShapeGen(
a_IniFile, a_IniFile,
m_BiomeGen, *m_BiomeGen,
m_Seed, m_Seed,
CacheOffByDefault CacheOffByDefault
); );
@ -351,8 +351,8 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
{ {
m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen( m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen(
a_IniFile, a_IniFile,
m_BiomeGen, *m_BiomeGen,
m_ShapeGen, *m_ShapeGen,
m_Seed m_Seed
); );
@ -361,11 +361,11 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile)
int CompoGenCacheSize = a_IniFile.GetValueSetI("Generator", "CompositionGenCacheSize", 64); int CompoGenCacheSize = a_IniFile.GetValueSetI("Generator", "CompositionGenCacheSize", 64);
if (CompoGenCacheSize > 0) if (CompoGenCacheSize > 0)
{ {
m_CompositionGen = std::make_shared<cCompoGenCache>(m_CompositionGen, CompoGenCacheSize); m_CompositionGen = std::make_unique<cCompoGenCache>(std::move(m_CompositionGen), CompoGenCacheSize);
} }
// Create a cache of the composited heightmaps, so that finishers may use it: // Create a cache of the composited heightmaps, so that finishers may use it:
m_CompositedHeightCache = std::make_shared<cHeiGenMultiCache>(std::make_shared<cCompositedHeiGen>(m_BiomeGen, m_ShapeGen, m_CompositionGen), 16, 128); m_CompositedHeightCache = std::make_unique<cHeiGenMultiCache>(std::make_unique<cCompositedHeiGen>(*m_BiomeGen, *m_ShapeGen, *m_CompositionGen), 16, 128);
// 128 subcaches of depth 16 each = 0.5 MiB of RAM. Acceptable, for the amount of work this saves. // 128 subcaches of depth 16 each = 0.5 MiB of RAM. Acceptable, for the amount of work this saves.
} }
@ -392,13 +392,13 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
// Finishers, alpha-sorted: // Finishers, alpha-sorted:
if (NoCaseCompare(finisher, "Animals") == 0) if (NoCaseCompare(finisher, "Animals") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenPassiveMobs(m_Seed, a_IniFile, m_Dimension)); m_FinishGens.push_back(std::make_unique<cFinishGenPassiveMobs>(m_Seed, a_IniFile, m_Dimension));
} }
else if (NoCaseCompare(finisher, "BottomLava") == 0) else if (NoCaseCompare(finisher, "BottomLava") == 0)
{ {
int DefaultBottomLavaLevel = (m_Dimension == dimNether) ? 30 : 10; int DefaultBottomLavaLevel = (m_Dimension == dimNether) ? 30 : 10;
int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel); int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel);
m_FinishGens.emplace_back(new cFinishGenBottomLava(BottomLavaLevel)); m_FinishGens.push_back(std::make_unique<cFinishGenBottomLava>(BottomLavaLevel));
} }
else if (NoCaseCompare(finisher, "DeadBushes") == 0) else if (NoCaseCompare(finisher, "DeadBushes") == 0)
{ {
@ -421,26 +421,26 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
AllowedBlocks.push_back(E_BLOCK_HARDENED_CLAY); AllowedBlocks.push_back(E_BLOCK_HARDENED_CLAY);
AllowedBlocks.push_back(E_BLOCK_STAINED_CLAY); AllowedBlocks.push_back(E_BLOCK_STAINED_CLAY);
m_FinishGens.emplace_back(new cFinishGenSingleTopBlock(m_Seed, E_BLOCK_DEAD_BUSH, AllowedBiomes, 2, AllowedBlocks)); m_FinishGens.push_back(std::make_unique<cFinishGenSingleTopBlock>(m_Seed, E_BLOCK_DEAD_BUSH, AllowedBiomes, 2, AllowedBlocks));
} }
else if (NoCaseCompare(finisher, "DirectOverhangs") == 0) else if (NoCaseCompare(finisher, "DirectOverhangs") == 0)
{ {
m_FinishGens.emplace_back(new cStructGenDirectOverhangs(m_Seed)); m_FinishGens.push_back(std::make_unique<cStructGenDirectOverhangs>(m_Seed));
} }
else if (NoCaseCompare(finisher, "DirtPockets") == 0) else if (NoCaseCompare(finisher, "DirtPockets") == 0)
{ {
auto gen = std::make_shared<cFinishGenOrePockets>(m_Seed + 1, cFinishGenOrePockets::DefaultNaturalPatches()); auto Gen = std::make_unique<cFinishGenOrePockets>(m_Seed + 1, cFinishGenOrePockets::DefaultNaturalPatches());
gen->Initialize(a_IniFile, "DirtPockets"); Gen->Initialize(a_IniFile, "DirtPockets");
m_FinishGens.push_back(gen); m_FinishGens.push_back(std::move(Gen));
} }
else if (NoCaseCompare(finisher, "DistortedMembraneOverhangs") == 0) else if (NoCaseCompare(finisher, "DistortedMembraneOverhangs") == 0)
{ {
m_FinishGens.emplace_back(new cStructGenDistortedMembraneOverhangs(m_Seed)); m_FinishGens.push_back(std::make_unique<cStructGenDistortedMembraneOverhangs>(m_Seed));
} }
else if (NoCaseCompare(finisher, "DualRidgeCaves") == 0) else if (NoCaseCompare(finisher, "DualRidgeCaves") == 0)
{ {
float Threshold = static_cast<float>(a_IniFile.GetValueSetF("Generator", "DualRidgeCavesThreshold", 0.3)); float Threshold = static_cast<float>(a_IniFile.GetValueSetF("Generator", "DualRidgeCavesThreshold", 0.3));
m_FinishGens.emplace_back(new cStructGenDualRidgeCaves(m_Seed, Threshold)); m_FinishGens.push_back(std::make_unique<cStructGenDualRidgeCaves>(m_Seed, Threshold));
} }
else if (NoCaseCompare(finisher, "DungeonRooms") == 0) else if (NoCaseCompare(finisher, "DungeonRooms") == 0)
{ {
@ -448,24 +448,24 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
int MaxSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMaxSize", 7); int MaxSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMaxSize", 7);
int MinSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMinSize", 5); int MinSize = a_IniFile.GetValueSetI("Generator", "DungeonRoomsMinSize", 5);
AString HeightDistrib = a_IniFile.GetValueSet ("Generator", "DungeonRoomsHeightDistrib", "0, 0; 10, 10; 11, 500; 40, 500; 60, 40; 90, 1"); AString HeightDistrib = a_IniFile.GetValueSet ("Generator", "DungeonRoomsHeightDistrib", "0, 0; 10, 10; 11, 500; 40, 500; 60, 40; 90, 1");
m_FinishGens.emplace_back(new cDungeonRoomsFinisher(m_ShapeGen, m_Seed, GridSize, MaxSize, MinSize, HeightDistrib)); m_FinishGens.push_back(std::make_unique<cDungeonRoomsFinisher>(*m_ShapeGen, m_Seed, GridSize, MaxSize, MinSize, HeightDistrib));
} }
else if (NoCaseCompare(finisher, "GlowStone") == 0) else if (NoCaseCompare(finisher, "GlowStone") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenGlowStone(m_Seed)); m_FinishGens.push_back(std::make_unique<cFinishGenGlowStone>(m_Seed));
} }
else if (NoCaseCompare(finisher, "Ice") == 0) else if (NoCaseCompare(finisher, "Ice") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenIce); m_FinishGens.push_back(std::make_unique<cFinishGenIce>());
} }
else if (NoCaseCompare(finisher, "LavaLakes") == 0) else if (NoCaseCompare(finisher, "LavaLakes") == 0)
{ {
int Probability = a_IniFile.GetValueSetI("Generator", "LavaLakesProbability", 10); int Probability = a_IniFile.GetValueSetI("Generator", "LavaLakesProbability", 10);
m_FinishGens.emplace_back(new cStructGenLakes(m_Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, m_ShapeGen, Probability)); m_FinishGens.push_back(std::make_unique<cStructGenLakes>(m_Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, *m_ShapeGen, Probability));
} }
else if (NoCaseCompare(finisher, "LavaSprings") == 0) else if (NoCaseCompare(finisher, "LavaSprings") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenFluidSprings(m_Seed, E_BLOCK_LAVA, a_IniFile, m_Dimension)); m_FinishGens.push_back(std::make_unique<cFinishGenFluidSprings>(m_Seed, E_BLOCK_LAVA, a_IniFile, m_Dimension));
} }
else if (NoCaseCompare(finisher, "Lilypads") == 0) else if (NoCaseCompare(finisher, "Lilypads") == 0)
{ {
@ -479,11 +479,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
AllowedBlocks.push_back(E_BLOCK_WATER); AllowedBlocks.push_back(E_BLOCK_WATER);
AllowedBlocks.push_back(E_BLOCK_STATIONARY_WATER); AllowedBlocks.push_back(E_BLOCK_STATIONARY_WATER);
m_FinishGens.emplace_back(new cFinishGenSingleTopBlock(m_Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks)); m_FinishGens.push_back(std::make_unique<cFinishGenSingleTopBlock>(m_Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks));
} }
else if (NoCaseCompare(finisher, "MarbleCaves") == 0) else if (NoCaseCompare(finisher, "MarbleCaves") == 0)
{ {
m_FinishGens.emplace_back(new cStructGenMarbleCaves(m_Seed)); m_FinishGens.push_back(std::make_unique<cStructGenMarbleCaves>(m_Seed));
} }
else if (NoCaseCompare(finisher, "MineShafts") == 0) else if (NoCaseCompare(finisher, "MineShafts") == 0)
{ {
@ -493,37 +493,37 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
int ChanceCorridor = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCorridor", 600); int ChanceCorridor = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCorridor", 600);
int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200); int ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200);
int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200); int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200);
m_FinishGens.emplace_back(new cStructGenMineShafts( m_FinishGens.push_back(std::make_unique<cStructGenMineShafts>(
m_Seed, GridSize, MaxOffset, MaxSystemSize, m_Seed, GridSize, MaxOffset, MaxSystemSize,
ChanceCorridor, ChanceCrossing, ChanceStaircase ChanceCorridor, ChanceCrossing, ChanceStaircase
)); ));
} }
else if (NoCaseCompare(finisher, "NaturalPatches") == 0) else if (NoCaseCompare(finisher, "NaturalPatches") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenOreNests(m_Seed + 1, cFinishGenOreNests::DefaultNaturalPatches())); m_FinishGens.push_back(std::make_unique<cFinishGenOreNests>(m_Seed + 1, cFinishGenOreNests::DefaultNaturalPatches()));
} }
else if (NoCaseCompare(finisher, "NetherClumpFoliage") == 0) else if (NoCaseCompare(finisher, "NetherClumpFoliage") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenNetherClumpFoliage(m_Seed)); m_FinishGens.push_back(std::make_unique<cFinishGenNetherClumpFoliage>(m_Seed));
} }
else if (NoCaseCompare(finisher, "NetherOreNests") == 0) else if (NoCaseCompare(finisher, "NetherOreNests") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenOreNests(m_Seed + 2, cFinishGenOreNests::DefaultNetherOres())); m_FinishGens.push_back(std::make_unique<cFinishGenOreNests>(m_Seed + 2, cFinishGenOreNests::DefaultNetherOres()));
} }
else if (NoCaseCompare(finisher, "OreNests") == 0) else if (NoCaseCompare(finisher, "OreNests") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenOreNests(m_Seed + 3, cFinishGenOreNests::DefaultOverworldOres())); m_FinishGens.push_back(std::make_unique<cFinishGenOreNests>(m_Seed + 3, cFinishGenOreNests::DefaultOverworldOres()));
} }
else if (NoCaseCompare(finisher, "OrePockets") == 0) else if (NoCaseCompare(finisher, "OrePockets") == 0)
{ {
auto gen = std::make_shared<cFinishGenOrePockets>(m_Seed + 2, cFinishGenOrePockets::DefaultOverworldOres()); auto Gen = std::make_unique<cFinishGenOrePockets>(m_Seed + 2, cFinishGenOrePockets::DefaultOverworldOres());
gen->Initialize(a_IniFile, "OrePockets"); Gen->Initialize(a_IniFile, "OrePockets");
m_FinishGens.push_back(gen); m_FinishGens.push_back(std::move(Gen));
} }
else if (NoCaseCompare(finisher, "OverworldClumpFlowers") == 0) else if (NoCaseCompare(finisher, "OverworldClumpFlowers") == 0)
{ {
auto flowers = cFinishGenClumpTopBlock::ParseIniFile(a_IniFile, "OverworldClumpFlowers"); auto flowers = cFinishGenClumpTopBlock::ParseIniFile(a_IniFile, "OverworldClumpFlowers");
m_FinishGens.emplace_back(new cFinishGenClumpTopBlock(m_Seed, flowers)); m_FinishGens.push_back(std::make_unique<cFinishGenClumpTopBlock>(m_Seed, flowers));
} }
else if (NoCaseCompare(finisher, "PieceStructures") == 0) else if (NoCaseCompare(finisher, "PieceStructures") == 0)
{ {
@ -533,10 +533,10 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
continue; continue;
} }
auto gen = std::make_shared<cPieceStructuresGen>(m_Seed); auto Gen = std::make_unique<cPieceStructuresGen>(m_Seed);
if (gen->Initialize(split[1], seaLevel, m_BiomeGen, m_CompositedHeightCache)) if (Gen->Initialize(split[1], seaLevel, *m_BiomeGen, *m_CompositedHeightCache))
{ {
m_FinishGens.push_back(gen); m_FinishGens.push_back(std::move(Gen));
} }
} }
else if (NoCaseCompare(finisher, "PreSimulator") == 0) else if (NoCaseCompare(finisher, "PreSimulator") == 0)
@ -546,11 +546,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
bool PreSimulateWater = a_IniFile.GetValueSetB("Generator", "PreSimulatorWater", true); bool PreSimulateWater = a_IniFile.GetValueSetB("Generator", "PreSimulatorWater", true);
bool PreSimulateLava = a_IniFile.GetValueSetB("Generator", "PreSimulatorLava", true); bool PreSimulateLava = a_IniFile.GetValueSetB("Generator", "PreSimulatorLava", true);
m_FinishGens.emplace_back(new cFinishGenPreSimulator(PreSimulateFallingBlocks, PreSimulateWater, PreSimulateLava)); m_FinishGens.push_back(std::make_unique<cFinishGenPreSimulator>(PreSimulateFallingBlocks, PreSimulateWater, PreSimulateLava));
} }
else if (NoCaseCompare(finisher, "Ravines") == 0) else if (NoCaseCompare(finisher, "Ravines") == 0)
{ {
m_FinishGens.emplace_back(new cStructGenRavines(m_Seed, 128)); m_FinishGens.push_back(std::make_unique<cStructGenRavines>(m_Seed, 128));
} }
else if (NoCaseCompare(finisher, "RoughRavines") == 0) else if (NoCaseCompare(finisher, "RoughRavines") == 0)
{ {
@ -570,7 +570,7 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
double MinCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightEdge", 38); double MinCeilingHeightEdge = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightEdge", 38);
double MaxCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightCenter", 58); double MaxCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightCenter", 58);
double MinCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightCenter", 36); double MinCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightCenter", 36);
m_FinishGens.emplace_back(new cRoughRavines( m_FinishGens.push_back(std::make_unique<cRoughRavines>(
m_Seed, MaxSize, MinSize, m_Seed, MaxSize, MinSize,
static_cast<float>(MaxCenterWidth), static_cast<float>(MaxCenterWidth),
static_cast<float>(MinCenterWidth), static_cast<float>(MinCenterWidth),
@ -595,33 +595,33 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
continue; continue;
} }
auto Gen = std::make_shared<cSinglePieceStructuresGen>(m_Seed); auto Gen = std::make_unique<cSinglePieceStructuresGen>(m_Seed);
if (Gen->Initialize(split[1], seaLevel, m_BiomeGen, m_CompositedHeightCache)) if (Gen->Initialize(split[1], seaLevel, *m_BiomeGen, *m_CompositedHeightCache))
{ {
m_FinishGens.push_back(Gen); m_FinishGens.push_back(std::move(Gen));
} }
} }
else if (NoCaseCompare(finisher, "SoulsandRims") == 0) else if (NoCaseCompare(finisher, "SoulsandRims") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenSoulsandRims(m_Seed)); m_FinishGens.push_back(std::make_unique<cFinishGenSoulsandRims>(m_Seed));
} }
else if (NoCaseCompare(finisher, "Snow") == 0) else if (NoCaseCompare(finisher, "Snow") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenSnow); m_FinishGens.push_back(std::make_unique<cFinishGenSnow>());
} }
else if (NoCaseCompare(finisher, "SprinkleFoliage") == 0) else if (NoCaseCompare(finisher, "SprinkleFoliage") == 0)
{ {
int MaxCactusHeight = a_IniFile.GetValueI("Plants", "MaxCactusHeight", 3); int MaxCactusHeight = a_IniFile.GetValueI("Plants", "MaxCactusHeight", 3);
int MaxSugarcaneHeight = a_IniFile.GetValueI("Plants", "MaxSugarcaneHeight", 3); int MaxSugarcaneHeight = a_IniFile.GetValueI("Plants", "MaxSugarcaneHeight", 3);
m_FinishGens.emplace_back(new cFinishGenSprinkleFoliage(m_Seed, MaxCactusHeight, MaxSugarcaneHeight)); m_FinishGens.push_back(std::make_unique<cFinishGenSprinkleFoliage>(m_Seed, MaxCactusHeight, MaxSugarcaneHeight));
} }
else if (NoCaseCompare(finisher, "TallGrass") == 0) else if (NoCaseCompare(finisher, "TallGrass") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenTallGrass(m_Seed)); m_FinishGens.push_back(std::make_unique<cFinishGenTallGrass>(m_Seed));
} }
else if (NoCaseCompare(finisher, "Trees") == 0) else if (NoCaseCompare(finisher, "Trees") == 0)
{ {
m_FinishGens.emplace_back(new cStructGenTrees(m_Seed, m_BiomeGen, m_ShapeGen, m_CompositionGen)); m_FinishGens.push_back(std::make_unique<cStructGenTrees>(m_Seed, *m_BiomeGen, *m_ShapeGen, *m_CompositionGen));
} }
else if (NoCaseCompare(finisher, "Villages") == 0) else if (NoCaseCompare(finisher, "Villages") == 0)
{ {
@ -633,28 +633,28 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
int MaxDensity = a_IniFile.GetValueSetI("Generator", "VillageMaxDensity", 80); int MaxDensity = a_IniFile.GetValueSetI("Generator", "VillageMaxDensity", 80);
AString PrefabList = a_IniFile.GetValueSet("Generator", "VillagePrefabs", "PlainsVillage, SandVillage"); AString PrefabList = a_IniFile.GetValueSet("Generator", "VillagePrefabs", "PlainsVillage, SandVillage");
auto Prefabs = StringSplitAndTrim(PrefabList, ","); auto Prefabs = StringSplitAndTrim(PrefabList, ",");
m_FinishGens.emplace_back(new cVillageGen(m_Seed, GridSize, MaxOffset, MaxDepth, MaxSize, MinDensity, MaxDensity, m_BiomeGen, m_CompositedHeightCache, seaLevel, Prefabs)); m_FinishGens.push_back(std::make_unique<cVillageGen>(m_Seed, GridSize, MaxOffset, MaxDepth, MaxSize, MinDensity, MaxDensity, *m_BiomeGen, *m_CompositedHeightCache, seaLevel, Prefabs));
} }
else if (NoCaseCompare(finisher, "Vines") == 0) else if (NoCaseCompare(finisher, "Vines") == 0)
{ {
int Level = a_IniFile.GetValueSetI("Generator", "VinesLevel", 40); int Level = a_IniFile.GetValueSetI("Generator", "VinesLevel", 40);
m_FinishGens.emplace_back(new cFinishGenVines(m_Seed, Level)); m_FinishGens.push_back(std::make_unique<cFinishGenVines>(m_Seed, Level));
} }
else if (NoCaseCompare(finisher, "WaterLakes") == 0) else if (NoCaseCompare(finisher, "WaterLakes") == 0)
{ {
int Probability = a_IniFile.GetValueSetI("Generator", "WaterLakesProbability", 25); int Probability = a_IniFile.GetValueSetI("Generator", "WaterLakesProbability", 25);
m_FinishGens.emplace_back(new cStructGenLakes(m_Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, m_ShapeGen, Probability)); m_FinishGens.push_back(std::make_unique<cStructGenLakes>(m_Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, *m_ShapeGen, Probability));
} }
else if (NoCaseCompare(finisher, "WaterSprings") == 0) else if (NoCaseCompare(finisher, "WaterSprings") == 0)
{ {
m_FinishGens.emplace_back(new cFinishGenFluidSprings(m_Seed, E_BLOCK_WATER, a_IniFile, m_Dimension)); m_FinishGens.push_back(std::make_unique<cFinishGenFluidSprings>(m_Seed, E_BLOCK_WATER, a_IniFile, m_Dimension));
} }
else if (NoCaseCompare(finisher, "WormNestCaves") == 0) else if (NoCaseCompare(finisher, "WormNestCaves") == 0)
{ {
int Size = a_IniFile.GetValueSetI("Generator", "WormNestCavesSize", 64); int Size = a_IniFile.GetValueSetI("Generator", "WormNestCavesSize", 64);
int Grid = a_IniFile.GetValueSetI("Generator", "WormNestCavesGrid", 96); int Grid = a_IniFile.GetValueSetI("Generator", "WormNestCavesGrid", 96);
int MaxOffset = a_IniFile.GetValueSetI("Generator", "WormNestMaxOffset", 32); int MaxOffset = a_IniFile.GetValueSetI("Generator", "WormNestMaxOffset", 32);
m_FinishGens.emplace_back(new cStructGenWormNestCaves(m_Seed, Size, Grid, MaxOffset)); m_FinishGens.push_back(std::make_unique<cStructGenWormNestCaves>(m_Seed, Size, Grid, MaxOffset));
} }
else else
{ {
@ -662,7 +662,3 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile)
} }
} // for itr - Str[] } // for itr - Str[]
} }

View File

@ -30,11 +30,6 @@ class cTerrainShapeGen;
class cTerrainHeightGen; class cTerrainHeightGen;
class cTerrainCompositionGen; class cTerrainCompositionGen;
class cFinishGen; class cFinishGen;
typedef std::shared_ptr<cBiomeGen> cBiomeGenPtr;
typedef std::shared_ptr<cTerrainShapeGen> cTerrainShapeGenPtr;
typedef std::shared_ptr<cTerrainHeightGen> cTerrainHeightGenPtr;
typedef std::shared_ptr<cTerrainCompositionGen> cTerrainCompositionGenPtr;
typedef std::shared_ptr<cFinishGen> cFinishGenPtr;
@ -60,7 +55,7 @@ public:
a_CacheOffByDefault gets set to whether the cache should be disabled by default. a_CacheOffByDefault gets set to whether the cache should be disabled by default.
Used in BiomeVisualiser, too. Used in BiomeVisualiser, too.
Implemented in BioGen.cpp! */ Implemented in BioGen.cpp! */
static cBiomeGenPtr CreateBiomeGen( static std::unique_ptr<cBiomeGen> CreateBiomeGen(
cIniFile & a_IniFile, cIniFile & a_IniFile,
int a_Seed, int a_Seed,
bool & a_CacheOffByDefault bool & a_CacheOffByDefault
@ -96,9 +91,9 @@ public:
a_CacheOffByDefault gets set to whether the cache should be disabled by default a_CacheOffByDefault gets set to whether the cache should be disabled by default
Implemented in ShapeGen.cpp! Implemented in ShapeGen.cpp!
*/ */
static cTerrainShapeGenPtr CreateShapeGen( static std::unique_ptr<cTerrainShapeGen> CreateShapeGen(
cIniFile & a_IniFile, cIniFile & a_IniFile,
const cBiomeGenPtr & a_BiomeGen, cBiomeGen & a_BiomeGen,
int a_Seed, int a_Seed,
bool & a_CacheOffByDefault bool & a_CacheOffByDefault
); );
@ -135,9 +130,9 @@ public:
} }
/** Creates a cTerrainHeightGen descendant based on the INI file settings. */ /** Creates a cTerrainHeightGen descendant based on the INI file settings. */
static cTerrainHeightGenPtr CreateHeightGen( static std::unique_ptr<cTerrainHeightGen> CreateHeightGen(
cIniFile & a_IniFile, cIniFile & a_IniFile,
const cBiomeGenPtr & a_BiomeGen, cBiomeGen & a_BiomeGen,
int a_Seed, int a_Seed,
bool & a_CacheOffByDefault bool & a_CacheOffByDefault
); );
@ -167,10 +162,10 @@ public:
/** Creates the correct TerrainCompositionGen descendant based on the ini file settings and the seed provided. /** 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_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. */ a_ShapeGen is the underlying shape generator, some composition generators may depend on it providing additional shape around the chunk. */
static cTerrainCompositionGenPtr CreateCompositionGen( static std::unique_ptr<cTerrainCompositionGen> CreateCompositionGen(
cIniFile & a_IniFile, cIniFile & a_IniFile,
const cBiomeGenPtr & a_BiomeGen, cBiomeGen & a_BiomeGen,
const cTerrainShapeGenPtr & a_ShapeGen, cTerrainShapeGen & a_ShapeGen,
int a_Seed int a_Seed
); );
} ; } ;
@ -194,8 +189,6 @@ public:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0; virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0;
} ; } ;
typedef std::list<cFinishGenPtr> cFinishGenList;
@ -223,19 +216,19 @@ protected:
// The generator's composition: // The generator's composition:
/** The biome generator. */ /** The biome generator. */
cBiomeGenPtr m_BiomeGen; std::unique_ptr<cBiomeGen> m_BiomeGen;
/** The terrain shape generator. */ /** The terrain shape generator. */
cTerrainShapeGenPtr m_ShapeGen; std::unique_ptr<cTerrainShapeGen> m_ShapeGen;
/** The terrain composition generator. */ /** The terrain composition generator. */
cTerrainCompositionGenPtr m_CompositionGen; std::unique_ptr<cTerrainCompositionGen> m_CompositionGen;
/** The cache for the heights of the composited terrain. */ /** The cache for the heights of the composited terrain. */
cTerrainHeightGenPtr m_CompositedHeightCache; std::unique_ptr<cTerrainHeightGen> m_CompositedHeightCache;
/** The finisher generators, in the order in which they are applied. */ /** The finisher generators, in the order in which they are applied. */
cFinishGenList m_FinishGens; std::vector<std::unique_ptr<cFinishGen>> m_FinishGens;
/** Reads the BiomeGen settings from the ini and initializes m_BiomeGen accordingly */ /** Reads the BiomeGen settings from the ini and initializes m_BiomeGen accordingly */
@ -250,7 +243,3 @@ protected:
/** Reads the finishers from the ini and initializes m_FinishGens accordingly */ /** Reads the finishers from the ini and initializes m_FinishGens accordingly */
void InitFinishGens(cIniFile & a_IniFile); void InitFinishGens(cIniFile & a_IniFile);
} ; } ;

View File

@ -20,10 +20,10 @@ class cCompositedHeiGen:
public cTerrainHeightGen public cTerrainHeightGen
{ {
public: public:
cCompositedHeiGen(cBiomeGenPtr a_BiomeGen, cTerrainShapeGenPtr a_ShapeGen, cTerrainCompositionGenPtr a_CompositionGen): cCompositedHeiGen(cBiomeGen & a_BiomeGen, cTerrainShapeGen & a_ShapeGen, cTerrainCompositionGen & a_CompositionGen):
m_BiomeGen(std::move(a_BiomeGen)), m_BiomeGen(a_BiomeGen),
m_ShapeGen(std::move(a_ShapeGen)), m_ShapeGen(a_ShapeGen),
m_CompositionGen(std::move(a_CompositionGen)) m_CompositionGen(a_CompositionGen)
{ {
} }
@ -33,20 +33,16 @@ public:
virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override
{ {
cChunkDesc::Shape shape; cChunkDesc::Shape shape;
m_ShapeGen->GenShape(a_ChunkCoords, shape); m_ShapeGen.GenShape(a_ChunkCoords, shape);
cChunkDesc desc(a_ChunkCoords); cChunkDesc desc(a_ChunkCoords);
m_BiomeGen->GenBiomes(a_ChunkCoords, desc.GetBiomeMap()); // Need to initialize biomes for the composition gen m_BiomeGen.GenBiomes(a_ChunkCoords, desc.GetBiomeMap()); // Need to initialize biomes for the composition gen
desc.SetHeightFromShape(shape); desc.SetHeightFromShape(shape);
m_CompositionGen->ComposeTerrain(desc, shape); m_CompositionGen.ComposeTerrain(desc, shape);
memcpy(a_HeightMap, desc.GetHeightMap(), sizeof(a_HeightMap)); memcpy(a_HeightMap, desc.GetHeightMap(), sizeof(a_HeightMap));
} }
protected: protected:
cBiomeGenPtr m_BiomeGen; cBiomeGen & m_BiomeGen;
cTerrainShapeGenPtr m_ShapeGen; cTerrainShapeGen & m_ShapeGen;
cTerrainCompositionGenPtr m_CompositionGen; cTerrainCompositionGen & m_CompositionGen;
}; };

View File

@ -118,12 +118,12 @@ const cDistortedHeightmap::sGenParam cDistortedHeightmap::m_GenParam[256] =
cDistortedHeightmap::cDistortedHeightmap(int a_Seed, const cBiomeGenPtr & a_BiomeGen) : cDistortedHeightmap::cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen) :
m_NoiseDistortX(a_Seed + 1000), m_NoiseDistortX(a_Seed + 1000),
m_NoiseDistortZ(a_Seed + 2000), m_NoiseDistortZ(a_Seed + 2000),
m_CurChunkCoords(0x7fffffff, 0x7fffffff), // Set impossible coords for the chunk so that it's always considered stale m_CurChunkCoords(0x7fffffff, 0x7fffffff), // Set impossible coords for the chunk so that it's always considered stale
m_BiomeGen(a_BiomeGen), m_BiomeGen(a_BiomeGen),
m_UnderlyingHeiGen(new cHeiGenBiomal(a_Seed, a_BiomeGen)), m_UnderlyingHeiGen(a_Seed, a_BiomeGen),
m_HeightGen(m_UnderlyingHeiGen, 64), m_HeightGen(m_UnderlyingHeiGen, 64),
m_IsInitialized(false) m_IsInitialized(false)
{ {
@ -297,7 +297,7 @@ void cDistortedHeightmap::UpdateDistortAmps(void)
{ {
for (int x = -1; x <= 1; x++) for (int x = -1; x <= 1; x++)
{ {
m_BiomeGen->GenBiomes({m_CurChunkCoords.m_ChunkX + x, m_CurChunkCoords.m_ChunkZ + z}, Biomes[x + 1][z + 1]); m_BiomeGen.GenBiomes({m_CurChunkCoords.m_ChunkX + x, m_CurChunkCoords.m_ChunkZ + z}, Biomes[x + 1][z + 1]);
} // for x } // for x
} // for z } // for z

View File

@ -26,7 +26,7 @@ class cDistortedHeightmap :
public cTerrainShapeGen public cTerrainShapeGen
{ {
public: public:
cDistortedHeightmap(int a_Seed, const cBiomeGenPtr & a_BiomeGen); cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen);
protected: protected:
typedef cChunkDef::BiomeMap BiomeNeighbors[3][3]; typedef cChunkDef::BiomeMap BiomeNeighbors[3][3];
@ -53,10 +53,10 @@ protected:
NOISE_DATATYPE m_DistortedHeightmap[17 * 257 * 17]; NOISE_DATATYPE m_DistortedHeightmap[17 * 257 * 17];
/** The bime generator to query for biomes. */ /** The bime generator to query for biomes. */
cBiomeGenPtr m_BiomeGen; cBiomeGen & m_BiomeGen;
/** The generator that provides the base heightmap (before distortion). */ /** The generator that provides the base heightmap (before distortion). */
cTerrainHeightGenPtr m_UnderlyingHeiGen; cHeiGenBiomal m_UnderlyingHeiGen;
/** Cache for m_UnderlyingHeiGen. */ /** Cache for m_UnderlyingHeiGen. */
cHeiGenCache m_HeightGen; cHeiGenCache m_HeightGen;

View File

@ -287,9 +287,9 @@ protected:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cDungeonRoomsFinisher: // cDungeonRoomsFinisher:
cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainShapeGenPtr a_ShapeGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib) : cDungeonRoomsFinisher::cDungeonRoomsFinisher(cTerrainShapeGen & a_ShapeGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib) :
Super(a_Seed + 100, a_GridSize, a_GridSize, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 1024), Super(a_Seed + 100, a_GridSize, a_GridSize, a_GridSize, a_GridSize, a_MaxSize, a_MaxSize, 1024),
m_ShapeGen(std::move(a_ShapeGen)), m_ShapeGen(a_ShapeGen),
m_MaxHalfSize((a_MaxSize + 1) / 2), m_MaxHalfSize((a_MaxSize + 1) / 2),
m_MinHalfSize((a_MinSize + 1) / 2), m_MinHalfSize((a_MinSize + 1) / 2),
m_HeightProbability(cChunkDef::Height) m_HeightProbability(cChunkDef::Height)
@ -322,7 +322,7 @@ cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int
int RelX = a_OriginX, RelY = 0, RelZ = a_OriginZ; int RelX = a_OriginX, RelY = 0, RelZ = a_OriginZ;
cChunkDef::AbsoluteToRelative(RelX, RelY, RelZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(RelX, RelY, RelZ, ChunkX, ChunkZ);
cChunkDesc::Shape shape; cChunkDesc::Shape shape;
m_ShapeGen->GenShape({ChunkX, ChunkZ}, shape); m_ShapeGen.GenShape({ChunkX, ChunkZ}, shape);
int height = 0; int height = 0;
int idx = RelX * 256 + RelZ * 16 * 256; int idx = RelX * 256 + RelZ * 16 * 256;
for (int y = 6; y < cChunkDef::Height; y++) for (int y = 6; y < cChunkDef::Height; y++)
@ -337,7 +337,3 @@ cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int
// Create the dungeon room descriptor: // Create the dungeon room descriptor:
return cStructurePtr(new cDungeonRoom(a_GridX, a_GridZ, a_OriginX, a_OriginZ, HalfSizeX, HalfSizeZ, height, m_Noise)); return cStructurePtr(new cDungeonRoom(a_GridX, a_GridZ, a_OriginX, a_OriginZ, HalfSizeX, HalfSizeZ, height, m_Noise));
} }

View File

@ -27,12 +27,12 @@ public:
a_ShapeGen is the underlying terrain shape generator, so that the rooms can always be placed under the terrain. a_ShapeGen is the underlying terrain shape generator, so that the rooms can always be placed under the terrain.
a_MaxSize and a_MinSize are the maximum and minimum sizes of the room's internal (air) area, in blocks across. a_MaxSize and a_MinSize are the maximum and minimum sizes of the room's internal (air) area, in blocks across.
a_HeightDistrib is the string defining the height distribution for the rooms (cProbabDistrib format). */ a_HeightDistrib is the string defining the height distribution for the rooms (cProbabDistrib format). */
cDungeonRoomsFinisher(cTerrainShapeGenPtr a_ShapeGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib); cDungeonRoomsFinisher(cTerrainShapeGen & a_ShapeGen, int a_Seed, int a_GridSize, int a_MaxSize, int a_MinSize, const AString & a_HeightDistrib);
protected: protected:
/** The shape gen that is used for limiting the rooms' Y coords */ /** The shape gen that is used for limiting the rooms' Y coords */
cTerrainShapeGenPtr m_ShapeGen; cTerrainShapeGen & m_ShapeGen;
/** Maximum half-size (from center to wall) of the dungeon room's inner (air) area. Default is 3 (vanilla). */ /** Maximum half-size (from center to wall) of the dungeon room's inner (air) area. Default is 3 (vanilla). */
int m_MaxHalfSize; int m_MaxHalfSize;
@ -47,7 +47,3 @@ protected:
// cGridStructGen overrides: // cGridStructGen overrides:
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override;
} ; } ;

View File

@ -106,8 +106,8 @@ void cHeiGenFlat::InitializeHeightGen(cIniFile & a_IniFile)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cHeiGenCache: // cHeiGenCache:
cHeiGenCache::cHeiGenCache(cTerrainHeightGenPtr a_HeiGenToCache, size_t a_CacheSize) : cHeiGenCache::cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, size_t a_CacheSize) :
m_HeiGenToCache(std::move(a_HeiGenToCache)), m_HeiGenToCache(a_HeiGenToCache),
m_CacheSize(a_CacheSize), m_CacheSize(a_CacheSize),
m_NumHits(0), m_NumHits(0),
m_NumMisses(0), m_NumMisses(0),
@ -161,7 +161,7 @@ void cHeiGenCache::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap
// Not in the cache: // Not in the cache:
m_NumMisses++; m_NumMisses++;
m_HeiGenToCache->GenHeightMap(a_ChunkCoords, a_HeightMap); m_HeiGenToCache.GenHeightMap(a_ChunkCoords, a_HeightMap);
// Insert it as the first item in the MRU order: // Insert it as the first item in the MRU order:
auto Idx = m_CacheOrder[m_CacheSize - 1]; auto Idx = m_CacheOrder[m_CacheSize - 1];
@ -219,14 +219,15 @@ bool cHeiGenCache::GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_Rel
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cHeiGenMultiCache: // cHeiGenMultiCache:
cHeiGenMultiCache::cHeiGenMultiCache(const cTerrainHeightGenPtr & a_HeiGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches): cHeiGenMultiCache::cHeiGenMultiCache(std::unique_ptr<cTerrainHeightGen> a_HeiGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches):
m_NumSubCaches(a_NumSubCaches) m_NumSubCaches(a_NumSubCaches),
m_Underlying(std::move(a_HeiGenToCache))
{ {
// Create the individual sub-caches: // Create the individual sub-caches:
m_SubCaches.reserve(a_NumSubCaches); m_SubCaches.reserve(a_NumSubCaches);
for (size_t i = 0; i < a_NumSubCaches; i++) for (size_t i = 0; i < a_NumSubCaches; i++)
{ {
m_SubCaches.emplace_back(std::make_shared<cHeiGenCache>(a_HeiGenToCache, a_SubCacheSize)); m_SubCaches.push_back(std::make_unique<cHeiGenCache>(*m_Underlying, a_SubCacheSize));
} }
} }
@ -517,7 +518,7 @@ void cHeiGenBiomal::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMa
{ {
for (int x = -1; x <= 1; x++) for (int x = -1; x <= 1; x++)
{ {
m_BiomeGen->GenBiomes({a_ChunkCoords.m_ChunkX + x, a_ChunkCoords.m_ChunkZ + z}, Biomes[x + 1][z + 1]); m_BiomeGen.GenBiomes({a_ChunkCoords.m_ChunkX + x, a_ChunkCoords.m_ChunkZ + z}, Biomes[x + 1][z + 1]);
} // for x } // for x
} // for z } // for z
@ -636,9 +637,9 @@ class cHeiGenMinMax:
public: public:
cHeiGenMinMax(int a_Seed, cBiomeGenPtr a_BiomeGen): cHeiGenMinMax(int a_Seed, cBiomeGen & a_BiomeGen):
m_Noise(a_Seed), m_Noise(a_Seed),
m_BiomeGen(std::move(a_BiomeGen)), m_BiomeGen(a_BiomeGen),
m_TotalWeight(0) m_TotalWeight(0)
{ {
// Initialize the weights: // Initialize the weights:
@ -664,7 +665,7 @@ public:
cChunkDef::BiomeMap neighborBiomes[3][3]; cChunkDef::BiomeMap neighborBiomes[3][3];
for (int z = 0; z < 3; z++) for (int x = 0; x < 3; x++) for (int z = 0; z < 3; z++) for (int x = 0; x < 3; x++)
{ {
m_BiomeGen->GenBiomes({a_ChunkCoords.m_ChunkX + x - 1, a_ChunkCoords.m_ChunkZ + z - 1}, neighborBiomes[z][x]); m_BiomeGen.GenBiomes({a_ChunkCoords.m_ChunkX + x - 1, a_ChunkCoords.m_ChunkZ + z - 1}, neighborBiomes[z][x]);
} }
// Get the min and max heights based on the biomes: // Get the min and max heights based on the biomes:
@ -735,7 +736,7 @@ protected:
cPerlinNoise m_Perlin; cPerlinNoise m_Perlin;
/** The biome generator to query for the underlying biomes. */ /** The biome generator to query for the underlying biomes. */
cBiomeGenPtr m_BiomeGen; cBiomeGen & m_BiomeGen;
/** Weights applied to each of the min / max values in the neighborhood of the currently evaluated column. */ /** Weights applied to each of the min / max values in the neighborhood of the currently evaluated column. */
double m_Weights[AVERAGING_SIZE * 2 + 1][AVERAGING_SIZE * 2 + 1]; double m_Weights[AVERAGING_SIZE * 2 + 1][AVERAGING_SIZE * 2 + 1];
@ -831,7 +832,7 @@ protected:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cTerrainHeightGen: // cTerrainHeightGen:
cTerrainHeightGenPtr cTerrainHeightGen::CreateHeightGen(cIniFile & a_IniFile, const cBiomeGenPtr & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault) std::unique_ptr<cTerrainHeightGen> cTerrainHeightGen::CreateHeightGen(cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault)
{ {
AString HeightGenName = a_IniFile.GetValueSet("Generator", "HeightGen", ""); AString HeightGenName = a_IniFile.GetValueSet("Generator", "HeightGen", "");
if (HeightGenName.empty()) if (HeightGenName.empty())
@ -841,55 +842,55 @@ cTerrainHeightGenPtr cTerrainHeightGen::CreateHeightGen(cIniFile & a_IniFile, co
} }
a_CacheOffByDefault = false; a_CacheOffByDefault = false;
cTerrainHeightGenPtr res; std::unique_ptr<cTerrainHeightGen> res;
if (NoCaseCompare(HeightGenName, "Flat") == 0) if (NoCaseCompare(HeightGenName, "Flat") == 0)
{ {
res = std::make_shared<cHeiGenFlat>(); res = std::make_unique<cHeiGenFlat>();
a_CacheOffByDefault = true; // We're generating faster than a cache would retrieve data a_CacheOffByDefault = true; // We're generating faster than a cache would retrieve data
} }
else if (NoCaseCompare(HeightGenName, "classic") == 0) else if (NoCaseCompare(HeightGenName, "classic") == 0)
{ {
res = std::make_shared<cHeiGenClassic>(a_Seed); res = std::make_unique<cHeiGenClassic>(a_Seed);
} }
else if (NoCaseCompare(HeightGenName, "DistortedHeightmap") == 0) else if (NoCaseCompare(HeightGenName, "DistortedHeightmap") == 0)
{ {
// Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it
// Return an empty pointer, the caller will create the proper generator: // Return an empty pointer, the caller will create the proper generator:
return cTerrainHeightGenPtr(); return nullptr;
} }
else if (NoCaseCompare(HeightGenName, "End") == 0) else if (NoCaseCompare(HeightGenName, "End") == 0)
{ {
// Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it
// Return an empty pointer, the caller will create the proper generator: // Return an empty pointer, the caller will create the proper generator:
return cTerrainHeightGenPtr(); return nullptr;
} }
else if (NoCaseCompare(HeightGenName, "MinMax") == 0) else if (NoCaseCompare(HeightGenName, "MinMax") == 0)
{ {
res = std::make_shared<cHeiGenMinMax>(a_Seed, a_BiomeGen); res = std::make_unique<cHeiGenMinMax>(a_Seed, a_BiomeGen);
} }
else if (NoCaseCompare(HeightGenName, "Mountains") == 0) else if (NoCaseCompare(HeightGenName, "Mountains") == 0)
{ {
res = std::make_shared<cHeiGenMountains>(a_Seed); res = std::make_unique<cHeiGenMountains>(a_Seed);
} }
else if (NoCaseCompare(HeightGenName, "BiomalNoise3D") == 0) else if (NoCaseCompare(HeightGenName, "BiomalNoise3D") == 0)
{ {
// Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it
// Return an empty pointer, the caller will create the proper generator: // Return an empty pointer, the caller will create the proper generator:
return cTerrainHeightGenPtr(); return nullptr;
} }
else if (NoCaseCompare(HeightGenName, "Steppy") == 0) else if (NoCaseCompare(HeightGenName, "Steppy") == 0)
{ {
res = std::make_shared<cHeiGenSteppy>(a_Seed); res = std::make_unique<cHeiGenSteppy>(a_Seed);
} }
else if (NoCaseCompare(HeightGenName, "Noise3D") == 0) else if (NoCaseCompare(HeightGenName, "Noise3D") == 0)
{ {
// Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it // Not a heightmap-based generator, but it used to be accessible via HeightGen, so we need to skip making the default out of it
// Return an empty pointer, the caller will create the proper generator: // Return an empty pointer, the caller will create the proper generator:
return cTerrainHeightGenPtr(); return nullptr;
} }
else if (NoCaseCompare(HeightGenName, "Biomal") == 0) else if (NoCaseCompare(HeightGenName, "Biomal") == 0)
{ {
res = std::make_shared<cHeiGenBiomal>(a_Seed, a_BiomeGen); res = std::make_unique<cHeiGenBiomal>(a_Seed, a_BiomeGen);
/* /*
// Performance-testing: // Performance-testing:

View File

@ -28,8 +28,7 @@ class cHeiGenCache :
public cTerrainHeightGen public cTerrainHeightGen
{ {
public: public:
cHeiGenCache(cTerrainHeightGenPtr a_HeiGenToCache, size_t a_CacheSize); cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, size_t a_CacheSize);
virtual ~cHeiGenCache() override = default;
// cTerrainHeightGen overrides: // cTerrainHeightGen overrides:
virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override;
@ -51,7 +50,7 @@ protected:
} ; } ;
/** The terrain height generator that is being cached. */ /** The terrain height generator that is being cached. */
cTerrainHeightGenPtr m_HeiGenToCache; cTerrainHeightGen & m_HeiGenToCache;
// To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data
size_t m_CacheSize; size_t m_CacheSize;
@ -73,7 +72,7 @@ class cHeiGenMultiCache:
public cTerrainHeightGen public cTerrainHeightGen
{ {
public: public:
cHeiGenMultiCache(const cTerrainHeightGenPtr & a_HeightGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches); cHeiGenMultiCache(std::unique_ptr<cTerrainHeightGen> a_HeightGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches);
// cTerrainHeightGen overrides: // cTerrainHeightGen overrides:
virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override;
@ -83,9 +82,6 @@ public:
bool GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height); bool GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height);
protected: protected:
typedef std::shared_ptr<cHeiGenCache> cHeiGenCachePtr;
typedef std::vector<cHeiGenCachePtr> cHeiGenCachePtrs;
/** The coefficient used to turn Z coords into index (x + Coeff * z). */ /** The coefficient used to turn Z coords into index (x + Coeff * z). */
static const size_t m_CoeffZ = 5; static const size_t m_CoeffZ = 5;
@ -94,7 +90,10 @@ protected:
size_t m_NumSubCaches; size_t m_NumSubCaches;
/** The individual sub-caches. */ /** The individual sub-caches. */
cHeiGenCachePtrs m_SubCaches; std::vector<std::unique_ptr<cHeiGenCache>> m_SubCaches;
/** The underlying height generator. */
std::unique_ptr<cTerrainHeightGen> m_Underlying;
}; };
@ -174,9 +173,9 @@ class cHeiGenBiomal:
public: public:
cHeiGenBiomal(int a_Seed, cBiomeGenPtr a_BiomeGen): cHeiGenBiomal(int a_Seed, cBiomeGen & a_BiomeGen):
m_Noise(a_Seed), m_Noise(a_Seed),
m_BiomeGen(std::move(a_BiomeGen)) m_BiomeGen(a_BiomeGen)
{ {
} }
@ -192,8 +191,8 @@ protected:
typedef cChunkDef::BiomeMap BiomeNeighbors[3][3]; typedef cChunkDef::BiomeMap BiomeNeighbors[3][3];
cNoise m_Noise; cNoise m_Noise;
cBiomeGenPtr m_BiomeGen; cBiomeGen & m_BiomeGen;
// Per-biome terrain generator parameters: // Per-biome terrain generator parameters:
struct sGenParam struct sGenParam
@ -208,7 +207,3 @@ protected:
NOISE_DATATYPE GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const BiomeNeighbors & a_BiomeNeighbors); NOISE_DATATYPE GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const BiomeNeighbors & a_BiomeNeighbors);
} ; } ;

View File

@ -506,12 +506,12 @@ void cNoise3DComposable::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cBiomalNoise3DComposable: // cBiomalNoise3DComposable:
cBiomalNoise3DComposable::cBiomalNoise3DComposable(int a_Seed, cBiomeGenPtr a_BiomeGen) : cBiomalNoise3DComposable::cBiomalNoise3DComposable(int a_Seed, cBiomeGen & a_BiomeGen) :
m_ChoiceNoise(a_Seed), m_ChoiceNoise(a_Seed),
m_DensityNoiseA(a_Seed + 1), m_DensityNoiseA(a_Seed + 1),
m_DensityNoiseB(a_Seed + 2), m_DensityNoiseB(a_Seed + 2),
m_BaseNoise(a_Seed + 3), m_BaseNoise(a_Seed + 3),
m_BiomeGen(std::move(a_BiomeGen)), m_BiomeGen(a_BiomeGen),
m_LastChunkCoords(0x7fffffff, 0x7fffffff) // Set impossible coords for the chunk so that it's always considered stale m_LastChunkCoords(0x7fffffff, 0x7fffffff) // Set impossible coords for the chunk so that it's always considered stale
{ {
// Generate the weight distribution for summing up neighboring biomes: // Generate the weight distribution for summing up neighboring biomes:
@ -654,7 +654,7 @@ void cBiomalNoise3DComposable::CalcBiomeParamArrays(cChunkCoords a_ChunkCoords,
{ {
for (int x = 0; x < 3; x++) for (int x = 0; x < 3; x++)
{ {
m_BiomeGen->GenBiomes({a_ChunkCoords.m_ChunkX + x - 1, a_ChunkCoords.m_ChunkZ + z - 1}, neighborBiomes[x + 3 * z]); m_BiomeGen.GenBiomes({a_ChunkCoords.m_ChunkX + x - 1, a_ChunkCoords.m_ChunkZ + z - 1}, neighborBiomes[x + 3 * z]);
} }
} }
@ -791,8 +791,3 @@ void cBiomalNoise3DComposable::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::
} // for x } // for x
} // for z } // for z
} }

View File

@ -136,7 +136,7 @@ class cBiomalNoise3DComposable :
public cTerrainShapeGen public cTerrainShapeGen
{ {
public: public:
cBiomalNoise3DComposable(int a_Seed, cBiomeGenPtr a_BiomeGen); cBiomalNoise3DComposable(int a_Seed, cBiomeGen & a_BiomeGen);
void Initialize(cIniFile & a_IniFile); void Initialize(cIniFile & a_IniFile);
@ -161,7 +161,7 @@ protected:
cOctavedNoise<cInterpolNoise<Interp5Deg>> m_BaseNoise; cOctavedNoise<cInterpolNoise<Interp5Deg>> m_BaseNoise;
/** The underlying biome generator. */ /** The underlying biome generator. */
cBiomeGenPtr m_BiomeGen; cBiomeGen & m_BiomeGen;
/** Block height of the sealevel, used for composing the terrain. */ /** Block height of the sealevel, used for composing the terrain. */
int m_SeaLevel; int m_SeaLevel;
@ -207,7 +207,3 @@ protected:
virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override; virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override;
virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); } virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); }
} ; } ;

View File

@ -115,7 +115,7 @@ public:
/** Called when the piece pool is assigned to a generator, /** Called when the piece pool is assigned to a generator,
so that the strategies may bind to the underlying subgenerators. */ so that the strategies may bind to the underlying subgenerators. */
virtual void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_TerrainHeightGen, int a_SeaLevel) {} virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) {}
}; };
typedef std::shared_ptr<cVerticalStrategy> cVerticalStrategyPtr; typedef std::shared_ptr<cVerticalStrategy> cVerticalStrategyPtr;
@ -142,7 +142,7 @@ public:
/** Called when the piece pool is assigned to a generator, /** Called when the piece pool is assigned to a generator,
so that the limits may bind to the underlying subgenerators. */ so that the limits may bind to the underlying subgenerators. */
virtual void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_TerrainHeightGen, int a_SeaLevel) {} virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) {}
}; };
typedef std::shared_ptr<cVerticalLimit> cVerticalLimitPtr; typedef std::shared_ptr<cVerticalLimit> cVerticalLimitPtr;
@ -328,8 +328,3 @@ protected:
typedef std::unique_ptr<cPlacedPiece> cPlacedPiecePtr; typedef std::unique_ptr<cPlacedPiece> cPlacedPiecePtr;
typedef std::vector<cPlacedPiecePtr> cPlacedPieces; typedef std::vector<cPlacedPiecePtr> cPlacedPieces;

View File

@ -20,10 +20,10 @@ class cPieceStructuresGen::cGen:
public: public:
cGen(int a_Seed, cBiomeGenPtr a_BiomeGen, cTerrainHeightGenPtr a_HeightGen, int a_SeaLevel, const AString & a_Name): cGen(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel, const AString & a_Name):
Super(a_Seed), Super(a_Seed),
m_BiomeGen(std::move(a_BiomeGen)), m_BiomeGen(a_BiomeGen),
m_HeightGen(std::move(a_HeightGen)), m_HeightGen(a_HeightGen),
m_SeaLevel(a_SeaLevel), m_SeaLevel(a_SeaLevel),
m_Name(a_Name), m_Name(a_Name),
m_MaxDepth(5) m_MaxDepth(5)
@ -95,10 +95,10 @@ protected:
typedef std::vector<cFreeConnector> cFreeConnectors; typedef std::vector<cFreeConnector> cFreeConnectors;
/** The underlying biome generator that defines whether the structure is created or not */ /** The underlying biome generator that defines whether the structure is created or not */
cBiomeGenPtr m_BiomeGen; cBiomeGen & m_BiomeGen;
/** The underlying height generator, used to position the prefabs crossing chunk borders if they are set to FitGround. */ /** The underlying height generator, used to position the prefabs crossing chunk borders if they are set to FitGround. */
cTerrainHeightGenPtr m_HeightGen; cTerrainHeightGen & m_HeightGen;
/** The world's sea level, if available. Used for some cVerticalStrategy descendants. */ /** The world's sea level, if available. Used for some cVerticalStrategy descendants. */
int m_SeaLevel; int m_SeaLevel;
@ -129,7 +129,7 @@ cPieceStructuresGen::cPieceStructuresGen(int a_Seed):
bool cPieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel, const cBiomeGenPtr & a_BiomeGen, const cTerrainHeightGenPtr & a_HeightGen) bool cPieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen)
{ {
// Load each piecepool: // Load each piecepool:
auto Structures = StringSplitAndTrim(a_Prefabs, "|"); auto Structures = StringSplitAndTrim(a_Prefabs, "|");
@ -172,8 +172,3 @@ void cPieceStructuresGen::GenFinish(cChunkDesc & a_Chunk)
Gen->GenFinish(a_Chunk); Gen->GenFinish(a_Chunk);
} }
} }

View File

@ -34,7 +34,7 @@ public:
a_Prefabs contains the list of prefab sets that should be activated, "|"-separated. a_Prefabs contains the list of prefab sets that should be activated, "|"-separated.
All problems are logged to the console and the generator skips over them. All problems are logged to the console and the generator skips over them.
Returns true if at least one prefab set is valid (the generator should be kept). */ Returns true if at least one prefab set is valid (the generator should be kept). */
bool Initialize(const AString & a_Prefabs, int a_SeaLevel, const cBiomeGenPtr & a_BiomeGen, const cTerrainHeightGenPtr & a_HeightGen); bool Initialize(const AString & a_Prefabs, int a_SeaLevel, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen);
// cFinishGen override: // cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
@ -54,7 +54,3 @@ protected:
/** The seed for the random number generator */ /** The seed for the random number generator */
int m_Seed; int m_Seed;
}; };

View File

@ -724,7 +724,7 @@ AString cPrefabPiecePool::GetMetadata(const AString & a_ParamName) const
void cPrefabPiecePool::AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_HeightGen, int a_SeaLevel) void cPrefabPiecePool::AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel)
{ {
// Assign the generator linkage to all starting pieces' VerticalStrategies: // Assign the generator linkage to all starting pieces' VerticalStrategies:
for (auto & piece: m_StartingPieces) for (auto & piece: m_StartingPieces)
@ -808,7 +808,3 @@ void cPrefabPiecePool::Reset(void)
{ {
// Do nothing // Do nothing
} }

View File

@ -108,7 +108,7 @@ public:
/** Called when the piece pool is assigned to a generator, /** Called when the piece pool is assigned to a generator,
so that the individual starting pieces' vertical strategies may bind to the underlying subgenerators. */ so that the individual starting pieces' vertical strategies may bind to the underlying subgenerators. */
void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_HeightGen, int a_SeaLevel); void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel);
// cPiecePool overrides: // cPiecePool overrides:
virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override; virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override;

View File

@ -15,11 +15,11 @@ cPrefabStructure::cPrefabStructure(
int a_GridX, int a_GridZ, int a_GridX, int a_GridZ,
int a_OriginX, int a_OriginZ, int a_OriginX, int a_OriginZ,
cPlacedPieces && a_Pieces, cPlacedPieces && a_Pieces,
cTerrainHeightGenPtr a_HeightGen cTerrainHeightGen & a_HeightGen
): ):
Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ),
m_Pieces(std::move(a_Pieces)), m_Pieces(std::move(a_Pieces)),
m_HeightGen(std::move(a_HeightGen)) m_HeightGen(a_HeightGen)
{ {
} }
@ -55,11 +55,7 @@ void cPrefabStructure::PlacePieceOnGround(cPlacedPiece & a_Piece)
int BlockY; int BlockY;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cChunkDef::HeightMap HeightMap; cChunkDef::HeightMap HeightMap;
m_HeightGen->GenHeightMap({ChunkX, ChunkZ}, HeightMap); m_HeightGen.GenHeightMap({ChunkX, ChunkZ}, HeightMap);
int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ); int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ);
a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1); a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1);
} }

View File

@ -27,7 +27,7 @@ public:
int a_GridX, int a_GridZ, int a_GridX, int a_GridZ,
int a_OriginX, int a_OriginZ, int a_OriginX, int a_OriginZ,
cPlacedPieces && a_Pieces, cPlacedPieces && a_Pieces,
cTerrainHeightGenPtr a_HeightGen cTerrainHeightGen & a_HeightGen
); );
protected: protected:
@ -35,7 +35,7 @@ protected:
cPlacedPieces m_Pieces; cPlacedPieces m_Pieces;
/** The height generator used when adjusting pieces onto the ground. */ /** The height generator used when adjusting pieces onto the ground. */
cTerrainHeightGenPtr m_HeightGen; cTerrainHeightGen & m_HeightGen;
// cGridStructGen::cStructure overrides: // cGridStructGen::cStructure overrides:
@ -45,7 +45,3 @@ protected:
Ground level is assumed to be represented by the first connector in the piece. */ Ground level is assumed to be represented by the first connector in the piece. */
void PlacePieceOnGround(cPlacedPiece & a_Piece); void PlacePieceOnGround(cPlacedPiece & a_Piece);
}; };

View File

@ -23,7 +23,7 @@ class cTerrainHeightToShapeGen:
public cTerrainShapeGen public cTerrainShapeGen
{ {
public: public:
cTerrainHeightToShapeGen(cTerrainHeightGenPtr a_HeightGen): cTerrainHeightToShapeGen(std::unique_ptr<cTerrainHeightGen> a_HeightGen):
m_HeightGen(std::move(a_HeightGen)) m_HeightGen(std::move(a_HeightGen))
{ {
} }
@ -63,7 +63,7 @@ public:
protected: protected:
/** The height generator being converted. */ /** The height generator being converted. */
cTerrainHeightGenPtr m_HeightGen; std::unique_ptr<cTerrainHeightGen> m_HeightGen;
}; };
typedef std::shared_ptr<cTerrainHeightToShapeGen> cTerrainHeightToShapeGenPtr; typedef std::shared_ptr<cTerrainHeightToShapeGen> cTerrainHeightToShapeGenPtr;
@ -75,9 +75,9 @@ typedef std::shared_ptr<cTerrainHeightToShapeGen> cTerrainHeightToShapeGenPtr;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cTerrainShapeGen: // cTerrainShapeGen:
cTerrainShapeGenPtr cTerrainShapeGen::CreateShapeGen( std::unique_ptr<cTerrainShapeGen> cTerrainShapeGen::CreateShapeGen(
cIniFile & a_IniFile, cIniFile & a_IniFile,
const cBiomeGenPtr & a_BiomeGen, cBiomeGen & a_BiomeGen,
int a_Seed, int a_Seed,
bool & a_CacheOffByDefault bool & a_CacheOffByDefault
) )
@ -92,10 +92,10 @@ cTerrainShapeGenPtr cTerrainShapeGen::CreateShapeGen(
// If the shapegen is HeightMap, redirect to older HeightMap-based generators: // If the shapegen is HeightMap, redirect to older HeightMap-based generators:
if (NoCaseCompare(shapeGenName, "HeightMap") == 0) if (NoCaseCompare(shapeGenName, "HeightMap") == 0)
{ {
cTerrainHeightGenPtr heightGen = cTerrainHeightGen::CreateHeightGen(a_IniFile, a_BiomeGen, a_Seed, a_CacheOffByDefault); auto heightGen = cTerrainHeightGen::CreateHeightGen(a_IniFile, a_BiomeGen, a_Seed, a_CacheOffByDefault);
if (heightGen != nullptr) if (heightGen != nullptr)
{ {
return std::make_shared<cTerrainHeightToShapeGen>(heightGen); return std::make_unique<cTerrainHeightToShapeGen>(std::move(heightGen));
} }
// The height gen was not recognized; several heightgens were promoted to shape gens, so let's try them instead: // The height gen was not recognized; several heightgens were promoted to shape gens, so let's try them instead:
@ -110,22 +110,22 @@ cTerrainShapeGenPtr cTerrainShapeGen::CreateShapeGen(
// Choose the shape generator based on the name: // Choose the shape generator based on the name:
a_CacheOffByDefault = false; a_CacheOffByDefault = false;
cTerrainShapeGenPtr res; std::unique_ptr<cTerrainShapeGen> res;
if (NoCaseCompare(shapeGenName, "DistortedHeightmap") == 0) if (NoCaseCompare(shapeGenName, "DistortedHeightmap") == 0)
{ {
res = std::make_shared<cDistortedHeightmap>(a_Seed, a_BiomeGen); res = std::make_unique<cDistortedHeightmap>(a_Seed, a_BiomeGen);
} }
else if (NoCaseCompare(shapeGenName, "End") == 0) else if (NoCaseCompare(shapeGenName, "End") == 0)
{ {
res = std::make_shared<cEndGen>(a_Seed); res = std::make_unique<cEndGen>(a_Seed);
} }
else if (NoCaseCompare(shapeGenName, "BiomalNoise3D") == 0) else if (NoCaseCompare(shapeGenName, "BiomalNoise3D") == 0)
{ {
res = std::make_shared<cBiomalNoise3DComposable>(a_Seed, a_BiomeGen); res = std::make_unique<cBiomalNoise3DComposable>(a_Seed, a_BiomeGen);
} }
else if (NoCaseCompare(shapeGenName, "Noise3D") == 0) else if (NoCaseCompare(shapeGenName, "Noise3D") == 0)
{ {
res = std::make_shared<cNoise3DComposable>(a_Seed); res = std::make_unique<cNoise3DComposable>(a_Seed);
} }
else if (NoCaseCompare(shapeGenName, "TwoHeights") == 0) else if (NoCaseCompare(shapeGenName, "TwoHeights") == 0)
{ {
@ -144,7 +144,3 @@ cTerrainShapeGenPtr cTerrainShapeGen::CreateShapeGen(
return res; return res;
} }

View File

@ -14,10 +14,10 @@ class cSinglePieceStructuresGen::cGen :
{ {
using Super = cGridStructGen; using Super = cGridStructGen;
public: public:
cGen(int a_Seed, cBiomeGenPtr a_BiomeGen, cTerrainHeightGenPtr a_HeightGen, int a_SeaLevel, const AString & a_Name): cGen(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel, const AString & a_Name):
Super(a_Seed), Super(a_Seed),
m_BiomeGen(std::move(a_BiomeGen)), m_BiomeGen(a_BiomeGen),
m_HeightGen(std::move(a_HeightGen)), m_HeightGen(a_HeightGen),
m_SeaLevel(a_SeaLevel), m_SeaLevel(a_SeaLevel),
m_Name(a_Name) m_Name(a_Name)
{ {
@ -61,7 +61,7 @@ public:
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ);
cChunkDef::BiomeMap Biomes; cChunkDef::BiomeMap Biomes;
m_BiomeGen->GenBiomes({ChunkX, ChunkZ}, Biomes); m_BiomeGen.GenBiomes({ChunkX, ChunkZ}, Biomes);
// Checks if the biome at the origin position is allowed // Checks if the biome at the origin position is allowed
auto Relative = cChunkDef::AbsoluteToRelative(Vector3i(a_OriginX, 1, a_OriginZ), {ChunkX, ChunkZ}); auto Relative = cChunkDef::AbsoluteToRelative(Vector3i(a_OriginX, 1, a_OriginZ), {ChunkX, ChunkZ});
@ -132,10 +132,10 @@ public:
protected: protected:
/** The underlying biome generator that defines whether the structure is created or not */ /** The underlying biome generator that defines whether the structure is created or not */
cBiomeGenPtr m_BiomeGen; cBiomeGen & m_BiomeGen;
/** The underlying height generator, used to position the prefabs crossing chunk borders if they are set to FitGround. */ /** The underlying height generator, used to position the prefabs crossing chunk borders if they are set to FitGround. */
cTerrainHeightGenPtr m_HeightGen; cTerrainHeightGen & m_HeightGen;
/** The world's sea level, if available. Used for some cVerticalStrategy descendants. */ /** The world's sea level, if available. Used for some cVerticalStrategy descendants. */
int m_SeaLevel; int m_SeaLevel;
@ -160,7 +160,7 @@ cSinglePieceStructuresGen::cSinglePieceStructuresGen(int a_Seed) :
bool cSinglePieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel, const cBiomeGenPtr & a_BiomeGen, const cTerrainHeightGenPtr & a_HeightGen) bool cSinglePieceStructuresGen::Initialize(const AString & a_Prefabs, int a_SeaLevel, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen)
{ {
// Load each piecepool: // Load each piecepool:
auto Structures = StringSplitAndTrim(a_Prefabs, "|"); auto Structures = StringSplitAndTrim(a_Prefabs, "|");

View File

@ -30,7 +30,7 @@ public:
a_Prefabs contains the list of prefab sets that should be activated, "|"-separated. a_Prefabs contains the list of prefab sets that should be activated, "|"-separated.
All problems are logged to the console and the generator skips over them. All problems are logged to the console and the generator skips over them.
Returns true if at least one prefab set is valid (the generator should be kept). */ Returns true if at least one prefab set is valid (the generator should be kept). */
bool Initialize(const AString & a_Prefabs, int a_SeaLevel, const cBiomeGenPtr & a_BiomeGen, const cTerrainHeightGenPtr & a_HeightGen); bool Initialize(const AString & a_Prefabs, int a_SeaLevel, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen);
// cFinishGen override: // cFinishGen override:

View File

@ -40,10 +40,10 @@ void cStructGenTrees::GenFinish(cChunkDesc & a_ChunkDesc)
// TODO: This may cause a lot of wasted calculations, instead of pulling data out of a single (cChunkDesc) cache // TODO: This may cause a lot of wasted calculations, instead of pulling data out of a single (cChunkDesc) cache
cChunkDesc::Shape workerShape; cChunkDesc::Shape workerShape;
m_BiomeGen->GenBiomes ({BaseX, BaseZ}, WorkerDesc.GetBiomeMap()); m_BiomeGen.GenBiomes ({BaseX, BaseZ}, WorkerDesc.GetBiomeMap());
m_ShapeGen->GenShape ({BaseX, BaseZ}, workerShape); m_ShapeGen.GenShape ({BaseX, BaseZ}, workerShape);
WorkerDesc.SetHeightFromShape (workerShape); WorkerDesc.SetHeightFromShape (workerShape);
m_CompositionGen->ComposeTerrain(WorkerDesc, workerShape); m_CompositionGen.ComposeTerrain(WorkerDesc, workerShape);
} }
else else
{ {
@ -575,7 +575,3 @@ void cStructGenDistortedMembraneOverhangs::GenFinish(cChunkDesc & a_ChunkDesc)
} // for x } // for x
} // for z } // for z
} }

View File

@ -22,21 +22,21 @@ class cStructGenTrees :
public cFinishGen public cFinishGen
{ {
public: public:
cStructGenTrees(int a_Seed, cBiomeGenPtr a_BiomeGen, cTerrainShapeGenPtr a_ShapeGen, cTerrainCompositionGenPtr a_CompositionGen) : cStructGenTrees(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainShapeGen & a_ShapeGen, cTerrainCompositionGen & a_CompositionGen) :
m_Seed(a_Seed), m_Seed(a_Seed),
m_Noise(a_Seed), m_Noise(a_Seed),
m_BiomeGen(std::move(a_BiomeGen)), m_BiomeGen(a_BiomeGen),
m_ShapeGen(std::move(a_ShapeGen)), m_ShapeGen(a_ShapeGen),
m_CompositionGen(std::move(a_CompositionGen)) m_CompositionGen(a_CompositionGen)
{} {}
protected: protected:
int m_Seed; int m_Seed;
cNoise m_Noise; cNoise m_Noise;
cBiomeGenPtr m_BiomeGen; cBiomeGen & m_BiomeGen;
cTerrainShapeGenPtr m_ShapeGen; cTerrainShapeGen & m_ShapeGen;
cTerrainCompositionGenPtr m_CompositionGen; cTerrainCompositionGen & m_CompositionGen;
/** Generates and applies an image of a single tree. /** Generates and applies an image of a single tree.
Parts of the tree inside the chunk are applied to a_ChunkDesc. Parts of the tree inside the chunk are applied to a_ChunkDesc.
@ -78,20 +78,20 @@ class cStructGenLakes :
public cFinishGen public cFinishGen
{ {
public: public:
cStructGenLakes(int a_Seed, BLOCKTYPE a_Fluid, cTerrainShapeGenPtr a_ShapeGen, int a_Probability) : cStructGenLakes(int a_Seed, BLOCKTYPE a_Fluid, cTerrainShapeGen & a_ShapeGen, int a_Probability) :
m_Noise(a_Seed), m_Noise(a_Seed),
m_Seed(a_Seed), m_Seed(a_Seed),
m_Fluid(a_Fluid), m_Fluid(a_Fluid),
m_ShapeGen(std::move(a_ShapeGen)), m_ShapeGen(a_ShapeGen),
m_Probability(a_Probability) m_Probability(a_Probability)
{ {
} }
protected: protected:
cNoise m_Noise; cNoise m_Noise;
int m_Seed; int m_Seed;
BLOCKTYPE m_Fluid; BLOCKTYPE m_Fluid;
cTerrainShapeGenPtr m_ShapeGen; cTerrainShapeGen & m_ShapeGen;
/** Chance, [0 .. 100], of a chunk having the lake. */ /** Chance, [0 .. 100], of a chunk having the lake. */
int m_Probability; int m_Probability;
@ -143,7 +143,3 @@ protected:
// cFinishGen override: // cFinishGen override:
virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
} ; } ;

View File

@ -21,7 +21,7 @@ class cTwoHeights:
public: public:
cTwoHeights(int a_Seed, const cBiomeGenPtr & a_BiomeGen): cTwoHeights(int a_Seed, cBiomeGen & a_BiomeGen):
m_Seed(a_Seed), m_Seed(a_Seed),
m_Choice(a_Seed), m_Choice(a_Seed),
m_HeightA(a_Seed + 1, a_BiomeGen), m_HeightA(a_Seed + 1, a_BiomeGen),
@ -113,11 +113,7 @@ protected:
cTerrainShapeGenPtr CreateShapeGenTwoHeights(int a_Seed, const cBiomeGenPtr & a_BiomeGen) std::unique_ptr<cTerrainShapeGen> CreateShapeGenTwoHeights(int a_Seed, cBiomeGen & a_BiomeGen)
{ {
return std::make_shared<cTwoHeights>(a_Seed, a_BiomeGen); return std::make_unique<cTwoHeights>(a_Seed, a_BiomeGen);
} }

View File

@ -16,8 +16,4 @@
/** Creates and returns a new instance of the cTwoHeights terrain shape generator. /** Creates and returns a new instance of the cTwoHeights terrain shape generator.
The instance must be Initialize()-d before it is used. */ The instance must be Initialize()-d before it is used. */
extern cTerrainShapeGenPtr CreateShapeGenTwoHeights(int a_Seed, const cBiomeGenPtr & a_BiomeGen); extern std::unique_ptr<cTerrainShapeGen> CreateShapeGenTwoHeights(int a_Seed, cBiomeGen & a_BiomeGen);

View File

@ -133,6 +133,7 @@ class cVerticalLimitAboveTerrain:
public: public:
virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override virtual bool CanBeAtHeight(int a_BlockX, int a_BlockZ, int a_Height) override
{ {
ASSERT(m_TerrainHeightGen != nullptr);
auto terrainHeight = m_TerrainHeightGen->GetHeightAt(a_BlockX, a_BlockZ); auto terrainHeight = m_TerrainHeightGen->GetHeightAt(a_BlockX, a_BlockZ);
int compareHeight = a_Height - terrainHeight; int compareHeight = a_Height - terrainHeight;
return ( return (
@ -151,14 +152,14 @@ public:
} }
virtual void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_TerrainHeightGen, int a_SeaLevel) override virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override
{ {
m_TerrainHeightGen = a_TerrainHeightGen; m_TerrainHeightGen = &a_TerrainHeightGen;
} }
protected: protected:
/** The underlying height generator. */ /** The underlying height generator. */
cTerrainHeightGenPtr m_TerrainHeightGen; cTerrainHeightGen * m_TerrainHeightGen;
/** How many blocks above the terrain level do we accept on minimum. */ /** How many blocks above the terrain level do we accept on minimum. */
int m_MinBlocksAbove; int m_MinBlocksAbove;
@ -198,15 +199,15 @@ public:
} }
virtual void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_TerrainHeightGen, int a_SeaLevel) override virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override
{ {
m_TerrainHeightGen = a_TerrainHeightGen; m_TerrainHeightGen = &a_TerrainHeightGen;
m_SeaLevel = a_SeaLevel; m_SeaLevel = a_SeaLevel;
} }
protected: protected:
/** The underlying height generator. */ /** The underlying height generator. */
cTerrainHeightGenPtr m_TerrainHeightGen; cTerrainHeightGen * m_TerrainHeightGen;
/** The sealevel for the current world. */ /** The sealevel for the current world. */
int m_SeaLevel; int m_SeaLevel;
@ -282,14 +283,14 @@ public:
} }
virtual void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_TerrainHeightGen, int a_SeaLevel) override virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override
{ {
m_TerrainHeightGen = a_TerrainHeightGen; m_TerrainHeightGen = &a_TerrainHeightGen;
} }
protected: protected:
/** The underlying height generator. */ /** The underlying height generator. */
cTerrainHeightGenPtr m_TerrainHeightGen; cTerrainHeightGen * m_TerrainHeightGen;
/** How many blocks below the terrain level do we accept on minimum. */ /** How many blocks below the terrain level do we accept on minimum. */
int m_MinBlocksBelow; int m_MinBlocksBelow;
@ -328,15 +329,15 @@ public:
} }
virtual void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_TerrainHeightGen, int a_SeaLevel) override virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override
{ {
m_TerrainHeightGen = a_TerrainHeightGen; m_TerrainHeightGen = &a_TerrainHeightGen;
m_SeaLevel = a_SeaLevel; m_SeaLevel = a_SeaLevel;
} }
protected: protected:
/** The underlying height generator. */ /** The underlying height generator. */
cTerrainHeightGenPtr m_TerrainHeightGen; cTerrainHeightGen * m_TerrainHeightGen;
/** The sealevel for the current world. */ /** The sealevel for the current world. */
int m_SeaLevel; int m_SeaLevel;
@ -413,7 +414,3 @@ cPiece::cVerticalLimitPtr CreateVerticalLimitFromString(const AString & a_LimitD
return Limit; return Limit;
} }

View File

@ -162,7 +162,7 @@ public:
} }
virtual void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_TerrainHeightGen, int a_SeaLevel) override virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_TerrainHeightGen, int a_SeaLevel) override
{ {
m_Seed = a_Seed + SEED_OFFSET; m_Seed = a_Seed + SEED_OFFSET;
} }
@ -209,10 +209,10 @@ public:
} }
virtual void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_HeightGen, int a_SeaLevel) override virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel) override
{ {
m_Seed = a_Seed + SEED_OFFSET; m_Seed = a_Seed + SEED_OFFSET;
m_HeightGen = a_HeightGen; m_HeightGen = &a_HeightGen;
} }
protected: protected:
@ -220,7 +220,7 @@ protected:
int m_Seed; int m_Seed;
/** Height generator from which the top of the terrain is read. */ /** Height generator from which the top of the terrain is read. */
cTerrainHeightGenPtr m_HeightGen; cTerrainHeightGen * m_HeightGen;
/** Minimum relative height at which the prefab is placed. */ /** Minimum relative height at which the prefab is placed. */
int m_MinRelHeight; int m_MinRelHeight;
@ -265,10 +265,10 @@ public:
} }
virtual void AssignGens(int a_Seed, cBiomeGenPtr & a_BiomeGen, cTerrainHeightGenPtr & a_HeightGen, int a_SeaLevel) override virtual void AssignGens(int a_Seed, cBiomeGen & a_BiomeGen, cTerrainHeightGen & a_HeightGen, int a_SeaLevel) override
{ {
m_Seed = a_Seed + SEED_OFFSET; m_Seed = a_Seed + SEED_OFFSET;
m_HeightGen = a_HeightGen; m_HeightGen = &a_HeightGen;
m_SeaLevel = a_SeaLevel; m_SeaLevel = a_SeaLevel;
} }
@ -277,7 +277,7 @@ protected:
int m_Seed; int m_Seed;
/** Height generator from which the top of the terrain is read. */ /** Height generator from which the top of the terrain is read. */
cTerrainHeightGenPtr m_HeightGen; cTerrainHeightGen * m_HeightGen;
/** The sea level used by the world. */ /** The sea level used by the world. */
int m_SeaLevel; int m_SeaLevel;
@ -342,7 +342,3 @@ cPiece::cVerticalStrategyPtr CreateVerticalStrategyFromString(const AString & a_
return Strategy; return Strategy;
} }

View File

@ -125,7 +125,7 @@ public:
int a_MaxSize, int a_MaxSize,
int a_Density, int a_Density,
cVillagePiecePool & a_Prefabs, cVillagePiecePool & a_Prefabs,
cTerrainHeightGenPtr a_HeightGen cTerrainHeightGen & a_HeightGen
): ):
Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ),
m_Seed(a_Seed), m_Seed(a_Seed),
@ -137,7 +137,7 @@ public:
{a_OriginX + a_MaxSize, cChunkDef::Height - 1, a_OriginZ + a_MaxSize} {a_OriginX + a_MaxSize, cChunkDef::Height - 1, a_OriginZ + a_MaxSize}
), ),
m_Prefabs(a_Prefabs), m_Prefabs(a_Prefabs),
m_HeightGen(std::move(a_HeightGen)) m_HeightGen(a_HeightGen)
{ {
// Generate the pieces for this village; don't care about the Y coord: // Generate the pieces for this village; don't care about the Y coord:
cPieceGeneratorBFSTree pg(*this, a_Seed); cPieceGeneratorBFSTree pg(*this, a_Seed);
@ -169,7 +169,7 @@ protected:
cVillagePiecePool & m_Prefabs; cVillagePiecePool & m_Prefabs;
/** The underlying height generator, used for placing the structures on top of the terrain. */ /** The underlying height generator, used for placing the structures on top of the terrain. */
cTerrainHeightGenPtr m_HeightGen; cTerrainHeightGen & m_HeightGen;
/** The village pieces, placed by the generator. */ /** The village pieces, placed by the generator. */
cPlacedPieces m_Pieces; cPlacedPieces m_Pieces;
@ -182,7 +182,7 @@ protected:
// Each intersecting prefab is placed on ground, then drawn // Each intersecting prefab is placed on ground, then drawn
// Each intersecting road is drawn by replacing top soil blocks with gravel / sandstone blocks // Each intersecting road is drawn by replacing top soil blocks with gravel / sandstone blocks
cChunkDef::HeightMap HeightMap; // Heightmap for this chunk, used by roads cChunkDef::HeightMap HeightMap; // Heightmap for this chunk, used by roads
m_HeightGen->GenHeightMap(a_Chunk.GetChunkCoords(), HeightMap); m_HeightGen.GenHeightMap(a_Chunk.GetChunkCoords(), HeightMap);
for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) for (cPlacedPieces::iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr)
{ {
const cPrefab & Prefab = static_cast<const cPrefab &>((*itr)->GetPiece()); const cPrefab & Prefab = static_cast<const cPrefab &>((*itr)->GetPiece());
@ -212,7 +212,7 @@ protected:
int BlockY; int BlockY;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cChunkDef::HeightMap HeightMap; cChunkDef::HeightMap HeightMap;
m_HeightGen->GenHeightMap({ChunkX, ChunkZ}, HeightMap); m_HeightGen.GenHeightMap({ChunkX, ChunkZ}, HeightMap);
int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ); int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ);
a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1); a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1);
} }
@ -337,8 +337,8 @@ cVillageGen::cVillageGen(
int a_MaxSize, int a_MaxSize,
int a_MinDensity, int a_MinDensity,
int a_MaxDensity, int a_MaxDensity,
cBiomeGenPtr a_BiomeGen, cBiomeGen & a_BiomeGen,
cTerrainHeightGenPtr a_HeightGen, cTerrainHeightGen & a_HeightGen,
int a_SeaLevel, int a_SeaLevel,
const AStringVector & a_PrefabsToLoad const AStringVector & a_PrefabsToLoad
) : ) :
@ -348,8 +348,8 @@ cVillageGen::cVillageGen(
m_MaxSize(a_MaxSize), m_MaxSize(a_MaxSize),
m_MinDensity(a_MinDensity), m_MinDensity(a_MinDensity),
m_MaxDensity(a_MaxDensity), m_MaxDensity(a_MaxDensity),
m_BiomeGen(std::move(a_BiomeGen)), m_BiomeGen(a_BiomeGen),
m_HeightGen(std::move(a_HeightGen)) m_HeightGen(a_HeightGen)
{ {
for (const auto & toLoad: a_PrefabsToLoad) for (const auto & toLoad: a_PrefabsToLoad)
{ {
@ -379,7 +379,7 @@ cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_GridX, int a_Gr
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ);
cChunkDef::BiomeMap Biomes; cChunkDef::BiomeMap Biomes;
m_BiomeGen->GenBiomes({ChunkX, ChunkZ}, Biomes); m_BiomeGen.GenBiomes({ChunkX, ChunkZ}, Biomes);
// Get a list of pools that support each biome within the chunk: // Get a list of pools that support each biome within the chunk:
// If just one column's biome is not allowed, the pool is not used because it's likely that an unfriendly biome is too close // If just one column's biome is not allowed, the pool is not used because it's likely that an unfriendly biome is too close
@ -424,7 +424,3 @@ cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_GridX, int a_Gr
// Create a village based on the chosen prefabs: // Create a village based on the chosen prefabs:
return cStructurePtr(new cVillage(m_Seed, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize, Density, *pool.get(), m_HeightGen)); return cStructurePtr(new cVillage(m_Seed, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize, Density, *pool.get(), m_HeightGen));
} }

View File

@ -38,8 +38,8 @@ public:
int a_MaxDepth, int a_MaxDepth,
int a_MaxSize, int a_MaxSize,
int a_MinDensity, int a_MaxDensity, int a_MinDensity, int a_MaxDensity,
cBiomeGenPtr a_BiomeGen, cBiomeGen & a_BiomeGen,
cTerrainHeightGenPtr a_HeightGen, cTerrainHeightGen & a_HeightGen,
int a_SeaLevel, int a_SeaLevel,
const AStringVector & a_PrefabsToLoad const AStringVector & a_PrefabsToLoad
); );
@ -64,10 +64,10 @@ protected:
int m_MaxDensity; int m_MaxDensity;
/** The underlying biome generator that defines whether the village is created or not */ /** The underlying biome generator that defines whether the village is created or not */
cBiomeGenPtr m_BiomeGen; cBiomeGen & m_BiomeGen;
/** The underlying height generator, used to position the prefabs crossing chunk borders */ /** The underlying height generator, used to position the prefabs crossing chunk borders */
cTerrainHeightGenPtr m_HeightGen; cTerrainHeightGen & m_HeightGen;
/** All available prefab sets. Each village gets one of these chosen randomly. */ /** All available prefab sets. Each village gets one of these chosen randomly. */
cVillagePiecePools m_Pools; cVillagePiecePools m_Pools;
@ -76,7 +76,3 @@ protected:
// cGridStructGen overrides: // cGridStructGen overrides:
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override;
} ; } ;