forked from Mirrorlandia_minetest/minetest
Fix mapgen using unitialised height map values
This commit is contained in:
parent
3d505b2b5f
commit
daa1c30b35
@ -41,6 +41,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
const char *GenElementManager::ELEMENT_TITLE = "element";
|
const char *GenElementManager::ELEMENT_TITLE = "element";
|
||||||
|
|
||||||
|
static const s16 INVALID_HEIGHT = MAP_GENERATION_LIMIT + 1;
|
||||||
|
|
||||||
FlagDesc flagdesc_mapgen[] = {
|
FlagDesc flagdesc_mapgen[] = {
|
||||||
{"trees", MG_TREES},
|
{"trees", MG_TREES},
|
||||||
{"caves", MG_CAVES},
|
{"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)
|
void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax)
|
||||||
{
|
{
|
||||||
if (!heightmap)
|
if (!heightmap)
|
||||||
@ -166,11 +174,13 @@ void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax)
|
|||||||
for (s16 x = nmin.X; x <= nmax.X; x++, index++) {
|
for (s16 x = nmin.X; x <= nmax.X; x++, index++) {
|
||||||
s16 y = findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
|
s16 y = findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
|
||||||
|
|
||||||
// if the values found are out of range, trust the old heightmap
|
if (heightmap[index] != INVALID_HEIGHT) {
|
||||||
if (y == nmax.Y && heightmap[index] > nmax.Y)
|
// if the values found are out of range, trust the old heightmap
|
||||||
continue;
|
if (y == nmax.Y && heightmap[index] > nmax.Y)
|
||||||
if (y == nmin.Y - 1 && heightmap[index] < nmin.Y)
|
continue;
|
||||||
continue;
|
if (y == nmin.Y - 1 && heightmap[index] < nmin.Y)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
heightmap[index] = y;
|
heightmap[index] = y;
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,7 @@ public:
|
|||||||
static u32 getBlockSeed2(v3s16 p, int seed);
|
static u32 getBlockSeed2(v3s16 p, int seed);
|
||||||
s16 findGroundLevelFull(v2s16 p2d);
|
s16 findGroundLevelFull(v2s16 p2d);
|
||||||
s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
|
s16 findGroundLevel(v2s16 p2d, s16 ymin, s16 ymax);
|
||||||
|
void initHeightMap(s16 *dest, size_t len);
|
||||||
void updateHeightmap(v3s16 nmin, v3s16 nmax);
|
void updateHeightmap(v3s16 nmin, v3s16 nmax);
|
||||||
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
|
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@ MapgenV5::MapgenV5(int mapgenid, MapgenParams *params, EmergeManager *emerge)
|
|||||||
this->biomemap = new u8[csize.X * csize.Z];
|
this->biomemap = new u8[csize.X * csize.Z];
|
||||||
this->heightmap = new s16[csize.X * csize.Z];
|
this->heightmap = new s16[csize.X * csize.Z];
|
||||||
|
|
||||||
|
initHeightMap(this->heightmap, csize.X * csize.Z);
|
||||||
|
|
||||||
MapgenV5Params *sp = (MapgenV5Params *)params->sparams;
|
MapgenV5Params *sp = (MapgenV5Params *)params->sparams;
|
||||||
this->spflags = sp->spflags;
|
this->spflags = sp->spflags;
|
||||||
|
|
||||||
|
@ -57,6 +57,8 @@ MapgenV6::MapgenV6(int mapgenid, MapgenParams *params, EmergeManager *emerge)
|
|||||||
|
|
||||||
this->heightmap = new s16[csize.X * csize.Z];
|
this->heightmap = new s16[csize.X * csize.Z];
|
||||||
|
|
||||||
|
initHeightMap(this->heightmap, csize.X * csize.Z);
|
||||||
|
|
||||||
MapgenV6Params *sp = (MapgenV6Params *)params->sparams;
|
MapgenV6Params *sp = (MapgenV6Params *)params->sparams;
|
||||||
this->spflags = sp->spflags;
|
this->spflags = sp->spflags;
|
||||||
this->freq_desert = sp->freq_desert;
|
this->freq_desert = sp->freq_desert;
|
||||||
|
@ -64,6 +64,8 @@ MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge)
|
|||||||
this->heightmap = new s16[csize.X * csize.Z];
|
this->heightmap = new s16[csize.X * csize.Z];
|
||||||
this->ridge_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;
|
MapgenV7Params *sp = (MapgenV7Params *)params->sparams;
|
||||||
this->spflags = sp->spflags;
|
this->spflags = sp->spflags;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user