From 27d0e01160e3ec04460c20eb9e0682a1bb88e270 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 6 May 2013 07:59:59 +0000 Subject: DistortedHeightmap: Slight speed increase git-svn-id: http://mc-server.googlecode.com/svn/trunk@1448 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Generating/DistortedHeightmap.cpp | 7 +++++++ source/Generating/DistortedHeightmap.h | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/source/Generating/DistortedHeightmap.cpp b/source/Generating/DistortedHeightmap.cpp index b495aab22..275acb4ab 100644 --- a/source/Generating/DistortedHeightmap.cpp +++ b/source/Generating/DistortedHeightmap.cpp @@ -85,6 +85,7 @@ void cDistortedHeightmap::PrepareState(int a_ChunkX, int a_ChunkZ) m_CurChunkX = a_ChunkX; m_CurChunkZ = a_ChunkZ; + m_HeightGen.GenHeightMap(a_ChunkX, a_ChunkZ, m_CurChunkHeights); GenerateNoiseArray(m_NoiseArrayX, m_Noise1, m_Noise2, m_Noise3); UpdateDistortAmps(); } @@ -236,6 +237,12 @@ int cDistortedHeightmap::GetHeightmapAt(NOISE_DATATYPE a_X, NOISE_DATATYPE a_Z) int ChunkZ = (int)floor(a_Z / (NOISE_DATATYPE)16); int RelX = (int)(a_X - (NOISE_DATATYPE)ChunkX * cChunkDef::Width); int RelZ = (int)(a_Z - (NOISE_DATATYPE)ChunkZ * cChunkDef::Width); + + // If we're withing the same chunk, return the pre-cached heightmap: + if ((ChunkX == m_CurChunkX) && (ChunkZ == m_CurChunkZ)) + { + return cChunkDef::GetHeight(m_CurChunkHeights, RelX, RelZ); + } 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 8c1b136b8..65ec70a6d 100644 --- a/source/Generating/DistortedHeightmap.h +++ b/source/Generating/DistortedHeightmap.h @@ -55,6 +55,9 @@ protected: cBiomeGen & m_BiomeGen; cHeiGenCache m_HeightGen; // This generator provides us with base heightmap (before distortion) + /// Heightmap for the current chunk, before distortion (from m_HeightGen). Used for optimization. + cChunkDef::HeightMap m_CurChunkHeights; + // Per-biome terrain generator parameters: struct sGenParam { @@ -85,6 +88,7 @@ protected: /// Calculates the X and Z distortion amplitudes based on the neighbors' biomes void GetDistortAmpsAt(BiomeNeighbors & a_Neighbors, int a_RelX, int a_RelZ, NOISE_DATATYPE & a_DistortAmpX, NOISE_DATATYPE & a_DistortAmpZ); + // cTerrainHeightGen overrides: virtual void GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMap & a_HeightMap) override; -- cgit v1.2.3