mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
Remove FastMath
hotspot has intrinsics for almost everything we use it for
This commit is contained in:
@@ -5,11 +5,4 @@ version = version("1.1.0")
|
||||
dependencies {
|
||||
api("commons-io:commons-io:2.7")
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
implementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
testImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||
}
|
||||
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
relocate("org.apache.commons", "com.dfsek.terra.addons.terrascript.lib.commons")
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.terrascript.lib.jafama")
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -102,21 +100,21 @@ public class Scope {
|
||||
}
|
||||
|
||||
private void updateBoolSize(int size) {
|
||||
this.boolSize = FastMath.max(boolSize, size);
|
||||
this.boolSize = Math.max(boolSize, size);
|
||||
if(parent != null) {
|
||||
parent.updateBoolSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNumSize(int size) {
|
||||
this.numSize = FastMath.max(numSize, size);
|
||||
this.numSize = Math.max(numSize, size);
|
||||
if(parent != null) {
|
||||
parent.updateNumSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStrSize(int size) {
|
||||
this.strSize = FastMath.max(strSize, size);
|
||||
this.strSize = Math.max(strSize, size);
|
||||
if(parent != null) {
|
||||
parent.updateStrSize(size);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@@ -40,7 +38,7 @@ public class EqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
Object leftValue = left.apply(implementationArguments, scope);
|
||||
Object rightValue = right.apply(implementationArguments, scope);
|
||||
if(leftValue instanceof Number l && rightValue instanceof Number r) {
|
||||
return FastMath.abs(l.doubleValue() - r.doubleValue()) <= EPSILON;
|
||||
return Math.abs(l.doubleValue() - r.doubleValue()) <= EPSILON;
|
||||
}
|
||||
|
||||
return leftValue.equals(rightValue);
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@@ -33,7 +31,7 @@ public class NotEqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
Object leftValue = left.apply(implementationArguments, scope);
|
||||
Object rightValue = right.apply(implementationArguments, scope);
|
||||
if(leftValue instanceof Number l && rightValue instanceof Number r) {
|
||||
return FastMath.abs(l.doubleValue() - r.doubleValue()) > EPSILON;
|
||||
return Math.abs(l.doubleValue() - r.doubleValue()) > EPSILON;
|
||||
}
|
||||
|
||||
return !leftValue.equals(rightValue);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -44,6 +43,7 @@ import com.dfsek.terra.api.registry.key.Keyed;
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
import com.dfsek.terra.api.world.WritableWorld;
|
||||
@@ -100,25 +100,25 @@ public class StructureScript implements Structure, Keyed<StructureScript> {
|
||||
Returnable.ReturnType.NUMBER))
|
||||
.registerFunction("print",
|
||||
new UnaryStringFunctionBuilder(string -> LOGGER.info("[TerraScript:{}] {}", id, string)))
|
||||
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> FastMath.abs(number.doubleValue())))
|
||||
.registerFunction("pow2", new UnaryNumberFunctionBuilder(number -> FastMath.pow2(number.doubleValue())))
|
||||
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> Math.abs(number.doubleValue())))
|
||||
.registerFunction("pow2", new UnaryNumberFunctionBuilder(number -> Math.pow(number.doubleValue(), 2)))
|
||||
.registerFunction("pow", new BinaryNumberFunctionBuilder(
|
||||
(number, number2) -> FastMath.pow(number.doubleValue(), number2.doubleValue())))
|
||||
.registerFunction("sqrt", new UnaryNumberFunctionBuilder(number -> FastMath.sqrt(number.doubleValue())))
|
||||
.registerFunction("floor", new UnaryNumberFunctionBuilder(number -> FastMath.floor(number.doubleValue())))
|
||||
.registerFunction("ceil", new UnaryNumberFunctionBuilder(number -> FastMath.ceil(number.doubleValue())))
|
||||
.registerFunction("log", new UnaryNumberFunctionBuilder(number -> FastMath.log(number.doubleValue())))
|
||||
.registerFunction("round", new UnaryNumberFunctionBuilder(number -> FastMath.round(number.doubleValue())))
|
||||
.registerFunction("sin", new UnaryNumberFunctionBuilder(number -> FastMath.sin(number.doubleValue())))
|
||||
.registerFunction("cos", new UnaryNumberFunctionBuilder(number -> FastMath.cos(number.doubleValue())))
|
||||
.registerFunction("tan", new UnaryNumberFunctionBuilder(number -> FastMath.tan(number.doubleValue())))
|
||||
.registerFunction("asin", new UnaryNumberFunctionBuilder(number -> FastMath.asin(number.doubleValue())))
|
||||
.registerFunction("acos", new UnaryNumberFunctionBuilder(number -> FastMath.acos(number.doubleValue())))
|
||||
.registerFunction("atan", new UnaryNumberFunctionBuilder(number -> FastMath.atan(number.doubleValue())))
|
||||
(number, number2) -> Math.pow(number.doubleValue(), number2.doubleValue())))
|
||||
.registerFunction("sqrt", new UnaryNumberFunctionBuilder(number -> Math.sqrt(number.doubleValue())))
|
||||
.registerFunction("floor", new UnaryNumberFunctionBuilder(number -> Math.floor(number.doubleValue())))
|
||||
.registerFunction("ceil", new UnaryNumberFunctionBuilder(number -> Math.ceil(number.doubleValue())))
|
||||
.registerFunction("log", new UnaryNumberFunctionBuilder(number -> Math.log(number.doubleValue())))
|
||||
.registerFunction("round", new UnaryNumberFunctionBuilder(number -> Math.round(number.doubleValue())))
|
||||
.registerFunction("sin", new UnaryNumberFunctionBuilder(number -> MathUtil.sin(number.doubleValue())))
|
||||
.registerFunction("cos", new UnaryNumberFunctionBuilder(number -> MathUtil.cos(number.doubleValue())))
|
||||
.registerFunction("tan", new UnaryNumberFunctionBuilder(number -> Math.tan(number.doubleValue())))
|
||||
.registerFunction("asin", new UnaryNumberFunctionBuilder(number -> Math.asin(number.doubleValue())))
|
||||
.registerFunction("acos", new UnaryNumberFunctionBuilder(number -> Math.acos(number.doubleValue())))
|
||||
.registerFunction("atan", new UnaryNumberFunctionBuilder(number -> Math.atan(number.doubleValue())))
|
||||
.registerFunction("max", new BinaryNumberFunctionBuilder(
|
||||
(number, number2) -> FastMath.max(number.doubleValue(), number2.doubleValue())))
|
||||
(number, number2) -> Math.max(number.doubleValue(), number2.doubleValue())))
|
||||
.registerFunction("min", new BinaryNumberFunctionBuilder(
|
||||
(number, number2) -> FastMath.min(number.doubleValue(), number2.doubleValue())));
|
||||
(number, number2) -> Math.min(number.doubleValue(), number2.doubleValue())));
|
||||
|
||||
if(!platform.getTerraConfig().isDebugScript()) {
|
||||
parser.ignoreFunction("debugBlock");
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@@ -48,9 +46,9 @@ public class BiomeFunction implements Function<String> {
|
||||
return grid.getBiome(arguments.getOrigin()
|
||||
.toVector3()
|
||||
.mutable()
|
||||
.add(Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
.add(Vector3.of((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope).intValue(),
|
||||
FastMath.roundToInt(xz.getZ()))).immutable(), arguments.getWorld().getSeed()).getID();
|
||||
(int) Math.round(xz.getZ()))).immutable(), arguments.getWorld().getSeed()).getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -73,9 +72,9 @@ public class BlockFunction implements Function<Void> {
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
|
||||
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
try {
|
||||
Vector3.Mutable set = Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
Vector3.Mutable set = Vector3.of((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope).doubleValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
|
||||
(int) Math.round(xz.getZ())).mutable().add(arguments.getOrigin());
|
||||
BlockState current = arguments.getWorld().getBlockState(set);
|
||||
if(overwrite.apply(implementationArguments, scope) || current.isAir()) {
|
||||
arguments.getWorld().setBlockState(set, rot, physics.apply(implementationArguments, scope));
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@@ -45,9 +43,9 @@ public class CheckBlockFunction implements Function<String> {
|
||||
.getBlockState(arguments.getOrigin()
|
||||
.toVector3()
|
||||
.mutable()
|
||||
.add(Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
.add(Vector3.of((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope)
|
||||
.doubleValue(), FastMath.roundToInt(xz.getZ()))))
|
||||
.doubleValue(), (int) Math.round(xz.getZ()))))
|
||||
.getAsString();
|
||||
if(data.contains("[")) return data.substring(0, data.indexOf('[')); // Strip properties
|
||||
else return data;
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@@ -37,9 +35,9 @@ public class GetMarkFunction implements Function<String> {
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
|
||||
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
|
||||
String mark = arguments.getMark(Vector3.of(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(
|
||||
String mark = arguments.getMark(Vector3.of((int) Math.floor(xz.getX()), (int) Math.floor(
|
||||
y.apply(implementationArguments, scope).doubleValue()),
|
||||
FastMath.floorToInt(xz.getZ()))
|
||||
(int) Math.floor(xz.getZ()))
|
||||
.mutable()
|
||||
.add(arguments.getOrigin())
|
||||
.immutable());
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -66,10 +65,10 @@ public class LootFunction implements Function<Void> {
|
||||
|
||||
registry.get(RegistryKey.parse(id))
|
||||
.ifPresentOrElse(table -> {
|
||||
Vector3 apply = Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
Vector3 apply = Vector3.of((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope)
|
||||
.intValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
(int) Math.round(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
|
||||
try {
|
||||
BlockEntity data = arguments.getWorld().getBlockEntity(apply);
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
@@ -46,8 +44,8 @@ public class PullFunction implements Function<Void> {
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, scope).doubleValue(),
|
||||
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
|
||||
Vector3.Mutable mutable = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).intValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
|
||||
Vector3.Mutable mutable = Vector3.of((int) Math.round(xz.getX()), y.apply(implementationArguments, scope).intValue(),
|
||||
(int) Math.round(xz.getZ())).mutable().add(arguments.getOrigin());
|
||||
while(mutable.getY() > arguments.getWorld().getMinHeight()) {
|
||||
if(!arguments.getWorld().getBlockState(mutable).isAir()) {
|
||||
arguments.getWorld().setBlockState(mutable, data);
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@@ -40,10 +38,10 @@ public class SetMarkFunction implements Function<Void> {
|
||||
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
|
||||
|
||||
arguments.setMark(Vector3.of(FastMath.floorToInt(xz.getX()),
|
||||
FastMath.floorToInt(
|
||||
arguments.setMark(Vector3.of((int) Math.floor(xz.getX()),
|
||||
(int) Math.floor(
|
||||
y.apply(implementationArguments, scope).doubleValue()),
|
||||
FastMath.floorToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable(),
|
||||
(int) Math.floor(xz.getZ())).mutable().add(arguments.getOrigin()).immutable(),
|
||||
mark.apply(implementationArguments, scope));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -45,8 +44,8 @@ public class StateFunction implements Function<Void> {
|
||||
z.apply(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
|
||||
|
||||
Vector3 origin = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, scope).intValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
Vector3 origin = Vector3.of((int) Math.round(xz.getX()), y.apply(implementationArguments, scope).intValue(),
|
||||
(int) Math.round(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
try {
|
||||
BlockEntity state = arguments.getWorld().getBlockEntity(origin);
|
||||
state.applyState(data.apply(implementationArguments, scope));
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -79,17 +78,17 @@ public class StructureFunction implements Function<Boolean> {
|
||||
if(script instanceof StructureScript structureScript) {
|
||||
return structureScript.generate(arguments.getOrigin(),
|
||||
arguments.getWorld()
|
||||
.buffer(FastMath.roundToInt(xz.getX()),
|
||||
.buffer((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope).intValue(),
|
||||
FastMath.roundToInt(xz.getZ())),
|
||||
(int) Math.round(xz.getZ())),
|
||||
arguments.getRandom(),
|
||||
arguments.getRotation().rotate(rotation1), arguments.getRecursions() + 1);
|
||||
}
|
||||
return script.generate(arguments.getOrigin(),
|
||||
arguments.getWorld()
|
||||
.buffer(FastMath.roundToInt(xz.getX()),
|
||||
.buffer((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope).intValue(),
|
||||
FastMath.roundToInt(xz.getZ())),
|
||||
(int) Math.round(xz.getZ())),
|
||||
arguments.getRandom(),
|
||||
arguments.getRotation().rotate(rotation1));
|
||||
}).orElseGet(() -> {
|
||||
|
||||
Reference in New Issue
Block a user