27 Super(a_GridX, a_GridZ, a_OriginX, a_OriginZ)
44 int a_GridSizeX,
int a_GridSizeZ,
45 int a_MaxOffsetX,
int a_MaxOffsetZ,
46 int a_MaxStructureSizeX,
int a_MaxStructureSizeZ,
51 m_GridSizeX(a_GridSizeX),
52 m_GridSizeZ(a_GridSizeZ),
53 m_MaxOffsetX(a_MaxOffsetX),
54 m_MaxOffsetZ(a_MaxOffsetZ),
55 m_MaxStructureSizeX(a_MaxStructureSizeX),
56 m_MaxStructureSizeZ(a_MaxStructureSizeZ),
57 m_MaxCacheSize(a_MaxCacheSize)
61 LOG(
"Grid Size cannot be zero, setting to 1");
66 LOG(
"Grid Size cannot be zero, setting to 1");
74 "cGridStructGen: The cache size is too small (%u), increasing the cache size to %u to avoid inefficiency.",
75 static_cast<unsigned>(a_MaxCacheSize),
static_cast<unsigned>(
m_MaxCacheSize)
92 m_MaxStructureSizeX(128),
93 m_MaxStructureSizeZ(128),
124 auto seedOffset = GetStringMapInteger<int>(a_GeneratorParams,
"SeedOffset", 0);
150 for (cStructurePtrs::iterator itr =
m_Cache.begin(), end =
m_Cache.end(); itr != end;)
153 ((*itr)->m_GridX >= MinX) && ((*itr)->m_GridX < MaxX) &&
154 ((*itr)->m_GridZ >= MinZ) && ((*itr)->m_GridZ < MaxZ)
158 a_Structures.push_back(*itr);
169 for (
int x = MinGridX; x < MaxGridX; x++)
172 for (
int z = MinGridZ; z < MaxGridZ; z++)
176 for (cStructurePtrs::const_iterator itr = a_Structures.begin(), end = a_Structures.end(); itr != end; ++itr)
178 if (((*itr)->m_GridX == GridX) && ((*itr)->m_GridZ == GridZ))
189 if (Structure.get() ==
nullptr)
193 a_Structures.push_back(Structure);
200 m_Cache.splice(
m_Cache.begin(), StructuresCopy, StructuresCopy.begin(), StructuresCopy.end());
203 size_t CacheSize = 0;
204 for (cStructurePtrs::iterator itr =
m_Cache.begin(), end =
m_Cache.end(); itr != end; ++itr)
206 CacheSize += (*itr)->GetCacheCost();
226 for (cStructurePtrs::const_iterator itr = Structures.begin(); itr != Structures.end(); ++itr)
228 (*itr)->DrawIntoChunk(a_ChunkDesc);
void LOG(std::string_view a_Format, const Args &... args)
void LOGINFO(std::string_view a_Format, const Args &... args)
std::map< AString, AString > AStringMap
A string dictionary, used for key-value pairs.
A cStructure descendant representing an empty structure.
cEmptyStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ)
virtual void DrawIntoChunk(cChunkDesc &a_ChunkDesc) override
Draws self into the specified chunk.
int m_MaxStructureSizeZ
Maximum theoretical size of the structure in the Z axis.
std::shared_ptr< cStructure > cStructurePtr
virtual void GenFinish(cChunkDesc &a_ChunkDesc) override
cGridStructGen(int a_Seed, int a_GridSizeX, int a_GridSizeZ, int a_MaxOffsetX, int a_MaxOffsetZ, int a_MaxStructureSizeX, int a_MaxStructureSizeZ, size_t a_MaxCacheSize)
int m_MaxOffsetX
The maximum offset of the structure's origin from the grid midpoint, in X coord.
int m_GridSizeX
The size of each grid's cell in the X axis.
int m_Seed
Seed for generating grid offsets and also available for descendants.
virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ)=0
Create a new structure at the specified gridpoint.
int m_MaxOffsetZ
The maximum offset of the structure's origin from the grid midpoint, in Z coord.
void GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructurePtrs &a_Structures)
Returns all structures that may intersect the given chunk.
int m_MaxStructureSizeX
Maximum theoretical size of the structure in the X axis.
void SetGeneratorParams(const AStringMap &a_GeneratorParams)
Sets the generator params based on the dictionary passed in.
std::list< cStructurePtr > cStructurePtrs
cStructurePtrs m_Cache
Cache for the most recently generated structures, ordered by the recentness.
cNoise m_Noise
The noise used for generating grid offsets.
int m_GridSizeZ
The size of each grid's cell in the Z axis.
size_t m_MaxCacheSize
Maximum allowed sum of costs for items in the cache.
int m_BaseSeed
Base seed of the world for which the generator generates chunk.
Represents a single structure that occupies the grid point.
int IntNoise2DInt(int a_X, int a_Y) const