summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-06 14:20:25 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-06 14:20:25 +0200
commit7004622e8b99c56ef4cc8c528fbe510b36d604ed (patch)
tree12abd33e558e18db32dddbc2d20b9087bd418e3f /source
parentDistortedHeightmap: Slight speed increase (diff)
downloadcuberite-7004622e8b99c56ef4cc8c528fbe510b36d604ed.tar
cuberite-7004622e8b99c56ef4cc8c528fbe510b36d604ed.tar.gz
cuberite-7004622e8b99c56ef4cc8c528fbe510b36d604ed.tar.bz2
cuberite-7004622e8b99c56ef4cc8c528fbe510b36d604ed.tar.lz
cuberite-7004622e8b99c56ef4cc8c528fbe510b36d604ed.tar.xz
cuberite-7004622e8b99c56ef4cc8c528fbe510b36d604ed.tar.zst
cuberite-7004622e8b99c56ef4cc8c528fbe510b36d604ed.zip
Diffstat (limited to '')
-rw-r--r--source/Generating/DistortedHeightmap.cpp13
-rw-r--r--source/Generating/DistortedHeightmap.h3
-rw-r--r--source/Generating/HeiGen.cpp17
-rw-r--r--source/Generating/HeiGen.h3
4 files changed, 34 insertions, 2 deletions
diff --git a/source/Generating/DistortedHeightmap.cpp b/source/Generating/DistortedHeightmap.cpp
index 275acb4ab..a8441525b 100644
--- a/source/Generating/DistortedHeightmap.cpp
+++ b/source/Generating/DistortedHeightmap.cpp
@@ -55,7 +55,8 @@ cDistortedHeightmap::cDistortedHeightmap(int a_Seed, cBiomeGen & a_BiomeGen) :
m_NoiseArrayX(m_NoiseArray),
m_NoiseArrayZ(m_NoiseArray + 17 * 17 * 32),
m_BiomeGen(a_BiomeGen),
- m_HeightGen(new cHeiGenBiomal(a_Seed, a_BiomeGen), 64)
+ m_UnderlyingHeiGen(a_Seed, a_BiomeGen),
+ m_HeightGen(&m_UnderlyingHeiGen, 64)
{
}
@@ -243,6 +244,16 @@ int cDistortedHeightmap::GetHeightmapAt(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Z)
{
return cChunkDef::GetHeight(m_CurChunkHeights, RelX, RelZ);
}
+
+ // Ask the cache:
+ HEIGHTTYPE res = 0;
+ if (m_HeightGen.GetHeightAt(ChunkX, ChunkZ, RelX, RelZ, res))
+ {
+ // The height was in the cache
+ return res;
+ }
+
+ // The height is not in the cache, generate full heightmap and get it there:
cChunkDef::HeightMap Heightmap;
m_HeightGen.GenHeightMap(ChunkX, ChunkZ, Heightmap);
return cChunkDef::GetHeight(Heightmap, RelX, RelZ);
diff --git a/source/Generating/DistortedHeightmap.h b/source/Generating/DistortedHeightmap.h
index 65ec70a6d..83c638ce8 100644
--- a/source/Generating/DistortedHeightmap.h
+++ b/source/Generating/DistortedHeightmap.h
@@ -53,7 +53,8 @@ protected:
NOISE_DATATYPE * m_NoiseArrayZ;
cBiomeGen & m_BiomeGen;
- cHeiGenCache m_HeightGen; // This generator provides us with base heightmap (before distortion)
+ cHeiGenBiomal m_UnderlyingHeiGen; // This generator provides us with base heightmap (before distortion)
+ cHeiGenCache m_HeightGen; // Cache above m_UnderlyingHeiGen
/// Heightmap for the current chunk, before distortion (from m_HeightGen). Used for optimization.
cChunkDef::HeightMap m_CurChunkHeights;
diff --git a/source/Generating/HeiGen.cpp b/source/Generating/HeiGen.cpp
index d012792bb..99fe5bd32 100644
--- a/source/Generating/HeiGen.cpp
+++ b/source/Generating/HeiGen.cpp
@@ -116,6 +116,23 @@ void cHeiGenCache::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap
+bool cHeiGenCache::GetHeightAt(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelZ, HEIGHTTYPE & a_Height)
+{
+ for (int i = 0; i < m_CacheSize; i++)
+ {
+ if ((m_CacheData[i].m_ChunkX == a_ChunkX) && (m_CacheData[i].m_ChunkZ == a_ChunkZ))
+ {
+ a_Height = cChunkDef::GetHeight(m_CacheData[i].m_HeightMap, a_RelX, a_RelZ);
+ return true;
+ }
+ } // for i - m_CacheData[]
+ return false;
+}
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cHeiGenClassic:
diff --git a/source/Generating/HeiGen.h b/source/Generating/HeiGen.h
index 4bc55a958..437b5f104 100644
--- a/source/Generating/HeiGen.h
+++ b/source/Generating/HeiGen.h
@@ -50,6 +50,9 @@ public:
// cTerrainHeightGen override:
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:
cTerrainHeightGen * m_HeiGenToCache;