mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-23 08:38:51 +00:00
Replace Math with FastMath for improved performance.
FastMath is a drop in replacement for the native Java math class with improved performance and fall backs to the native Java math class if necessary. https://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/util/FastMath.html This requires further testing and might cause chunk borders due the FastMath giving slightly different results than the native Java math class. I also added .idea/Terra.iml to the .gitignore
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.FastNoiseLite;
|
||||
@@ -15,7 +16,7 @@ public class SimplexCarver extends Carver {
|
||||
private final FastNoiseLite height;
|
||||
private final FastNoiseLite column;
|
||||
private final FastNoiseLite hasCaves;
|
||||
private final double root2inverse = 1D / Math.sqrt(2);
|
||||
private final double root2inverse = 1D / FastMath.sqrt(2);
|
||||
|
||||
public SimplexCarver(int minY, int maxY) {
|
||||
super(minY, maxY);
|
||||
@@ -41,7 +42,7 @@ public class SimplexCarver extends Carver {
|
||||
}
|
||||
|
||||
private static double acot(double x) {
|
||||
return Math.PI / 2 - Math.atan(x);
|
||||
return FastMath.PI / 2 - FastMath.atan(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,15 +54,15 @@ public class SimplexCarver extends Carver {
|
||||
for(int z = oz; z < oz + 16; z++) {
|
||||
double heightNoise = height.getNoise(x, z);
|
||||
double mainNoise = noise.getNoise(x, z) * 2;
|
||||
double columnNoise = Math.pow(Math.max(column.getNoise(x, z), 0) * 2, 3);
|
||||
double hc = (acot(16 * (hasCaves.getNoise(x, z) - 0.2)) / Math.PI) - 0.1;
|
||||
double columnNoise = FastMath.pow(FastMath.max(column.getNoise(x, z), 0) * 2, 3);
|
||||
double hc = (acot(16 * (hasCaves.getNoise(x, z) - 0.2)) / FastMath.PI) - 0.1;
|
||||
CarvingData.CarvingType type = CarvingData.CarvingType.BOTTOM;
|
||||
double simplex = (Math.pow(mainNoise + root2inverse, 3) / 2 + columnNoise) * hc;
|
||||
double simplex = (FastMath.pow(mainNoise + root2inverse, 3) / 2 + columnNoise) * hc;
|
||||
for(int y = 0; y < 64; y++) {
|
||||
double finalNoise = (-0.05 * Math.abs(y - (heightNoise * 16 + 24)) + 1 - simplex) * hc;
|
||||
double finalNoise = (-0.05 * FastMath.abs(y - (heightNoise * 16 + 24)) + 1 - simplex) * hc;
|
||||
if(finalNoise > 0.5) {
|
||||
c.carve(x - ox, y, z - oz, type);
|
||||
double finalNoiseUp = (-0.05 * Math.abs((y + 1) - (heightNoise * 16 + 24)) + 1 - simplex) * hc;
|
||||
double finalNoiseUp = (-0.05 * FastMath.abs((y + 1) - (heightNoise * 16 + 24)) + 1 - simplex) * hc;
|
||||
if(finalNoiseUp > 0.5) {
|
||||
type = CarvingData.CarvingType.CENTER;
|
||||
} else type = CarvingData.CarvingType.TOP;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.carving;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
@@ -81,9 +82,9 @@ public class UserDefinedCarver extends Carver {
|
||||
@Override
|
||||
public void step() {
|
||||
if(steps == nextDirection) {
|
||||
direction.rotateAroundX(Math.toRadians((getRandom().nextGaussian()) * mutate[0] * recalcMagnitude));
|
||||
direction.rotateAroundY(Math.toRadians((getRandom().nextGaussian()) * mutate[1] * recalcMagnitude));
|
||||
direction.rotateAroundZ(Math.toRadians((getRandom().nextGaussian()) * mutate[2] * recalcMagnitude));
|
||||
direction.rotateAroundX(FastMath.toRadians((getRandom().nextGaussian()) * mutate[0] * recalcMagnitude));
|
||||
direction.rotateAroundY(FastMath.toRadians((getRandom().nextGaussian()) * mutate[1] * recalcMagnitude));
|
||||
direction.rotateAroundZ(FastMath.toRadians((getRandom().nextGaussian()) * mutate[2] * recalcMagnitude));
|
||||
currentRotation = new double[] {(getRandom().nextGaussian()) * mutate[0],
|
||||
(getRandom().nextGaussian()) * mutate[1],
|
||||
(getRandom().nextGaussian()) * mutate[2]};
|
||||
@@ -92,10 +93,10 @@ public class UserDefinedCarver extends Carver {
|
||||
steps++;
|
||||
setRadius(new int[] {(int) (runningRadius * radiusMultiplier[0]), (int) (runningRadius * radiusMultiplier[1]), (int) (runningRadius * radiusMultiplier[2])});
|
||||
runningRadius += (getRandom().nextDouble() - 0.5) * mutate[3];
|
||||
runningRadius = Math.max(Math.min(runningRadius, maxRad), 1);
|
||||
direction.rotateAroundX(Math.toRadians(currentRotation[0] * mutate[0]));
|
||||
direction.rotateAroundY(Math.toRadians(currentRotation[1] * mutate[1]));
|
||||
direction.rotateAroundZ(Math.toRadians(currentRotation[2] * mutate[2]));
|
||||
runningRadius = FastMath.max(FastMath.min(runningRadius, maxRad), 1);
|
||||
direction.rotateAroundX(FastMath.toRadians(currentRotation[0] * mutate[0]));
|
||||
direction.rotateAroundY(FastMath.toRadians(currentRotation[1] * mutate[1]));
|
||||
direction.rotateAroundZ(FastMath.toRadians(currentRotation[2] * mutate[2]));
|
||||
getRunning().add(direction);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user