elevation tweaks & general cleanup

This commit is contained in:
dfsek
2020-12-30 00:03:02 -07:00
parent 7d0149b59d
commit a68b85c522
13 changed files with 66 additions and 186 deletions
@@ -15,9 +15,6 @@ public class ChunkInterpolator3 {
private final Generator[][] gens = new Generator[7][7];
private final boolean[][] needsBiomeInterp = new boolean[5][5];
private final double[][][] noiseStorage = new double[7][7][65];
private final int xOrigin;
private final int zOrigin;
private final World w;
/**
* Instantiates a 3D ChunkInterpolator at a pair of chunk coordinates, with a BiomeGrid and FastNoiseLite instance.
@@ -27,9 +24,8 @@ public class ChunkInterpolator3 {
* @param grid BiomeGrid to use for noise fetching.
*/
public ChunkInterpolator3(World w, int chunkX, int chunkZ, BiomeGrid grid) {
this.xOrigin = chunkX << 4;
this.zOrigin = chunkZ << 4;
this.w = w;
int xOrigin = chunkX << 4;
int zOrigin = chunkZ << 4;
for(int x = -1; x < 6; x++) {
@@ -39,11 +35,17 @@ public class ChunkInterpolator3 {
}
for(int x = 0; x < 5; x++) {
for(int z = 0; z < 5; z++) {
needsBiomeInterp[x][z] = compareGens(x+1, z+1);
needsBiomeInterp[x][z] = compareGens(x + 1, z + 1);
}
}
storeNoise();
for(byte x = -1; x < 6; x++) {
for(byte z = -1; z < 6; z++) {
for(int y = 0; y < 65; y++) {
noiseStorage[x + 1][z + 1][y] = gens[x + 1][z + 1].getNoise(w, (x << 2) + xOrigin, y << 2, (z << 2) + zOrigin);
}
}
}
for(byte x = 0; x < 4; x++) {
for(byte z = 0; z < 4; z++) {
@@ -56,7 +58,7 @@ public class ChunkInterpolator3 {
biomeAvg(x, y, z + 1),
biomeAvg(x + 1, y, z + 1),
biomeAvg(x, y + 1, z + 1),
biomeAvg(x + 1, y + 1, z + 1), gens[x+1][z+1].getInterpolationType());
biomeAvg(x + 1, y + 1, z + 1));
}
}
}
@@ -80,15 +82,6 @@ public class ChunkInterpolator3 {
return !comp.equals(gens[x - 1][z + 1]);
}
private void storeNoise() {
for(byte x = - 1; x < 6; x++) {
for(byte z = - 1; z < 6; z++) {
for(int y = 0; y < 64; y++) {
noiseStorage[x + 1][z + 1][y] = gens[x + 1][z + 1].getNoise(w, (x << 2) + xOrigin, y << 2, (z << 2) + zOrigin);
}
}
}
}
private double biomeAvg(int x, int y, int z) {
if(needsBiomeInterp[x][z]) return (noiseStorage[x + 2][z + 1][y]
@@ -1,13 +1,10 @@
package com.dfsek.terra.api.math.interpolation;
import net.jafama.FastMath;
/**
* Class for bilinear interpolation of values arranged on a unit square.
*/
public class Interpolator {
private final double v0, v1, v2, v3;
private final Type type;
/**
* Constructs an interpolator with given values as vertices of a unit square.
@@ -17,12 +14,11 @@ public class Interpolator {
* @param v2 - (0,1)
* @param v3 - (1,1)
*/
public Interpolator(double v0, double v1, double v2, double v3, Type type) {
public Interpolator(double v0, double v1, double v2, double v3) {
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.type = type;
}
/**
@@ -33,12 +29,9 @@ public class Interpolator {
* @param v1 - Value at v1.
* @return double - The interpolated value.
*/
public static double lerp(double t, double v0, double v1, Type type) {
switch(type) {
case LINEAR: return v0 + t * (v1 - v0);
case NEAREST_NEIGHBOR: return FastMath.abs(v0-t) > FastMath.abs(v1-t) ? v1 : v0;
default: throw new IllegalStateException();
}
public static double lerp(double t, double v0, double v1) {
return v0 + t * (v1 - v0);
}
/**
@@ -49,13 +42,8 @@ public class Interpolator {
* @return double - The interpolated value.
*/
public double bilerp(double s, double t) {
double v01 = lerp(s, v0, v1, type);
double v23 = lerp(s, v2, v3, type);
double v = lerp(t, v01, v23, type);
return v;
}
public enum Type {
LINEAR, NEAREST_NEIGHBOR
double v01 = lerp(s, v0, v1);
double v23 = lerp(s, v2, v3);
return lerp(t, v01, v23);
}
}
@@ -5,7 +5,6 @@ package com.dfsek.terra.api.math.interpolation;
*/
public class Interpolator3 {
private final double _000, _100, _010, _110, _001, _101, _011, _111;
private final Interpolator.Type type;
/**
* Constructs an interpolator with given values as vertices of a unit cube.
@@ -20,7 +19,7 @@ public class Interpolator3 {
*/
public Interpolator3(double _000, double _100,
double _010, double _110, double _001, double _101,
double _011, double _111, Interpolator.Type type) {
double _011, double _111) {
this._000 = _000;
this._001 = _001;
this._010 = _010;
@@ -29,12 +28,11 @@ public class Interpolator3 {
this._101 = _101;
this._110 = _110;
this._111 = _111;
this.type = type;
}
public double trilerp(double x, double y, double z) {
Interpolator top = new Interpolator(_000, _010, _001, _011, type);
Interpolator bottom = new Interpolator(_100, _110, _101, _111, type);
return Interpolator.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z), type);
Interpolator top = new Interpolator(_000, _010, _001, _011);
Interpolator bottom = new Interpolator(_100, _110, _101, _111);
return Interpolator.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z));
}
}
@@ -23,13 +23,6 @@ public interface Biome {
*/
Generator getGenerator();
/**
* Returns the Decorator instance containing information about the population in the biome.
*
* @return Decorator - the Decorator instance.
*/
Decorator getDecorator();
/**
* Gets the BiomeTerrain instance used to generate the biome in this world.
*
@@ -1,20 +0,0 @@
package com.dfsek.terra.api.world.biome;
import com.dfsek.terra.api.math.ProbabilityCollection;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.tree.Tree;
public abstract class Decorator {
public abstract ProbabilityCollection<Tree> getTrees();
public abstract int getTreeDensity();
public abstract boolean overrideStructureChance();
public abstract ProbabilityCollection<Flora> getFlora();
public abstract int getFloraChance();
}
@@ -1,11 +1,10 @@
package com.dfsek.terra.api.world.biome;
import com.dfsek.terra.api.math.interpolation.Interpolator;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.world.palette.Palette;
public abstract class Generator {
public interface Generator {
/**
* Gets the 3D noise at a pair of coordinates using the provided FastNoiseLite instance.
*
@@ -14,27 +13,19 @@ public abstract class Generator {
* @param z - The z coordinate.
* @return double - Noise value at the specified coordinates.
*/
public abstract double getNoise(World w, int x, int y, int z);
double getNoise(World w, int x, int y, int z);
/**
* Gets the BlocPalette to generate the biome with.
*
* @return BlocPalette - The biome's palette.
*/
public abstract Palette<BlockData> getPalette(int y);
Palette<BlockData> getPalette(int y);
/**
* Returns true if the biome should be interpolated just once, false to use advanced interpolation + blending.
*
* @return Whether biome should use minimal interpolation
*/
public abstract boolean useMinimalInterpolation();
/**
* Get the type of interpolation to use in this biome.
* @return Interpolation type
*/
public Interpolator.Type getInterpolationType() {
return Interpolator.Type.LINEAR;
}
boolean useMinimalInterpolation();
}