diff options
Diffstat (limited to '')
-rw-r--r-- | src/Generating/GridStructGen.h | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/src/Generating/GridStructGen.h b/src/Generating/GridStructGen.h index 234cc75c5..03131fce9 100644 --- a/src/Generating/GridStructGen.h +++ b/src/Generating/GridStructGen.h @@ -10,6 +10,7 @@ #pragma once #include "ComposableGenerator.h" +#include "../Noise.h" @@ -19,7 +20,12 @@ Defines a grid in the XZ space with predefined cell size in each direction. Each cell then receives exactly one structure (provided by the descendant class). The structure is placed within the cell, but doesn't need to be bounded by the cell, it can be well outside the cell; the generator uses the MaxStructureSize parameter -to determine how far away from the cell the structure can be at most. +to determine how far away from the cell the structure can be at most. Each structure has an offset from the +grid's center point, the offset is generated randomly from a range given to this class as a parameter. + +Each structure thus contains the coords of its grid center (m_GridX, m_GridZ) and the actual origin from +which it's built (m_OriginX, m_OriginZ). + This class provides a cache for the structures generated for successive chunks and manages that cache. It also provides the cFinishGen override that uses the cache to actually generate the structure into chunk data. @@ -39,24 +45,21 @@ class cGridStructGen : public cFinishGen { public: - cGridStructGen( - int a_Seed, - int a_GridSizeX, int a_GridSizeZ, - int a_MaxStructureSizeX, int a_MaxStructureSizeZ, - size_t a_MaxCacheSize - ); - -protected: /** Represents a single structure that occupies the grid point. Knows how to draw itself into a chunk. */ class cStructure { public: - /** The origin (the coords of the gridpoint for which the structure is generated) */ + /** The grid point for which the structure is generated. */ + int m_GridX, m_GridZ; + + /** The origin (the coords for which the structure is generated) */ int m_OriginX, m_OriginZ; - /** Creates a structure that has its originset at the specified coords. */ - cStructure (int a_OriginX, int a_OriginZ) : + /** Creates a structure that has its origin set at the specified coords. */ + cStructure (int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) : + m_GridX(a_GridX), + m_GridZ(a_GridZ), m_OriginX(a_OriginX), m_OriginZ(a_OriginZ) { @@ -75,15 +78,33 @@ protected: typedef std::list<cStructurePtr> cStructurePtrs; - /** Seed for generating the semi-random grid. */ + 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 + ); + +protected: + /** Seed for generating grid offsets and also available for descendants. */ int m_Seed; + /** The noise used for generating grid offsets. */ + cNoise m_Noise; + /** The size of each grid's cell in the X axis */ int m_GridSizeX; /** The size of each grid's cell in the Z axis */ int m_GridSizeZ; + /** The maximum offset of the structure's origin from the grid midpoint, in X coord. */ + int m_MaxOffsetX; + + /** The maximum offset of the structure's origin from the grid midpoint, in Z coord. */ + int m_MaxOffsetZ; + /** Maximum theoretical size of the structure in the X axis. This limits the structures considered for a single chunk, so the lesser the number, the better performance. Structures large than this may get cropped. */ @@ -115,7 +136,7 @@ protected: // Functions for the descendants to override: /** Create a new structure at the specified gridpoint */ - virtual cStructurePtr CreateStructure(int a_OriginX, int a_OriginZ) = 0; + virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) = 0; } ; |