diff options
author | Alexander Harkness <me@bearbin.net> | 2024-11-02 22:27:47 +0100 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2024-11-02 22:27:47 +0100 |
commit | cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a (patch) | |
tree | f647b20e1823f1846af88e832cf82a4a02e96e69 /src/Generating/HeiGen.h | |
parent | Improve clang-format config file, remove automatically enforced code style from contrib guide. (diff) | |
download | cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.gz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.bz2 cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.lz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.xz cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.tar.zst cuberite-cb50ec10591c0e0e4b9915e642bc50d3d8d1fd0a.zip |
Diffstat (limited to 'src/Generating/HeiGen.h')
-rw-r--r-- | src/Generating/HeiGen.h | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/src/Generating/HeiGen.h b/src/Generating/HeiGen.h index 6f2101043..d40c052c5 100644 --- a/src/Generating/HeiGen.h +++ b/src/Generating/HeiGen.h @@ -24,10 +24,9 @@ Also implements the heightmap cache /** A simple cache that stores N most recently generated chunks' heightmaps; N being settable upon creation */ -class cHeiGenCache : - public cTerrainHeightGen +class cHeiGenCache : public cTerrainHeightGen { -public: + public: cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, size_t a_CacheSize); // cTerrainHeightGen overrides: @@ -37,42 +36,46 @@ public: /** 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: + protected: struct sCacheData { cChunkCoords m_Coords; cChunkDef::HeightMap m_HeightMap; /** Default constructor: Fill in bogus coords, so that the item is not used until properly calculated. */ - sCacheData(): + sCacheData() : m_Coords(0x7fffffff, 0x7fffffff) - {} - } ; + { + } + }; /** The terrain height generator that is being cached. */ cTerrainHeightGen & m_HeiGenToCache; // To avoid moving large amounts of data for the MRU behavior, we MRU-ize indices to an array of the actual data - size_t m_CacheSize; - std::vector<size_t> m_CacheOrder; // MRU-ized order, indices into m_CacheData array - std::vector<sCacheData> m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used + size_t m_CacheSize; + std::vector<size_t> m_CacheOrder; // MRU-ized order, indices into m_CacheData array + std::vector<sCacheData> m_CacheData; // m_CacheData[m_CacheOrder[0]] is the most recently used // Cache statistics size_t m_NumHits; size_t m_NumMisses; size_t m_TotalChain; // Number of cache items walked to get to a hit (only added for hits) -} ; +}; /** Caches heightmaps in multiple underlying caches to improve the distribution and lower the chain length. */ -class cHeiGenMultiCache: - public cTerrainHeightGen +class cHeiGenMultiCache : public cTerrainHeightGen { -public: - cHeiGenMultiCache(std::unique_ptr<cTerrainHeightGen> a_HeightGenToCache, size_t a_SubCacheSize, size_t a_NumSubCaches); + public: + cHeiGenMultiCache( + std::unique_ptr<cTerrainHeightGen> a_HeightGenToCache, + size_t a_SubCacheSize, + size_t a_NumSubCaches + ); // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; @@ -81,8 +84,7 @@ public: /** 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: - + protected: /** The coefficient used to turn Z coords into index (x + Coeff * z). */ static const size_t m_CoeffZ = 5; @@ -100,33 +102,32 @@ protected: -class cHeiGenFlat : - public cTerrainHeightGen +class cHeiGenFlat : public cTerrainHeightGen { -public: - cHeiGenFlat(void) : m_Height(5) {} - -protected: + public: + cHeiGenFlat(void) : + m_Height(5) + { + } + protected: HEIGHTTYPE m_Height; // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; virtual void InitializeHeightGen(cIniFile & a_IniFile) override; -} ; +}; -class cHeiGenClassic : - public cTerrainHeightGen +class cHeiGenClassic : public cTerrainHeightGen { -public: + public: cHeiGenClassic(int a_Seed); -protected: - + protected: int m_Seed; cNoise m_Noise; float m_HeightFreq1, m_HeightAmp1; @@ -138,20 +139,18 @@ protected: // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; virtual void InitializeHeightGen(cIniFile & a_IniFile) override; -} ; +}; -class cHeiGenMountains : - public cTerrainHeightGen +class cHeiGenMountains : public cTerrainHeightGen { -public: + public: cHeiGenMountains(int a_Seed); -protected: - + protected: int m_Seed; cRidgedMultiNoise m_MountainNoise; cRidgedMultiNoise m_DitchNoise; @@ -160,35 +159,32 @@ protected: // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; virtual void InitializeHeightGen(cIniFile & a_IniFile) override; -} ; +}; -class cHeiGenBiomal: - public cTerrainHeightGen +class cHeiGenBiomal : public cTerrainHeightGen { using Super = cTerrainHeightGen; -public: - - cHeiGenBiomal(int a_Seed, cBiomeGen & a_BiomeGen): - m_Noise(a_Seed), - m_BiomeGen(a_BiomeGen) + public: + cHeiGenBiomal(int a_Seed, cBiomeGen & a_BiomeGen) : + m_Noise(a_Seed), m_BiomeGen(a_BiomeGen) { } // cTerrainHeightGen overrides: virtual void GenHeightMap(cChunkCoords a_ChunkCoords, cChunkDef::HeightMap & a_HeightMap) override; - virtual HEIGHTTYPE GetHeightAt(int a_BlockX, int a_BlockZ) override // Need to provide this override due to clang's overzealous detection of overloaded virtuals + virtual HEIGHTTYPE GetHeightAt(int a_BlockX, int a_BlockZ) + override // Need to provide this override due to clang's overzealous detection of overloaded virtuals { return Super::GetHeightAt(a_BlockX, a_BlockZ); } virtual void InitializeHeightGen(cIniFile & a_IniFile) override; -protected: - + protected: typedef cChunkDef::BiomeMap BiomeNeighbors[3][3]; cNoise m_Noise; @@ -201,9 +197,15 @@ protected: float m_HeightFreq2, m_HeightAmp2; float m_HeightFreq3, m_HeightAmp3; float m_BaseHeight; - } ; + }; static const sGenParam m_GenParam[256]; - NOISE_DATATYPE GetHeightAt(int a_RelX, int a_RelZ, int a_ChunkX, int a_ChunkZ, const BiomeNeighbors & a_BiomeNeighbors); -} ; + NOISE_DATATYPE GetHeightAt( + int a_RelX, + int a_RelZ, + int a_ChunkX, + int a_ChunkZ, + const BiomeNeighbors & a_BiomeNeighbors + ); +}; |