From 1cd8351054c6f0b120e603e0e25b85da385f185a Mon Sep 17 00:00:00 2001 From: kwolekr Date: Mon, 7 Jan 2013 16:42:00 -0500 Subject: [PATCH] Fix MapgenV6::getGroundLevelAtPoint() --- src/mapgen.h | 2 +- src/mapgen_v6.cpp | 35 +++++++++++++++++++++++++++++++++-- src/noise.h | 24 ++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/mapgen.h b/src/mapgen.h index ba1ea86c3..68f6f61e2 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -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); diff --git a/src/mapgen_v6.cpp b/src/mapgen_v6.cpp index fc6ef89e8..a86edcca9 100644 --- a/src/mapgen_v6.cpp +++ b/src/mapgen_v6.cpp @@ -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; } diff --git a/src/noise.h b/src/noise.h index 9fb6d48a1..e725b4e47 100644 --- a/src/noise.h +++ b/src/noise.h @@ -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 * \ -- 2.25.1