From 5ca3a7c2e76bc91356aaa1c6bc3d12bb2a3c6e9c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 8 Mar 2021 16:39:43 +0000 Subject: shared_ptr -> unique_ptr in generators --- src/Generating/BioGen.cpp | 43 +++++---- src/Generating/BioGen.h | 21 ++--- src/Generating/CompoGen.cpp | 6 +- src/Generating/CompoGen.h | 8 +- src/Generating/CompoGenBiomal.cpp | 7 +- src/Generating/CompoGenBiomal.h | 6 +- src/Generating/ComposableGenerator.cpp | 132 ++++++++++++++-------------- src/Generating/ComposableGenerator.h | 37 +++----- src/Generating/CompositedHeiGen.h | 24 +++-- src/Generating/DistortedHeightmap.cpp | 6 +- src/Generating/DistortedHeightmap.h | 6 +- src/Generating/DungeonRoomsFinisher.cpp | 10 +-- src/Generating/DungeonRoomsFinisher.h | 8 +- src/Generating/HeiGen.cpp | 47 +++++----- src/Generating/HeiGen.h | 27 +++--- src/Generating/Noise3DGenerator.cpp | 11 +-- src/Generating/Noise3DGenerator.h | 8 +- src/Generating/PiecePool.h | 9 +- src/Generating/PieceStructuresGen.cpp | 17 ++-- src/Generating/PieceStructuresGen.h | 6 +- src/Generating/PrefabPiecePool.cpp | 6 +- src/Generating/PrefabPiecePool.h | 2 +- src/Generating/PrefabStructure.cpp | 10 +-- src/Generating/PrefabStructure.h | 8 +- src/Generating/ShapeGen.cpp | 26 +++--- src/Generating/SinglePieceStructuresGen.cpp | 14 +-- src/Generating/SinglePieceStructuresGen.h | 2 +- src/Generating/StructGen.cpp | 12 +-- src/Generating/StructGen.h | 30 +++---- src/Generating/TwoHeights.cpp | 10 +-- src/Generating/TwoHeights.h | 6 +- src/Generating/VerticalLimit.cpp | 29 +++--- src/Generating/VerticalStrategy.cpp | 18 ++-- src/Generating/VillageGen.cpp | 24 +++-- src/Generating/VillageGen.h | 12 +-- 35 files changed, 263 insertions(+), 385 deletions(-) (limited to 'src/Generating') diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 9a97be006..74547800f 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -57,8 +57,8 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cBioGenCache: -cBioGenCache::cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize) : - m_BioGenToCache(std::move(a_BioGenToCache)), +cBioGenCache::cBioGenCache(cBiomeGen & a_BioGenToCache, size_t a_CacheSize) : + m_BioGenToCache(a_BioGenToCache), m_CacheSize(a_CacheSize), m_NumHits(0), m_NumMisses(0), @@ -110,7 +110,7 @@ void cBioGenCache::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a // Not in the cache: 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: 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) { 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(const cBiomeGenPtr & a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches) : - m_NumSubCaches(a_NumSubCaches) +cBioGenMulticache::cBioGenMulticache(std::unique_ptr a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches) : + m_NumSubCaches(a_NumSubCaches), + m_Underlying(std::move(a_BioGenToCache)) { m_Caches.reserve(a_NumSubCaches); 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(*m_Underlying, a_SubCacheSize)); } } @@ -167,7 +168,7 @@ void cBioGenMulticache::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMa void cBioGenMulticache::InitializeBiomeGen(cIniFile & a_IniFile) { - for (const auto & itr : m_Caches) + for (auto & itr : m_Caches) { itr->InitializeBiomeGen(a_IniFile); } @@ -1133,7 +1134,7 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cBiomeGen: -cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault) +std::unique_ptr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault) { AString BiomeGenName = a_IniFile.GetValue("Generator", "BiomeGen"); if (BiomeGenName.empty()) @@ -1142,37 +1143,37 @@ cBiomeGenPtr cBiomeGen::CreateBiomeGen(cIniFile & a_IniFile, int a_Seed, bool & BiomeGenName = "Grown"; } - cBiomeGen * res = nullptr; + std::unique_ptr res; a_CacheOffByDefault = false; if (NoCaseCompare(BiomeGenName, "constant") == 0) { - res = new cBioGenConstant; + res = std::make_unique(); a_CacheOffByDefault = true; // we're generating faster than a cache would retrieve data :) } else if (NoCaseCompare(BiomeGenName, "checkerboard") == 0) { - res = new cBioGenCheckerboard; + res = std::make_unique(); a_CacheOffByDefault = true; // we're (probably) generating faster than a cache would retrieve data } else if (NoCaseCompare(BiomeGenName, "voronoi") == 0) { - res = new cBioGenVoronoi(a_Seed); + res = std::make_unique(a_Seed); } else if (NoCaseCompare(BiomeGenName, "distortedvoronoi") == 0) { - res = new cBioGenDistortedVoronoi(a_Seed); + res = std::make_unique(a_Seed); } else if (NoCaseCompare(BiomeGenName, "twolevel") == 0) { - res = new cBioGenTwoLevel(a_Seed); + res = std::make_unique(a_Seed); } else if (NoCaseCompare(BiomeGenName, "multistepmap") == 0) { - res = new cBioGenMultiStepMap(a_Seed); + res = std::make_unique(a_Seed); } else if (NoCaseCompare(BiomeGenName, "grownprot") == 0) { - res = new cBioGenProtGrown(a_Seed); + res = std::make_unique(a_Seed); } 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()); } - res = new cBioGenGrown(a_Seed); + res = std::make_unique(a_Seed); } res->InitializeBiomeGen(a_IniFile); - return cBiomeGenPtr(res); + return res; } @@ -1234,7 +1235,3 @@ protected: } g_BioGenPerfTest; #endif - - - - diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h index c23c8ac46..3c630e396 100644 --- a/src/Generating/BioGen.h +++ b/src/Generating/BioGen.h @@ -49,13 +49,13 @@ class cBioGenCache: public: - cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize); - virtual ~cBioGenCache() override = default; - + cBioGenCache(cBiomeGen & a_BioGenToCache, size_t a_CacheSize); protected: - cBiomeGenPtr m_BioGenToCache; + friend class cBioGenMulticache; + + cBiomeGen & m_BioGenToCache; struct sCacheData { @@ -97,17 +97,18 @@ public: 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_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 a_BioGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches); protected: - typedef std::vector cBiomeGenPtrs; - /** Number of sub-caches. Pulled out of m_Caches.size() for faster access. */ size_t m_NumSubCaches; /** Individual sub-caches. */ - cBiomeGenPtrs m_Caches; + std::vector> m_Caches; + + /** The underlying biome generator. */ + std::unique_ptr m_Underlying; 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 */ EMCSBiome SelectBiome(int a_BiomeGroup, size_t a_BiomeIdx, int a_DistLevel); } ; - - - - diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp index 7cc8fa095..02786ede9 100644 --- a/src/Generating/CompoGen.cpp +++ b/src/Generating/CompoGen.cpp @@ -329,7 +329,7 @@ void cCompoGenNether::InitializeCompoGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cCompoGenCache: -cCompoGenCache::cCompoGenCache(cTerrainCompositionGenPtr a_Underlying, int a_CacheSize) : +cCompoGenCache::cCompoGenCache(std::unique_ptr a_Underlying, int a_CacheSize) : m_Underlying(std::move(a_Underlying)), m_CacheSize(a_CacheSize), m_CacheOrder(new int[ToUnsigned(a_CacheSize)]), @@ -430,7 +430,3 @@ void cCompoGenCache::InitializeCompoGen(cIniFile & a_IniFile) { m_Underlying->InitializeCompoGen(a_IniFile); } - - - - diff --git a/src/Generating/CompoGen.h b/src/Generating/CompoGen.h index bc15a2dcb..53154ec07 100644 --- a/src/Generating/CompoGen.h +++ b/src/Generating/CompoGen.h @@ -115,7 +115,7 @@ class cCompoGenCache : public cTerrainCompositionGen { public: - cCompoGenCache(cTerrainCompositionGenPtr a_Underlying, int a_CacheSize); // Doesn't take ownership of a_Underlying + cCompoGenCache(std::unique_ptr a_Underlying, int a_CacheSize); virtual ~cCompoGenCache() override; // cTerrainCompositionGen override: @@ -124,7 +124,7 @@ public: protected: - cTerrainCompositionGenPtr m_Underlying; + std::unique_ptr m_Underlying; struct sCacheData { @@ -145,7 +145,3 @@ protected: int m_NumMisses; int m_TotalChain; // Number of cache items walked to get to a hit (only added for hits) } ; - - - - diff --git a/src/Generating/CompoGenBiomal.cpp b/src/Generating/CompoGenBiomal.cpp index 951cb1a64..967a4a89c 100644 --- a/src/Generating/CompoGenBiomal.cpp +++ b/src/Generating/CompoGenBiomal.cpp @@ -582,10 +582,7 @@ protected: -cTerrainCompositionGenPtr CreateCompoGenBiomal(int a_Seed) +std::unique_ptr CreateCompoGenBiomal(int a_Seed) { - return std::make_shared(a_Seed); + return std::make_unique(a_Seed); } - - - diff --git a/src/Generating/CompoGenBiomal.h b/src/Generating/CompoGenBiomal.h index a3a65d3dc..6248b19d4 100644 --- a/src/Generating/CompoGenBiomal.h +++ b/src/Generating/CompoGenBiomal.h @@ -14,8 +14,4 @@ /** Returns a new instance of the Biomal composition generator. */ -cTerrainCompositionGenPtr CreateCompoGenBiomal(int a_Seed); - - - - +std::unique_ptr CreateCompoGenBiomal(int a_Seed); diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 0e637613b..d5c64e4c4 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -38,10 +38,10 @@ //////////////////////////////////////////////////////////////////////////////// // cTerrainCompositionGen: -cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen( +std::unique_ptr cTerrainCompositionGen::CreateCompositionGen( cIniFile & a_IniFile, - const cBiomeGenPtr & a_BiomeGen, - const cTerrainShapeGenPtr & a_ShapeGen, + cBiomeGen & a_BiomeGen, + cTerrainShapeGen & a_ShapeGen, int a_Seed ) { @@ -53,7 +53,7 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen( } // Compositor list is alpha-sorted - cTerrainCompositionGenPtr res; + std::unique_ptr res; if (NoCaseCompare(CompoGenName, "Biomal") == 0) { res = CreateCompoGenBiomal(a_Seed); @@ -65,11 +65,11 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen( } else if (NoCaseCompare(CompoGenName, "Classic") == 0) { - res = std::make_shared(); + res = std::make_unique(); } else if (NoCaseCompare(CompoGenName, "DebugBiomes") == 0) { - res = std::make_shared(); + res = std::make_unique(); } else if (NoCaseCompare(CompoGenName, "DistortedHeightmap") == 0) { @@ -78,11 +78,11 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen( } else if (NoCaseCompare(CompoGenName, "End") == 0) { - res = std::make_shared(a_Seed); + res = std::make_unique(a_Seed); } else if (NoCaseCompare(CompoGenName, "Nether") == 0) { - res = std::make_shared(a_Seed); + res = std::make_unique(a_Seed); } else if (NoCaseCompare(CompoGenName, "Noise3D") == 0) { @@ -91,7 +91,7 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen( } else if (NoCaseCompare(CompoGenName, "SameBlock") == 0) { - res = std::make_shared(); + res = std::make_unique(); } else { @@ -104,7 +104,7 @@ cTerrainCompositionGenPtr cTerrainCompositionGen::CreateCompositionGen( // Read the settings from the ini file: res->InitializeCompoGen(a_IniFile); - return cTerrainCompositionGenPtr(res); + return res; } @@ -181,10 +181,10 @@ void cComposableGenerator::Generate(cChunkDesc & a_ChunkDesc) 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); - } // for itr - m_FinishGens[] + Finisher->GenFinish(a_ChunkDesc); + } ShouldUpdateHeightmap = true; } @@ -302,11 +302,11 @@ void cComposableGenerator::InitBiomeGen(cIniFile & a_IniFile) if (MultiCacheLength > 0) { LOGD("Enabling multicache for biomegen of length %d.", MultiCacheLength); - m_BiomeGen = std::make_shared(m_BiomeGen, static_cast(CacheSize), static_cast(MultiCacheLength)); + m_BiomeGen = std::make_unique(std::move(m_BiomeGen), static_cast(CacheSize), static_cast(MultiCacheLength)); } else { - m_BiomeGen = std::make_shared(m_BiomeGen, static_cast(CacheSize)); + m_BiomeGen = std::make_unique(std::move(m_BiomeGen), static_cast(CacheSize), 1); } } @@ -319,7 +319,7 @@ void cComposableGenerator::InitShapeGen(cIniFile & a_IniFile) bool CacheOffByDefault = false; m_ShapeGen = cTerrainShapeGen::CreateShapeGen( a_IniFile, - m_BiomeGen, + *m_BiomeGen, m_Seed, CacheOffByDefault ); @@ -351,8 +351,8 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile) { m_CompositionGen = cTerrainCompositionGen::CreateCompositionGen( a_IniFile, - m_BiomeGen, - m_ShapeGen, + *m_BiomeGen, + *m_ShapeGen, m_Seed ); @@ -361,11 +361,11 @@ void cComposableGenerator::InitCompositionGen(cIniFile & a_IniFile) int CompoGenCacheSize = a_IniFile.GetValueSetI("Generator", "CompositionGenCacheSize", 64); if (CompoGenCacheSize > 0) { - m_CompositionGen = std::make_shared(m_CompositionGen, CompoGenCacheSize); + m_CompositionGen = std::make_unique(std::move(m_CompositionGen), CompoGenCacheSize); } // Create a cache of the composited heightmaps, so that finishers may use it: - m_CompositedHeightCache = std::make_shared(std::make_shared(m_BiomeGen, m_ShapeGen, m_CompositionGen), 16, 128); + m_CompositedHeightCache = std::make_unique(std::make_unique(*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. } @@ -392,13 +392,13 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) // Finishers, alpha-sorted: if (NoCaseCompare(finisher, "Animals") == 0) { - m_FinishGens.emplace_back(new cFinishGenPassiveMobs(m_Seed, a_IniFile, m_Dimension)); + m_FinishGens.push_back(std::make_unique(m_Seed, a_IniFile, m_Dimension)); } else if (NoCaseCompare(finisher, "BottomLava") == 0) { int DefaultBottomLavaLevel = (m_Dimension == dimNether) ? 30 : 10; int BottomLavaLevel = a_IniFile.GetValueSetI("Generator", "BottomLavaLevel", DefaultBottomLavaLevel); - m_FinishGens.emplace_back(new cFinishGenBottomLava(BottomLavaLevel)); + m_FinishGens.push_back(std::make_unique(BottomLavaLevel)); } 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_STAINED_CLAY); - m_FinishGens.emplace_back(new cFinishGenSingleTopBlock(m_Seed, E_BLOCK_DEAD_BUSH, AllowedBiomes, 2, AllowedBlocks)); + m_FinishGens.push_back(std::make_unique(m_Seed, E_BLOCK_DEAD_BUSH, AllowedBiomes, 2, AllowedBlocks)); } else if (NoCaseCompare(finisher, "DirectOverhangs") == 0) { - m_FinishGens.emplace_back(new cStructGenDirectOverhangs(m_Seed)); + m_FinishGens.push_back(std::make_unique(m_Seed)); } else if (NoCaseCompare(finisher, "DirtPockets") == 0) { - auto gen = std::make_shared(m_Seed + 1, cFinishGenOrePockets::DefaultNaturalPatches()); - gen->Initialize(a_IniFile, "DirtPockets"); - m_FinishGens.push_back(gen); + auto Gen = std::make_unique(m_Seed + 1, cFinishGenOrePockets::DefaultNaturalPatches()); + Gen->Initialize(a_IniFile, "DirtPockets"); + m_FinishGens.push_back(std::move(Gen)); } else if (NoCaseCompare(finisher, "DistortedMembraneOverhangs") == 0) { - m_FinishGens.emplace_back(new cStructGenDistortedMembraneOverhangs(m_Seed)); + m_FinishGens.push_back(std::make_unique(m_Seed)); } else if (NoCaseCompare(finisher, "DualRidgeCaves") == 0) { float Threshold = static_cast(a_IniFile.GetValueSetF("Generator", "DualRidgeCavesThreshold", 0.3)); - m_FinishGens.emplace_back(new cStructGenDualRidgeCaves(m_Seed, Threshold)); + m_FinishGens.push_back(std::make_unique(m_Seed, Threshold)); } 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 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"); - m_FinishGens.emplace_back(new cDungeonRoomsFinisher(m_ShapeGen, m_Seed, GridSize, MaxSize, MinSize, HeightDistrib)); + m_FinishGens.push_back(std::make_unique(*m_ShapeGen, m_Seed, GridSize, MaxSize, MinSize, HeightDistrib)); } else if (NoCaseCompare(finisher, "GlowStone") == 0) { - m_FinishGens.emplace_back(new cFinishGenGlowStone(m_Seed)); + m_FinishGens.push_back(std::make_unique(m_Seed)); } else if (NoCaseCompare(finisher, "Ice") == 0) { - m_FinishGens.emplace_back(new cFinishGenIce); + m_FinishGens.push_back(std::make_unique()); } else if (NoCaseCompare(finisher, "LavaLakes") == 0) { 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(m_Seed * 5 + 16873, E_BLOCK_STATIONARY_LAVA, *m_ShapeGen, Probability)); } 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(m_Seed, E_BLOCK_LAVA, a_IniFile, m_Dimension)); } 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_STATIONARY_WATER); - m_FinishGens.emplace_back(new cFinishGenSingleTopBlock(m_Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks)); + m_FinishGens.push_back(std::make_unique(m_Seed, E_BLOCK_LILY_PAD, AllowedBiomes, 4, AllowedBlocks)); } else if (NoCaseCompare(finisher, "MarbleCaves") == 0) { - m_FinishGens.emplace_back(new cStructGenMarbleCaves(m_Seed)); + m_FinishGens.push_back(std::make_unique(m_Seed)); } 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 ChanceCrossing = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceCrossing", 200); int ChanceStaircase = a_IniFile.GetValueSetI("Generator", "MineShaftsChanceStaircase", 200); - m_FinishGens.emplace_back(new cStructGenMineShafts( + m_FinishGens.push_back(std::make_unique( m_Seed, GridSize, MaxOffset, MaxSystemSize, ChanceCorridor, ChanceCrossing, ChanceStaircase )); } else if (NoCaseCompare(finisher, "NaturalPatches") == 0) { - m_FinishGens.emplace_back(new cFinishGenOreNests(m_Seed + 1, cFinishGenOreNests::DefaultNaturalPatches())); + m_FinishGens.push_back(std::make_unique(m_Seed + 1, cFinishGenOreNests::DefaultNaturalPatches())); } else if (NoCaseCompare(finisher, "NetherClumpFoliage") == 0) { - m_FinishGens.emplace_back(new cFinishGenNetherClumpFoliage(m_Seed)); + m_FinishGens.push_back(std::make_unique(m_Seed)); } else if (NoCaseCompare(finisher, "NetherOreNests") == 0) { - m_FinishGens.emplace_back(new cFinishGenOreNests(m_Seed + 2, cFinishGenOreNests::DefaultNetherOres())); + m_FinishGens.push_back(std::make_unique(m_Seed + 2, cFinishGenOreNests::DefaultNetherOres())); } else if (NoCaseCompare(finisher, "OreNests") == 0) { - m_FinishGens.emplace_back(new cFinishGenOreNests(m_Seed + 3, cFinishGenOreNests::DefaultOverworldOres())); + m_FinishGens.push_back(std::make_unique(m_Seed + 3, cFinishGenOreNests::DefaultOverworldOres())); } else if (NoCaseCompare(finisher, "OrePockets") == 0) { - auto gen = std::make_shared(m_Seed + 2, cFinishGenOrePockets::DefaultOverworldOres()); - gen->Initialize(a_IniFile, "OrePockets"); - m_FinishGens.push_back(gen); + auto Gen = std::make_unique(m_Seed + 2, cFinishGenOrePockets::DefaultOverworldOres()); + Gen->Initialize(a_IniFile, "OrePockets"); + m_FinishGens.push_back(std::move(Gen)); } else if (NoCaseCompare(finisher, "OverworldClumpFlowers") == 0) { auto flowers = cFinishGenClumpTopBlock::ParseIniFile(a_IniFile, "OverworldClumpFlowers"); - m_FinishGens.emplace_back(new cFinishGenClumpTopBlock(m_Seed, flowers)); + m_FinishGens.push_back(std::make_unique(m_Seed, flowers)); } else if (NoCaseCompare(finisher, "PieceStructures") == 0) { @@ -533,10 +533,10 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) continue; } - auto gen = std::make_shared(m_Seed); - if (gen->Initialize(split[1], seaLevel, m_BiomeGen, m_CompositedHeightCache)) + auto Gen = std::make_unique(m_Seed); + 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) @@ -546,11 +546,11 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) bool PreSimulateWater = a_IniFile.GetValueSetB("Generator", "PreSimulatorWater", 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(PreSimulateFallingBlocks, PreSimulateWater, PreSimulateLava)); } else if (NoCaseCompare(finisher, "Ravines") == 0) { - m_FinishGens.emplace_back(new cStructGenRavines(m_Seed, 128)); + m_FinishGens.push_back(std::make_unique(m_Seed, 128)); } 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 MaxCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMaxCeilingHeightCenter", 58); double MinCeilingHeightCenter = a_IniFile.GetValueSetF("Generator", "RoughRavinesMinCeilingHeightCenter", 36); - m_FinishGens.emplace_back(new cRoughRavines( + m_FinishGens.push_back(std::make_unique( m_Seed, MaxSize, MinSize, static_cast(MaxCenterWidth), static_cast(MinCenterWidth), @@ -595,33 +595,33 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) continue; } - auto Gen = std::make_shared(m_Seed); - if (Gen->Initialize(split[1], seaLevel, m_BiomeGen, m_CompositedHeightCache)) + auto Gen = std::make_unique(m_Seed); + 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) { - m_FinishGens.emplace_back(new cFinishGenSoulsandRims(m_Seed)); + m_FinishGens.push_back(std::make_unique(m_Seed)); } else if (NoCaseCompare(finisher, "Snow") == 0) { - m_FinishGens.emplace_back(new cFinishGenSnow); + m_FinishGens.push_back(std::make_unique()); } else if (NoCaseCompare(finisher, "SprinkleFoliage") == 0) { int MaxCactusHeight = a_IniFile.GetValueI("Plants", "MaxCactusHeight", 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(m_Seed, MaxCactusHeight, MaxSugarcaneHeight)); } else if (NoCaseCompare(finisher, "TallGrass") == 0) { - m_FinishGens.emplace_back(new cFinishGenTallGrass(m_Seed)); + m_FinishGens.push_back(std::make_unique(m_Seed)); } 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(m_Seed, *m_BiomeGen, *m_ShapeGen, *m_CompositionGen)); } else if (NoCaseCompare(finisher, "Villages") == 0) { @@ -633,28 +633,28 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) int MaxDensity = a_IniFile.GetValueSetI("Generator", "VillageMaxDensity", 80); AString PrefabList = a_IniFile.GetValueSet("Generator", "VillagePrefabs", "PlainsVillage, SandVillage"); 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(m_Seed, GridSize, MaxOffset, MaxDepth, MaxSize, MinDensity, MaxDensity, *m_BiomeGen, *m_CompositedHeightCache, seaLevel, Prefabs)); } else if (NoCaseCompare(finisher, "Vines") == 0) { int Level = a_IniFile.GetValueSetI("Generator", "VinesLevel", 40); - m_FinishGens.emplace_back(new cFinishGenVines(m_Seed, Level)); + m_FinishGens.push_back(std::make_unique(m_Seed, Level)); } else if (NoCaseCompare(finisher, "WaterLakes") == 0) { 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(m_Seed * 3 + 652, E_BLOCK_STATIONARY_WATER, *m_ShapeGen, Probability)); } 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(m_Seed, E_BLOCK_WATER, a_IniFile, m_Dimension)); } else if (NoCaseCompare(finisher, "WormNestCaves") == 0) { int Size = a_IniFile.GetValueSetI("Generator", "WormNestCavesSize", 64); int Grid = a_IniFile.GetValueSetI("Generator", "WormNestCavesGrid", 96); 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(m_Seed, Size, Grid, MaxOffset)); } else { @@ -662,7 +662,3 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) } } // for itr - Str[] } - - - - diff --git a/src/Generating/ComposableGenerator.h b/src/Generating/ComposableGenerator.h index 661a7276b..4105fbf83 100644 --- a/src/Generating/ComposableGenerator.h +++ b/src/Generating/ComposableGenerator.h @@ -30,11 +30,6 @@ class cTerrainShapeGen; class cTerrainHeightGen; class cTerrainCompositionGen; class cFinishGen; -typedef std::shared_ptr cBiomeGenPtr; -typedef std::shared_ptr cTerrainShapeGenPtr; -typedef std::shared_ptr cTerrainHeightGenPtr; -typedef std::shared_ptr cTerrainCompositionGenPtr; -typedef std::shared_ptr cFinishGenPtr; @@ -60,7 +55,7 @@ public: a_CacheOffByDefault gets set to whether the cache should be disabled by default. Used in BiomeVisualiser, too. Implemented in BioGen.cpp! */ - static cBiomeGenPtr CreateBiomeGen( + static std::unique_ptr CreateBiomeGen( cIniFile & a_IniFile, int a_Seed, bool & a_CacheOffByDefault @@ -96,9 +91,9 @@ public: a_CacheOffByDefault gets set to whether the cache should be disabled by default Implemented in ShapeGen.cpp! */ - static cTerrainShapeGenPtr CreateShapeGen( + static std::unique_ptr CreateShapeGen( cIniFile & a_IniFile, - const cBiomeGenPtr & a_BiomeGen, + cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault ); @@ -135,9 +130,9 @@ public: } /** Creates a cTerrainHeightGen descendant based on the INI file settings. */ - static cTerrainHeightGenPtr CreateHeightGen( + static std::unique_ptr CreateHeightGen( cIniFile & a_IniFile, - const cBiomeGenPtr & a_BiomeGen, + cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault ); @@ -167,10 +162,10 @@ public: /** Creates the correct TerrainCompositionGen descendant based on the ini file settings and the seed provided. a_BiomeGen is the underlying biome generator, some composition generators may depend on it providing additional biomes around the chunk a_ShapeGen is the underlying shape generator, some composition generators may depend on it providing additional shape around the chunk. */ - static cTerrainCompositionGenPtr CreateCompositionGen( + static std::unique_ptr CreateCompositionGen( cIniFile & a_IniFile, - const cBiomeGenPtr & a_BiomeGen, - const cTerrainShapeGenPtr & a_ShapeGen, + cBiomeGen & a_BiomeGen, + cTerrainShapeGen & a_ShapeGen, int a_Seed ); } ; @@ -194,8 +189,6 @@ public: virtual void GenFinish(cChunkDesc & a_ChunkDesc) = 0; } ; -typedef std::list cFinishGenList; - @@ -223,19 +216,19 @@ protected: // The generator's composition: /** The biome generator. */ - cBiomeGenPtr m_BiomeGen; + std::unique_ptr m_BiomeGen; /** The terrain shape generator. */ - cTerrainShapeGenPtr m_ShapeGen; + std::unique_ptr m_ShapeGen; /** The terrain composition generator. */ - cTerrainCompositionGenPtr m_CompositionGen; + std::unique_ptr m_CompositionGen; /** The cache for the heights of the composited terrain. */ - cTerrainHeightGenPtr m_CompositedHeightCache; + std::unique_ptr m_CompositedHeightCache; /** The finisher generators, in the order in which they are applied. */ - cFinishGenList m_FinishGens; + std::vector> m_FinishGens; /** 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 */ void InitFinishGens(cIniFile & a_IniFile); } ; - - - - diff --git a/src/Generating/CompositedHeiGen.h b/src/Generating/CompositedHeiGen.h index 400008d88..6107d33ae 100644 --- a/src/Generating/CompositedHeiGen.h +++ b/src/Generating/CompositedHeiGen.h @@ -20,10 +20,10 @@ class cCompositedHeiGen: public cTerrainHeightGen { public: - cCompositedHeiGen(cBiomeGenPtr a_BiomeGen, cTerrainShapeGenPtr a_ShapeGen, cTerrainCompositionGenPtr a_CompositionGen): - m_BiomeGen(std::move(a_BiomeGen)), - m_ShapeGen(std::move(a_ShapeGen)), - m_CompositionGen(std::move(a_CompositionGen)) + cCompositedHeiGen(cBiomeGen & a_BiomeGen, cTerrainShapeGen & a_ShapeGen, cTerrainCompositionGen & a_CompositionGen): + m_BiomeGen(a_BiomeGen), + m_ShapeGen(a_ShapeGen), + m_CompositionGen(a_CompositionGen) { } @@ -33,20 +33,16 @@ public: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override { cChunkDesc::Shape shape; - m_ShapeGen->GenShape(a_ChunkCoords, shape); + m_ShapeGen.GenShape(a_ChunkCoords, shape); 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); - m_CompositionGen->ComposeTerrain(desc, shape); + m_CompositionGen.ComposeTerrain(desc, shape); memcpy(a_HeightMap, desc.GetHeightMap(), sizeof(a_HeightMap)); } protected: - cBiomeGenPtr m_BiomeGen; - cTerrainShapeGenPtr m_ShapeGen; - cTerrainCompositionGenPtr m_CompositionGen; + cBiomeGen & m_BiomeGen; + cTerrainShapeGen & m_ShapeGen; + cTerrainCompositionGen & m_CompositionGen; }; - - - - diff --git a/src/Generating/DistortedHeightmap.cpp b/src/Generating/DistortedHeightmap.cpp index 11c873967..a0732287b 100644 --- a/src/Generating/DistortedHeightmap.cpp +++ b/src/Generating/DistortedHeightmap.cpp @@ -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_NoiseDistortZ(a_Seed + 2000), m_CurChunkCoords(0x7fffffff, 0x7fffffff), // Set impossible coords for the chunk so that it's always considered stale m_BiomeGen(a_BiomeGen), - m_UnderlyingHeiGen(new cHeiGenBiomal(a_Seed, a_BiomeGen)), + m_UnderlyingHeiGen(a_Seed, a_BiomeGen), m_HeightGen(m_UnderlyingHeiGen, 64), m_IsInitialized(false) { @@ -297,7 +297,7 @@ void cDistortedHeightmap::UpdateDistortAmps(void) { 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 z diff --git a/src/Generating/DistortedHeightmap.h b/src/Generating/DistortedHeightmap.h index bc6d079ba..f523b8109 100644 --- a/src/Generating/DistortedHeightmap.h +++ b/src/Generating/DistortedHeightmap.h @@ -26,7 +26,7 @@ class cDistortedHeightmap : public cTerrainShapeGen { public: - cDistortedHeightmap(int a_Seed, const cBiomeGenPtr & a_BiomeGen); + cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen); protected: typedef cChunkDef::BiomeMap BiomeNeighbors[3][3]; @@ -53,10 +53,10 @@ protected: NOISE_DATATYPE m_DistortedHeightmap[17 * 257 * 17]; /** The bime generator to query for biomes. */ - cBiomeGenPtr m_BiomeGen; + cBiomeGen & m_BiomeGen; /** The generator that provides the base heightmap (before distortion). */ - cTerrainHeightGenPtr m_UnderlyingHeiGen; + cHeiGenBiomal m_UnderlyingHeiGen; /** Cache for m_UnderlyingHeiGen. */ cHeiGenCache m_HeightGen; diff --git a/src/Generating/DungeonRoomsFinisher.cpp b/src/Generating/DungeonRoomsFinisher.cpp index 4196e16ee..96dd28333 100644 --- a/src/Generating/DungeonRoomsFinisher.cpp +++ b/src/Generating/DungeonRoomsFinisher.cpp @@ -287,9 +287,9 @@ protected: //////////////////////////////////////////////////////////////////////////////// // 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), - m_ShapeGen(std::move(a_ShapeGen)), + m_ShapeGen(a_ShapeGen), m_MaxHalfSize((a_MaxSize + 1) / 2), m_MinHalfSize((a_MinSize + 1) / 2), m_HeightProbability(cChunkDef::Height) @@ -322,7 +322,7 @@ cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int int RelX = a_OriginX, RelY = 0, RelZ = a_OriginZ; cChunkDef::AbsoluteToRelative(RelX, RelY, RelZ, ChunkX, ChunkZ); cChunkDesc::Shape shape; - m_ShapeGen->GenShape({ChunkX, ChunkZ}, shape); + m_ShapeGen.GenShape({ChunkX, ChunkZ}, shape); int height = 0; int idx = RelX * 256 + RelZ * 16 * 256; for (int y = 6; y < cChunkDef::Height; y++) @@ -337,7 +337,3 @@ cDungeonRoomsFinisher::cStructurePtr cDungeonRoomsFinisher::CreateStructure(int // Create the dungeon room descriptor: return cStructurePtr(new cDungeonRoom(a_GridX, a_GridZ, a_OriginX, a_OriginZ, HalfSizeX, HalfSizeZ, height, m_Noise)); } - - - - diff --git a/src/Generating/DungeonRoomsFinisher.h b/src/Generating/DungeonRoomsFinisher.h index 72ac5cb51..bd5380448 100644 --- a/src/Generating/DungeonRoomsFinisher.h +++ b/src/Generating/DungeonRoomsFinisher.h @@ -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_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). */ - 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: /** 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). */ int m_MaxHalfSize; @@ -47,7 +47,3 @@ protected: // cGridStructGen overrides: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; } ; - - - - diff --git a/src/Generating/HeiGen.cpp b/src/Generating/HeiGen.cpp index 4efb89be5..2e4b4fb3c 100644 --- a/src/Generating/HeiGen.cpp +++ b/src/Generating/HeiGen.cpp @@ -106,8 +106,8 @@ void cHeiGenFlat::InitializeHeightGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cHeiGenCache: -cHeiGenCache::cHeiGenCache(cTerrainHeightGenPtr a_HeiGenToCache, size_t a_CacheSize) : - m_HeiGenToCache(std::move(a_HeiGenToCache)), +cHeiGenCache::cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, size_t a_CacheSize) : + m_HeiGenToCache(a_HeiGenToCache), m_CacheSize(a_CacheSize), m_NumHits(0), m_NumMisses(0), @@ -161,7 +161,7 @@ void cHeiGenCache::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap // Not in the cache: 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: 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(const cTerrainHeightGenPtr & a_HeiGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches): - m_NumSubCaches(a_NumSubCaches) +cHeiGenMultiCache::cHeiGenMultiCache(std::unique_ptr a_HeiGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches): + m_NumSubCaches(a_NumSubCaches), + m_Underlying(std::move(a_HeiGenToCache)) { // Create the individual sub-caches: m_SubCaches.reserve(a_NumSubCaches); for (size_t i = 0; i < a_NumSubCaches; i++) { - m_SubCaches.emplace_back(std::make_shared(a_HeiGenToCache, a_SubCacheSize)); + m_SubCaches.push_back(std::make_unique(*m_Underlying, a_SubCacheSize)); } } @@ -517,7 +518,7 @@ void cHeiGenBiomal::GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMa { 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 z @@ -636,9 +637,9 @@ class cHeiGenMinMax: public: - cHeiGenMinMax(int a_Seed, cBiomeGenPtr a_BiomeGen): + cHeiGenMinMax(int a_Seed, cBiomeGen & a_BiomeGen): m_Noise(a_Seed), - m_BiomeGen(std::move(a_BiomeGen)), + m_BiomeGen(a_BiomeGen), m_TotalWeight(0) { // Initialize the weights: @@ -664,7 +665,7 @@ public: cChunkDef::BiomeMap neighborBiomes[3][3]; 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: @@ -735,7 +736,7 @@ protected: cPerlinNoise m_Perlin; /** 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. */ double m_Weights[AVERAGING_SIZE * 2 + 1][AVERAGING_SIZE * 2 + 1]; @@ -831,7 +832,7 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cTerrainHeightGen: -cTerrainHeightGenPtr cTerrainHeightGen::CreateHeightGen(cIniFile & a_IniFile, const cBiomeGenPtr & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault) +std::unique_ptr cTerrainHeightGen::CreateHeightGen(cIniFile & a_IniFile, cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault) { AString HeightGenName = a_IniFile.GetValueSet("Generator", "HeightGen", ""); if (HeightGenName.empty()) @@ -841,55 +842,55 @@ cTerrainHeightGenPtr cTerrainHeightGen::CreateHeightGen(cIniFile & a_IniFile, co } a_CacheOffByDefault = false; - cTerrainHeightGenPtr res; + std::unique_ptr res; if (NoCaseCompare(HeightGenName, "Flat") == 0) { - res = std::make_shared(); + res = std::make_unique(); a_CacheOffByDefault = true; // We're generating faster than a cache would retrieve data } else if (NoCaseCompare(HeightGenName, "classic") == 0) { - res = std::make_shared(a_Seed); + res = std::make_unique(a_Seed); } 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 // Return an empty pointer, the caller will create the proper generator: - return cTerrainHeightGenPtr(); + return nullptr; } 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 // Return an empty pointer, the caller will create the proper generator: - return cTerrainHeightGenPtr(); + return nullptr; } else if (NoCaseCompare(HeightGenName, "MinMax") == 0) { - res = std::make_shared(a_Seed, a_BiomeGen); + res = std::make_unique(a_Seed, a_BiomeGen); } else if (NoCaseCompare(HeightGenName, "Mountains") == 0) { - res = std::make_shared(a_Seed); + res = std::make_unique(a_Seed); } 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 // Return an empty pointer, the caller will create the proper generator: - return cTerrainHeightGenPtr(); + return nullptr; } else if (NoCaseCompare(HeightGenName, "Steppy") == 0) { - res = std::make_shared(a_Seed); + res = std::make_unique(a_Seed); } 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 // Return an empty pointer, the caller will create the proper generator: - return cTerrainHeightGenPtr(); + return nullptr; } else if (NoCaseCompare(HeightGenName, "Biomal") == 0) { - res = std::make_shared(a_Seed, a_BiomeGen); + res = std::make_unique(a_Seed, a_BiomeGen); /* // Performance-testing: diff --git a/src/Generating/HeiGen.h b/src/Generating/HeiGen.h index ebdfef70f..6f2101043 100644 --- a/src/Generating/HeiGen.h +++ b/src/Generating/HeiGen.h @@ -28,8 +28,7 @@ class cHeiGenCache : public cTerrainHeightGen { public: - cHeiGenCache(cTerrainHeightGenPtr a_HeiGenToCache, size_t a_CacheSize); - virtual ~cHeiGenCache() override = default; + cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, size_t a_CacheSize); // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; @@ -51,7 +50,7 @@ protected: } ; /** 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 size_t m_CacheSize; @@ -73,7 +72,7 @@ class cHeiGenMultiCache: public cTerrainHeightGen { public: - cHeiGenMultiCache(const cTerrainHeightGenPtr & a_HeightGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches); + cHeiGenMultiCache(std::unique_ptr a_HeightGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches); // cTerrainHeightGen overrides: 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); protected: - typedef std::shared_ptr cHeiGenCachePtr; - typedef std::vector cHeiGenCachePtrs; - /** The coefficient used to turn Z coords into index (x + Coeff * z). */ static const size_t m_CoeffZ = 5; @@ -94,7 +90,10 @@ protected: size_t m_NumSubCaches; /** The individual sub-caches. */ - cHeiGenCachePtrs m_SubCaches; + std::vector> m_SubCaches; + + /** The underlying height generator. */ + std::unique_ptr m_Underlying; }; @@ -174,9 +173,9 @@ class cHeiGenBiomal: public: - cHeiGenBiomal(int a_Seed, cBiomeGenPtr a_BiomeGen): + cHeiGenBiomal(int a_Seed, cBiomeGen & a_BiomeGen): 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]; - cNoise m_Noise; - cBiomeGenPtr m_BiomeGen; + cNoise m_Noise; + cBiomeGen & m_BiomeGen; // Per-biome terrain generator parameters: 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); } ; - - - - diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp index 362c6d9a2..ecf135a26 100644 --- a/src/Generating/Noise3DGenerator.cpp +++ b/src/Generating/Noise3DGenerator.cpp @@ -506,12 +506,12 @@ void cNoise3DComposable::GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape //////////////////////////////////////////////////////////////////////////////// // cBiomalNoise3DComposable: -cBiomalNoise3DComposable::cBiomalNoise3DComposable(int a_Seed, cBiomeGenPtr a_BiomeGen) : +cBiomalNoise3DComposable::cBiomalNoise3DComposable(int a_Seed, cBiomeGen & a_BiomeGen) : m_ChoiceNoise(a_Seed), m_DensityNoiseA(a_Seed + 1), m_DensityNoiseB(a_Seed + 2), 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 { // 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++) { - 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 z } - - - - - diff --git a/src/Generating/Noise3DGenerator.h b/src/Generating/Noise3DGenerator.h index 43245bebd..9aceffc1d 100644 --- a/src/Generating/Noise3DGenerator.h +++ b/src/Generating/Noise3DGenerator.h @@ -136,7 +136,7 @@ class cBiomalNoise3DComposable : public cTerrainShapeGen { public: - cBiomalNoise3DComposable(int a_Seed, cBiomeGenPtr a_BiomeGen); + cBiomalNoise3DComposable(int a_Seed, cBiomeGen & a_BiomeGen); void Initialize(cIniFile & a_IniFile); @@ -161,7 +161,7 @@ protected: cOctavedNoise> m_BaseNoise; /** The underlying biome generator. */ - cBiomeGenPtr m_BiomeGen; + cBiomeGen & m_BiomeGen; /** Block height of the sealevel, used for composing the terrain. */ int m_SeaLevel; @@ -207,7 +207,3 @@ protected: virtual void GenShape(cChunkCoords a_ChunkCoords, cChunkDesc::Shape & a_Shape) override; virtual void InitializeShapeGen(cIniFile & a_IniFile) override { Initialize(a_IniFile); } } ; - - - - diff --git a/src/Generating/PiecePool.h b/src/Generating/PiecePool.h index 0849f4ebc..8beaf0c31 100644 --- a/src/Generating/PiecePool.h +++ b/src/Generating/PiecePool.h @@ -115,7 +115,7 @@ public: /** Called when the piece pool is assigned to a generator, 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 cVerticalStrategyPtr; @@ -142,7 +142,7 @@ public: /** Called when the piece pool is assigned to a generator, 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 cVerticalLimitPtr; @@ -328,8 +328,3 @@ protected: typedef std::unique_ptr cPlacedPiecePtr; typedef std::vector cPlacedPieces; - - - - - diff --git a/src/Generating/PieceStructuresGen.cpp b/src/Generating/PieceStructuresGen.cpp index dbfe16b47..56890597a 100644 --- a/src/Generating/PieceStructuresGen.cpp +++ b/src/Generating/PieceStructuresGen.cpp @@ -20,10 +20,10 @@ class cPieceStructuresGen::cGen: 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), - m_BiomeGen(std::move(a_BiomeGen)), - m_HeightGen(std::move(a_HeightGen)), + m_BiomeGen(a_BiomeGen), + m_HeightGen(a_HeightGen), m_SeaLevel(a_SeaLevel), m_Name(a_Name), m_MaxDepth(5) @@ -95,10 +95,10 @@ protected: typedef std::vector cFreeConnectors; /** 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. */ - cTerrainHeightGenPtr m_HeightGen; + cTerrainHeightGen & m_HeightGen; /** The world's sea level, if available. Used for some cVerticalStrategy descendants. */ 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: auto Structures = StringSplitAndTrim(a_Prefabs, "|"); @@ -172,8 +172,3 @@ void cPieceStructuresGen::GenFinish(cChunkDesc & a_Chunk) Gen->GenFinish(a_Chunk); } } - - - - - diff --git a/src/Generating/PieceStructuresGen.h b/src/Generating/PieceStructuresGen.h index c3d7c4ee3..224e6b262 100644 --- a/src/Generating/PieceStructuresGen.h +++ b/src/Generating/PieceStructuresGen.h @@ -34,7 +34,7 @@ public: 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. 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: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; @@ -54,7 +54,3 @@ protected: /** The seed for the random number generator */ int m_Seed; }; - - - - diff --git a/src/Generating/PrefabPiecePool.cpp b/src/Generating/PrefabPiecePool.cpp index 28355660c..88e670026 100644 --- a/src/Generating/PrefabPiecePool.cpp +++ b/src/Generating/PrefabPiecePool.cpp @@ -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: for (auto & piece: m_StartingPieces) @@ -808,7 +808,3 @@ void cPrefabPiecePool::Reset(void) { // Do nothing } - - - - diff --git a/src/Generating/PrefabPiecePool.h b/src/Generating/PrefabPiecePool.h index 6bbb7ac13..708b9be57 100644 --- a/src/Generating/PrefabPiecePool.h +++ b/src/Generating/PrefabPiecePool.h @@ -108,7 +108,7 @@ public: /** Called when the piece pool is assigned to a generator, 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: virtual cPieces GetPiecesWithConnector(int a_ConnectorType) override; diff --git a/src/Generating/PrefabStructure.cpp b/src/Generating/PrefabStructure.cpp index 127cd0018..9814610b4 100644 --- a/src/Generating/PrefabStructure.cpp +++ b/src/Generating/PrefabStructure.cpp @@ -15,11 +15,11 @@ cPrefabStructure::cPrefabStructure( int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, cPlacedPieces && a_Pieces, - cTerrainHeightGenPtr a_HeightGen + cTerrainHeightGen & a_HeightGen ): Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), 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; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::HeightMap HeightMap; - m_HeightGen->GenHeightMap({ChunkX, ChunkZ}, HeightMap); + m_HeightGen.GenHeightMap({ChunkX, ChunkZ}, HeightMap); int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ); a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1); } - - - - diff --git a/src/Generating/PrefabStructure.h b/src/Generating/PrefabStructure.h index e102b4863..8b489d866 100644 --- a/src/Generating/PrefabStructure.h +++ b/src/Generating/PrefabStructure.h @@ -27,7 +27,7 @@ public: int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ, cPlacedPieces && a_Pieces, - cTerrainHeightGenPtr a_HeightGen + cTerrainHeightGen & a_HeightGen ); protected: @@ -35,7 +35,7 @@ protected: cPlacedPieces m_Pieces; /** The height generator used when adjusting pieces onto the ground. */ - cTerrainHeightGenPtr m_HeightGen; + cTerrainHeightGen & m_HeightGen; // cGridStructGen::cStructure overrides: @@ -45,7 +45,3 @@ protected: Ground level is assumed to be represented by the first connector in the piece. */ void PlacePieceOnGround(cPlacedPiece & a_Piece); }; - - - - diff --git a/src/Generating/ShapeGen.cpp b/src/Generating/ShapeGen.cpp index 1efbf1010..f46c0c8e9 100644 --- a/src/Generating/ShapeGen.cpp +++ b/src/Generating/ShapeGen.cpp @@ -23,7 +23,7 @@ class cTerrainHeightToShapeGen: public cTerrainShapeGen { public: - cTerrainHeightToShapeGen(cTerrainHeightGenPtr a_HeightGen): + cTerrainHeightToShapeGen(std::unique_ptr a_HeightGen): m_HeightGen(std::move(a_HeightGen)) { } @@ -63,7 +63,7 @@ public: protected: /** The height generator being converted. */ - cTerrainHeightGenPtr m_HeightGen; + std::unique_ptr m_HeightGen; }; typedef std::shared_ptr cTerrainHeightToShapeGenPtr; @@ -75,9 +75,9 @@ typedef std::shared_ptr cTerrainHeightToShapeGenPtr; //////////////////////////////////////////////////////////////////////////////// // cTerrainShapeGen: -cTerrainShapeGenPtr cTerrainShapeGen::CreateShapeGen( +std::unique_ptr cTerrainShapeGen::CreateShapeGen( cIniFile & a_IniFile, - const cBiomeGenPtr & a_BiomeGen, + cBiomeGen & a_BiomeGen, int a_Seed, bool & a_CacheOffByDefault ) @@ -92,10 +92,10 @@ cTerrainShapeGenPtr cTerrainShapeGen::CreateShapeGen( // If the shapegen is HeightMap, redirect to older HeightMap-based generators: 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) { - return std::make_shared(heightGen); + return std::make_unique(std::move(heightGen)); } // 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: a_CacheOffByDefault = false; - cTerrainShapeGenPtr res; + std::unique_ptr res; if (NoCaseCompare(shapeGenName, "DistortedHeightmap") == 0) { - res = std::make_shared(a_Seed, a_BiomeGen); + res = std::make_unique(a_Seed, a_BiomeGen); } else if (NoCaseCompare(shapeGenName, "End") == 0) { - res = std::make_shared(a_Seed); + res = std::make_unique(a_Seed); } else if (NoCaseCompare(shapeGenName, "BiomalNoise3D") == 0) { - res = std::make_shared(a_Seed, a_BiomeGen); + res = std::make_unique(a_Seed, a_BiomeGen); } else if (NoCaseCompare(shapeGenName, "Noise3D") == 0) { - res = std::make_shared(a_Seed); + res = std::make_unique(a_Seed); } else if (NoCaseCompare(shapeGenName, "TwoHeights") == 0) { @@ -144,7 +144,3 @@ cTerrainShapeGenPtr cTerrainShapeGen::CreateShapeGen( return res; } - - - - diff --git a/src/Generating/SinglePieceStructuresGen.cpp b/src/Generating/SinglePieceStructuresGen.cpp index 84b246715..fb6dcd67d 100644 --- a/src/Generating/SinglePieceStructuresGen.cpp +++ b/src/Generating/SinglePieceStructuresGen.cpp @@ -14,10 +14,10 @@ class cSinglePieceStructuresGen::cGen : { using Super = cGridStructGen; 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), - m_BiomeGen(std::move(a_BiomeGen)), - m_HeightGen(std::move(a_HeightGen)), + m_BiomeGen(a_BiomeGen), + m_HeightGen(a_HeightGen), m_SeaLevel(a_SeaLevel), m_Name(a_Name) { @@ -61,7 +61,7 @@ public: int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ); 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 auto Relative = cChunkDef::AbsoluteToRelative(Vector3i(a_OriginX, 1, a_OriginZ), {ChunkX, ChunkZ}); @@ -132,10 +132,10 @@ public: protected: /** 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. */ - cTerrainHeightGenPtr m_HeightGen; + cTerrainHeightGen & m_HeightGen; /** The world's sea level, if available. Used for some cVerticalStrategy descendants. */ 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: auto Structures = StringSplitAndTrim(a_Prefabs, "|"); diff --git a/src/Generating/SinglePieceStructuresGen.h b/src/Generating/SinglePieceStructuresGen.h index c14757738..386d0f9ae 100644 --- a/src/Generating/SinglePieceStructuresGen.h +++ b/src/Generating/SinglePieceStructuresGen.h @@ -30,7 +30,7 @@ public: 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. 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: diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index fd78ceb3e..3bdf94d1c 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -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 cChunkDesc::Shape workerShape; - m_BiomeGen->GenBiomes ({BaseX, BaseZ}, WorkerDesc.GetBiomeMap()); - m_ShapeGen->GenShape ({BaseX, BaseZ}, workerShape); - WorkerDesc.SetHeightFromShape (workerShape); - m_CompositionGen->ComposeTerrain(WorkerDesc, workerShape); + m_BiomeGen.GenBiomes ({BaseX, BaseZ}, WorkerDesc.GetBiomeMap()); + m_ShapeGen.GenShape ({BaseX, BaseZ}, workerShape); + WorkerDesc.SetHeightFromShape (workerShape); + m_CompositionGen.ComposeTerrain(WorkerDesc, workerShape); } else { @@ -575,7 +575,3 @@ void cStructGenDistortedMembraneOverhangs::GenFinish(cChunkDesc & a_ChunkDesc) } // for x } // for z } - - - - diff --git a/src/Generating/StructGen.h b/src/Generating/StructGen.h index ae7626873..ec3ed89f6 100644 --- a/src/Generating/StructGen.h +++ b/src/Generating/StructGen.h @@ -22,21 +22,21 @@ class cStructGenTrees : public cFinishGen { 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_Noise(a_Seed), - m_BiomeGen(std::move(a_BiomeGen)), - m_ShapeGen(std::move(a_ShapeGen)), - m_CompositionGen(std::move(a_CompositionGen)) + m_BiomeGen(a_BiomeGen), + m_ShapeGen(a_ShapeGen), + m_CompositionGen(a_CompositionGen) {} protected: int m_Seed; cNoise m_Noise; - cBiomeGenPtr m_BiomeGen; - cTerrainShapeGenPtr m_ShapeGen; - cTerrainCompositionGenPtr m_CompositionGen; + cBiomeGen & m_BiomeGen; + cTerrainShapeGen & m_ShapeGen; + cTerrainCompositionGen & m_CompositionGen; /** Generates and applies an image of a single tree. Parts of the tree inside the chunk are applied to a_ChunkDesc. @@ -78,20 +78,20 @@ class cStructGenLakes : public cFinishGen { 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_Seed(a_Seed), m_Fluid(a_Fluid), - m_ShapeGen(std::move(a_ShapeGen)), + m_ShapeGen(a_ShapeGen), m_Probability(a_Probability) { } protected: - cNoise m_Noise; - int m_Seed; - BLOCKTYPE m_Fluid; - cTerrainShapeGenPtr m_ShapeGen; + cNoise m_Noise; + int m_Seed; + BLOCKTYPE m_Fluid; + cTerrainShapeGen & m_ShapeGen; /** Chance, [0 .. 100], of a chunk having the lake. */ int m_Probability; @@ -143,7 +143,3 @@ protected: // cFinishGen override: virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; } ; - - - - diff --git a/src/Generating/TwoHeights.cpp b/src/Generating/TwoHeights.cpp index 377127c00..91c67608c 100644 --- a/src/Generating/TwoHeights.cpp +++ b/src/Generating/TwoHeights.cpp @@ -21,7 +21,7 @@ class cTwoHeights: public: - cTwoHeights(int a_Seed, const cBiomeGenPtr & a_BiomeGen): + cTwoHeights(int a_Seed, cBiomeGen & a_BiomeGen): m_Seed(a_Seed), m_Choice(a_Seed), m_HeightA(a_Seed + 1, a_BiomeGen), @@ -113,11 +113,7 @@ protected: -cTerrainShapeGenPtr CreateShapeGenTwoHeights(int a_Seed, const cBiomeGenPtr & a_BiomeGen) +std::unique_ptr CreateShapeGenTwoHeights(int a_Seed, cBiomeGen & a_BiomeGen) { - return std::make_shared(a_Seed, a_BiomeGen); + return std::make_unique(a_Seed, a_BiomeGen); } - - - - diff --git a/src/Generating/TwoHeights.h b/src/Generating/TwoHeights.h index 7dcf47c77..fbdcfdcfd 100644 --- a/src/Generating/TwoHeights.h +++ b/src/Generating/TwoHeights.h @@ -16,8 +16,4 @@ /** Creates and returns a new instance of the cTwoHeights terrain shape generator. The instance must be Initialize()-d before it is used. */ -extern cTerrainShapeGenPtr CreateShapeGenTwoHeights(int a_Seed, const cBiomeGenPtr & a_BiomeGen); - - - - +extern std::unique_ptr CreateShapeGenTwoHeights(int a_Seed, cBiomeGen & a_BiomeGen); diff --git a/src/Generating/VerticalLimit.cpp b/src/Generating/VerticalLimit.cpp index f6b1b456c..b3e8ea35d 100644 --- a/src/Generating/VerticalLimit.cpp +++ b/src/Generating/VerticalLimit.cpp @@ -133,6 +133,7 @@ class cVerticalLimitAboveTerrain: public: 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); int compareHeight = a_Height - terrainHeight; 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: /** The underlying height generator. */ - cTerrainHeightGenPtr m_TerrainHeightGen; + cTerrainHeightGen * m_TerrainHeightGen; /** How many blocks above the terrain level do we accept on minimum. */ 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; } protected: /** The underlying height generator. */ - cTerrainHeightGenPtr m_TerrainHeightGen; + cTerrainHeightGen * m_TerrainHeightGen; /** The sealevel for the current world. */ 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: /** The underlying height generator. */ - cTerrainHeightGenPtr m_TerrainHeightGen; + cTerrainHeightGen * m_TerrainHeightGen; /** How many blocks below the terrain level do we accept on minimum. */ 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; } protected: /** The underlying height generator. */ - cTerrainHeightGenPtr m_TerrainHeightGen; + cTerrainHeightGen * m_TerrainHeightGen; /** The sealevel for the current world. */ int m_SeaLevel; @@ -413,7 +414,3 @@ cPiece::cVerticalLimitPtr CreateVerticalLimitFromString(const AString & a_LimitD return Limit; } - - - - diff --git a/src/Generating/VerticalStrategy.cpp b/src/Generating/VerticalStrategy.cpp index 0651958f9..9fd11865b 100644 --- a/src/Generating/VerticalStrategy.cpp +++ b/src/Generating/VerticalStrategy.cpp @@ -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; } @@ -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_HeightGen = a_HeightGen; + m_HeightGen = &a_HeightGen; } protected: @@ -220,7 +220,7 @@ protected: int m_Seed; /** 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. */ 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_HeightGen = a_HeightGen; + m_HeightGen = &a_HeightGen; m_SeaLevel = a_SeaLevel; } @@ -277,7 +277,7 @@ protected: int m_Seed; /** Height generator from which the top of the terrain is read. */ - cTerrainHeightGenPtr m_HeightGen; + cTerrainHeightGen * m_HeightGen; /** The sea level used by the world. */ int m_SeaLevel; @@ -342,7 +342,3 @@ cPiece::cVerticalStrategyPtr CreateVerticalStrategyFromString(const AString & a_ return Strategy; } - - - - diff --git a/src/Generating/VillageGen.cpp b/src/Generating/VillageGen.cpp index d46c0d64a..6575b2f3a 100644 --- a/src/Generating/VillageGen.cpp +++ b/src/Generating/VillageGen.cpp @@ -125,7 +125,7 @@ public: int a_MaxSize, int a_Density, cVillagePiecePool & a_Prefabs, - cTerrainHeightGenPtr a_HeightGen + cTerrainHeightGen & a_HeightGen ): Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ), m_Seed(a_Seed), @@ -137,7 +137,7 @@ public: {a_OriginX + a_MaxSize, cChunkDef::Height - 1, a_OriginZ + a_MaxSize} ), 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: cPieceGeneratorBFSTree pg(*this, a_Seed); @@ -169,7 +169,7 @@ protected: cVillagePiecePool & m_Prefabs; /** 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. */ cPlacedPieces m_Pieces; @@ -182,7 +182,7 @@ protected: // Each intersecting prefab is placed on ground, then drawn // Each intersecting road is drawn by replacing top soil blocks with gravel / sandstone blocks 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) { const cPrefab & Prefab = static_cast((*itr)->GetPiece()); @@ -212,7 +212,7 @@ protected: int BlockY; cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::HeightMap HeightMap; - m_HeightGen->GenHeightMap({ChunkX, ChunkZ}, HeightMap); + m_HeightGen.GenHeightMap({ChunkX, ChunkZ}, HeightMap); int TerrainHeight = cChunkDef::GetHeight(HeightMap, BlockX, BlockZ); a_Piece.MoveToGroundBy(TerrainHeight - FirstConnector.m_Pos.y + 1); } @@ -337,8 +337,8 @@ cVillageGen::cVillageGen( int a_MaxSize, int a_MinDensity, int a_MaxDensity, - cBiomeGenPtr a_BiomeGen, - cTerrainHeightGenPtr a_HeightGen, + cBiomeGen & a_BiomeGen, + cTerrainHeightGen & a_HeightGen, int a_SeaLevel, const AStringVector & a_PrefabsToLoad ) : @@ -348,8 +348,8 @@ cVillageGen::cVillageGen( m_MaxSize(a_MaxSize), m_MinDensity(a_MinDensity), m_MaxDensity(a_MaxDensity), - m_BiomeGen(std::move(a_BiomeGen)), - m_HeightGen(std::move(a_HeightGen)) + m_BiomeGen(a_BiomeGen), + m_HeightGen(a_HeightGen) { for (const auto & toLoad: a_PrefabsToLoad) { @@ -379,7 +379,7 @@ cGridStructGen::cStructurePtr cVillageGen::CreateStructure(int a_GridX, int a_Gr int ChunkX, ChunkZ; cChunkDef::BlockToChunk(a_OriginX, a_OriginZ, ChunkX, ChunkZ); 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: // 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: return cStructurePtr(new cVillage(m_Seed, a_GridX, a_GridZ, a_OriginX, a_OriginZ, m_MaxDepth, m_MaxSize, Density, *pool.get(), m_HeightGen)); } - - - - diff --git a/src/Generating/VillageGen.h b/src/Generating/VillageGen.h index 42c5b7bb0..c59c089d3 100644 --- a/src/Generating/VillageGen.h +++ b/src/Generating/VillageGen.h @@ -38,8 +38,8 @@ public: int a_MaxDepth, int a_MaxSize, int a_MinDensity, int a_MaxDensity, - cBiomeGenPtr a_BiomeGen, - cTerrainHeightGenPtr a_HeightGen, + cBiomeGen & a_BiomeGen, + cTerrainHeightGen & a_HeightGen, int a_SeaLevel, const AStringVector & a_PrefabsToLoad ); @@ -64,10 +64,10 @@ protected: int m_MaxDensity; /** 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 */ - cTerrainHeightGenPtr m_HeightGen; + cTerrainHeightGen & m_HeightGen; /** All available prefab sets. Each village gets one of these chosen randomly. */ cVillagePiecePools m_Pools; @@ -76,7 +76,3 @@ protected: // cGridStructGen overrides: virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) override; } ; - - - - -- cgit v1.2.3