Fix terrain height bug in mgValleys

Implements https://github.com/minetest/minetest/pull/7756
master
Treer 2018-09-29 16:40:31 +10:00
parent c17c91d234
commit 003705c8a4
2 changed files with 26 additions and 17 deletions

View File

@ -15,16 +15,16 @@ public class MapgenValleysParams extends MapgenParams {
public int spflags = FLAG_VALLEYS_ALT_CHILL | FLAG_VALLEYS_HUMID_RIVERS | FLAG_VALLEYS_VARY_RIVER_DEPTH | FLAG_VALLEYS_ALT_DRY;
public NoiseParams np_cave1 = new NoiseParams(0, 12.0f, new Vector3f(61, 61, 61), 52534, (short)3, 0.5f, 2.0f);
public NoiseParams np_cave2 = new NoiseParams(0, 12.0f, new Vector3f(67, 67, 67), 10325, (short)3, 0.5f, 2.0f);
public NoiseParams np_filler_depth = new NoiseParams(0, 1.2f, new Vector3f(256, 256, 256), 1605, (short)3, 0.5f, 2.0f);
public NoiseParams np_inter_valley_fill = new NoiseParams(0, 1.0f, new Vector3f(256, 512, 256), 1993, (short)6, 0.8f, 2.0f);
public NoiseParams np_inter_valley_slope = new NoiseParams(0.5f, 0.5f, new Vector3f(128, 128, 128), 746, (short)1, 1.0f, 2.0f);
public NoiseParams np_rivers = new NoiseParams(0, 1.0f, new Vector3f(256, 256, 256), -6050, (short)5, 0.6f, 2.0f);
public NoiseParams np_massive_caves = new NoiseParams(0, 1.0f, new Vector3f(768, 256, 768), 59033, (short)6, 0.63f, 2.0f);
public NoiseParams np_terrain_height = new NoiseParams(-10, 50.0f, new Vector3f(1024, 1024, 1024), 5202, (short)6, 0.4f, 2.0f);
public NoiseParams np_valley_depth = new NoiseParams(5, 4.0f, new Vector3f(512, 512, 512), -1914, (short)1, 1.0f, 2.0f);
public NoiseParams np_valley_profile = new NoiseParams(0.6f, 0.5f, new Vector3f(512, 512, 512), 777, (short)1, 1.0f, 2.0f);
public NoiseParams np_cave1 = new NoiseParams(0, 12.0f, new Vector3f(61, 61, 61), 52534, (short)3, 0.5f, 2.0f);
public NoiseParams np_cave2 = new NoiseParams(0, 12.0f, new Vector3f(67, 67, 67), 10325, (short)3, 0.5f, 2.0f);
public NoiseParams np_cavern = new NoiseParams(0, 1.0f, new Vector3f(768, 256, 768), 59033, (short)6, 0.63f, 2.0f);
public short large_cave_depth = -33;
public short massive_cave_depth = -256; // highest altitude of massive caves

View File

@ -30,16 +30,16 @@ public class BiomeDataOracleValleys extends MinetestBiomeDataOracle implements I
static final float alt_to_humid = 10.0f;
private Noise noise_cave1;
private Noise noise_cave2;
private Noise noise_filler_depth;
private Noise noise_inter_valley_fill;
private Noise noise_inter_valley_slope;
private Noise noise_rivers;
private Noise noise_massive_caves;
private Noise noise_terrain_height;
private Noise noise_valley_depth;
private Noise noise_valley_profile;
private Noise noise_cave1;
private Noise noise_cave2;
private Noise noise_cavern;
boolean humid_rivers;
boolean use_altitude_chill;
@ -66,7 +66,7 @@ public class BiomeDataOracleValleys extends MinetestBiomeDataOracle implements I
float valley;
float valley_profile;
float slope;
float inter_valley_fill;
//float inter_valley_fill; (doesn't seem to be used)
float heat;
float humidity;
@ -192,7 +192,7 @@ public class BiomeDataOracleValleys extends MinetestBiomeDataOracle implements I
// 1-down overgeneraion
noise_cave1 = new Noise(valleysParams.np_cave1, this.seed, params.chunk_length_x, params.chunk_length_y + 1, params.chunk_length_z);
noise_cave2 = new Noise(valleysParams.np_cave2, this.seed, params.chunk_length_x, params.chunk_length_y + 1, params.chunk_length_z);
noise_massive_caves = new Noise(valleysParams.np_massive_caves, this.seed, params.chunk_length_x, params.chunk_length_y + 1, params.chunk_length_z);
noise_cavern = new Noise(valleysParams.np_cavern, this.seed, params.chunk_length_x, params.chunk_length_y + 1, params.chunk_length_z);
} catch (InvalidNoiseParamsException ex) {
AmidstLogger.error("Invalid valleysParams from Minetest game. " + ex);
@ -237,7 +237,7 @@ public class BiomeDataOracleValleys extends MinetestBiomeDataOracle implements I
tempTerrainNoise.valley = Noise.NoisePerlin2D(noise_valley_depth.np, x, z, seed);
tempTerrainNoise.valley_profile = Noise.NoisePerlin2D(noise_valley_profile.np, x, z, seed);
tempTerrainNoise.slope = Noise.NoisePerlin2D(noise_inter_valley_slope.np, x, z, seed);
tempTerrainNoise.inter_valley_fill = 0.f;
//tempTerrainNoise.inter_valley_fill = 0.f;
float terrain_height = adjustedTerrainLevelFromNoise(tempTerrainNoise);
@ -290,16 +290,25 @@ public class BiomeDataOracleValleys extends MinetestBiomeDataOracle implements I
float adjustedTerrainLevelFromNoise(TerrainNoise tn)
{
float mount = terrainLevelFromNoise(tn);
float result = mount;
int y_start = (int)(mount < 0.f ? (mount - 0.5f) : (mount + 0.5f)); // was "myround(muount);", s32 myround(f32 f) { return (s32)(f < 0.f ? (f - 0.5f) : (f + 0.5f)); }
for (int y = y_start; y <= y_start + 1000; y++) {
float fill = Noise.NoisePerlin3D(noise_inter_valley_fill.np, tn.x, y, tn.z, seed);
if (fill * tn.slope < y - mount) {
mount = Math.max(y - 1, mount); // was using MYMAX(),, #define MYMAX(a, b) ((a) > (b) ? (a) : (b))
break;
}
}
return mount;
float fill = Noise.NoisePerlin3D(noise_inter_valley_fill.np, tn.x, y_start, tn.z, seed);
boolean isGround = fill * tn.slope >= y_start - mount;
int searchDirection = isGround ? 1 : -1;
for (int i = 1; i <= 1000; i++) {
int y = y_start + (i * searchDirection);
fill = Noise.NoisePerlin3D(noise_inter_valley_fill.np, tn.x, y, tn.z, seed);
boolean wasGround = isGround;
isGround = fill * tn.slope >= y - mount;
if (isGround) result = y;
if (isGround != wasGround) break;
}
return result;
}
/**