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:
Bud Gidiere
2020-11-18 17:23:09 -06:00
parent 19162a1924
commit 0a77487399
21 changed files with 73 additions and 52 deletions

View File

@@ -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);
}
}