DistortedHeightmap: Small optimizations, memory leak fix.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@1449 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
27d0e01160
commit
7004622e8b
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user