Stateless simplex
This commit is contained in:
@@ -103,19 +103,19 @@ public abstract class GenerateFilter{
|
||||
//TODO would be nice if these functions used the seed and ditched "in" completely; simplex should be stateless
|
||||
|
||||
protected float noise(GenerateInput in, float scl, float mag){
|
||||
return (float)in.noise.octaveNoise2D(1f, 0f, 1f / scl, in.x, in.y) * mag;
|
||||
return (float)Simplex.noise2d(seed, 1f, 0f, 1f / scl, in.x, in.y) * mag;
|
||||
}
|
||||
|
||||
protected float noise(GenerateInput in, float scl, float mag, float octaves, float persistence){
|
||||
return (float)in.noise.octaveNoise2D(octaves, persistence, 1f / scl, in.x, in.y) * mag;
|
||||
return (float)Simplex.noise2d(seed, octaves, persistence, 1f / scl, in.x, in.y) * mag;
|
||||
}
|
||||
|
||||
protected float rnoise(float x, float y, float scl, float mag){
|
||||
return RidgedPerlin.noise2d(seed + 1, (int)(x), (int)(y), 1f / scl) * mag;
|
||||
return Ridged.noise2d(seed + 1, (int)(x), (int)(y), 1f / scl) * mag;
|
||||
}
|
||||
|
||||
protected float rnoise(float x, float y, int octaves, float scl, float falloff, float mag){
|
||||
return RidgedPerlin.noise2d(seed + 1, (int)(x), (int)(y), octaves, falloff, 1f / scl) * mag;
|
||||
return Ridged.noise2d(seed + 1, (int)(x), (int)(y), octaves, falloff, 1f / scl) * mag;
|
||||
}
|
||||
|
||||
protected float chance(int x, int y){
|
||||
@@ -131,7 +131,6 @@ public abstract class GenerateFilter{
|
||||
/** output parameters */
|
||||
public Block floor, block, overlay;
|
||||
|
||||
Simplex noise = new Simplex();
|
||||
TileProvider buffer;
|
||||
|
||||
public void set(int x, int y, Block block, Block floor, Block overlay){
|
||||
@@ -146,7 +145,6 @@ public abstract class GenerateFilter{
|
||||
this.buffer = buffer;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
noise.setSeed(filter.seed);
|
||||
}
|
||||
|
||||
Tile tile(float x, float y){
|
||||
|
||||
@@ -18,7 +18,6 @@ import static mindustry.Vars.*;
|
||||
public abstract class PlanetGenerator extends BasicGenerator implements HexMesher{
|
||||
protected IntSeq ints = new IntSeq();
|
||||
protected Sector sector;
|
||||
protected Simplex noise = new Simplex();
|
||||
|
||||
/** Should generate sector bases for a planet. */
|
||||
public void generateSector(Sector sector){
|
||||
@@ -116,7 +115,7 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe
|
||||
@Override
|
||||
protected float noise(float x, float y, double octaves, double falloff, double scl, double mag){
|
||||
Vec3 v = sector.rect.project(x, y);
|
||||
return (float)noise.octaveNoise3D(octaves, falloff, 1f / scl, v.x, v.y, v.z) * (float)mag;
|
||||
return (float)Simplex.noise3d(0, octaves, falloff, 1f / scl, v.x, v.y, v.z) * (float)mag;
|
||||
}
|
||||
|
||||
/** @return the scaling factor for sector rects. */
|
||||
|
||||
@@ -18,6 +18,8 @@ import mindustry.world.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class SerpuloPlanetGenerator extends PlanetGenerator{
|
||||
static final int seed = 0;
|
||||
|
||||
BaseGenerator basegen = new BaseGenerator();
|
||||
float scl = 5f;
|
||||
float waterOffset = 0.07f;
|
||||
@@ -55,7 +57,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
|
||||
|
||||
float rawHeight(Vec3 position){
|
||||
position = Tmp.v33.set(position).scl(scl);
|
||||
return (Mathf.pow((float)noise.octaveNoise3D(7, 0.5f, 1f/3f, position.x, position.y, position.z), 2.3f) + waterOffset) / (1f + waterOffset);
|
||||
return (Mathf.pow((float)Simplex.noise3d(seed, 7, 0.5f, 1f/3f, position.x, position.y, position.z), 2.3f) + waterOffset) / (1f + waterOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,7 +116,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
|
||||
tile.floor = getBlock(position);
|
||||
tile.block = tile.floor.asFloor().wall;
|
||||
|
||||
if(RidgedPerlin.noise3d(1, position.x, position.y, position.z, 2, 22) > 0.31){
|
||||
if(Ridged.noise3d(1, position.x, position.y, position.z, 2, 22) > 0.31){
|
||||
tile.block = Blocks.air;
|
||||
}
|
||||
}
|
||||
@@ -125,12 +127,12 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
|
||||
position = Tmp.v33.set(position).scl(scl);
|
||||
float rad = scl;
|
||||
float temp = Mathf.clamp(Math.abs(position.y * 2f) / (rad));
|
||||
float tnoise = (float)noise.octaveNoise3D(7, 0.56, 1f/3f, position.x, position.y + 999f, position.z);
|
||||
float tnoise = (float)Simplex.noise3d(seed, 7, 0.56, 1f/3f, position.x, position.y + 999f, position.z);
|
||||
temp = Mathf.lerp(temp, tnoise, 0.5f);
|
||||
height *= 1.2f;
|
||||
height = Mathf.clamp(height);
|
||||
|
||||
float tar = (float)noise.octaveNoise3D(4, 0.55f, 1f/2f, position.x, position.y + 999f, position.z) * 0.3f + Tmp.v31.dst(0, 0, 1f) * 0.2f;
|
||||
float tar = (float)Simplex.noise3d(seed, 4, 0.55f, 1f/2f, position.x, position.y + 999f, position.z) * 0.3f + Tmp.v31.dst(0, 0, 1f) * 0.2f;
|
||||
|
||||
Block res = arr[Mathf.clamp((int)(temp * arr.length), 0, arr[0].length - 1)][Mathf.clamp((int)(height * arr[0].length), 0, arr[0].length - 1)];
|
||||
if(tar > 0.5f){
|
||||
@@ -143,7 +145,7 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
|
||||
@Override
|
||||
protected float noise(float x, float y, double octaves, double falloff, double scl, double mag){
|
||||
Vec3 v = sector.rect.project(x, y).scl(5f);
|
||||
return (float)noise.octaveNoise3D(octaves, falloff, 1f / scl, v.x, v.y, v.z) * (float)mag;
|
||||
return (float)Simplex.noise3d(seed, octaves, falloff, 1f / scl, v.x, v.y, v.z) * (float)mag;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,15 +252,15 @@ public class SerpuloPlanetGenerator extends PlanetGenerator{
|
||||
float scl = 1f;
|
||||
float addscl = 1.3f;
|
||||
|
||||
if(noise.octaveNoise3D(2, 0.5, scl, sector.tile.v.x, sector.tile.v.y, sector.tile.v.z)*nmag + poles > 0.25f*addscl){
|
||||
if(Simplex.noise3d(seed, 2, 0.5, scl, sector.tile.v.x, sector.tile.v.y, sector.tile.v.z)*nmag + poles > 0.25f*addscl){
|
||||
ores.add(Blocks.oreCoal);
|
||||
}
|
||||
|
||||
if(noise.octaveNoise3D(2, 0.5, scl, sector.tile.v.x + 1, sector.tile.v.y, sector.tile.v.z)*nmag + poles > 0.5f*addscl){
|
||||
if(Simplex.noise3d(seed, 2, 0.5, scl, sector.tile.v.x + 1, sector.tile.v.y, sector.tile.v.z)*nmag + poles > 0.5f*addscl){
|
||||
ores.add(Blocks.oreTitanium);
|
||||
}
|
||||
|
||||
if(noise.octaveNoise3D(2, 0.5, scl, sector.tile.v.x + 2, sector.tile.v.y, sector.tile.v.z)*nmag + poles > 0.7f*addscl){
|
||||
if(Simplex.noise3d(seed, 2, 0.5, scl, sector.tile.v.x + 2, sector.tile.v.y, sector.tile.v.z)*nmag + poles > 0.7f*addscl){
|
||||
ores.add(Blocks.oreThorium);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user