aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorparamat <mat.gregory@virginmedia.com>2015-07-05 00:56:31 +0100
committerparamat <mat.gregory@virginmedia.com>2015-07-08 00:49:04 +0100
commitba15c98e4d5d7f4bc515e351d6af1a084d46092e (patch)
treeba0ee52b54de1185e9740adc58f7972984befc3a /src
parentd92d376148f7ed35df1c757aab5eca5645bb8ddd (diff)
downloadminetest-ba15c98e4d5d7f4bc515e351d6af1a084d46092e.tar.gz
minetest-ba15c98e4d5d7f4bc515e351d6af1a084d46092e.tar.bz2
minetest-ba15c98e4d5d7f4bc515e351d6af1a084d46092e.zip
Mgv7: Auto-set lowest mountain generation level
Lowest level of base terrain determines mountain generation in mapchunk Change some positional function arguments from int to s16
Diffstat (limited to 'src')
-rw-r--r--src/mapgen_v7.cpp45
-rw-r--r--src/mapgen_v7.h14
2 files changed, 31 insertions, 28 deletions
diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp
index a111256a4..4eb305dc5 100644
--- a/src/mapgen_v7.cpp
+++ b/src/mapgen_v7.cpp
@@ -363,10 +363,7 @@ void MapgenV7::calculateNoise()
noise_ridge_uwater->perlinMap2D(x, z);
}
- if ((spflags & MGV7_MOUNTAINS) && node_max.Y >= MOUNTAIN_BASE) {
- noise_mountain->perlinMap3D(x, y, z);
- noise_mount_height->perlinMap2D(x, z);
- }
+ // Mountain noises are calculated in generateMountainTerrain()
noise_filler_depth->perlinMap2D(x, z);
noise_heat->perlinMap2D(x, z);
@@ -397,7 +394,7 @@ Biome *MapgenV7::getBiomeAtPoint(v3s16 p)
}
//needs to be updated
-float MapgenV7::baseTerrainLevelAtPoint(int x, int z)
+float MapgenV7::baseTerrainLevelAtPoint(s16 x, s16 z)
{
float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed);
hselect = rangelim(hselect, 0.0, 1.0);
@@ -430,7 +427,7 @@ float MapgenV7::baseTerrainLevelFromMap(int index)
}
-bool MapgenV7::getMountainTerrainAtPoint(int x, int y, int z)
+bool MapgenV7::getMountainTerrainAtPoint(s16 x, s16 y, s16 z)
{
float mnt_h_n = NoisePerlin2D(&noise_mount_height->np, x, z, seed);
float mnt_n = NoisePerlin3D(&noise_mountain->np, x, y, z, seed);
@@ -438,7 +435,7 @@ bool MapgenV7::getMountainTerrainAtPoint(int x, int y, int z)
}
-bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, int y)
+bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y)
{
float mounthn = noise_mount_height->result[idx_xz];
float mountn = noise_mountain->result[idx_xyz];
@@ -483,26 +480,30 @@ void MapgenV7::carveRivers() {
int MapgenV7::generateTerrain()
{
- int ymax = generateBaseTerrain();
+ s16 stone_surface_min_y;
+ s16 stone_surface_max_y;
+
+ generateBaseTerrain(&stone_surface_min_y, &stone_surface_max_y);
- if (spflags & MGV7_MOUNTAINS)
- ymax = generateMountainTerrain(ymax);
+ if ((spflags & MGV7_MOUNTAINS) && stone_surface_min_y < node_max.Y)
+ stone_surface_max_y = generateMountainTerrain(stone_surface_max_y);
if (spflags & MGV7_RIDGES)
generateRidgeTerrain();
- return ymax;
+ return stone_surface_max_y;
}
-int MapgenV7::generateBaseTerrain()
+void MapgenV7::generateBaseTerrain(s16 *stone_surface_min_y, s16 *stone_surface_max_y)
{
MapNode n_air(CONTENT_AIR);
MapNode n_stone(c_stone);
MapNode n_water(c_water_source);
- int stone_surface_max_y = -MAP_GENERATION_LIMIT;
v3s16 em = vm->m_area.getExtent();
+ s16 surface_min_y = MAP_GENERATION_LIMIT;
+ s16 surface_max_y = -MAP_GENERATION_LIMIT;
u32 index = 0;
for (s16 z = node_min.Z; z <= node_max.Z; z++)
@@ -513,8 +514,11 @@ int MapgenV7::generateBaseTerrain()
heightmap[index] = surface_y;
ridge_heightmap[index] = surface_y;
- if (surface_y > stone_surface_max_y)
- stone_surface_max_y = surface_y;
+ if (surface_y < surface_min_y)
+ surface_min_y = surface_y;
+
+ if (surface_y > surface_max_y)
+ surface_max_y = surface_y;
u32 i = vm->m_area.index(x, node_min.Y - 1, z);
for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
@@ -530,14 +534,15 @@ int MapgenV7::generateBaseTerrain()
}
}
- return stone_surface_max_y;
+ *stone_surface_min_y = surface_min_y;
+ *stone_surface_max_y = surface_max_y;
}
-int MapgenV7::generateMountainTerrain(int ymax)
+int MapgenV7::generateMountainTerrain(s16 ymax)
{
- if (node_max.Y < MOUNTAIN_BASE)
- return ymax;
+ noise_mountain->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
+ noise_mount_height->perlinMap2D(node_min.X, node_min.Z);
MapNode n_stone(c_stone);
u32 j = 0;
@@ -848,7 +853,7 @@ void MapgenV7::addTopNodes()
#endif
-void MapgenV7::generateCaves(int max_stone_y)
+void MapgenV7::generateCaves(s16 max_stone_y)
{
if (max_stone_y >= node_min.Y) {
u32 index = 0;
diff --git a/src/mapgen_v7.h b/src/mapgen_v7.h
index 6fa1a0f1c..c0cfa8c77 100644
--- a/src/mapgen_v7.h
+++ b/src/mapgen_v7.h
@@ -22,8 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mapgen.h"
-#define MOUNTAIN_BASE -112
-
/////////////////// Mapgen V7 flags
#define MGV7_MOUNTAINS 0x01
#define MGV7_RIDGES 0x02
@@ -107,16 +105,16 @@ public:
int getGroundLevelAtPoint(v2s16 p);
Biome *getBiomeAtPoint(v3s16 p);
- float baseTerrainLevelAtPoint(int x, int z);
+ float baseTerrainLevelAtPoint(s16 x, s16 z);
float baseTerrainLevelFromMap(int index);
- bool getMountainTerrainAtPoint(int x, int y, int z);
- bool getMountainTerrainFromMap(int idx_xyz, int idx_xz, int y);
+ bool getMountainTerrainAtPoint(s16 x, s16 y, s16 z);
+ bool getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y);
void calculateNoise();
virtual int generateTerrain();
- int generateBaseTerrain();
- int generateMountainTerrain(int ymax);
+ void generateBaseTerrain(s16 *stone_surface_min_y, s16 *stone_surface_max_y);
+ int generateMountainTerrain(s16 ymax);
void generateRidgeTerrain();
MgStoneType generateBiomes(float *heat_map, float *humidity_map);
@@ -124,7 +122,7 @@ public:
//void addTopNodes();
- void generateCaves(int max_stone_y);
+ void generateCaves(s16 max_stone_y);
};
struct MapgenFactoryV7 : public MapgenFactory {