mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
configurable blending distance
This commit is contained in:
@@ -8,7 +8,9 @@ import java.util.Random;
|
||||
/**
|
||||
* Utility class for mathematical functions.
|
||||
*/
|
||||
public class MathUtil {
|
||||
public final class MathUtil {
|
||||
private static final double EPSILON = 0.1E-5;
|
||||
|
||||
/**
|
||||
* Gets the standard deviation of an array of doubles.
|
||||
*
|
||||
@@ -57,29 +59,13 @@ public class MathUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute binary logarithm
|
||||
* Compare 2 floating-point values with epsilon to account for rounding errors
|
||||
*
|
||||
* @param bits Input
|
||||
* @return Binary logarithm
|
||||
* @param a Value 1
|
||||
* @param b Value 2
|
||||
* @return Whether these values are equal
|
||||
*/
|
||||
public static int binlog(int bits) {
|
||||
int log = 0;
|
||||
if((bits & 0xffff0000) != 0) {
|
||||
bits >>>= 16;
|
||||
log = 16;
|
||||
}
|
||||
if(bits >= 256) {
|
||||
bits >>>= 8;
|
||||
log += 8;
|
||||
}
|
||||
if(bits >= 16) {
|
||||
bits >>>= 4;
|
||||
log += 4;
|
||||
}
|
||||
if(bits >= 4) {
|
||||
bits >>>= 2;
|
||||
log += 2;
|
||||
}
|
||||
return log + (bits >>> 1);
|
||||
public static boolean equals(double a, double b) {
|
||||
return a == b || FastMath.abs(a - b) < EPSILON;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ValidatedConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ValidationException;
|
||||
import com.dfsek.terra.api.math.MathUtil;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -51,6 +53,16 @@ public class ConfigPackTemplate implements ValidatedConfigTemplate {
|
||||
@Default
|
||||
private double blendAmp = 4.0D;
|
||||
|
||||
@Value("blend.terrain.base")
|
||||
@Default
|
||||
private int baseBlend = 4;
|
||||
|
||||
|
||||
@Value("blend.terrain.elevation")
|
||||
@Default
|
||||
private int elevationBlend = 4;
|
||||
|
||||
|
||||
@Value("erode.enable")
|
||||
@Default
|
||||
private boolean erode = false;
|
||||
@@ -243,12 +255,27 @@ public class ConfigPackTemplate implements ValidatedConfigTemplate {
|
||||
return imageLoader;
|
||||
}
|
||||
|
||||
public int getBaseBlend() {
|
||||
return baseBlend;
|
||||
}
|
||||
|
||||
public int getElevationBlend() {
|
||||
return elevationBlend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
if(gridType.equals(TerraBiomeGrid.Type.RADIAL) && internalGrid == null)
|
||||
throw new ValidationException("No internal BiomeGrid specified");
|
||||
if(biomeZChannel.equals(biomeXChannel) || zoneChannel.equals(biomeXChannel) || zoneChannel.equals(biomeZChannel))
|
||||
throw new ValidationException("2 objects share the same image channels: biome-x and biome-z");
|
||||
|
||||
if(!MathUtil.equals(FastMath.log(baseBlend) / FastMath.log(2d), FastMath.round(FastMath.log(baseBlend) / FastMath.log(2d)))) {
|
||||
throw new ValidationException("Biome base blend value \"" + baseBlend + "\" is not a power of 2.");
|
||||
}
|
||||
if(!MathUtil.equals(FastMath.log(elevationBlend) / FastMath.log(2d), FastMath.round(FastMath.log(elevationBlend) / FastMath.log(2d)))) {
|
||||
throw new ValidationException("Biome elevation blend value \"" + baseBlend + "\" is not a power of 2.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class MasterChunkGenerator implements TerraChunkGenerator {
|
||||
int xOrig = (chunkX << 4);
|
||||
int zOrig = (chunkZ << 4);
|
||||
|
||||
Sampler sampler = new Sampler(chunkX, chunkZ, tw.getGrid(), world, 4, 8);
|
||||
Sampler sampler = new Sampler(chunkX, chunkZ, tw.getGrid(), world, configPack.getTemplate().getElevationBlend(), configPack.getTemplate().getBaseBlend());
|
||||
|
||||
for(byte x = 0; x < 16; x++) {
|
||||
for(byte z = 0; z < 16; z++) {
|
||||
|
||||
Reference in New Issue
Block a user