summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCraig Robbins <kde.psych@gmail.com>2015-03-05 16:25:53 +1000
committerCraig Robbins <kde.psych@gmail.com>2015-03-06 01:42:55 +1000
commitdaa1c30b35396653563ca9517cfd9f9934fd8cda (patch)
tree63fd5a47916260da161e7fe991cf50de85b73d91 /src
parent3d505b2b5f6cf6a8c3475a40991d7d1f8ef75365 (diff)
downloadminetest-daa1c30b35396653563ca9517cfd9f9934fd8cda.tar.gz
minetest-daa1c30b35396653563ca9517cfd9f9934fd8cda.tar.bz2
minetest-daa1c30b35396653563ca9517cfd9f9934fd8cda.zip
Fix mapgen using unitialised height map values
Diffstat (limited to 'src')
-rw-r--r--src/mapgen.cpp20
-rw-r--r--src/mapgen.h1
-rw-r--r--src/mapgen_v5.cpp2
-rw-r--r--src/mapgen_v6.cpp2
-rw-r--r--src/mapgen_v7.cpp2
5 files changed, 22 insertions, 5 deletions
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;
}
diff --git a/src/mapgen.h b/src/mapgen.h
index f2e63e533..01710786b 100644
--- a/src/mapgen.h
+++ b/src/mapgen.h
@@ -151,6 +151,7 @@ public:
static u32 getBlockSeed2(v3s16 p, int seed);
s16 findGroundLevelFull(v2s16 p2d);
s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
+ void initHeightMap(s16 *dest, size_t len);
void updateHeightmap(v3s16 nmin, v3s16 nmax);
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp
index 9392c35b1..34484c7e5 100644
--- a/src/mapgen_v5.cpp
+++ b/src/mapgen_v5.cpp
@@ -60,6 +60,8 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge)
this->biomemap = new u8[csize.X * csize.Z];
this->heightmap = new s16[csize.X * csize.Z];
+ initHeightMap(this->heightmap, csize.X * csize.Z);
+
MapgenV5Params *sp = (MapgenV5Params *)params->sparams;
this->spflags = sp->spflags;
diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp
index 58e6022f8..8ea4cd21d 100644
--- a/src/mapgen_v6.cpp
+++ b/src/mapgen_v6.cpp
@@ -57,6 +57,8 @@ MapgenV6::MapgenV6(int mapgenid, MapgenParams *params, EmergeManager *emerge)
this->heightmap = new s16[csize.X * csize.Z];
+ initHeightMap(this->heightmap, csize.X * csize.Z);
+
MapgenV6Params *sp = (MapgenV6Params *)params->sparams;
this->spflags = sp->spflags;
this->freq_desert = sp->freq_desert;
diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp
index 6bdb5a177..21ee967c6 100644
--- a/src/mapgen_v7.cpp
+++ b/src/mapgen_v7.cpp
@@ -64,6 +64,8 @@ MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge)
this->heightmap = new s16[csize.X * csize.Z];
this->ridge_heightmap = new s16[csize.X * csize.Z];
+ initHeightMap(this->heightmap, csize.X * csize.Z);
+
MapgenV7Params *sp = (MapgenV7Params *)params->sparams;
this->spflags = sp->spflags;