Started working on better world gen
This commit is contained in:
parent
5de32258ca
commit
0cbb9c8551
|
|
@ -6,24 +6,63 @@ import gl_engine.MathHelpers;
|
||||||
|
|
||||||
public class NoiseGeneratorSimplex implements NoiseGenerator
|
public class NoiseGeneratorSimplex implements NoiseGenerator
|
||||||
{
|
{
|
||||||
private OpenSimplexNoise simplex;
|
private OpenSimplexNoise[] simplex;
|
||||||
private double off_x, off_y, off_z;
|
private double off_x, off_y, off_z;
|
||||||
|
|
||||||
public NoiseGeneratorSimplex(Random rand)
|
public NoiseGeneratorSimplex(Random rand, int octaves)
|
||||||
{
|
{
|
||||||
simplex = new OpenSimplexNoise(rand.nextLong());
|
simplex = new OpenSimplexNoise[octaves];
|
||||||
off_x = MathHelpers.map(rand.nextDouble(), 0, 1, -1024, 1024);
|
off_x = MathHelpers.map(rand.nextDouble(), 0, 1, -1024, 1024);
|
||||||
off_y = MathHelpers.map(rand.nextDouble(), 0, 1, -1024, 1024);
|
off_y = MathHelpers.map(rand.nextDouble(), 0, 1, -1024, 1024);
|
||||||
off_z = MathHelpers.map(rand.nextDouble(), 0, 1, -1024, 1024);
|
off_z = MathHelpers.map(rand.nextDouble(), 0, 1, -1024, 1024);
|
||||||
|
|
||||||
|
for(int i=0;i<octaves;i++) {
|
||||||
|
simplex[i] = new OpenSimplexNoise(rand.nextLong());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NoiseGeneratorSimplex(Random rand) {
|
||||||
|
this(rand, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double eval(double x, double y) {
|
public double eval(double x, double y)
|
||||||
return simplex.eval(x + off_x, y + off_y);
|
{
|
||||||
|
double v = 0;
|
||||||
|
double t = 0;
|
||||||
|
|
||||||
|
x += off_x;
|
||||||
|
y += off_y;
|
||||||
|
|
||||||
|
for(int i=0;i<simplex.length;i++)
|
||||||
|
{
|
||||||
|
double m = MathHelpers.squared(i + 1);
|
||||||
|
|
||||||
|
v += simplex[i].eval(x * m, y * m) / m;
|
||||||
|
t += 1 / m;
|
||||||
|
}
|
||||||
|
|
||||||
|
return v / t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double eval(double x, double y, double z) {
|
public double eval(double x, double y, double z)
|
||||||
return simplex.eval(x + off_x, y + off_y, z + off_z);
|
{
|
||||||
|
double v = 0;
|
||||||
|
double t = 0;
|
||||||
|
|
||||||
|
x += off_x;
|
||||||
|
y += off_y;
|
||||||
|
z += off_z;
|
||||||
|
|
||||||
|
for(int i=0;i<simplex.length;i++)
|
||||||
|
{
|
||||||
|
double m = MathHelpers.squared(i + 1);
|
||||||
|
|
||||||
|
v += simplex[i].eval(x * m, y * m, z * m) / m;
|
||||||
|
t += 1 / m;
|
||||||
|
}
|
||||||
|
|
||||||
|
return v / t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ public class LayerGenCaves extends LayerGen
|
||||||
new NoiseGeneratorSimplex(rand), // Humidity
|
new NoiseGeneratorSimplex(rand), // Humidity
|
||||||
new NoiseGeneratorSimplex(lrand), // Cave structure
|
new NoiseGeneratorSimplex(lrand), // Cave structure
|
||||||
new NoiseGeneratorSimplex(lrand), // Caverns
|
new NoiseGeneratorSimplex(lrand), // Caverns
|
||||||
|
new NoiseGeneratorSimplex(lrand), // Wall width
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,6 +93,7 @@ public class LayerGenCaves extends LayerGen
|
||||||
// Get the noise value and the position vector
|
// Get the noise value and the position vector
|
||||||
double noise_n = 100 - MathHelpers.positive( layer.noise_gens[2].eval(cx/16.0, cy/16.0) * 100 );
|
double noise_n = 100 - MathHelpers.positive( layer.noise_gens[2].eval(cx/16.0, cy/16.0) * 100 );
|
||||||
double noise_c = layer.noise_gens[3].eval(cx/32.0, cy/32.0);
|
double noise_c = layer.noise_gens[3].eval(cx/32.0, cy/32.0);
|
||||||
|
double noise_w = layer.noise_gens[4].eval(cx/32.0, cy/32.0) * 30 + 100;
|
||||||
boolean cavern = false;
|
boolean cavern = false;
|
||||||
|
|
||||||
Tile floor = Tiles.STONE;
|
Tile floor = Tiles.STONE;
|
||||||
|
|
@ -111,7 +113,7 @@ public class LayerGenCaves extends LayerGen
|
||||||
cavern = noise_c < -0.5 && temperature > 0.45;
|
cavern = noise_c < -0.5 && temperature > 0.45;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(noise_n > 80 || cavern) {
|
if(noise_n > noise_w || cavern) {
|
||||||
chunk.setBackTile(floor.getDefaultState(), pos);
|
chunk.setBackTile(floor.getDefaultState(), pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,13 +67,14 @@ public class LayerGenEarth extends LayerGen
|
||||||
|
|
||||||
layer.noise_gens = new NoiseGenerator[]
|
layer.noise_gens = new NoiseGenerator[]
|
||||||
{
|
{
|
||||||
new NoiseGeneratorSimplex(rand), // Temperature
|
new NoiseGeneratorSimplex(rand, 64), // Temperature
|
||||||
new NoiseGeneratorSimplex(rand), // Humidity
|
new NoiseGeneratorSimplex(rand, 64), // Humidity
|
||||||
|
|
||||||
new NoiseGeneratorSimplex(lrand), // Wind
|
new NoiseGeneratorSimplex(lrand), // Wind
|
||||||
new NoiseGeneratorSimplex(lrand), // Wind
|
new NoiseGeneratorSimplex(lrand), // Wind
|
||||||
new NoiseGeneratorSimplex(lrand), // Water
|
new NoiseGeneratorSimplex(lrand, 4), // Water
|
||||||
new NoiseGeneratorSimplex(lrand), // Rocks
|
new NoiseGeneratorSimplex(lrand), // Rocks
|
||||||
|
new NoiseGeneratorSimplex(lrand), // Offset
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue