Cuberite
A lightweight, fast and extensible game server for Minecraft
GridStructGen.h
Go to the documentation of this file.
1 
2 // GridStructGen.h
3 
4 // Declares the cGridStructGen class representing a common base class for structure generators that place structures in a semi-random grid
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "ComposableGenerator.h"
13 #include "../Noise/Noise.h"
14 
15 
16 
17 
18 
45  public cFinishGen
46 {
47 public:
49  class cStructure
50  {
51  public:
54 
57 
58 
60  cStructure (int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) :
61  m_GridX(a_GridX),
62  m_GridZ(a_GridZ),
63  m_OriginX(a_OriginX),
64  m_OriginZ(a_OriginZ)
65  {
66  }
67 
68  // Force a virtual destructor in descendants:
69  virtual ~cStructure() {}
70 
72  virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) = 0;
73 
75  virtual size_t GetCacheCost(void) const { return 1; }
76  } ;
77  typedef std::shared_ptr<cStructure> cStructurePtr;
78  typedef std::list<cStructurePtr> cStructurePtrs;
79 
80 
82  int a_Seed,
83  int a_GridSizeX, int a_GridSizeZ,
84  int a_MaxOffsetX, int a_MaxOffsetZ,
85  int a_MaxStructureSizeX, int a_MaxStructureSizeZ,
86  size_t a_MaxCacheSize
87  );
88 
91  cGridStructGen(int a_Seed);
92 
95  void SetGeneratorParams(const AStringMap & a_GeneratorParams);
96 
97  // cFinishGen override:
98  virtual void GenFinish(cChunkDesc & a_ChunkDesc) override;
99 
100 protected:
103 
106  int m_Seed;
107 
110 
113 
116 
119 
122 
127 
132 
136 
139 
140 
142  void ClearCache(void);
143 
147  void GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructurePtrs & a_Structures);
148 
149  // Functions for the descendants to override:
151  virtual cStructurePtr CreateStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ) = 0;
152 } ;
153 
154 
155 
156 
157 
std::map< AString, AString > AStringMap
A string dictionary, used for key-value pairs.
Definition: StringUtils.h:16
The interface that a finisher must implement Finisher implements changes to the chunk after the rough...
Generates structures in a semi-random grid.
Definition: GridStructGen.h:46
int m_MaxStructureSizeZ
Maximum theoretical size of the structure in the Z axis.
std::shared_ptr< cStructure > cStructurePtr
Definition: GridStructGen.h:77
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 ClearCache(void)
Clears everything from the cache.
void SetGeneratorParams(const AStringMap &a_GeneratorParams)
Sets the generator params based on the dictionary passed in.
std::list< cStructurePtr > cStructurePtrs
Definition: GridStructGen.h:78
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.
Definition: GridStructGen.h:50
virtual void DrawIntoChunk(cChunkDesc &a_ChunkDesc)=0
Draws self into the specified chunk.
virtual size_t GetCacheCost(void) const
Returns the cost of keeping this structure in the cache.
Definition: GridStructGen.h:75
int m_GridX
The grid point for which the structure is generated.
Definition: GridStructGen.h:53
cStructure(int a_GridX, int a_GridZ, int a_OriginX, int a_OriginZ)
Creates a structure that has its origin set at the specified coords.
Definition: GridStructGen.h:60
int m_OriginX
The origin (the coords for which the structure is generated)
Definition: GridStructGen.h:56
Definition: Noise.h:20