Fix MapgenV6::getGroundLevelAtPoint()
authorkwolekr <mirrorisim@gmail.com>
Mon, 7 Jan 2013 21:42:00 +0000 (16:42 -0500)
committerPerttu Ahola <celeron55@gmail.com>
Mon, 21 Jan 2013 19:41:37 +0000 (21:41 +0200)
src/mapgen.h
src/mapgen_v6.cpp
src/noise.h

index ba1ea86c3bed4eecfa7f3e5924b9b5b3420d2336..68f6f61e2de28e2e5b33141da1622dfcebf0ae87 100644 (file)
@@ -202,7 +202,7 @@ public:
        void makeChunk(BlockMakeData *data);
        int getGroundLevelAtPoint(v2s16 p);
 
-
+       double baseRockLevelFromNoise(v2s16 p);
        static s16 find_ground_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
        static s16 find_stone_level(VoxelManipulator &vmanip, v2s16 p2d, INodeDefManager *ndef);
        void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree, INodeDefManager *ndef);
index fc6ef89e8c549495931e2c7a6f8330b77a7402f1..a86edcca952c03daebc7f702717c03244844904c 100644 (file)
@@ -311,9 +311,40 @@ double MapgenV6::base_rock_level_2d(u64 seed, v2s16 p)
        return h;
 }
 
+double MapgenV6::baseRockLevelFromNoise(v2s16 p) {
+       double base = water_level + 
+               NoisePerlin2DPosOffset(noise_terrain_base->np, p.X, 0.5, p.Y, 0.5, seed);
+       double higher = water_level +
+               NoisePerlin2DPosOffset(noise_terrain_higher->np, p.X, 0.5, p.Y, 0.5, seed);
+
+       if (higher < base)
+               higher = base;
+
+       double b = NoisePerlin2DPosOffset(noise_steepness->np, p.X, 0.5, p.Y, 0.5, seed);
+       b = rangelim(b, 0.0, 1000.0);
+       b = b*b*b*b*b*b*b;
+       b *= 5;
+       b = rangelim(b, 0.5, 1000.0);
+
+       if(b > 1.5 && b < 100.0){
+               if(b < 10.0)
+                       b = 1.5;
+               else
+                       b = 100.0;
+       }
+       
+       double a_off = -0.20;
+       double a = 0.5 + b * (a_off + NoisePerlin2DNoTxfmPosOffset(
+                       noise_height_select->np, p.X, 0.5, p.Y, 0.5, seed));
+       a = rangelim(a, 0.0, 1.0);
+
+       return base * (1.0 - a) + higher * a;
+}
+
+
 s16 MapgenV6::find_ground_level_from_noise(u64 seed, v2s16 p2d, s16 precision)
 {
-       return base_rock_level_2d(seed, p2d) + AVERAGE_MUD_AMOUNT;
+       return baseRockLevelFromNoise(p2d) + AVERAGE_MUD_AMOUNT;
 }
 
 double MapgenV6::get_mud_add_amount(u64 seed, v2s16 p)
@@ -363,7 +394,7 @@ u32 MapgenV6::get_blockseed(u64 seed, v3s16 p)
 
 
 int MapgenV6::getGroundLevelAtPoint(v2s16 p) {
-       return base_rock_level_2d(seed, p) + AVERAGE_MUD_AMOUNT;
+       return baseRockLevelFromNoise(p) + AVERAGE_MUD_AMOUNT;
 }
 
 
index 9fb6d48a14886f9b0d49a985b1735e1c873f174b..e725b4e4791b2580ccd995a2501ec26ef2ebffa7 100644 (file)
@@ -132,8 +132,28 @@ inline float easeCurve(float t) {
        return t * t * t * (t * (6.f * t - 15.f) + 10.f);
 }
 
-#define NoisePerlin2D(np, x, y, s) ((np)->offset + (np)->scale * \
-               noise2d_perlin((float)(x) / (np)->spread.X, (float)(y) / (np)->spread.Y, \
+#define NoisePerlin2D(np, x, y, s) \
+               ((np)->offset + (np)->scale * noise2d_perlin( \
+               (float)(x) / (np)->spread.X, \
+               (float)(y) / (np)->spread.Y, \
+               (s) + (np)->seed, (np)->octaves, (np)->persist))
+
+#define NoisePerlin2DNoTxfm(np, x, y, s) \
+               (noise2d_perlin( \
+               (float)(x) / (np)->spread.X, \
+               (float)(y) / (np)->spread.Y, \
+               (s) + (np)->seed, (np)->octaves, (np)->persist))
+
+#define NoisePerlin2DPosOffset(np, x, xoff, y, yoff, s) \
+               ((np)->offset + (np)->scale * noise2d_perlin( \
+               (float)(xoff) + (float)(x) / (np)->spread.X, \
+               (float)(yoff) + (float)(y) / (np)->spread.Y, \
+               (s) + (np)->seed, (np)->octaves, (np)->persist))
+
+#define NoisePerlin2DNoTxfmPosOffset(np, x, xoff, y, yoff, s) \
+               (noise2d_perlin( \
+               (float)(xoff) + (float)(x) / (np)->spread.X, \
+               (float)(yoff) + (float)(y) / (np)->spread.Y, \
                (s) + (np)->seed, (np)->octaves, (np)->persist))
 
 #define NoisePerlin3D(np, x, y, z, s) ((np)->offset + (np)->scale * \