aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorparamat <mat.gregory@virginmedia.com>2014-11-10 21:57:34 +0000
committerkwolekr <kwolekr@minetest.net>2014-11-20 21:07:20 -0500
commitd39887daddf36c08ee1297ecf02a01d72a652026 (patch)
treed18daa6168949bb49a2d355374d056fe3be5a702
parentc4e393deea4f1a6d242a3fdf392c463ed5a3b58d (diff)
downloadminetest-d39887daddf36c08ee1297ecf02a01d72a652026.tar.gz
minetest-d39887daddf36c08ee1297ecf02a01d72a652026.tar.bz2
minetest-d39887daddf36c08ee1297ecf02a01d72a652026.zip
Mgv5 get ground level at point function. Fast spawn player version
-rw-r--r--src/mapgen_v5.cpp41
-rw-r--r--src/mapgen_v5.h1
2 files changed, 38 insertions, 4 deletions
diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp
index bb8c703cc..4f66f943c 100644
--- a/src/mapgen_v5.cpp
+++ b/src/mapgen_v5.cpp
@@ -192,15 +192,48 @@ void MapgenV5Params::writeParams(Settings *settings) {
}
+int MapgenV5::getGroundLevelAtPoint(v2s16 p) {
+ //TimeTaker t("getGroundLevelAtPoint", NULL, PRECISION_MICRO);
+
+ float f = 0.55 + NoisePerlin2D(noise_factor->np, p.X, p.Y, seed);
+ if(f < 0.01)
+ f = 0.01;
+ else if(f >= 1.0)
+ f *= 1.6;
+ float h = water_level + NoisePerlin2D(noise_height->np, p.X, p.Y, seed);
+
+ s16 search_top = water_level + 15;
+ s16 search_base = water_level;
+ // Use these 2 lines instead for a slower search returning highest ground level
+ //s16 search_top = h + f * noise_ground->np->octaves * noise_ground->np->scale;
+ //s16 search_base = h - f * noise_ground->np->octaves * noise_ground->np->scale;
+
+ s16 level = -31000;
+ for (s16 y = search_top; y >= search_base; y--) {
+ float n_ground = NoisePerlin3DEased(noise_ground->np, p.X, y, p.Y, seed);
+ if(n_ground * f > y - h) {
+ if(y >= search_top - 7)
+ break;
+ else
+ level = y;
+ break;
+ }
+ }
+
+ //printf("getGroundLevelAtPoint: %dus\n", t.stop());
+ return level;
+}
+
+
void MapgenV5::makeChunk(BlockMakeData *data) {
assert(data->vmanip);
assert(data->nodedef);
assert(data->blockpos_requested.X >= data->blockpos_min.X &&
- data->blockpos_requested.Y >= data->blockpos_min.Y &&
- data->blockpos_requested.Z >= data->blockpos_min.Z);
+ data->blockpos_requested.Y >= data->blockpos_min.Y &&
+ data->blockpos_requested.Z >= data->blockpos_min.Z);
assert(data->blockpos_requested.X <= data->blockpos_max.X &&
- data->blockpos_requested.Y <= data->blockpos_max.Y &&
- data->blockpos_requested.Z <= data->blockpos_max.Z);
+ data->blockpos_requested.Y <= data->blockpos_max.Y &&
+ data->blockpos_requested.Z <= data->blockpos_max.Z);
generating = true;
vm = data->vmanip;
diff --git a/src/mapgen_v5.h b/src/mapgen_v5.h
index f50afc42d..84e63672b 100644
--- a/src/mapgen_v5.h
+++ b/src/mapgen_v5.h
@@ -94,6 +94,7 @@ public:
~MapgenV5();
virtual void makeChunk(BlockMakeData *data);
+ int getGroundLevelAtPoint(v2s16 p);
void calculateNoise();
void generateBaseTerrain();
void generateBlobs();