diff options
Diffstat (limited to 'src/Generating/GridStructGen.cpp')
-rw-r--r-- | src/Generating/GridStructGen.cpp | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/src/Generating/GridStructGen.cpp b/src/Generating/GridStructGen.cpp index 4a565f220..9868aa15f 100644 --- a/src/Generating/GridStructGen.cpp +++ b/src/Generating/GridStructGen.cpp @@ -1,7 +1,8 @@ // GridStructGen.cpp -// Implements the cGridStructGen class representing a common base class for structure generators that place structures in a semi-random grid +// Implements the cGridStructGen class representing a common base class for structure generators that place structures +// in a semi-random grid #include "Globals.h" #include "GridStructGen.h" @@ -16,24 +17,22 @@ /** A cStructure descendant representing an empty structure. Used when the generator descended from cGridStructGen doesn't return any structure, to keep at least the Origin coords so that the structure isn't queried over and over again. */ -class cEmptyStructure: - public cGridStructGen::cStructure +class cEmptyStructure : public cGridStructGen::cStructure { using Super = cGridStructGen::cStructure; -public: - + public: cEmptyStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ) { } -protected: + protected: virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override { // Do nothing } -} ; +}; @@ -41,9 +40,12 @@ protected: cGridStructGen::cGridStructGen( int a_Seed, - int a_GridSizeX, int a_GridSizeZ, - int a_MaxOffsetX, int a_MaxOffsetZ, - int a_MaxStructureSizeX, int a_MaxStructureSizeZ, + int a_GridSizeX, + int a_GridSizeZ, + int a_MaxOffsetX, + int a_MaxOffsetZ, + int a_MaxStructureSizeX, + int a_MaxStructureSizeZ, size_t a_MaxCacheSize ) : m_Seed(a_Seed), @@ -66,13 +68,17 @@ cGridStructGen::cGridStructGen( LOG("Grid Size cannot be zero, setting to 1"); m_GridSizeZ = 1; } - size_t NumStructuresPerQuery = static_cast<size_t>(((m_MaxStructureSizeX + m_MaxOffsetX) / m_GridSizeX + 1) * ((m_MaxStructureSizeZ + m_MaxOffsetZ) / m_GridSizeZ + 1)); + size_t NumStructuresPerQuery = static_cast<size_t>( + ((m_MaxStructureSizeX + m_MaxOffsetX) / m_GridSizeX + 1) * + ((m_MaxStructureSizeZ + m_MaxOffsetZ) / m_GridSizeZ + 1) + ); if (NumStructuresPerQuery > m_MaxCacheSize) { m_MaxCacheSize = NumStructuresPerQuery * 4; LOGINFO( "cGridStructGen: The cache size is too small (%u), increasing the cache size to %u to avoid inefficiency.", - static_cast<unsigned>(a_MaxCacheSize), static_cast<unsigned>(m_MaxCacheSize) + static_cast<unsigned>(a_MaxCacheSize), + static_cast<unsigned>(m_MaxCacheSize) ); } } @@ -81,7 +87,7 @@ cGridStructGen::cGridStructGen( -cGridStructGen::cGridStructGen(int a_Seed): +cGridStructGen::cGridStructGen(int a_Seed) : m_BaseSeed(a_Seed), m_Seed(a_Seed), m_Noise(a_Seed), @@ -102,13 +108,13 @@ cGridStructGen::cGridStructGen(int a_Seed): void cGridStructGen::SetGeneratorParams(const AStringMap & a_GeneratorParams) { ASSERT(m_Cache.empty()); // No changing the params after chunks are generated - m_GridSizeX = GetStringMapInteger<int> (a_GeneratorParams, "GridSizeX", m_GridSizeX); - m_GridSizeZ = GetStringMapInteger<int> (a_GeneratorParams, "GridSizeZ", m_GridSizeZ); - m_MaxOffsetX = GetStringMapInteger<int> (a_GeneratorParams, "MaxOffsetX", m_MaxOffsetX); - m_MaxOffsetZ = GetStringMapInteger<int> (a_GeneratorParams, "MaxOffsetZ", m_MaxOffsetZ); - m_MaxStructureSizeX = GetStringMapInteger<int> (a_GeneratorParams, "MaxStructureSizeX", m_MaxStructureSizeX); - m_MaxStructureSizeZ = GetStringMapInteger<int> (a_GeneratorParams, "MaxStructureSizeZ", m_MaxStructureSizeZ); - m_MaxCacheSize = GetStringMapInteger<size_t>(a_GeneratorParams, "MaxCacheSize", m_MaxCacheSize); + m_GridSizeX = GetStringMapInteger<int>(a_GeneratorParams, "GridSizeX", m_GridSizeX); + m_GridSizeZ = GetStringMapInteger<int>(a_GeneratorParams, "GridSizeZ", m_GridSizeZ); + m_MaxOffsetX = GetStringMapInteger<int>(a_GeneratorParams, "MaxOffsetX", m_MaxOffsetX); + m_MaxOffsetZ = GetStringMapInteger<int>(a_GeneratorParams, "MaxOffsetZ", m_MaxOffsetZ); + m_MaxStructureSizeX = GetStringMapInteger<int>(a_GeneratorParams, "MaxStructureSizeX", m_MaxStructureSizeX); + m_MaxStructureSizeZ = GetStringMapInteger<int>(a_GeneratorParams, "MaxStructureSizeZ", m_MaxStructureSizeZ); + m_MaxCacheSize = GetStringMapInteger<size_t>(a_GeneratorParams, "MaxCacheSize", m_MaxCacheSize); // Silently fix out-of-range parameters: if (m_MaxOffsetX < 1) @@ -149,10 +155,8 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur // Walk the cache, move each structure that we want into a_Structures: for (cStructurePtrs::iterator itr = m_Cache.begin(), end = m_Cache.end(); itr != end;) { - if ( - ((*itr)->m_GridX >= MinX) && ((*itr)->m_GridX < MaxX) && - ((*itr)->m_GridZ >= MinZ) && ((*itr)->m_GridZ < MaxZ) - ) + if (((*itr)->m_GridX >= MinX) && ((*itr)->m_GridX < MaxX) && ((*itr)->m_GridZ >= MinZ) && + ((*itr)->m_GridZ < MaxZ)) { // want a_Structures.push_back(*itr); @@ -183,8 +187,10 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur } // for itr - a_Structures[] if (!Found) { - int OriginX = GridX + ((m_Noise.IntNoise2DInt(GridX + 3, GridZ + 5) / 7) % (m_MaxOffsetX * 2)) - m_MaxOffsetX; - int OriginZ = GridZ + ((m_Noise.IntNoise2DInt(GridX + 5, GridZ + 3) / 7) % (m_MaxOffsetZ * 2)) - m_MaxOffsetZ; + int OriginX = + GridX + ((m_Noise.IntNoise2DInt(GridX + 3, GridZ + 5) / 7) % (m_MaxOffsetX * 2)) - m_MaxOffsetX; + int OriginZ = + GridZ + ((m_Noise.IntNoise2DInt(GridX + 5, GridZ + 3) / 7) % (m_MaxOffsetZ * 2)) - m_MaxOffsetZ; cStructurePtr Structure = CreateStructure(GridX, GridZ, OriginX, OriginZ); if (Structure.get() == nullptr) { @@ -196,7 +202,7 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur } // for x // Copy a_Forts into m_Cache to the beginning: - cStructurePtrs StructuresCopy (a_Structures); + cStructurePtrs StructuresCopy(a_Structures); m_Cache.splice(m_Cache.begin(), StructuresCopy, StructuresCopy.begin(), StructuresCopy.end()); // Trim the cache if it's too long: @@ -228,8 +234,3 @@ void cGridStructGen::GenFinish(cChunkDesc & a_ChunkDesc) (*itr)->DrawIntoChunk(a_ChunkDesc); } // for itr - Structures[] } - - - - - |