mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-14 11:46:06 +00:00
update to latest Paralithic
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import com.dfsek.terra.getGitHash
|
||||
|
||||
val versionObj = Version("4", "0", "0", true)
|
||||
val versionObj = Version("4", "1", "0", true)
|
||||
|
||||
allprojects {
|
||||
version = versionObj
|
||||
|
||||
@@ -13,7 +13,7 @@ dependencies {
|
||||
"shadedApi"("org.apache.commons:commons-rng-core:1.3")
|
||||
"shadedApi"("commons-io:commons-io:2.4")
|
||||
|
||||
"shadedApi"("com.dfsek:Paralithic:0.1.1+255d4f9")
|
||||
"shadedApi"("com.dfsek:Paralithic:0.3.0")
|
||||
"shadedApi"("com.dfsek:Tectonic:1.2.3")
|
||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||
"shadedApi"("org.yaml:snakeyaml:1.27")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.api.math.parsii;
|
||||
|
||||
import com.dfsek.paralithic.function.dynamic.DynamicFunction;
|
||||
|
||||
import com.dfsek.paralithic.functions.dynamic.DynamicFunction;
|
||||
|
||||
public class BlankFunction implements DynamicFunction {
|
||||
private final int args;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.dfsek.terra.api.math.parsii.defined;
|
||||
|
||||
import com.dfsek.paralithic.Expression;
|
||||
import com.dfsek.paralithic.function.dynamic.DynamicFunction;
|
||||
import com.dfsek.paralithic.functions.dynamic.DynamicFunction;
|
||||
|
||||
|
||||
public class UserDefinedFunction implements DynamicFunction {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.api.math.parsii.noise;
|
||||
|
||||
import com.dfsek.paralithic.function.dynamic.DynamicFunction;
|
||||
|
||||
import com.dfsek.paralithic.functions.dynamic.DynamicFunction;
|
||||
|
||||
public interface NoiseFunction extends DynamicFunction {
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ public class CarverCache {
|
||||
BiomeProvider provider = main.getWorld(w).getBiomeProvider();
|
||||
if(CarverCache.this.carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + CarverCache.this.carver.hashCode())))) {
|
||||
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
|
||||
CarverCache.this.carver.getSeedVar().setValue(seed);
|
||||
Random r = new FastRandom(seed);
|
||||
Worm carving = CarverCache.this.carver.getWorm(seed, new Vector3((chunkX << 4) + r.nextInt(16), CarverCache.this.carver.getConfig().getHeight().get(r), (chunkZ << 4) + r.nextInt(16)));
|
||||
List<Worm.WormPoint> points = new GlueList<>();
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.dfsek.terra.carving;
|
||||
|
||||
import com.dfsek.paralithic.Expression;
|
||||
import com.dfsek.paralithic.eval.parser.Parser;
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.terra.api.core.TerraPlugin;
|
||||
import com.dfsek.terra.api.math.Range;
|
||||
import com.dfsek.terra.api.math.parsii.defined.UserDefinedFunction;
|
||||
@@ -16,18 +20,12 @@ import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
import net.jafama.FastMath;
|
||||
import parsii.eval.Expression;
|
||||
import parsii.eval.Parser;
|
||||
import parsii.eval.Scope;
|
||||
import parsii.eval.Variable;
|
||||
import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UserDefinedCarver extends Carver {
|
||||
private final double[] start; // 0, 1, 2 = x, y, z.
|
||||
@@ -40,13 +38,6 @@ public class UserDefinedCarver extends Carver {
|
||||
private final Expression xRad;
|
||||
private final Expression yRad;
|
||||
private final Expression zRad;
|
||||
private final Variable lengthVar;
|
||||
private final Variable position;
|
||||
private final Variable seedVar;
|
||||
|
||||
private final Variable xOrigin;
|
||||
private final Variable yOrigin;
|
||||
private final Variable zOrigin;
|
||||
|
||||
private final Map<World, CarverCache> cacheMap = new ConcurrentHashMap<>();
|
||||
private final TerraPlugin main;
|
||||
@@ -83,20 +74,20 @@ public class UserDefinedCarver extends Carver {
|
||||
FunctionTemplate fun = entry.getValue();
|
||||
|
||||
Scope functionScope = new Scope().withParent(parent);
|
||||
List<Variable> variables = fun.getArgs().stream().map(functionScope::create).collect(Collectors.toList());
|
||||
|
||||
p.registerFunction(id, new UserDefinedFunction(p.parse(fun.getFunction(), functionScope), variables));
|
||||
p.registerFunction(id, new UserDefinedFunction(p.parse(fun.getFunction(), functionScope), fun.getArgs().size()));
|
||||
}
|
||||
|
||||
Scope s = new Scope().withParent(parent);
|
||||
|
||||
lengthVar = s.create("length");
|
||||
position = s.create("position");
|
||||
seedVar = s.create("seed");
|
||||
|
||||
xOrigin = s.create("x");
|
||||
yOrigin = s.create("y");
|
||||
zOrigin = s.create("z");
|
||||
s.addInvocationVariable("x");
|
||||
s.addInvocationVariable("y");
|
||||
s.addInvocationVariable("z");
|
||||
|
||||
s.addInvocationVariable("length");
|
||||
s.addInvocationVariable("position");
|
||||
s.addInvocationVariable("seed");
|
||||
|
||||
|
||||
xRad = p.parse(radii.get(0), s);
|
||||
@@ -108,19 +99,7 @@ public class UserDefinedCarver extends Carver {
|
||||
@Override
|
||||
public Worm getWorm(long l, Vector3 vector) {
|
||||
Random r = new FastRandom(l + hash);
|
||||
return new UserDefinedWorm(length.get(r) / 2, r, vector, topCut, bottomCut);
|
||||
}
|
||||
|
||||
protected Variable getSeedVar() {
|
||||
return seedVar;
|
||||
}
|
||||
|
||||
protected Variable getLengthVar() {
|
||||
return lengthVar;
|
||||
}
|
||||
|
||||
protected Variable getPosition() {
|
||||
return position;
|
||||
return new UserDefinedWorm(length.get(r) / 2, r, vector, topCut, bottomCut, l);
|
||||
}
|
||||
|
||||
public void setStep(double step) {
|
||||
@@ -168,21 +147,21 @@ public class UserDefinedCarver extends Carver {
|
||||
|
||||
private class UserDefinedWorm extends Worm {
|
||||
private final Vector3 direction;
|
||||
private final Vector3 origin;
|
||||
private int steps;
|
||||
private int nextDirection = 0;
|
||||
private double[] currentRotation = new double[3];
|
||||
private final long seed;
|
||||
|
||||
public UserDefinedWorm(int length, Random r, Vector3 origin, int topCut, int bottomCut) {
|
||||
public UserDefinedWorm(int length, Random r, Vector3 origin, int topCut, int bottomCut, long seed) {
|
||||
super(length, r, origin);
|
||||
this.origin = origin;
|
||||
this.seed = seed;
|
||||
super.setTopCut(topCut);
|
||||
super.setBottomCut(bottomCut);
|
||||
direction = new Vector3((r.nextDouble() - 0.5D) * start[0], (r.nextDouble() - 0.5D) * start[1], (r.nextDouble() - 0.5D) * start[2]).normalize().multiply(step);
|
||||
position.setValue(0);
|
||||
lengthVar.setValue(length);
|
||||
xOrigin.setValue(origin.getX());
|
||||
yOrigin.setValue(origin.getY());
|
||||
zOrigin.setValue(origin.getZ());
|
||||
setRadius(new int[] {(int) (xRad.evaluate()), (int) (yRad.evaluate()), (int) (zRad.evaluate())});
|
||||
double[] args = {origin.getX(), origin.getY(), origin.getZ(), length, 0, seed};
|
||||
setRadius(new int[] {(int) (xRad.evaluate(args)), (int) (yRad.evaluate(args)), (int) (zRad.evaluate(args))});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,7 +170,7 @@ public class UserDefinedCarver extends Carver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void step() {
|
||||
public void step() {
|
||||
if(steps == nextDirection) {
|
||||
direction.rotateAroundX(FastMath.toRadians((getRandom().nextGaussian()) * mutate[0] * recalcMagnitude));
|
||||
direction.rotateAroundY(FastMath.toRadians((getRandom().nextGaussian()) * mutate[1] * recalcMagnitude));
|
||||
@@ -202,8 +181,8 @@ public class UserDefinedCarver extends Carver {
|
||||
nextDirection += recalc.get(getRandom());
|
||||
}
|
||||
steps++;
|
||||
position.setValue(steps);
|
||||
setRadius(new int[] {(int) (xRad.evaluate()), (int) (yRad.evaluate()), (int) (zRad.evaluate())});
|
||||
double[] args = {origin.getX(), origin.getY(), origin.getZ(), getLength(), steps, seed};
|
||||
setRadius(new int[] {(int) (xRad.evaluate(args)), (int) (yRad.evaluate(args)), (int) (zRad.evaluate(args))});
|
||||
direction.rotateAroundX(FastMath.toRadians(currentRotation[0] * mutate[0]));
|
||||
direction.rotateAroundY(FastMath.toRadians(currentRotation[1] * mutate[1]));
|
||||
direction.rotateAroundZ(FastMath.toRadians(currentRotation[2] * mutate[2]));
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.paralithic.eval.tokenizer.ParseException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.api.core.TerraPlugin;
|
||||
import com.dfsek.terra.api.math.MathUtil;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
Reference in New Issue
Block a user