From 7004622e8b99c56ef4cc8c528fbe510b36d604ed Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 6 May 2013 12:20:25 +0000 Subject: DistortedHeightmap: Small optimizations, memory leak fix. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1449 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Generating/DistortedHeightmap.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'source/Generating/DistortedHeightmap.cpp') 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); -- cgit v1.2.3