From daa1c30b35396653563ca9517cfd9f9934fd8cda Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Thu, 5 Mar 2015 16:25:53 +1000 Subject: Fix mapgen using unitialised height map values --- src/mapgen.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/mapgen.cpp') diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 071c60138..17aa1dd92 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -41,6 +41,8 @@ with this program; if not, write to the Free Software Foundation, Inc., const char *GenElementManager::ELEMENT_TITLE = "element"; +static const s16 INVALID_HEIGHT = MAP_GENERATION_LIMIT + 1; + FlagDesc flagdesc_mapgen[] = { {"trees", MG_TREES}, {"caves", MG_CAVES}, @@ -155,6 +157,12 @@ s16 Mapgen::findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax) } +void Mapgen::initHeightMap(s16 *dest, size_t len) +{ + for (size_t i = 0; i < len; i++) + dest[i] = INVALID_HEIGHT; +} + void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) { if (!heightmap) @@ -166,11 +174,13 @@ void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) for (s16 x = nmin.X; x <= nmax.X; x++, index++) { s16 y = findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y); - // if the values found are out of range, trust the old heightmap - if (y == nmax.Y && heightmap[index] > nmax.Y) - continue; - if (y == nmin.Y - 1 && heightmap[index] < nmin.Y) - continue; + if (heightmap[index] != INVALID_HEIGHT) { + // if the values found are out of range, trust the old heightmap + if (y == nmax.Y && heightmap[index] > nmax.Y) + continue; + if (y == nmin.Y - 1 && heightmap[index] < nmin.Y) + continue; + } heightmap[index] = y; } -- cgit v1.2.3