summaryrefslogtreecommitdiffstats
path: root/src/Generating/HeiGen.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-11-24 21:56:25 +0100
committerMattes D <github@xoft.cz>2014-11-24 21:56:25 +0100
commit9f4562289e4e0dfddd590f39e9f008ed8bf6da4d (patch)
tree758fac8b34ebf688986f1000cfa15a79bbebedab /src/Generating/HeiGen.h
parentMerge pull request #1611 from mc-server/SpawnPrepare (diff)
parentAdded TwoHeights shape generator. (diff)
downloadcuberite-9f4562289e4e0dfddd590f39e9f008ed8bf6da4d.tar
cuberite-9f4562289e4e0dfddd590f39e9f008ed8bf6da4d.tar.gz
cuberite-9f4562289e4e0dfddd590f39e9f008ed8bf6da4d.tar.bz2
cuberite-9f4562289e4e0dfddd590f39e9f008ed8bf6da4d.tar.lz
cuberite-9f4562289e4e0dfddd590f39e9f008ed8bf6da4d.tar.xz
cuberite-9f4562289e4e0dfddd590f39e9f008ed8bf6da4d.tar.zst
cuberite-9f4562289e4e0dfddd590f39e9f008ed8bf6da4d.zip
Diffstat (limited to 'src/Generating/HeiGen.h')
-rw-r--r--src/Generating/HeiGen.h98
1 files changed, 66 insertions, 32 deletions
diff --git a/src/Generating/HeiGen.h b/src/Generating/HeiGen.h
index b3c9483fb..62bb227c6 100644
--- a/src/Generating/HeiGen.h
+++ b/src/Generating/HeiGen.h
@@ -2,10 +2,12 @@
// HeiGen.h
/*
-Interfaces to the various height generators:
+Interfaces to the various height-based terrain shape generators:
- cHeiGenFlat
- cHeiGenClassic
- cHeiGenBiomal
+
+Also implements the heightmap cache
*/
@@ -21,26 +23,7 @@ Interfaces to the various height generators:
-class cHeiGenFlat :
- public cTerrainHeightGen
-{
-public:
- cHeiGenFlat(void) : m_Height(5) {}
-
-protected:
-
- int m_Height;
-
- // cTerrainHeightGen overrides:
- virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
- virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
-} ;
-
-
-
-
-
-/// A simple cache that stores N most recently generated chunks' heightmaps; N being settable upon creation
+/** A simple cache that stores N most recently generated chunks' heightmaps; N being settable upon creation */
class cHeiGenCache :
public cTerrainHeightGen
{
@@ -50,15 +33,11 @@ public:
// cTerrainHeightGen overrides:
virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
- virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
- /// Retrieves height at the specified point in the cache, returns true if found, false if not found
+ /** Retrieves height at the specified point in the cache, returns true if found, false if not found */
bool GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height);
protected:
-
- cTerrainHeightGenPtr m_HeiGenToCache;
-
struct sCacheData
{
int m_ChunkX;
@@ -66,6 +45,9 @@ protected:
cChunkDef::HeightMap m_HeightMap;
} ;
+ /** The terrain height generator that is being cached. */
+ cTerrainHeightGenPtr m_HeiGenToCache;
+
// To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data
int m_CacheSize;
int * m_CacheOrder; // MRU-ized order, indices into m_CacheData array
@@ -81,6 +63,57 @@ protected:
+/** Caches heightmaps in multiple underlying caches to improve the distribution and lower the chain length. */
+class cHeiGenMultiCache:
+ public cTerrainHeightGen
+{
+public:
+ cHeiGenMultiCache(cTerrainHeightGenPtr a_HeightGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches);
+
+ // cTerrainHeightGen overrides:
+ virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
+
+ /** Retrieves height at the specified point in the cache, returns true if found, false if not found */
+ bool GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height);
+
+protected:
+ typedef SharedPtr<cHeiGenCache> cHeiGenCachePtr;
+ typedef std::vector<cHeiGenCachePtr> cHeiGenCachePtrs;
+
+
+ /** The coefficient used to turn Z coords into index (x + Coeff * z). */
+ static const size_t m_CoeffZ = 5;
+
+ /** Number of sub-caches, pulled out of m_SubCaches.size() for performance reasons. */
+ size_t m_NumSubCaches;
+
+ /** The individual sub-caches. */
+ cHeiGenCachePtrs m_SubCaches;
+};
+
+
+
+
+
+class cHeiGenFlat :
+ public cTerrainHeightGen
+{
+public:
+ cHeiGenFlat(void) : m_Height(5) {}
+
+protected:
+
+ int m_Height;
+
+ // cTerrainHeightGen overrides:
+ virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
+ virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
+} ;
+
+
+
+
+
class cHeiGenClassic :
public cTerrainHeightGen
{
@@ -137,7 +170,11 @@ public:
m_BiomeGen(a_BiomeGen)
{
}
-
+
+ // cTerrainHeightGen overrides:
+ virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
+ virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
+
protected:
typedef cChunkDef::BiomeMap BiomeNeighbors[3][3];
@@ -154,11 +191,8 @@ protected:
float m_BaseHeight;
} ;
static const sGenParam m_GenParam[256];
-
- // cTerrainHeightGen overrides:
- virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override;
- virtual void InitializeHeightGen(cIniFile & a_IniFile) override;
-
+
+
NOISE_DATATYPE GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const BiomeNeighbors & a_BiomeNeighbors);
} ;