mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-05-20 16:50:28 +00:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a028b193a | |||
| d31679e6be | |||
| 43d52e4bc1 | |||
| accc07fa07 | |||
| 1ae0d1f867 | |||
| 370b2e0122 | |||
| 331075e54d | |||
| 973590f5fd | |||
| 1a5ab6b505 | |||
| 14732328cd | |||
| 6c7974c302 | |||
| 1204b7a8c1 | |||
| fbe1c76e26 | |||
| add7803e65 | |||
| 4393a16b2f | |||
| b4fa635455 | |||
| 9f425c6159 | |||
| 158ffba2a5 | |||
| b7326c0ff6 | |||
| f70a83aec3 | |||
| 589cf83c38 | |||
| c374c2d5ef | |||
| 13782bb51e | |||
| 1aa3ef813c | |||
| 6cc53beecb | |||
| 2c45ba91aa | |||
| 6244ffca63 | |||
| 59d943b3ea | |||
| f605ee1937 | |||
| f87b7c07d9 | |||
| f1124aae6b | |||
| 9c8298fe53 | |||
| d69b0dba90 | |||
| 42166d5239 | |||
| d6772f51ea | |||
| f469193909 | |||
| 10d723372d | |||
| 1d05f95f74 | |||
| bd73427072 | |||
| 017b4608bc | |||
| 5f340f8ffd | |||
| 5b35eb041b | |||
| 699d5d1d62 | |||
| 07e3d0058d | |||
| b1ad820e1c | |||
| 3644ee7fca |
+3
-3
@@ -1,8 +1,8 @@
|
||||
preRelease(true)
|
||||
|
||||
versionProjects(":common:api", version("6.5.0"))
|
||||
versionProjects(":common:implementation", version("6.5.0"))
|
||||
versionProjects(":platforms", version("6.5.0"))
|
||||
versionProjects(":common:api", version("6.6.0"))
|
||||
versionProjects(":common:implementation", version("6.6.0"))
|
||||
versionProjects(":platforms", version("6.6.0"))
|
||||
|
||||
|
||||
allprojects {
|
||||
|
||||
@@ -74,5 +74,6 @@ object Versions {
|
||||
object CLI {
|
||||
const val nbt = "6.1"
|
||||
const val logback = "1.5.8"
|
||||
const val picocli = "4.7.6"
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.addons.biome.extrusion.api;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public interface Extrusion {
|
||||
Biome extrude(Biome original, int x, int y, int z, long seed);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.dfsek.terra.addons.biome.pipeline.api.delegate;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
|
||||
final class SelfDelegate implements BiomeDelegate {
|
||||
public static final SelfDelegate INSTANCE = new SelfDelegate();
|
||||
|
||||
+2
-2
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.biome.holder;
|
||||
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
|
||||
|
||||
public class PaletteHolderBuilder {
|
||||
private final TreeMap<Integer, Palette> paletteMap = new TreeMap<>();
|
||||
|
||||
+2
-2
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.feature.distributor.distributors;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.addons.feature.distributor.util.Point;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class PointSetDistributor implements Distributor {
|
||||
private final Set<Point> points;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
version = version("1.1.0")
|
||||
version = version("1.2.0")
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(project(":common:addons:manifest-addon-loader"))
|
||||
|
||||
+38
-9
@@ -9,17 +9,48 @@ package com.dfsek.terra.addons.noise;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.addons.noise.config.CubicSplinePointTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler;
|
||||
import com.dfsek.terra.addons.noise.config.templates.*;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.*;
|
||||
import com.dfsek.terra.addons.noise.config.templates.BinaryArithmeticTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.CacheSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.DerivativeNoiseSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.DomainWarpTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.FunctionTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.ImageSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.KernelTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.LinearHeightmapSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.TranslateSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.CellularNoiseTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.ConstantNoiseTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.DistanceSamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.ExpressionFunctionTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.GaborNoiseTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.PseudoErosionTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.SimpleNoiseTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.fractal.BrownianMotionTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.fractal.PingPongTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.noise.fractal.RidgedFractalTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.*;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ClampNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.CubicSplineNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ExpressionNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.LinearMapNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.LinearNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.NormalNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.PosterizationNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ProbabilityNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.config.templates.normalizer.ScaleNormalizerTemplate;
|
||||
import com.dfsek.terra.addons.noise.math.CubicSpline;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.*;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.AdditionSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.DivisionSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.MaxSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.MinSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.MultiplicationSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.arithmetic.SubtractionSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.CellularSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.DistanceSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.random.GaussianNoiseSampler;
|
||||
@@ -41,10 +72,6 @@ import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public class NoiseAddon implements AddonInitializer {
|
||||
public static final TypeKey<Supplier<ObjectTemplate<NoiseSampler>>> NOISE_SAMPLER_TOKEN = new TypeKey<>() {
|
||||
@@ -76,6 +103,7 @@ public class NoiseAddon implements AddonInitializer {
|
||||
.applyLoader(DerivativeNoiseSampler.class, DerivativeNoiseSamplerTemplate::new);
|
||||
|
||||
noiseRegistry.register(addon.key("LINEAR"), LinearNormalizerTemplate::new);
|
||||
noiseRegistry.register(addon.key("LINEAR_MAP"), LinearMapNormalizerTemplate::new);
|
||||
noiseRegistry.register(addon.key("NORMAL"), NormalNormalizerTemplate::new);
|
||||
noiseRegistry.register(addon.key("CLAMP"), ClampNormalizerTemplate::new);
|
||||
noiseRegistry.register(addon.key("PROBABILITY"), ProbabilityNormalizerTemplate::new);
|
||||
@@ -97,7 +125,6 @@ public class NoiseAddon implements AddonInitializer {
|
||||
noiseRegistry.register(addon.key("SIMPLEX"), () -> new SimpleNoiseTemplate(SimplexSampler::new));
|
||||
noiseRegistry.register(addon.key("GABOR"), GaborNoiseTemplate::new);
|
||||
noiseRegistry.register(addon.key("PSEUDOEROSION"), PseudoErosionTemplate::new);
|
||||
noiseRegistry.register(addon.key("DERIVATIVE"), DerivativeFractalTemplate::new);
|
||||
|
||||
noiseRegistry.register(addon.key("VALUE"), () -> new SimpleNoiseTemplate(ValueSampler::new));
|
||||
noiseRegistry.register(addon.key("VALUE_CUBIC"), () -> new SimpleNoiseTemplate(ValueCubicSampler::new));
|
||||
@@ -124,6 +151,8 @@ public class NoiseAddon implements AddonInitializer {
|
||||
noiseRegistry.register(addon.key("MAX"), () -> new BinaryArithmeticTemplate<>(MaxSampler::new));
|
||||
noiseRegistry.register(addon.key("MIN"), () -> new BinaryArithmeticTemplate<>(MinSampler::new));
|
||||
|
||||
noiseRegistry.register(addon.key("CACHE"), () -> new CacheSamplerTemplate(plugin.getGenerationThreads()));
|
||||
|
||||
|
||||
Map<String, DimensionApplicableNoiseSampler> packSamplers = new LinkedHashMap<>();
|
||||
Map<String, FunctionTemplate> packFunctions = new LinkedHashMap<>();
|
||||
|
||||
+3
-3
@@ -11,14 +11,14 @@ import com.dfsek.tectonic.api.config.template.ConfigTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.noise.config.DimensionApplicableNoiseSampler;
|
||||
import com.dfsek.terra.addons.noise.config.templates.FunctionTemplate;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class NoiseConfigPackTemplate implements ConfigTemplate, Properties {
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.dfsek.terra.addons.noise.config.templates;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.CacheSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.LinearHeightmapSampler;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public class CacheSamplerTemplate extends SamplerTemplate<LinearHeightmapSampler> {
|
||||
@Value("sampler")
|
||||
@Default
|
||||
private NoiseSampler sampler;
|
||||
|
||||
private final int generationThreads;
|
||||
|
||||
public CacheSamplerTemplate(int generationThreads) {
|
||||
this.generationThreads = generationThreads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoiseSampler get() {
|
||||
return new CacheSampler(sampler, getDimensions(), generationThreads);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -14,7 +14,8 @@ public class DerivativeNoiseSamplerTemplate extends SamplerTemplate<DerivativeNo
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
if (!DerivativeNoiseSampler.isDifferentiable(sampler)) throw new ValidationException("Provided sampler does not support calculating a derivative");
|
||||
if(!DerivativeNoiseSampler.isDifferentiable(sampler)) throw new ValidationException(
|
||||
"Provided sampler does not support calculating a derivative");
|
||||
return super.validate();
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -8,16 +8,15 @@
|
||||
package com.dfsek.terra.addons.noise.config.templates;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.ImageSampler;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.ImageSampler;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
@SuppressWarnings({ "unused", "FieldMayBeFinal" })
|
||||
public class ImageSamplerTemplate extends SamplerTemplate<ImageSampler> {
|
||||
|
||||
+6
-1
@@ -34,7 +34,11 @@ public class CellularNoiseTemplate extends NoiseTemplate<CellularSampler> {
|
||||
@Value("lookup")
|
||||
@Default
|
||||
private @Meta NoiseSampler lookup = new OpenSimplex2Sampler();
|
||||
|
||||
|
||||
@Value("salt-lookup")
|
||||
@Default
|
||||
private @Meta boolean saltLookup = true;
|
||||
|
||||
@Override
|
||||
public NoiseSampler get() {
|
||||
CellularSampler sampler = new CellularSampler();
|
||||
@@ -44,6 +48,7 @@ public class CellularNoiseTemplate extends NoiseTemplate<CellularSampler> {
|
||||
sampler.setReturnType(cellularReturnType);
|
||||
sampler.setDistanceFunction(cellularDistanceFunction);
|
||||
sampler.setSalt(salt);
|
||||
sampler.setSaltLookup(saltLookup);
|
||||
return sampler;
|
||||
}
|
||||
}
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package com.dfsek.terra.addons.noise.config.templates.noise;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.noise.config.templates.SamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.simplex.DerivativeFractal;
|
||||
|
||||
|
||||
public class DerivativeFractalTemplate extends SamplerTemplate<DerivativeFractal> {
|
||||
|
||||
@Value("octaves")
|
||||
@Default
|
||||
private int octaves = 3;
|
||||
|
||||
@Value("gain")
|
||||
@Default
|
||||
private double gain = 0.5;
|
||||
|
||||
@Value("lacunarity")
|
||||
@Default
|
||||
private double lacunarity = 2.0;
|
||||
|
||||
@Value("frequency")
|
||||
@Default
|
||||
private double frequency = 0.02;
|
||||
|
||||
@Override
|
||||
public DerivativeFractal get() {
|
||||
return new DerivativeFractal(octaves, gain, lacunarity, frequency);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.dfsek.terra.addons.noise.config.templates.noise;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.DerivativeNoiseFunction;
|
||||
|
||||
|
||||
public abstract class DerivativeNoiseTemplate<T extends DerivativeNoiseFunction> extends NoiseTemplate<T> {
|
||||
|
||||
}
|
||||
+15
-6
@@ -3,12 +3,16 @@ package com.dfsek.terra.addons.noise.config.templates.noise;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.noise.config.templates.SamplerTemplate;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.PseudoErosion;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.PseudoErosionSampler;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.simplex.OpenSimplex2Sampler;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
|
||||
|
||||
public class PseudoErosionTemplate extends SamplerTemplate<PseudoErosion> {
|
||||
public class PseudoErosionTemplate extends NoiseTemplate<PseudoErosionSampler> {
|
||||
@Value("frequency")
|
||||
@Default
|
||||
protected @Meta double frequency = 1d;
|
||||
|
||||
@Value("octaves")
|
||||
@Default
|
||||
@@ -26,6 +30,7 @@ public class PseudoErosionTemplate extends SamplerTemplate<PseudoErosion> {
|
||||
@Default
|
||||
private double slopeStrength = 1.0;
|
||||
|
||||
|
||||
@Value("branch-strength")
|
||||
@Default
|
||||
private double branchStrength = 1.0;
|
||||
@@ -39,7 +44,8 @@ public class PseudoErosionTemplate extends SamplerTemplate<PseudoErosion> {
|
||||
private double erosionFrequency = 0.02;
|
||||
|
||||
@Value("sampler")
|
||||
private DerivativeNoiseSampler heightSampler;
|
||||
@Default
|
||||
private DerivativeNoiseSampler heightSampler = new OpenSimplex2Sampler();
|
||||
|
||||
@Value("slope-mask.enable")
|
||||
@Default
|
||||
@@ -62,9 +68,12 @@ public class PseudoErosionTemplate extends SamplerTemplate<PseudoErosion> {
|
||||
private boolean averageErosionImpulses = true;
|
||||
|
||||
@Override
|
||||
public PseudoErosion get() {
|
||||
return new PseudoErosion(octaves, gain, lacunarity,
|
||||
public PseudoErosionSampler get() {
|
||||
PseudoErosionSampler pseudoErosion = new PseudoErosionSampler(octaves, gain, lacunarity,
|
||||
slopeStrength, branchStrength, strength,
|
||||
erosionFrequency, heightSampler, slopeMask, slopeMaskFull, slopeMaskNone, jitterModifier, averageErosionImpulses);
|
||||
pseudoErosion.setFrequency(frequency);
|
||||
pseudoErosion.setSalt(salt);
|
||||
return pseudoErosion;
|
||||
}
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.dfsek.terra.addons.noise.config.templates.normalizer;
|
||||
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
|
||||
import com.dfsek.terra.addons.noise.normalizer.LinearMapNormalizer;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public class LinearMapNormalizerTemplate extends NormalizerTemplate<LinearMapNormalizer> {
|
||||
|
||||
@Value("from.a")
|
||||
@Default
|
||||
private @Meta double aFrom = -1;
|
||||
|
||||
@Value("from.b")
|
||||
@Default
|
||||
private @Meta double bFrom = 1;
|
||||
|
||||
@Value("to.a")
|
||||
private @Meta double aTo;
|
||||
|
||||
@Value("to.b")
|
||||
private @Meta double bTo;
|
||||
|
||||
@Override
|
||||
public NoiseSampler get() {
|
||||
return new LinearMapNormalizer(function, aFrom, aTo, bFrom, bTo);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.dfsek.terra.addons.noise.normalizer;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public class LinearMapNormalizer extends Normalizer {
|
||||
|
||||
private final double aFrom;
|
||||
|
||||
private final double aTo;
|
||||
|
||||
private final double bFrom;
|
||||
|
||||
private final double bTo;
|
||||
|
||||
public LinearMapNormalizer(NoiseSampler sampler, double aFrom, double aTo, double bFrom, double bTo) {
|
||||
super(sampler);
|
||||
this.aFrom = aFrom;
|
||||
this.aTo = aTo;
|
||||
this.bFrom = bFrom;
|
||||
this.bTo = bTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double normalize(double in) {
|
||||
return (in - aFrom) * (aTo - bTo) / (aFrom - bFrom) + aTo;
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package com.dfsek.terra.addons.noise.samplers;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
|
||||
|
||||
public class CacheSampler implements DerivativeNoiseSampler {
|
||||
|
||||
private final NoiseSampler sampler;
|
||||
private final LoadingCache<DoubleSeededVector2, Double> cache2D;
|
||||
private final LoadingCache<DoubleSeededVector3, Double> cache3D;
|
||||
private final LoadingCache<DoubleSeededVector2, double[]> cache2DDirv;
|
||||
private final LoadingCache<DoubleSeededVector3, double[]> cache3DDirv;
|
||||
|
||||
public CacheSampler(NoiseSampler sampler, int dimensions, int generationThreads) {
|
||||
this.sampler = sampler;
|
||||
if (dimensions == 2) {
|
||||
this.cache2D = Caffeine
|
||||
.newBuilder()
|
||||
.initialCapacity(0)
|
||||
.maximumSize(256L * generationThreads) // 1 full chunk (high res)
|
||||
.build(vec -> sampler.noise(vec.seed, vec.x, vec.z));
|
||||
cache3D = null;
|
||||
cache3DDirv = null;
|
||||
if (DerivativeNoiseSampler.isDifferentiable(sampler)) {
|
||||
this.cache2DDirv = Caffeine
|
||||
.newBuilder()
|
||||
.initialCapacity(0)
|
||||
.maximumSize(256L * generationThreads) // 1 full chunk (high res)
|
||||
.build(vec -> ((DerivativeNoiseSampler) sampler).noised(vec.seed, vec.x, vec.z));
|
||||
} else {
|
||||
cache2DDirv = null;
|
||||
}
|
||||
} else {
|
||||
this.cache3D = Caffeine
|
||||
.newBuilder()
|
||||
.initialCapacity(0)
|
||||
.maximumSize(256L * generationThreads) // 1 full chunk (high res)
|
||||
.build(vec -> sampler.noise(vec.seed, vec.x, vec.y, vec.z));
|
||||
cache2D = null;
|
||||
cache2DDirv = null;
|
||||
if (DerivativeNoiseSampler.isDifferentiable(sampler)) {
|
||||
this.cache3DDirv = Caffeine
|
||||
.newBuilder()
|
||||
.initialCapacity(0)
|
||||
.maximumSize(256L * generationThreads) // 1 full chunk (high res)
|
||||
.build(vec -> ((DerivativeNoiseSampler) sampler).noised(vec.seed, vec.x, vec.y, vec.z));
|
||||
} else {
|
||||
cache3DDirv = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return DerivativeNoiseSampler.isDifferentiable(sampler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y) {
|
||||
return cache2DDirv.get(new DoubleSeededVector2(x, y, seed));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y, double z) {
|
||||
return cache3DDirv.get(new DoubleSeededVector3(x, y, z, seed));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y) {
|
||||
DoubleSeededVector2 vec = new DoubleSeededVector2(x, y, seed);
|
||||
if (cache2DDirv != null && cache2DDirv.estimatedSize() != 0) {
|
||||
return cache2DDirv.get(vec)[0];
|
||||
}
|
||||
return cache2D.get(vec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y, double z) {
|
||||
DoubleSeededVector3 vec = new DoubleSeededVector3(x, y, z, seed);
|
||||
if (cache3DDirv != null && cache3DDirv.estimatedSize() != 0) {
|
||||
return cache3DDirv.get(vec)[0];
|
||||
}
|
||||
return cache3D.get(vec);
|
||||
}
|
||||
|
||||
private record DoubleSeededVector3(double x, double y, double z, long seed) {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof DoubleSeededVector3 that) {
|
||||
return this.y == that.y && this.z == that.z && this.x == that.x && this.seed == that.seed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int code = (int) Double.doubleToLongBits(x);
|
||||
code = 31 * code + (int) Double.doubleToLongBits(y);
|
||||
code = 31 * code + (int) Double.doubleToLongBits(z);
|
||||
return 31 * code + (Long.hashCode(seed));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private record DoubleSeededVector2(double x, double z, long seed) {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(obj instanceof DoubleSeededVector2 that) {
|
||||
return this.z == that.z && this.x == that.x && this.seed == that.seed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int code = (int) Double.doubleToLongBits(x);
|
||||
code = 31 * code + (int) Double.doubleToLongBits(z);
|
||||
return 31 * code + (Long.hashCode(seed));
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -12,4 +12,14 @@ public class AdditionSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return left + right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operateDerivative(double[] left, double[] right) {
|
||||
int dimensions = left.length;
|
||||
double[] out = new double[dimensions];
|
||||
for(int i = 0; i < dimensions; i++) {
|
||||
out[i] = left[i] + right[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-1
@@ -1,9 +1,10 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.arithmetic;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public abstract class BinaryArithmeticSampler implements NoiseSampler {
|
||||
public abstract class BinaryArithmeticSampler implements DerivativeNoiseSampler {
|
||||
private final NoiseSampler left;
|
||||
private final NoiseSampler right;
|
||||
|
||||
@@ -12,6 +13,11 @@ public abstract class BinaryArithmeticSampler implements NoiseSampler {
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return DerivativeNoiseSampler.isDifferentiable(left) && DerivativeNoiseSampler.isDifferentiable(right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y) {
|
||||
return operate(left.noise(seed, x, y), right.noise(seed, x, y));
|
||||
@@ -22,5 +28,17 @@ public abstract class BinaryArithmeticSampler implements NoiseSampler {
|
||||
return operate(left.noise(seed, x, y, z), right.noise(seed, x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y) {
|
||||
return operateDerivative(((DerivativeNoiseSampler)left).noised(seed, x, y), ((DerivativeNoiseSampler)right).noised(seed, x, y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y, double z) {
|
||||
return operateDerivative(((DerivativeNoiseSampler)left).noised(seed, x, y, z), ((DerivativeNoiseSampler)right).noised(seed, x, y, z));
|
||||
}
|
||||
|
||||
public abstract double operate(double left, double right);
|
||||
|
||||
public abstract double[] operateDerivative(double[] left, double[] right);
|
||||
}
|
||||
|
||||
+11
@@ -12,4 +12,15 @@ public class DivisionSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return left / right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operateDerivative(double[] left, double[] right) {
|
||||
int dimensions = left.length;
|
||||
double[] out = new double[dimensions];
|
||||
out[0] = left[0] / right[0];
|
||||
for(int i = 1; i < dimensions; i++) {
|
||||
out[i] = (left[i] * right[0] - left[0] * right[i]) / (right[0] * right[0]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -12,4 +12,11 @@ public class MaxSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return Math.max(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operateDerivative(double[] left, double[] right) {
|
||||
double leftValue = left[0];
|
||||
double rightValue = right[0];
|
||||
return leftValue > rightValue ? left : right;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -12,4 +12,11 @@ public class MinSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return Math.min(left, right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operateDerivative(double[] left, double[] right) {
|
||||
double leftValue = left[0];
|
||||
double rightValue = right[0];
|
||||
return leftValue < rightValue ? left : right;
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -12,4 +12,15 @@ public class MultiplicationSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return left * right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operateDerivative(double[] left, double[] right) {
|
||||
int dimensions = left.length;
|
||||
double[] out = new double[dimensions];
|
||||
out[0] = left[0] * right[0];
|
||||
for(int i = 1; i < dimensions; i++) {
|
||||
out[i] = left[i] * right[0] + left[0] * right[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -12,4 +12,14 @@ public class SubtractionSampler extends BinaryArithmeticSampler {
|
||||
public double operate(double left, double right) {
|
||||
return left - right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] operateDerivative(double[] left, double[] right) {
|
||||
int dimensions = left.length;
|
||||
double[] out = new double[dimensions];
|
||||
for(int i = 0; i < dimensions; i++) {
|
||||
out[i] = left[i] - right[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-6
@@ -197,7 +197,9 @@ public class CellularSampler extends NoiseFunction {
|
||||
private double jitterModifier = 1.0;
|
||||
|
||||
private NoiseSampler noiseLookup;
|
||||
|
||||
|
||||
private boolean saltLookup;
|
||||
|
||||
public CellularSampler() {
|
||||
noiseLookup = new OpenSimplex2Sampler();
|
||||
}
|
||||
@@ -217,7 +219,11 @@ public class CellularSampler extends NoiseFunction {
|
||||
public void setReturnType(ReturnType returnType) {
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
|
||||
public void setSaltLookup(boolean saltLookup) {
|
||||
this.saltLookup = saltLookup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoiseRaw(long sl, double x, double y) {
|
||||
int seed = (int) sl;
|
||||
@@ -286,8 +292,8 @@ public class CellularSampler extends NoiseFunction {
|
||||
case Distance2Sub -> distance1 - distance0 - 1;
|
||||
case Distance2Mul -> distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div -> distance0 / distance1 - 1;
|
||||
case NoiseLookup -> noiseLookup.noise(sl, centerX, centerY);
|
||||
case LocalNoiseLookup -> noiseLookup.noise(sl, x / frequency - centerX, y / frequency - centerY);
|
||||
case NoiseLookup -> noiseLookup.noise(sl - (saltLookup ? 0 : salt), centerX, centerY);
|
||||
case LocalNoiseLookup -> noiseLookup.noise(sl - (saltLookup ? 0 : salt), x / frequency - centerX, y / frequency - centerY);
|
||||
case Distance3 -> distance2 - 1;
|
||||
case Distance3Add -> (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub -> distance2 - distance0 - 1;
|
||||
@@ -377,8 +383,8 @@ public class CellularSampler extends NoiseFunction {
|
||||
case Distance2Sub -> distance1 - distance0 - 1;
|
||||
case Distance2Mul -> distance1 * distance0 * 0.5 - 1;
|
||||
case Distance2Div -> distance0 / distance1 - 1;
|
||||
case NoiseLookup -> noiseLookup.noise(sl, centerX, centerY, centerZ);
|
||||
case LocalNoiseLookup -> noiseLookup.noise(sl, x / frequency - centerX, y / frequency - centerY, z / frequency - centerZ);
|
||||
case NoiseLookup -> noiseLookup.noise(sl - (saltLookup ? 0 : salt), centerX, centerY, centerZ);
|
||||
case LocalNoiseLookup -> noiseLookup.noise(sl - (saltLookup ? 0 : salt), x / frequency - centerX, y / frequency - centerY, z / frequency - centerZ);
|
||||
case Distance3 -> distance2 - 1;
|
||||
case Distance3Add -> (distance2 + distance0) * 0.5 - 1;
|
||||
case Distance3Sub -> distance2 - distance0 - 1;
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.noise;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
|
||||
|
||||
public abstract class DerivativeNoiseFunction extends NoiseFunction implements DerivativeNoiseSampler {
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y) {
|
||||
return getNoiseDerivativeRaw(seed + salt, x * frequency, y * frequency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y, double z) {
|
||||
return getNoiseDerivativeRaw(seed + salt, x * frequency, y * frequency, z * frequency);
|
||||
}
|
||||
|
||||
public abstract double[] getNoiseDerivativeRaw(long seed, double x, double y);
|
||||
|
||||
public abstract double[] getNoiseDerivativeRaw(long seed, double x, double y, double z);
|
||||
}
|
||||
-187
@@ -1,187 +0,0 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.noise;
|
||||
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
public class PseudoErosion implements NoiseSampler {
|
||||
public static final float TAU = (float) (2.0 * Math.PI);
|
||||
private static final float HASH_X = 0.3183099f;
|
||||
private static final float HASH_Y = 0.3678794f;
|
||||
private final int octaves;
|
||||
public final double gain;
|
||||
public final double lacunarity;
|
||||
public final double slopeStrength;
|
||||
public final double branchStrength;
|
||||
public final double erosionStrength;
|
||||
private final double erosionFrequency;
|
||||
private final DerivativeNoiseSampler sampler;
|
||||
private final boolean slopeMask;
|
||||
private final double slopeMaskFullSq;
|
||||
private final double slopeMaskNoneSq;
|
||||
private final double jitter;
|
||||
private final double maxCellDistSq;
|
||||
private final double maxCellDistSqRecip;
|
||||
private final boolean averageErosionImpulses;
|
||||
|
||||
public PseudoErosion(int octaves, double gain, double lacunarity, double slopeStrength, double branchStrength, double erosionStrength, double erosionFrequency, DerivativeNoiseSampler sampler,
|
||||
boolean slopeMask, double slopeMaskFull, double slopeMaskNone, double jitterModifier,
|
||||
boolean averageErosionImpulses) {
|
||||
this.octaves = octaves;
|
||||
this.gain = gain;
|
||||
this.lacunarity = lacunarity;
|
||||
this.slopeStrength = slopeStrength;
|
||||
this.branchStrength = branchStrength;
|
||||
this.erosionStrength = erosionStrength;
|
||||
this.erosionFrequency = erosionFrequency;
|
||||
this.sampler = sampler;
|
||||
this.slopeMask = slopeMask;
|
||||
// Square these values and maintain sign since they're compared to a
|
||||
// squared value, otherwise a sqrt would need to be used
|
||||
this.slopeMaskFullSq = slopeMaskFull * slopeMaskFull * Math.signum(slopeMaskFull);
|
||||
this.slopeMaskNoneSq = slopeMaskNone * slopeMaskNone * Math.signum((slopeMaskNone));
|
||||
this.jitter = 0.43701595 * jitterModifier;
|
||||
this.averageErosionImpulses = averageErosionImpulses;
|
||||
this.maxCellDistSq = 1 + jitter * jitter;
|
||||
this.maxCellDistSqRecip = 1 / maxCellDistSq;
|
||||
}
|
||||
|
||||
public static float hash(float x, float y) {
|
||||
float xx = x * HASH_X + HASH_Y;
|
||||
float yy = y * HASH_Y + HASH_X;
|
||||
|
||||
// Swapped the components here
|
||||
return 16 * (xx * yy * (xx + yy));
|
||||
}
|
||||
|
||||
public static float hashX(float n) {
|
||||
// Swapped the components here
|
||||
float nx = HASH_X * n;
|
||||
return -1.0f + 2.0f * fract(nx);
|
||||
}
|
||||
|
||||
public static float hashY(float n) {
|
||||
float ny = HASH_Y * n;
|
||||
return -1.0f + 2.0f * fract(ny);
|
||||
}
|
||||
|
||||
public static float fract(float x) {
|
||||
return (x - (float)Math.floor(x));
|
||||
}
|
||||
|
||||
public float[] erosion(float x, float y, float dirX, float dirY) {
|
||||
int gridX = Math.round(x);
|
||||
int gridY = Math.round(y);
|
||||
float noise = 0.0f;
|
||||
float dirOutX = 0.0f;
|
||||
float dirOutY = 0.0f;
|
||||
float cumAmp = 0.0f;
|
||||
|
||||
for (int cellX = gridX - 1; cellX <= gridX + 1; cellX++) {
|
||||
for (int cellY = gridY - 1; cellY <= gridY + 1; cellY++) {
|
||||
// TODO - Make seed affect hashing
|
||||
float cellHash = hash(cellX, cellY);
|
||||
float cellOffsetX = (float) (hashX(cellHash) * jitter);
|
||||
float cellOffsetY = (float) (hashY(cellHash) * jitter);
|
||||
float cellOriginDeltaX = (x - cellX) + cellOffsetX;
|
||||
float cellOriginDeltaY = (y - cellY) + cellOffsetY;
|
||||
float cellOriginDistSq = cellOriginDeltaX * cellOriginDeltaX + cellOriginDeltaY * cellOriginDeltaY;
|
||||
if (cellOriginDistSq > maxCellDistSq) continue; // Skip calculating cells too far away
|
||||
float ampTmp = (float) ((cellOriginDistSq * maxCellDistSqRecip) - 1); float amp = ampTmp * ampTmp; // Decrease cell amplitude further away
|
||||
cumAmp += amp;
|
||||
float directionalStrength = dot(cellOriginDeltaX, cellOriginDeltaY, dirX, dirY) * TAU;
|
||||
noise += (float) (MathUtil.cos(directionalStrength) * amp);
|
||||
float sinAngle = (float) MathUtil.sin(directionalStrength) * amp;
|
||||
dirOutX -= sinAngle * (cellOriginDeltaX + dirX);
|
||||
dirOutY -= sinAngle * (cellOriginDeltaY + dirY);
|
||||
}
|
||||
}
|
||||
if (averageErosionImpulses && cumAmp != 0) {
|
||||
noise /= cumAmp;
|
||||
dirOutX /= cumAmp;
|
||||
dirOutY /= cumAmp;
|
||||
}
|
||||
return new float[] {noise, dirOutX, dirOutY};
|
||||
}
|
||||
|
||||
public static double exp(double val) {
|
||||
final long tmp = (long) (1512775 * val + 1072632447);
|
||||
return Double.longBitsToDouble(tmp << 32);
|
||||
}
|
||||
|
||||
public static float smoothstep(float edge0, float edge1, float x) {
|
||||
// Scale, bias and saturate x to 0..1 range
|
||||
x = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
|
||||
// Evaluate polynomial
|
||||
return x * x * (3 - 2 * x);
|
||||
}
|
||||
|
||||
public static float clamp(float x, float minVal, float maxVal) {
|
||||
return Math.max(minVal, Math.min(maxVal, x));
|
||||
}
|
||||
|
||||
public float heightMap(long seed, float x, float y) {
|
||||
double[] sample = sampler.noised(seed, x, y);
|
||||
float height = (float) sample[0];
|
||||
float heightDirX = (float) sample[1];
|
||||
float heightDirY = (float) sample[2];
|
||||
|
||||
// Take the curl of the normal to get the gradient facing down the slope
|
||||
float baseDirX = heightDirY * (float) slopeStrength;
|
||||
float baseDirY = -heightDirX * (float) slopeStrength;
|
||||
|
||||
float erosion = 0.0f;
|
||||
float dirX = 0.0f;
|
||||
float dirY = 0.0f;
|
||||
float amp = 1.0f;
|
||||
float cumAmp = 0.0f;
|
||||
float freq = 1.0f;
|
||||
|
||||
// Stack erosion octaves
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
float[] erosionResult = erosion(
|
||||
x * freq * (float) erosionFrequency,
|
||||
y * freq * (float) erosionFrequency,
|
||||
baseDirX + dirY * (float) branchStrength,
|
||||
baseDirY - dirX * (float) branchStrength);
|
||||
erosion += erosionResult[0] * amp;
|
||||
dirX += erosionResult[1] * amp * freq;
|
||||
dirY += erosionResult[2] * amp * freq;
|
||||
cumAmp += amp;
|
||||
amp *= gain;
|
||||
freq *= lacunarity;
|
||||
}
|
||||
|
||||
// TODO - Test different output ranges, see how they affect visuals
|
||||
// Normalize erosion noise
|
||||
erosion /= cumAmp;
|
||||
// [-1, 1] -> [0, 1]
|
||||
erosion = erosion * 0.5F + 0.5F;
|
||||
|
||||
// Without masking, erosion noise in areas with small gradients tend to produce mounds,
|
||||
// this reduces erosion amplitude towards smaller gradients to avoid this
|
||||
if (slopeMask) {
|
||||
float dirMagSq = dot(baseDirX, baseDirY, baseDirX, baseDirY);
|
||||
float flatness = smoothstep((float) slopeMaskNoneSq, (float) slopeMaskFullSq, dirMagSq);
|
||||
erosion *= flatness;
|
||||
}
|
||||
|
||||
return (float) (height + erosion * erosionStrength);
|
||||
}
|
||||
|
||||
public static float dot(float x1, float y1, float x2, float y2) {
|
||||
return x1 * x2 + y1 * y2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y) {
|
||||
return heightMap(seed, (float) x, (float) y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y, double z) {
|
||||
return noise(seed, x, z);
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.noise;
|
||||
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
public class PseudoErosionSampler extends NoiseFunction {
|
||||
public static final double TAU = 2.0 * Math.PI;
|
||||
private static final double HASH_X = 0.3183099f;
|
||||
private static final double HASH_Y = 0.3678794f;
|
||||
public final double gain;
|
||||
public final double lacunarity;
|
||||
public final double slopeStrength;
|
||||
public final double branchStrength;
|
||||
public final double erosionStrength;
|
||||
private final int octaves;
|
||||
private final double erosionFrequency;
|
||||
private final DerivativeNoiseSampler sampler;
|
||||
private final boolean slopeMask;
|
||||
private final double slopeMaskFullSq;
|
||||
private final double slopeMaskNoneSq;
|
||||
private final double jitter;
|
||||
private final double maxCellDistSq;
|
||||
private final double maxCellDistSqRecip;
|
||||
private final boolean averageErosionImpulses;
|
||||
|
||||
public PseudoErosionSampler(int octaves, double gain, double lacunarity, double slopeStrength, double branchStrength,
|
||||
double erosionStrength, double erosionFrequency, DerivativeNoiseSampler sampler,
|
||||
boolean slopeMask, double slopeMaskFull, double slopeMaskNone, double jitterModifier,
|
||||
boolean averageErosionImpulses) {
|
||||
this.octaves = octaves;
|
||||
this.gain = gain;
|
||||
this.lacunarity = lacunarity;
|
||||
this.slopeStrength = slopeStrength;
|
||||
this.branchStrength = branchStrength;
|
||||
this.erosionStrength = erosionStrength;
|
||||
this.erosionFrequency = erosionFrequency;
|
||||
this.sampler = sampler;
|
||||
this.slopeMask = slopeMask;
|
||||
// Square these values and maintain sign since they're compared to a
|
||||
// squared value, otherwise a sqrt would need to be used
|
||||
this.slopeMaskFullSq = slopeMaskFull * slopeMaskFull * Math.signum(slopeMaskFull);
|
||||
this.slopeMaskNoneSq = slopeMaskNone * slopeMaskNone * Math.signum((slopeMaskNone));
|
||||
this.jitter = 0.43701595 * jitterModifier;
|
||||
this.averageErosionImpulses = averageErosionImpulses;
|
||||
this.maxCellDistSq = 1 + jitter * jitter;
|
||||
this.maxCellDistSqRecip = 1 / maxCellDistSq;
|
||||
}
|
||||
|
||||
public static double hashX(double seed, double n) {
|
||||
// Swapped the components here
|
||||
double nx = HASH_X * n * seed;
|
||||
return -1.0f + 2.0f * fract(nx);
|
||||
}
|
||||
|
||||
public static double hashY(double seed, double n) {
|
||||
double ny = HASH_Y * n * seed;
|
||||
return -1.0f + 2.0f * fract(ny);
|
||||
}
|
||||
|
||||
public static double fract(double x) {
|
||||
return (x - Math.floor(x));
|
||||
}
|
||||
|
||||
public static double smoothstep(double edge0, double edge1, double x) {
|
||||
// Scale, bias and saturate x to 0..1 range
|
||||
x = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
|
||||
// Evaluate polynomial
|
||||
return x * x * (3 - 2 * x);
|
||||
}
|
||||
|
||||
public static double clamp(double x, double minVal, double maxVal) {
|
||||
return Math.max(minVal, Math.min(maxVal, x));
|
||||
}
|
||||
|
||||
public static double dot(double x1, double y1, double x2, double y2) {
|
||||
return x1 * x2 + y1 * y2;
|
||||
}
|
||||
|
||||
public double[] erosion(int seed, double x, double y, double dirX, double dirY) {
|
||||
int gridX = (int) Math.round(x);
|
||||
int gridY = (int) Math.round(y);
|
||||
double noise = 0.0f;
|
||||
double dirOutX = 0.0f;
|
||||
double dirOutY = 0.0f;
|
||||
double cumAmp = 0.0f;
|
||||
|
||||
for(int cellX = gridX - 1; cellX <= gridX + 1; cellX++) {
|
||||
for(int cellY = gridY - 1; cellY <= gridY + 1; cellY++) {
|
||||
double cellHash = hash(seed, cellX, cellY);
|
||||
double cellOffsetX = hashX(seed, cellHash) * jitter;
|
||||
double cellOffsetY = hashY(seed, cellHash) * jitter;
|
||||
double cellOriginDeltaX = (x - cellX) + cellOffsetX;
|
||||
double cellOriginDeltaY = (y - cellY) + cellOffsetY;
|
||||
double cellOriginDistSq = cellOriginDeltaX * cellOriginDeltaX + cellOriginDeltaY * cellOriginDeltaY;
|
||||
if(cellOriginDistSq > maxCellDistSq) continue; // Skip calculating cells too far away
|
||||
double ampTmp = (cellOriginDistSq * maxCellDistSqRecip) - 1;
|
||||
double amp = ampTmp * ampTmp; // Decrease cell amplitude further away
|
||||
cumAmp += amp;
|
||||
double directionalStrength = dot(cellOriginDeltaX, cellOriginDeltaY, dirX, dirY) * TAU;
|
||||
noise += MathUtil.cos(directionalStrength) * amp;
|
||||
double sinAngle = MathUtil.sin(directionalStrength) * amp;
|
||||
dirOutX -= sinAngle * (cellOriginDeltaX + dirX);
|
||||
dirOutY -= sinAngle * (cellOriginDeltaY + dirY);
|
||||
}
|
||||
}
|
||||
if(averageErosionImpulses && cumAmp != 0) {
|
||||
noise /= cumAmp;
|
||||
dirOutX /= cumAmp;
|
||||
dirOutY /= cumAmp;
|
||||
}
|
||||
return new double[]{ noise, dirOutX, dirOutY };
|
||||
}
|
||||
|
||||
public double heightMap(long seed, double x, double y) {
|
||||
double[] sample = sampler.noised(seed, x, y);
|
||||
double height = sample[0];
|
||||
double heightDirX = sample[1];
|
||||
double heightDirY = sample[2];
|
||||
|
||||
// Take the curl of the normal to get the gradient facing down the slope
|
||||
double baseDirX = heightDirY * slopeStrength;
|
||||
double baseDirY = -heightDirX * slopeStrength;
|
||||
|
||||
double erosion = 0.0f;
|
||||
double dirX = 0.0f;
|
||||
double dirY = 0.0f;
|
||||
double amp = 1.0f;
|
||||
double cumAmp = 0.0f;
|
||||
double freq = 1.0f;
|
||||
|
||||
// Stack erosion octaves
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
double[] erosionResult = erosion((int) seed,
|
||||
x * freq * erosionFrequency,
|
||||
y * freq * erosionFrequency,
|
||||
baseDirX + dirY * branchStrength,
|
||||
baseDirY - dirX * branchStrength);
|
||||
erosion += erosionResult[0] * amp;
|
||||
dirX += erosionResult[1] * amp * freq;
|
||||
dirY += erosionResult[2] * amp * freq;
|
||||
cumAmp += amp;
|
||||
amp *= gain;
|
||||
freq *= lacunarity;
|
||||
}
|
||||
|
||||
// Normalize erosion noise
|
||||
erosion /= cumAmp;
|
||||
// [-1, 1] -> [0, 1]
|
||||
erosion = erosion * 0.5F + 0.5F;
|
||||
|
||||
// Without masking, erosion noise in areas with small gradients tend to produce mounds,
|
||||
// this reduces erosion amplitude towards smaller gradients to avoid this
|
||||
if(slopeMask) {
|
||||
double dirMagSq = dot(baseDirX, baseDirY, baseDirX, baseDirY);
|
||||
double flatness = smoothstep((double) slopeMaskNoneSq, slopeMaskFullSq, dirMagSq);
|
||||
erosion *= flatness;
|
||||
}
|
||||
|
||||
return height + erosion * erosionStrength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoiseRaw(long seed, double x, double y) {
|
||||
return heightMap(seed, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoiseRaw(long seed, double x, double y, double z) {
|
||||
return getNoiseRaw(seed, x, z);
|
||||
}
|
||||
}
|
||||
+57
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.fractal;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
@@ -52,4 +53,60 @@ public class BrownianMotionSampler extends FractalNoiseFunction {
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return DerivativeNoiseSampler.isDifferentiable(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y) {
|
||||
double[] sum = {0, 0, 0};
|
||||
double amp = fractalBounding;
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
// This should only be called after `input` is verified as a `DerivativeNoiseSampler`
|
||||
// so this should be a safe cast
|
||||
double[] noise = ((DerivativeNoiseSampler) input).noised(seed++, x, y);
|
||||
sum[0] += noise[0] * amp;
|
||||
|
||||
// Directional derivative of each octave can be subject to the same addition and product
|
||||
// as per derivative sum and product rules in order to produce the correct final derivative
|
||||
sum[1] += noise[1] * amp;
|
||||
sum[2] += noise[2] * amp;
|
||||
|
||||
amp *= MathUtil.lerp(weightedStrength, 1.0, Math.min(noise[0] + 1, 2) * 0.5);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
amp *= gain;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y, double z) {
|
||||
double[] sum = {0, 0, 0, 0};
|
||||
double amp = fractalBounding;
|
||||
|
||||
for(int i = 0; i < octaves; i++) {
|
||||
double[] noise = ((DerivativeNoiseSampler) input).noised(seed++, x, y, z);
|
||||
sum[0] += noise[0] * amp;
|
||||
|
||||
// See comment in 2D version
|
||||
sum[1] += noise[1] * amp;
|
||||
sum[2] += noise[2] * amp;
|
||||
sum[3] += noise[3] * amp;
|
||||
|
||||
amp *= MathUtil.lerp(weightedStrength, 1.0, (noise[0] + 1) * 0.5);
|
||||
|
||||
x *= lacunarity;
|
||||
y *= lacunarity;
|
||||
z *= lacunarity;
|
||||
amp *= gain;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
+17
-2
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.fractal;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.NoiseFunction;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.DerivativeNoiseFunction;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public abstract class FractalNoiseFunction extends NoiseFunction {
|
||||
public abstract class FractalNoiseFunction extends DerivativeNoiseFunction {
|
||||
protected final NoiseSampler input;
|
||||
protected double fractalBounding = 1 / 1.75;
|
||||
protected int octaves = 3;
|
||||
@@ -52,4 +52,19 @@ public abstract class FractalNoiseFunction extends NoiseFunction {
|
||||
public void setWeightedStrength(double weightedStrength) {
|
||||
this.weightedStrength = weightedStrength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y) {
|
||||
throw new UnsupportedOperationException("Implementation failed to check or set isDifferentiable correctly");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y, double z) {
|
||||
throw new UnsupportedOperationException("Implementation failed to check or set isDifferentiable correctly");
|
||||
}
|
||||
}
|
||||
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.simplex;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
|
||||
import static com.dfsek.terra.addons.noise.samplers.noise.PseudoErosion.dot;
|
||||
import static com.dfsek.terra.addons.noise.samplers.noise.PseudoErosion.hash;
|
||||
import static com.dfsek.terra.addons.noise.samplers.noise.PseudoErosion.hashX;
|
||||
import static com.dfsek.terra.addons.noise.samplers.noise.PseudoErosion.hashY;
|
||||
|
||||
|
||||
/**
|
||||
* Temporary sampler that provides derivatives to test pseudoerosion, should be replaced with
|
||||
* derivative versions of existing samplers
|
||||
*/
|
||||
public class DerivativeFractal implements DerivativeNoiseSampler {
|
||||
|
||||
private final int heightOctaves;
|
||||
private final double heightGain;
|
||||
private final double heightLacunarity;
|
||||
private final double frequency;
|
||||
|
||||
public DerivativeFractal(int octaves, double gain, double lacunarity, double frequency) {
|
||||
this.heightOctaves = octaves;
|
||||
this.heightGain = gain;
|
||||
this.heightLacunarity = lacunarity;
|
||||
this.frequency = frequency;
|
||||
}
|
||||
|
||||
private static float[] baseNoise(float px, float py) {
|
||||
float ix = (float)Math.floor(px);
|
||||
float iy = (float)Math.floor(py);
|
||||
float fx = px - ix;
|
||||
float fy = py - iy;
|
||||
|
||||
float ux = fx * fx * fx * (fx * (fx * 6.0f - 15.0f) + 10.0f);
|
||||
float uy = fy * fy * fy * (fy * (fy * 6.0f - 15.0f) + 10.0f);
|
||||
float dux = fx * fx * 30.0f * (fx * (fx - 2.0f) + 1.0f);
|
||||
float duy = fy * fy * 30.0f * (fy * (fy - 2.0f) + 1.0f);
|
||||
|
||||
float gan = hash(ix, iy);
|
||||
float gax = hashX(gan);
|
||||
float gay = hashY(gan);
|
||||
|
||||
float gbn = hash(ix + 1, iy);
|
||||
float gbx = hashX(gbn);
|
||||
float gby = hashY(gbn);
|
||||
|
||||
float gcn = hash(ix, iy + 1);
|
||||
float gcx = hashX(gcn);
|
||||
float gcy = hashY(gcn);
|
||||
|
||||
float gdn = hash(ix + 1, iy + 1);
|
||||
float gdx = hashX(gdn);
|
||||
float gdy = hashY(gdn);
|
||||
|
||||
float va = dot(gax, gay, fx, fy);
|
||||
float vb = dot(gbx, gby, fx - 1, fy);
|
||||
float vc = dot(gcx, gcy, fx, fy - 1);
|
||||
float vd = dot(gdx, gdy, fx - 1, fy - 1);
|
||||
|
||||
float u2x = gax + (gbx - gax) * ux + (gcx - gax) * uy + (gax - gbx - gcx + gdx) * ux * uy + dux * (uy * (va - vb - vc + vd) + vb - va);
|
||||
float u2y = gay + (gby - gay) * ux + (gcy - gay) * uy + (gay - gby - gcy + gdy) * ux * uy + duy * (ux * (va - vb - vc + vd) + vc - va);
|
||||
|
||||
return new float[] { va + ux * (vb - va) + uy * (vc - va) + ux * uy * (va - vb - vc + vd), u2x, u2y };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y) {
|
||||
x *= frequency;
|
||||
y *= frequency;
|
||||
double[] out = { 0.0f, 0.0f, 0.0f };
|
||||
float heightFreq = 1.0f;
|
||||
float heightAmp = 1f;
|
||||
float cumAmp = 0.0f;
|
||||
for (int i = 0; i < heightOctaves; i++) {
|
||||
float[] noise = baseNoise((float) (x * heightFreq), (float) (y * heightFreq));
|
||||
out[0] += noise[0] * heightAmp;
|
||||
out[1] += noise[1] * heightAmp * heightFreq;
|
||||
out[2] += noise[2] * heightAmp * heightFreq;
|
||||
cumAmp += heightAmp;
|
||||
heightAmp *= heightGain;
|
||||
heightFreq *= heightLacunarity;
|
||||
}
|
||||
out[0] /= cumAmp;
|
||||
out[1] /= cumAmp;
|
||||
out[2] /= cumAmp;
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y, double z) {
|
||||
return noised(seed, x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y) {
|
||||
return noised(seed, x, y)[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(long seed, double x, double y, double z) {
|
||||
return noised(seed, x, y, z)[0];
|
||||
}
|
||||
}
|
||||
+246
-10
@@ -7,13 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.simplex;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
|
||||
|
||||
/**
|
||||
* NoiseSampler implementation to provide OpenSimplex2 (Smooth Variant) noise.
|
||||
*/
|
||||
public class OpenSimplex2SSampler extends SimplexStyleSampler implements DerivativeNoiseSampler {
|
||||
public class OpenSimplex2SSampler extends SimplexStyleSampler {
|
||||
@Override
|
||||
@SuppressWarnings("NumericOverflow")
|
||||
public double getNoiseRaw(long sl, double x, double y) {
|
||||
@@ -286,7 +283,7 @@ public class OpenSimplex2SSampler extends SimplexStyleSampler implements Derivat
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long sl, double x, double y) {
|
||||
public double[] getNoiseDerivativeRaw(long sl, double x, double y) {
|
||||
int seed = (int) sl;
|
||||
// 2D OpenSimplex2S case is a modified 2D simplex noise.
|
||||
|
||||
@@ -325,7 +322,6 @@ public class OpenSimplex2SSampler extends SimplexStyleSampler implements Derivat
|
||||
out[2] = gy0 * aaaa0 - 8 * rampValue0 * aaa0 * y0;
|
||||
|
||||
|
||||
|
||||
double a1 = 2 * (1 - 2 * G2) * (1 / G2 - 2) * t + ((-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a0);
|
||||
double x1 = x0 - (1 - 2 * G2);
|
||||
double y1 = y0 - (1 - 2 * G2);
|
||||
@@ -407,7 +403,8 @@ public class OpenSimplex2SSampler extends SimplexStyleSampler implements Derivat
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2; }
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
} else {
|
||||
double x2 = x0 + (G2 - 1);
|
||||
double y2 = y0 + G2;
|
||||
@@ -434,7 +431,8 @@ public class OpenSimplex2SSampler extends SimplexStyleSampler implements Derivat
|
||||
double rampValue2 = gx2 * x2 + gy2 * y2;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2; }
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y2;
|
||||
}
|
||||
} else {
|
||||
double x2 = x0 + G2;
|
||||
double y2 = y0 + (G2 - 1);
|
||||
@@ -457,7 +455,245 @@ public class OpenSimplex2SSampler extends SimplexStyleSampler implements Derivat
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y, double z) {
|
||||
return new double[0];
|
||||
public double[] getNoiseDerivativeRaw(long sl, double x, double y, double z) {
|
||||
int seed = (int) sl;
|
||||
// 3D OpenSimplex2S case uses two offset rotated cube grids.
|
||||
final double R3 = (2.0 / 3.0);
|
||||
double r = (x + y + z) * R3; // Rotation, not skew
|
||||
x = r - x;
|
||||
y = r - y;
|
||||
z = r - z;
|
||||
|
||||
|
||||
int i = (int) Math.floor(x);
|
||||
int j = (int) Math.floor(y);
|
||||
int k = (int) Math.floor(z);
|
||||
double xi = x - i;
|
||||
double yi = y - j;
|
||||
double zi = z - k;
|
||||
|
||||
i *= PRIME_X;
|
||||
j *= PRIME_Y;
|
||||
k *= PRIME_Z;
|
||||
int seed2 = seed + 1293373;
|
||||
|
||||
int xNMask = (int) (-0.5 - xi);
|
||||
int yNMask = (int) (-0.5 - yi);
|
||||
int zNMask = (int) (-0.5 - zi);
|
||||
|
||||
double[] out = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
|
||||
double x0 = xi + xNMask;
|
||||
double y0 = yi + yNMask;
|
||||
double z0 = zi + zNMask;
|
||||
double a0 = 0.75 - x0 * x0 - y0 * y0 - z0 * z0;
|
||||
double aa0 = a0 * a0, aaa0 = aa0 * a0, aaaa0 = aa0 * aa0;
|
||||
int gi0 = gradCoordIndex(seed, i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z));
|
||||
double gx0 = GRADIENTS_3D[gi0], gy0 = GRADIENTS_3D[gi0 | 1], gz0 = GRADIENTS_3D[gi0 | 2];
|
||||
double rampValue0 = gx0 * x0 + gy0 * y0 + gz0 * z0;
|
||||
out[0] = aaaa0 * rampValue0;
|
||||
out[1] = gx0 * aaaa0 - 8 * rampValue0 * aaa0 * x0;
|
||||
out[2] = gy0 * aaaa0 - 8 * rampValue0 * aaa0 * y0;
|
||||
out[3] = gz0 * aaaa0 - 8 * rampValue0 * aaa0 * z0;
|
||||
|
||||
double x1 = xi - 0.5;
|
||||
double y1 = yi - 0.5;
|
||||
double z1 = zi - 0.5;
|
||||
double a1 = 0.75 - x1 * x1 - y1 * y1 - z1 * z1;
|
||||
double aa1 = a1 * a1, aaa1 = aa1 * a1, aaaa1 = aa1 * aa1;
|
||||
int gi1 = gradCoordIndex(seed2, i + PRIME_X, j + PRIME_Y, k + PRIME_Z);
|
||||
double gx1 = GRADIENTS_3D[gi1], gy1 = GRADIENTS_3D[gi1 | 1], gz1 = GRADIENTS_3D[gi1 | 2];
|
||||
double rampValue1 = gx1 * x1 + gy1 * y1 + gz1 * z1;
|
||||
out[0] += aaaa1 * rampValue1;
|
||||
out[1] += gx1 * aaaa1 - 8 * rampValue1 * aaa1 * x1;
|
||||
out[2] += gy1 * aaaa1 - 8 * rampValue1 * aaa1 * y1;
|
||||
out[3] += gz1 * aaaa1 - 8 * rampValue1 * aaa1 * z1;
|
||||
|
||||
double xAFlipMask0 = ((xNMask | 1) << 1) * x1;
|
||||
double yAFlipMask0 = ((yNMask | 1) << 1) * y1;
|
||||
double zAFlipMask0 = ((zNMask | 1) << 1) * z1;
|
||||
double xAFlipMask1 = (-2 - (xNMask << 2)) * x1 - 1.0;
|
||||
double yAFlipMask1 = (-2 - (yNMask << 2)) * y1 - 1.0;
|
||||
double zAFlipMask1 = (-2 - (zNMask << 2)) * z1 - 1.0;
|
||||
|
||||
boolean skip5 = false;
|
||||
double a2 = xAFlipMask0 + a0;
|
||||
if(a2 > 0) {
|
||||
double x2 = x0 - (xNMask | 1);
|
||||
double aa2 = a2 * a2, aaa2 = aa2 * a2, aaaa2 = aa2 * aa2;
|
||||
int gi2 = gradCoordIndex(seed, i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z));
|
||||
double gx2 = GRADIENTS_3D[gi2], gy2 = GRADIENTS_3D[gi2 | 1], gz2 = GRADIENTS_3D[gi2 | 2];
|
||||
double rampValue2 = gx2 * x2 + gy2 * y0 + gz2 * z0;
|
||||
out[0] += aaaa2 * rampValue2;
|
||||
out[1] += gx2 * aaaa2 - 8 * rampValue2 * aaa2 * x2;
|
||||
out[2] += gy2 * aaaa2 - 8 * rampValue2 * aaa2 * y0;
|
||||
out[3] += gz2 * aaaa2 - 8 * rampValue2 * aaa2 * z0;
|
||||
} else {
|
||||
double a3 = yAFlipMask0 + zAFlipMask0 + a0;
|
||||
if(a3 > 0) {
|
||||
double y3 = y0 - (yNMask | 1);
|
||||
double z3 = z0 - (zNMask | 1);
|
||||
double aa3 = a3 * a3, aaa3 = aa3 * a3, aaaa3 = aa3 * aa3;
|
||||
int gi3 = gradCoordIndex(seed, i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (~zNMask & PRIME_Z));
|
||||
double gx3 = GRADIENTS_3D[gi3], gy3 = GRADIENTS_3D[gi3 | 1], gz3 = GRADIENTS_3D[gi3 | 2];
|
||||
double rampValue3 = gx3 * x0 + gy3 * y3 + gz3 * z3;
|
||||
out[0] += aaaa3 * rampValue3;
|
||||
out[1] += gx3 * aaaa3 - 8 * rampValue3 * aaa3 * x0;
|
||||
out[2] += gy3 * aaaa3 - 8 * rampValue3 * aaa3 * y3;
|
||||
out[3] += gz3 * aaaa3 - 8 * rampValue3 * aaa3 * z3;
|
||||
}
|
||||
|
||||
double a4 = xAFlipMask1 + a1;
|
||||
if(a4 > 0) {
|
||||
double x4 = (xNMask | 1) + x1;
|
||||
double aa4 = a4 * a4, aaa4 = aa4 * a4, aaaa4 = aa4 * aa4;
|
||||
int gi4 = gradCoordIndex(seed2, i + (xNMask & (PRIME_X << 1)), j + PRIME_Y, k + PRIME_Z);
|
||||
double gx4 = GRADIENTS_3D[gi4], gy4 = GRADIENTS_3D[gi4 | 1], gz4 = GRADIENTS_3D[gi4 | 2];
|
||||
double rampValue4 = gx4 * x4 + gy4 * y1 + gz4 * z1;
|
||||
out[0] += aaaa4 * rampValue4;
|
||||
out[1] += gx4 * aaaa4 - 8 * rampValue4 * aaa4 * x4;
|
||||
out[2] += gy4 * aaaa4 - 8 * rampValue4 * aaa4 * y1;
|
||||
out[3] += gz4 * aaaa4 - 8 * rampValue4 * aaa4 * z1;
|
||||
skip5 = true;
|
||||
}
|
||||
}
|
||||
|
||||
boolean skip9 = false;
|
||||
double a6 = yAFlipMask0 + a0;
|
||||
if(a6 > 0) {
|
||||
double y6 = y0 - (yNMask | 1);
|
||||
double aa6 = a6 * a6, aaa6 = aa6 * a6, aaaa6 = aa6 * aa6;
|
||||
int gi6 = gradCoordIndex(seed, i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z));
|
||||
double gx6 = GRADIENTS_3D[gi6], gy6 = GRADIENTS_3D[gi6 | 1], gz6 = GRADIENTS_3D[gi6 | 2];
|
||||
double rampValue6 = gx6 * x0 + gy6 * y6 + gz6 * z0;
|
||||
out[0] += aaaa6 * rampValue6;
|
||||
out[1] += gx6 * aaaa6 - 8 * rampValue6 * aaa6 * x0;
|
||||
out[2] += gy6 * aaaa6 - 8 * rampValue6 * aaa6 * y6;
|
||||
out[3] += gz6 * aaaa6 - 8 * rampValue6 * aaa6 * z0;
|
||||
} else {
|
||||
double a7 = xAFlipMask0 + zAFlipMask0 + a0;
|
||||
if(a7 > 0) {
|
||||
double x7 = x0 - (xNMask | 1);
|
||||
double z7 = z0 - (zNMask | 1);
|
||||
double aa7 = a7 * a7, aaa7 = aa7 * a7, aaaa7 = aa7 * aa7;
|
||||
int gi7 = gradCoordIndex(seed, i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z));
|
||||
double gx7 = GRADIENTS_3D[gi7], gy7 = GRADIENTS_3D[gi7 | 1], gz7 = GRADIENTS_3D[gi7 | 2];
|
||||
double rampValue7 = gx7 * x7 + gy7 * y0 + gz7 * z7;
|
||||
out[0] += aaaa7 * rampValue7;
|
||||
out[1] += gx7 * aaaa7 - 8 * rampValue7 * aaa7 * x7;
|
||||
out[2] += gy7 * aaaa7 - 8 * rampValue7 * aaa7 * y0;
|
||||
out[3] += gz7 * aaaa7 - 8 * rampValue7 * aaa7 * z7;
|
||||
}
|
||||
|
||||
double a8 = yAFlipMask1 + a1;
|
||||
if(a8 > 0) {
|
||||
double y8 = (yNMask | 1) + y1;
|
||||
double aa8 = a8 * a8, aaa8 = aa8 * a8, aaaa8 = aa8 * aa8;
|
||||
int gi8 = gradCoordIndex(seed2, i + PRIME_X, j + (yNMask & (PRIME_Y << 1)), k + PRIME_Z);
|
||||
double gx8 = GRADIENTS_3D[gi8], gy8 = GRADIENTS_3D[gi8 | 1], gz8 = GRADIENTS_3D[gi8 | 2];
|
||||
double rampValue8 = gx8 * x1 + gy8 * y8 + gz8 * z1;
|
||||
out[0] += aaaa8 * rampValue8;
|
||||
out[1] += gx8 * aaaa8 - 8 * rampValue8 * aaa8 * x1;
|
||||
out[2] += gy8 * aaaa8 - 8 * rampValue8 * aaa8 * y8;
|
||||
out[3] += gz8 * aaaa8 - 8 * rampValue8 * aaa8 * z1;
|
||||
skip9 = true;
|
||||
}
|
||||
}
|
||||
|
||||
boolean skipD = false;
|
||||
double aA = zAFlipMask0 + a0;
|
||||
if(aA > 0) {
|
||||
double zA = z0 - (zNMask | 1);
|
||||
double aaA = aA * aA, aaaA = aaA * aA, aaaaA = aaA * aaA;
|
||||
int giA = gradCoordIndex(seed, i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z));
|
||||
double gxA = GRADIENTS_3D[giA], gyA = GRADIENTS_3D[giA | 1], gzA = GRADIENTS_3D[giA | 2];
|
||||
double rampValueA = gxA * x0 + gyA * y0 + gzA * zA;
|
||||
out[0] += aaaaA * rampValueA;
|
||||
out[1] += gxA * aaaaA - 8 * rampValueA * aaaA * x0;
|
||||
out[2] += gyA * aaaaA - 8 * rampValueA * aaaA * y0;
|
||||
out[3] += gzA * aaaaA - 8 * rampValueA * aaaA * zA;
|
||||
} else {
|
||||
double aB = xAFlipMask0 + yAFlipMask0 + a0;
|
||||
if(aB > 0) {
|
||||
double xB = x0 - (xNMask | 1);
|
||||
double yB = y0 - (yNMask | 1);
|
||||
double aaB = aB * aB, aaaB = aaB * aB, aaaaB = aaB * aaB;
|
||||
int giB = gradCoordIndex(seed, i + (~xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z));
|
||||
double gxB = GRADIENTS_3D[giB], gyB = GRADIENTS_3D[giB | 1], gzB = GRADIENTS_3D[giB | 2];
|
||||
double rampValueB = gxB * xB + gyB * yB + gzB * z0;
|
||||
out[0] += aaaaB * rampValueB;
|
||||
out[1] += gxB * aaaaB - 8 * rampValueB * aaaB * xB;
|
||||
out[2] += gyB * aaaaB - 8 * rampValueB * aaaB * yB;
|
||||
out[3] += gzB * aaaaB - 8 * rampValueB * aaaB * z0;
|
||||
}
|
||||
|
||||
double aC = zAFlipMask1 + a1;
|
||||
if(aC > 0) {
|
||||
double zC = (zNMask | 1) + z1;
|
||||
double aaC = aC * aC, aaaC = aaC * aC, aaaaC = aaC * aaC;
|
||||
int giC = gradCoordIndex(seed2, i + PRIME_X, j + PRIME_Y, k + (zNMask & (PRIME_Z << 1)));
|
||||
double gxC = GRADIENTS_3D[giC], gyC = GRADIENTS_3D[giC | 1], gzC = GRADIENTS_3D[giC | 2];
|
||||
double rampValueC = gxC * x1 + gyC * y1 + gzC * zC;
|
||||
out[0] += aaaaC * rampValueC;
|
||||
out[1] += gxC * aaaaC - 8 * rampValueC * aaaC * x1;
|
||||
out[2] += gyC * aaaaC - 8 * rampValueC * aaaC * y1;
|
||||
out[3] += gzC * aaaaC - 8 * rampValueC * aaaC * zC;
|
||||
skipD = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!skip5) {
|
||||
double a5 = yAFlipMask1 + zAFlipMask1 + a1;
|
||||
if(a5 > 0) {
|
||||
double y5 = (yNMask | 1) + y1;
|
||||
double z5 = (zNMask | 1) + z1;
|
||||
double aa5 = a5 * a5, aaa5 = aa5 * a5, aaaa5 = aa5 * aa5;
|
||||
int gi5 = gradCoordIndex(seed2, i + PRIME_X, j + (yNMask & (PRIME_Y << 1)), k + (zNMask & (PRIME_Z << 1)));
|
||||
double gx5 = GRADIENTS_3D[gi5], gy5 = GRADIENTS_3D[gi5 | 1], gz5 = GRADIENTS_3D[gi5 | 2];
|
||||
double rampValue5 = gx5 * x1 + gy5 * y5 + gz5 * z5;
|
||||
out[0] += aaaa5 * rampValue5;
|
||||
out[1] += gx5 * aaaa5 - 8 * rampValue5 * aaa5 * x1;
|
||||
out[2] += gy5 * aaaa5 - 8 * rampValue5 * aaa5 * y5;
|
||||
out[3] += gz5 * aaaa5 - 8 * rampValue5 * aaa5 * z5;
|
||||
}
|
||||
}
|
||||
|
||||
if(!skip9) {
|
||||
double a9 = xAFlipMask1 + zAFlipMask1 + a1;
|
||||
if(a9 > 0) {
|
||||
double x9 = (xNMask | 1) + x1;
|
||||
double z9 = (zNMask | 1) + z1;
|
||||
double aa9 = a9 * a9, aaa9 = aa9 * a9, aaaa9 = aa9 * aa9;
|
||||
int gi9 = gradCoordIndex(seed2, i + (xNMask & (PRIME_X << 1)), j + PRIME_Y, k + (zNMask & (PRIME_Z << 1)));
|
||||
double gx9 = GRADIENTS_3D[gi9], gy9 = GRADIENTS_3D[gi9 | 1], gz9 = GRADIENTS_3D[gi9 | 2];
|
||||
double rampValue9 = gx9 * x9 + gy9 * y1 + gz9 * z9;
|
||||
out[0] += aaaa9 * rampValue9;
|
||||
out[1] += gx9 * aaaa9 - 8 * rampValue9 * aaa9 * x9;
|
||||
out[2] += gy9 * aaaa9 - 8 * rampValue9 * aaa9 * y1;
|
||||
out[3] += gz9 * aaaa9 - 8 * rampValue9 * aaa9 * z9;
|
||||
}
|
||||
}
|
||||
|
||||
if(!skipD) {
|
||||
double aD = xAFlipMask1 + yAFlipMask1 + a1;
|
||||
if(aD > 0) {
|
||||
double xD = (xNMask | 1) + x1;
|
||||
double yD = (yNMask | 1) + y1;
|
||||
double aaD = aD * aD, aaaD = aaD * aD, aaaaD = aaD * aaD;
|
||||
int giD = gradCoordIndex(seed2, i + (xNMask & (PRIME_X << 1)), j + (yNMask & (PRIME_Y << 1)), k + PRIME_Z);
|
||||
double gxD = GRADIENTS_3D[giD], gyD = GRADIENTS_3D[giD | 1], gzD = GRADIENTS_3D[giD | 2];
|
||||
double rampValueD = gxD * xD + gyD * yD + gzD * z1;
|
||||
out[0] += aaaaD * rampValueD;
|
||||
out[1] += gxD * aaaaD - 8 * rampValueD * aaaD * xD;
|
||||
out[2] += gyD * aaaaD - 8 * rampValueD * aaaD * yD;
|
||||
out[3] += gzD * aaaaD - 8 * rampValueD * aaaD * z1;
|
||||
}
|
||||
}
|
||||
|
||||
out[0] *= 9.046026385208288;
|
||||
out[1] *= 9.046026385208288;
|
||||
out[2] *= 9.046026385208288;
|
||||
out[3] *= 9.046026385208288;
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
+205
-23
@@ -7,13 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.simplex;
|
||||
|
||||
import com.dfsek.terra.api.noise.DerivativeNoiseSampler;
|
||||
|
||||
|
||||
/**
|
||||
* NoiseSampler implementation to provide OpenSimplex2 noise.
|
||||
*/
|
||||
public class OpenSimplex2Sampler extends SimplexStyleSampler implements DerivativeNoiseSampler {
|
||||
public class OpenSimplex2Sampler extends SimplexStyleSampler {
|
||||
private static final double SQRT3 = 1.7320508075688772935274463415059;
|
||||
|
||||
@Override
|
||||
@@ -40,41 +37,37 @@ public class OpenSimplex2Sampler extends SimplexStyleSampler implements Derivati
|
||||
i *= PRIME_X;
|
||||
j *= PRIME_Y;
|
||||
|
||||
double n0, n1, n2;
|
||||
double value = 0;
|
||||
|
||||
double a = 0.5 - x0 * x0 - y0 * y0;
|
||||
if(a <= 0) n0 = 0;
|
||||
else {
|
||||
n0 = (a * a) * (a * a) * gradCoord(seed, i, j, x0, y0);
|
||||
if(a > 0) {
|
||||
value = (a * a) * (a * a) * gradCoord(seed, i, j, x0, y0);
|
||||
}
|
||||
|
||||
double c = 2 * (1 - 2 * G2) * (1 / G2 - 2) * t + ((-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
|
||||
if(c <= 0) n2 = 0;
|
||||
else {
|
||||
if(c > 0) {
|
||||
double x2 = x0 + (2 * G2 - 1);
|
||||
double y2 = y0 + (2 * G2 - 1);
|
||||
n2 = (c * c) * (c * c) * gradCoord(seed, i + PRIME_X, j + PRIME_Y, x2, y2);
|
||||
value += (c * c) * (c * c) * gradCoord(seed, i + PRIME_X, j + PRIME_Y, x2, y2);
|
||||
}
|
||||
|
||||
if(y0 > x0) {
|
||||
double x1 = x0 + G2;
|
||||
double y1 = y0 + (G2 - 1);
|
||||
double b = 0.5 - x1 * x1 - y1 * y1;
|
||||
if(b <= 0) n1 = 0;
|
||||
else {
|
||||
n1 = (b * b) * (b * b) * gradCoord(seed, i, j + PRIME_Y, x1, y1);
|
||||
if(b > 0) {
|
||||
value += (b * b) * (b * b) * gradCoord(seed, i, j + PRIME_Y, x1, y1);
|
||||
}
|
||||
} else {
|
||||
double x1 = x0 + (G2 - 1);
|
||||
double y1 = y0 + G2;
|
||||
double b = 0.5 - x1 * x1 - y1 * y1;
|
||||
if(b <= 0) n1 = 0;
|
||||
else {
|
||||
n1 = (b * b) * (b * b) * gradCoord(seed, i + PRIME_X, j, x1, y1);
|
||||
if(b > 0) {
|
||||
value += (b * b) * (b * b) * gradCoord(seed, i + PRIME_X, j, x1, y1);
|
||||
}
|
||||
}
|
||||
|
||||
return (n0 + n1 + n2) * 99.83685446303647f;
|
||||
return value * 99.83685446303647f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,16 +156,205 @@ public class OpenSimplex2Sampler extends SimplexStyleSampler implements Derivati
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y) {
|
||||
return new double[0];
|
||||
public double[] getNoiseDerivativeRaw(long sl, double x, double y) {
|
||||
int seed = (int) sl;
|
||||
// 2D OpenSimplex2 case uses the same algorithm as ordinary Simplex.
|
||||
final double G2 = (3 - SQRT3) / 6;
|
||||
|
||||
final double F2 = 0.5f * (SQRT3 - 1);
|
||||
double s = (x + y) * F2;
|
||||
x += s;
|
||||
y += s;
|
||||
|
||||
|
||||
int i = (int) Math.floor(x);
|
||||
int j = (int) Math.floor(y);
|
||||
double xi = x - i;
|
||||
double yi = y - j;
|
||||
|
||||
double t = (xi + yi) * G2;
|
||||
double x0 = xi - t;
|
||||
double y0 = yi - t;
|
||||
|
||||
i *= PRIME_X;
|
||||
j *= PRIME_Y;
|
||||
|
||||
double[] out = { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
double a = 0.5 - x0 * x0 - y0 * y0;
|
||||
if(a > 0) {
|
||||
double aa = a * a, aaa = aa * a, aaaa = aa * aa;
|
||||
int gi = gradCoordIndex(seed, i, j);
|
||||
double gx = GRADIENTS_2_D[gi], gy = GRADIENTS_2_D[gi | 1];
|
||||
double rampValue = gx * x0 + gy * y0;
|
||||
out[0] += aaaa * rampValue;
|
||||
out[1] += gx * aaaa - 8 * rampValue * aaa * x0;
|
||||
out[2] += gy * aaaa - 8 * rampValue * aaa * y0;
|
||||
}
|
||||
|
||||
double c = 2 * (1 - 2 * G2) * (1 / G2 - 2) * t + ((-2 * (1 - 2 * G2) * (1 - 2 * G2)) + a);
|
||||
if(c > 0) {
|
||||
double x2 = x0 + (2 * G2 - 1);
|
||||
double y2 = y0 + (2 * G2 - 1);
|
||||
double cc = c * c, ccc = cc * c, cccc = cc * cc;
|
||||
int gi = gradCoordIndex(seed, i + PRIME_X, j + PRIME_Y);
|
||||
double gx = GRADIENTS_2_D[gi], gy = GRADIENTS_2_D[gi | 1];
|
||||
double rampValue = gx * x2 + gy * y2;
|
||||
out[0] += cccc * rampValue;
|
||||
out[1] += gx * cccc - 8 * rampValue * ccc * x2;
|
||||
out[2] += gy * cccc - 8 * rampValue * ccc * y2;
|
||||
}
|
||||
|
||||
if(y0 > x0) {
|
||||
double x1 = x0 + G2;
|
||||
double y1 = y0 + (G2 - 1);
|
||||
double b = 0.5 - x1 * x1 - y1 * y1;
|
||||
if(b > 0) {
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i, j + PRIME_Y);
|
||||
double gx = GRADIENTS_2_D[gi], gy = GRADIENTS_2_D[gi | 1];
|
||||
double rampValue = gx * x1 + gy * y1;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x1;
|
||||
out[2] += gy * bbbb - 8 * rampValue * bbb * y1;
|
||||
}
|
||||
} else {
|
||||
double x1 = x0 + (G2 - 1);
|
||||
double y1 = y0 + G2;
|
||||
double b = 0.5 - x1 * x1 - y1 * y1;
|
||||
if(b > 0) {
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i + PRIME_X, j);
|
||||
double gx = GRADIENTS_2_D[gi], gy = GRADIENTS_2_D[gi | 1];
|
||||
double rampValue = gx * x1 + gy * y1;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x1;
|
||||
out[2] += gy * bbbb - 8 * rampValue * bbb * y1;
|
||||
}
|
||||
}
|
||||
|
||||
out[0] *= 99.83685446303647f;
|
||||
out[1] *= 99.83685446303647f;
|
||||
out[2] *= 99.83685446303647f;
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] noised(long seed, double x, double y, double z) {
|
||||
return new double[0];
|
||||
public double[] getNoiseDerivativeRaw(long sl, double x, double y, double z) {
|
||||
int seed = (int) sl;
|
||||
// 3D OpenSimplex2Sampler case uses two offset rotated cube grids.
|
||||
final double R3 = (2.0 / 3.0);
|
||||
double r = (x + y + z) * R3; // Rotation, not skew
|
||||
x = r - x;
|
||||
y = r - y;
|
||||
z = r - z;
|
||||
|
||||
|
||||
int i = (int) Math.round(x);
|
||||
int j = (int) Math.round(y);
|
||||
int k = (int) Math.round(z);
|
||||
double x0 = x - i;
|
||||
double y0 = y - j;
|
||||
double z0 = z - k;
|
||||
|
||||
int xNSign = (int) (-1.0 - x0) | 1;
|
||||
int yNSign = (int) (-1.0 - y0) | 1;
|
||||
int zNSign = (int) (-1.0 - z0) | 1;
|
||||
|
||||
double ax0 = xNSign * -x0;
|
||||
double ay0 = yNSign * -y0;
|
||||
double az0 = zNSign * -z0;
|
||||
|
||||
i *= PRIME_X;
|
||||
j *= PRIME_Y;
|
||||
k *= PRIME_Z;
|
||||
|
||||
double[] out = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
double a = (0.6f - x0 * x0) - (y0 * y0 + z0 * z0);
|
||||
|
||||
for(int l = 0; ; l++) {
|
||||
if(a > 0) {
|
||||
double aa = a * a, aaa = aa * a, aaaa = aa * aa;
|
||||
int gi = gradCoordIndex(seed, i, j, k);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * x0 + gy * y0 + gz * z0;
|
||||
out[0] += aaaa * rampValue;
|
||||
out[1] += gx * aaaa - 8 * rampValue * aaa * x0;
|
||||
out[1] += gy * aaaa - 8 * rampValue * aaa * y0;
|
||||
out[2] += gz * aaaa - 8 * rampValue * aaa * z0;
|
||||
}
|
||||
|
||||
if(ax0 >= ay0 && ax0 >= az0) {
|
||||
double b = a + ax0 + ax0;
|
||||
if(b > 1) {
|
||||
b -= 1;
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i - xNSign * PRIME_X, j, k);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * (x0 + xNSign) + gy * y0 + gz * z0;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * (x0 + xNSign);
|
||||
out[1] += gy * bbbb - 8 * rampValue * bbb * y0;
|
||||
out[2] += gz * bbbb - 8 * rampValue * bbb * z0;
|
||||
}
|
||||
} else if(ay0 > ax0 && ay0 >= az0) {
|
||||
double b = a + ay0 + ay0;
|
||||
if(b > 1) {
|
||||
b -= 1;
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i, j - yNSign * PRIME_Y, k);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * x0 + gy * (y0 + yNSign) + gz * z0;
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x0;
|
||||
out[1] += gy * bbbb - 8 * rampValue * bbb * (y0 + yNSign);
|
||||
out[2] += gz * bbbb - 8 * rampValue * bbb * z0;
|
||||
}
|
||||
} else {
|
||||
double b = a + az0 + az0;
|
||||
if(b > 1) {
|
||||
b -= 1;
|
||||
double bb = b * b, bbb = bb * b, bbbb = bb * bb;
|
||||
int gi = gradCoordIndex(seed, i, j, k - zNSign * PRIME_Z);
|
||||
double gx = GRADIENTS_3D[gi], gy = GRADIENTS_3D[gi | 1], gz = GRADIENTS_3D[gi | 2];
|
||||
double rampValue = gx * x0 + gy * y0 + gz * (z0 + zNSign);
|
||||
out[0] += bbbb * rampValue;
|
||||
out[1] += gx * bbbb - 8 * rampValue * bbb * x0;
|
||||
out[1] += gy * bbbb - 8 * rampValue * bbb * y0;
|
||||
out[2] += gz * bbbb - 8 * rampValue * bbb * (z0 + zNSign);
|
||||
}
|
||||
}
|
||||
|
||||
if(l == 1) break;
|
||||
|
||||
ax0 = 0.5 - ax0;
|
||||
ay0 = 0.5 - ay0;
|
||||
az0 = 0.5 - az0;
|
||||
|
||||
x0 = xNSign * ax0;
|
||||
y0 = yNSign * ay0;
|
||||
z0 = zNSign * az0;
|
||||
|
||||
a += (0.75 - ax0) - (ay0 + az0);
|
||||
|
||||
i += (xNSign >> 1) & PRIME_X;
|
||||
j += (yNSign >> 1) & PRIME_Y;
|
||||
k += (zNSign >> 1) & PRIME_Z;
|
||||
|
||||
xNSign = -xNSign;
|
||||
yNSign = -yNSign;
|
||||
zNSign = -zNSign;
|
||||
|
||||
seed = ~seed;
|
||||
}
|
||||
out[0] *= 32.69428253173828125;
|
||||
out[1] *= 32.69428253173828125;
|
||||
out[2] *= 32.69428253173828125;
|
||||
out[3] *= 32.69428253173828125;
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
+18
-2
@@ -7,13 +7,13 @@
|
||||
|
||||
package com.dfsek.terra.addons.noise.samplers.noise.simplex;
|
||||
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.NoiseFunction;
|
||||
import com.dfsek.terra.addons.noise.samplers.noise.DerivativeNoiseFunction;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract NoiseSampler implementation for simplex-style noise functions.
|
||||
*/
|
||||
public abstract class SimplexStyleSampler extends NoiseFunction {
|
||||
public abstract class SimplexStyleSampler extends DerivativeNoiseFunction {
|
||||
protected static final double[] GRADIENTS_2_D = {
|
||||
0.130526192220052d, 0.99144486137381d, 0.38268343236509d, 0.923879532511287d, 0.608761429008721d, 0.793353340291235d,
|
||||
0.793353340291235d, 0.608761429008721d, 0.923879532511287d, 0.38268343236509d, 0.99144486137381d, 0.130526192220051d,
|
||||
@@ -78,6 +78,7 @@ public abstract class SimplexStyleSampler extends NoiseFunction {
|
||||
1, 1, 0, 0, -1, 1, 0, 0, 1, -1, 0, 0, -1, -1, 0, 0,
|
||||
1, 1, 0, 0, 0, -1, 1, 0, -1, 1, 0, 0, 0, -1, -1, 0
|
||||
};
|
||||
|
||||
protected static int gradCoordIndex(int seed, int xPrimed, int yPrimed) {
|
||||
int hash = hash(seed, xPrimed, yPrimed);
|
||||
hash ^= hash >> 15;
|
||||
@@ -112,4 +113,19 @@ public abstract class SimplexStyleSampler extends NoiseFunction {
|
||||
|
||||
return xd * xg + yd * yg + zd * zg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y) {
|
||||
throw new UnsupportedOperationException("Implementation failed to check or set isDifferentiable correctly");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] getNoiseDerivativeRaw(long seed, double x, double y, double z) {
|
||||
throw new UnsupportedOperationException("Implementation failed to check or set isDifferentiable correctly");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDifferentiable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-7
@@ -11,13 +11,6 @@ import com.dfsek.tectonic.api.config.template.dynamic.DynamicTemplate;
|
||||
import com.dfsek.tectonic.api.config.template.dynamic.DynamicValue;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.generation.feature.config.BiomeFeatures;
|
||||
import com.dfsek.terra.addons.generation.feature.config.FeatureStageTemplate;
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
@@ -35,6 +28,9 @@ import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public class FeatureGenerationAddon implements AddonInitializer {
|
||||
public static final TypeKey<Supplier<ObjectTemplate<GenerationStage>>> STAGE_TYPE_KEY = new TypeKey<>() {
|
||||
|
||||
+3
-3
@@ -7,9 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.generation.feature;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.generation.feature.config.BiomeFeatures;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
@@ -22,6 +19,9 @@ import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
||||
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.Column;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class FeatureGenerationStage implements GenerationStage, StringIdentifiable {
|
||||
private final Platform platform;
|
||||
|
||||
+2
-2
@@ -1,7 +1,5 @@
|
||||
package com.dfsek.terra.addons.structure.mutator;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.registry.key.Keyed;
|
||||
import com.dfsek.terra.api.registry.key.RegistryKey;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
@@ -11,6 +9,8 @@ import com.dfsek.terra.api.world.WritableWorld;
|
||||
import com.dfsek.terra.api.world.util.ReadInterceptor;
|
||||
import com.dfsek.terra.api.world.util.WriteInterceptor;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class MutatedStructure implements Structure, Keyed<MutatedStructure> {
|
||||
private final RegistryKey key;
|
||||
|
||||
+4
-4
@@ -7,15 +7,15 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Token;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Token;
|
||||
|
||||
|
||||
public class ParserUtil {
|
||||
|
||||
|
||||
+2
-2
@@ -7,13 +7,13 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.CheckBlockFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class CheckBlockFunctionBuilder implements FunctionBuilder<CheckBlockFunction> {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -81,4 +81,7 @@ public interface Platform extends LoaderRegistrar {
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
Profiler getProfiler();
|
||||
|
||||
@Contract(pure = true)
|
||||
int getGenerationThreads();
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.dfsek.terra.api.event.events.platform;
|
||||
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
|
||||
public class CommandRegistrationEvent implements Event {
|
||||
private final CommandManager<CommandSender> commandManager;
|
||||
|
||||
@@ -6,10 +6,7 @@ package com.dfsek.terra.api.noise;
|
||||
public interface DerivativeNoiseSampler extends NoiseSampler {
|
||||
|
||||
static boolean isDifferentiable(NoiseSampler sampler) {
|
||||
if (sampler instanceof DerivativeNoiseSampler dSampler) {
|
||||
return dSampler.isDifferentiable();
|
||||
}
|
||||
return false;
|
||||
return sampler instanceof DerivativeNoiseSampler dSampler && dSampler.isDifferentiable();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,19 +19,23 @@ public interface DerivativeNoiseSampler extends NoiseSampler {
|
||||
|
||||
/**
|
||||
* Derivative return version of standard 2D noise evaluation
|
||||
*
|
||||
* @param seed
|
||||
* @param x
|
||||
* @param y
|
||||
*
|
||||
* @return 3 element array, in index order: noise value, partial x derivative, partial y derivative
|
||||
*/
|
||||
double[] noised(long seed, double x, double y);
|
||||
|
||||
/**
|
||||
* Derivative return version of standard 3D noise evaluation
|
||||
*
|
||||
* @param seed
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*
|
||||
* @return 4 element array, in index order: noise value, partial x derivative, partial y derivative, partial z derivative
|
||||
*/
|
||||
double[] noised(long seed, double x, double y, double z);
|
||||
|
||||
+4
-2
@@ -7,6 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.api.world.biome.generation;
|
||||
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -91,11 +93,11 @@ public interface BiomeProvider {
|
||||
return StreamSupport.stream(getBiomes().spliterator(), false);
|
||||
}
|
||||
|
||||
default CachingBiomeProvider caching() {
|
||||
default CachingBiomeProvider caching(Platform platform) {
|
||||
if(this instanceof CachingBiomeProvider cachingBiomeProvider) {
|
||||
return cachingBiomeProvider;
|
||||
}
|
||||
return new CachingBiomeProvider(this);
|
||||
return new CachingBiomeProvider(this, platform.getGenerationThreads());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+7
-6
@@ -21,19 +21,20 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
|
||||
private final LoadingCache<SeededVector3, Biome> cache;
|
||||
private final LoadingCache<SeededVector2, Optional<Biome>> baseCache;
|
||||
|
||||
protected CachingBiomeProvider(BiomeProvider delegate) {
|
||||
protected CachingBiomeProvider(BiomeProvider delegate, int generationThreads) {
|
||||
this.delegate = delegate;
|
||||
this.res = delegate.resolution();
|
||||
int size = generationThreads * 98304;
|
||||
this.cache = Caffeine
|
||||
.newBuilder()
|
||||
.scheduler(Scheduler.disabledScheduler())
|
||||
.initialCapacity(98304)
|
||||
.maximumSize(98304) // 1 full chunk (high res)
|
||||
.initialCapacity(size)
|
||||
.maximumSize(size) // 1 full chunk (high res)
|
||||
.build(vec -> delegate.getBiome(vec.x * res, vec.y * res, vec.z * res, vec.seed));
|
||||
|
||||
this.baseCache = Caffeine
|
||||
.newBuilder()
|
||||
.maximumSize(256) // 1 full chunk (high res)
|
||||
.maximumSize(256L * generationThreads) // 1 full chunk (high res)
|
||||
.build(vec -> delegate.getBaseBiome(vec.x * res, vec.z * res, vec.seed));
|
||||
|
||||
}
|
||||
@@ -77,7 +78,7 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
|
||||
int code = x;
|
||||
code = 31 * code + y;
|
||||
code = 31 * code + z;
|
||||
return 31 * code + ((int) (seed ^ (seed >>> 32)));
|
||||
return 31 * code + (Long.hashCode(seed));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ public class CachingBiomeProvider implements BiomeProvider, Handle {
|
||||
public int hashCode() {
|
||||
int code = x;
|
||||
code = 31 * code + z;
|
||||
return 31 * code + ((int) (seed ^ (seed >>> 32)));
|
||||
return 31 * code + (Long.hashCode(seed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,6 +310,24 @@ public abstract class AbstractPlatform implements Platform {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getGenerationThreadsWithReflection(String className, String fieldName, String project) {
|
||||
try {
|
||||
Class aClass = Class.forName(className);
|
||||
int threads = aClass.getField(fieldName).getInt(null);
|
||||
logger.info("{} found, setting {} generation threads.", project, threads);
|
||||
return threads;
|
||||
} catch(ClassNotFoundException e) {
|
||||
logger.info("{} not found.", project);
|
||||
} catch(NoSuchFieldException e) {
|
||||
logger.warn("{} found, but {} field not found this probably means {0} has changed its code and " +
|
||||
"Terra has not updated to reflect that.", project, fieldName);
|
||||
} catch(IllegalAccessException e) {
|
||||
logger.error("Failed to access {} field in {}, assuming 1 generation thread.", fieldName, project, e);
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
loaders.register(registry);
|
||||
@@ -339,4 +357,9 @@ public abstract class AbstractPlatform implements Platform {
|
||||
public @NotNull Profiler getProfiler() {
|
||||
return profiler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenerationThreads() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -232,7 +232,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
selfLoader.load(packPostTemplate, packManifest);
|
||||
seededBiomeProvider =
|
||||
template.getBiomeCache() ? packPostTemplate.getProviderBuilder().caching() : packPostTemplate.getProviderBuilder();
|
||||
template.getBiomeCache() ? packPostTemplate.getProviderBuilder().caching(platform) : packPostTemplate.getProviderBuilder();
|
||||
checkDeadEntries();
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -24,14 +24,15 @@ import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import com.dfsek.tectonic.api.loader.ConfigLoader;
|
||||
import com.dfsek.tectonic.api.preprocessor.Result;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
|
||||
public class MetaNumberPreprocessor extends MetaPreprocessor<Meta> {
|
||||
public static final TypeKey<String> META_STRING_KEY = new TypeKey<@Meta String>() {
|
||||
|
||||
+11
-6
@@ -17,6 +17,17 @@
|
||||
|
||||
package com.dfsek.terra.event;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.Event;
|
||||
import com.dfsek.terra.api.event.events.FailThroughEvent;
|
||||
@@ -25,12 +36,6 @@ import com.dfsek.terra.api.event.functional.EventContext;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class FunctionalEventHandlerImpl implements FunctionalEventHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FunctionalEventHandlerImpl.class);
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
|
||||
package com.dfsek.terra.bukkit;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Location;
|
||||
|
||||
|
||||
public class BukkitEntity implements Entity {
|
||||
private final org.bukkit.entity.Entity entity;
|
||||
|
||||
@@ -51,7 +51,13 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
|
||||
private final TerraBukkitPlugin plugin;
|
||||
|
||||
private int generationThreads;
|
||||
|
||||
public PlatformImpl(TerraBukkitPlugin plugin) {
|
||||
generationThreads = getGenerationThreadsWithReflection("ca.spottedleaf.moonrise.common.util.MoonriseCommon", "WORKER_THREADS", "Moonrise");
|
||||
if (generationThreads == 0) {
|
||||
generationThreads = 1;
|
||||
}
|
||||
this.plugin = plugin;
|
||||
load();
|
||||
}
|
||||
@@ -108,6 +114,11 @@ public class PlatformImpl extends AbstractPlatform {
|
||||
return itemHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenerationThreads() {
|
||||
return generationThreads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
|
||||
+2
-20
@@ -23,13 +23,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.bukkit.util.BukkitUtils;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
|
||||
|
||||
public class BukkitWorldHandle implements WorldHandle {
|
||||
@@ -61,22 +59,6 @@ public class BukkitWorldHandle implements WorldHandle {
|
||||
|
||||
@Override
|
||||
public @NotNull EntityType getEntity(@NotNull String id) {
|
||||
if(!id.contains(":")) { //TODO: remove in 7.0
|
||||
String newid = "minecraft:" + id.toLowerCase();
|
||||
;
|
||||
logger.warn(
|
||||
"Translating " + id + " to " + newid + ". In 1.20.3 entity parsing was reworked" +
|
||||
". You are advised to perform this rename in your config backs as this translation will be removed in the next major " +
|
||||
"version of Terra.");
|
||||
}
|
||||
if(!id.startsWith("minecraft:")) throw new IllegalArgumentException("Invalid entity identifier " + id);
|
||||
String entityID = id.toUpperCase(Locale.ROOT).substring(10);
|
||||
|
||||
return new BukkitEntityType(switch(entityID) {
|
||||
case "END_CRYSTAL" -> org.bukkit.entity.EntityType.END_CRYSTAL;
|
||||
case "ENDER_CRYSTAL" -> throw new IllegalArgumentException(
|
||||
"Invalid entity identifier " + id); // make sure this issue can't happen the other way around.
|
||||
default -> org.bukkit.entity.EntityType.valueOf(entityID);
|
||||
});
|
||||
return BukkitUtils.getEntityType(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,40 @@ package com.dfsek.terra.bukkit.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
|
||||
|
||||
public class BukkitUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BukkitUtils.class);
|
||||
|
||||
public static boolean isLiquid(BlockData blockState) {
|
||||
Material material = blockState.getMaterial();
|
||||
return material == Material.WATER || material == Material.LAVA;
|
||||
}
|
||||
|
||||
public static EntityType getEntityType(String id) {
|
||||
if(!id.contains(":")) { //TODO: remove in 7.0
|
||||
String newid = "minecraft:" + id.toLowerCase();
|
||||
;
|
||||
logger.warn(
|
||||
"Translating " + id + " to " + newid + ". In 1.20.3 entity parsing was reworked" +
|
||||
". You are advised to perform this rename in your config backs as this translation will be removed in the next major " +
|
||||
"version of Terra.");
|
||||
}
|
||||
if(!id.startsWith("minecraft:")) throw new IllegalArgumentException("Invalid entity identifier " + id);
|
||||
String entityID = id.toUpperCase(Locale.ROOT).substring(10);
|
||||
|
||||
return new BukkitEntityType(switch(entityID) {
|
||||
case "END_CRYSTAL" -> org.bukkit.entity.EntityType.END_CRYSTAL;
|
||||
case "ENDER_CRYSTAL" -> throw new IllegalArgumentException(
|
||||
"Invalid entity identifier " + id); // make sure this issue can't happen the other way around.
|
||||
default -> org.bukkit.entity.EntityType.valueOf(entityID);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -46,27 +45,12 @@ import com.dfsek.terra.bukkit.world.block.BukkitBlockTypeAndItem;
|
||||
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockState;
|
||||
import com.dfsek.terra.bukkit.world.inventory.BukkitItemStack;
|
||||
import com.dfsek.terra.bukkit.world.inventory.meta.BukkitEnchantment;
|
||||
import com.dfsek.terra.transform.MapTransform;
|
||||
import com.dfsek.terra.transform.TransformerImpl;
|
||||
|
||||
|
||||
/**
|
||||
* Utility class to adapt Bukkit enums to Terra enums.
|
||||
*/
|
||||
public final class BukkitAdapter {
|
||||
public static TransformerImpl<TreeType, String> TREE_TRANSFORMER = new TransformerImpl.Builder<TreeType, String>()
|
||||
.addTransform(new MapTransform<TreeType, String>()
|
||||
.add(TreeType.COCOA_TREE, "JUNGLE_COCOA")
|
||||
.add(TreeType.BIG_TREE, "LARGE_OAK")
|
||||
.add(TreeType.TALL_REDWOOD, "LARGE_SPRUCE")
|
||||
.add(TreeType.REDWOOD, "SPRUCE")
|
||||
.add(TreeType.TREE, "OAK")
|
||||
.add(TreeType.MEGA_REDWOOD, "MEGA_SPRUCE")
|
||||
.add(TreeType.SWAMP, "SWAMP_OAK"))
|
||||
.addTransform(TreeType::toString)
|
||||
.build();
|
||||
|
||||
|
||||
public static BlockState adapt(org.bukkit.block.data.BlockData data) {
|
||||
return BukkitBlockState.newInstance(data);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.bukkit.world;
|
||||
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
|
||||
|
||||
public class BukkitWorldProperties implements WorldProperties {
|
||||
private final WorldInfo delegate;
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import com.dfsek.terra.api.block.entity.MobSpawner;
|
||||
import com.dfsek.terra.api.block.entity.SerialState;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.bukkit.util.BukkitUtils;
|
||||
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
|
||||
|
||||
|
||||
@@ -115,7 +116,7 @@ public class BukkitMobSpawner extends BukkitBlockEntity implements MobSpawner {
|
||||
public void applyState(String state) {
|
||||
SerialState.parse(state).forEach((k, v) -> {
|
||||
switch(k) {
|
||||
case "type" -> setSpawnedType(new BukkitEntityType(org.bukkit.entity.EntityType.valueOf(v.toUpperCase())));
|
||||
case "type" -> setSpawnedType(BukkitUtils.getEntityType(v));
|
||||
case "delay" -> setDelay(Integer.parseInt(v));
|
||||
case "min_delay" -> setMinSpawnDelay(Integer.parseInt(v));
|
||||
case "max_delay" -> setMaxSpawnDelay(Integer.parseInt(v));
|
||||
|
||||
@@ -2,8 +2,8 @@ name: "Terra"
|
||||
main: "com.dfsek.terra.bukkit.TerraBukkitPlugin"
|
||||
version: "@VERSION@"
|
||||
load: "STARTUP"
|
||||
author: dfsek
|
||||
authors: [ "dfsek", "duplexsystem", "Astrash", "solonovamax", "Sancires", "Aureus", "RogueShade" ]
|
||||
website: "@WIKI@"
|
||||
api-version: "1.20"
|
||||
api-version: "1.21.1"
|
||||
description: "@DESCRIPTION@"
|
||||
folia-supported: true
|
||||
|
||||
@@ -10,6 +10,9 @@ dependencies {
|
||||
shadedApi("commons-io", "commons-io", Versions.Libraries.Internal.apacheIO)
|
||||
shadedApi("com.github.Querz", "NBT", Versions.CLI.nbt)
|
||||
|
||||
shadedImplementation("info.picocli", "picocli", Versions.CLI.picocli)
|
||||
annotationProcessor("info.picocli", "picocli-codegen", Versions.CLI.picocli)
|
||||
|
||||
shadedImplementation("com.google.guava", "guava", Versions.Libraries.Internal.guava)
|
||||
|
||||
shadedImplementation("ch.qos.logback", "logback-classic", Versions.CLI.logback)
|
||||
@@ -26,6 +29,12 @@ tasks.withType<Jar> {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
doFirst {
|
||||
options.compilerArgs.add("-Aproject=${project.group}/${project.name}")
|
||||
}
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set(javaMainClass)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public class CLIPlatform extends AbstractPlatform {
|
||||
private final CLIWorldHandle worldHandle = new CLIWorldHandle();
|
||||
private final CLIItemHandle itemHandle = new CLIItemHandle();
|
||||
|
||||
private final int generationThreads = Runtime.getRuntime().availableProcessors() - 1;
|
||||
|
||||
public CLIPlatform() {
|
||||
LOGGER.info("Root directory: {}", getDataFolder().getAbsoluteFile());
|
||||
load();
|
||||
@@ -58,4 +60,9 @@ public class CLIPlatform extends AbstractPlatform {
|
||||
super.register(registry);
|
||||
registry.registerLoader(PlatformBiome.class, (TypeLoader<PlatformBiome>) (annotatedType, o, configLoader, depthTracker) -> () -> o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenerationThreads() {
|
||||
return generationThreads;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,41 +5,74 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.api.util.vector.Vector2Int;
|
||||
import com.dfsek.terra.cli.world.CLIWorld;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.Option;
|
||||
|
||||
public final class TerraCLI {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TerraCLI.class);
|
||||
|
||||
public static void main(String... args) {
|
||||
//TODO auto pull in version
|
||||
@Command(name = "TerraCLI", mixinStandardHelpOptions = true, version = "6.6.0",
|
||||
description = "Generates a Terra World and saves it in minecraft region format.")
|
||||
public final class TerraCLI implements Callable<Integer> {
|
||||
@Option(names = { "-s", "--size"}, description = "Number of regions to generate.")
|
||||
private int size = 2;
|
||||
|
||||
@Option(names = { "-p", "--pack"}, description = "Config pack to use.")
|
||||
private String pack = "OVERWORLD";
|
||||
|
||||
@Option(names = { "--seed"}, description = "Seed for world generation.")
|
||||
private long seed = 0;
|
||||
|
||||
@Option(names = { "--max-height"}, description = "Maximum height of the world.")
|
||||
private int maxHeight = 384;
|
||||
|
||||
@Option(names = { "--min-height"}, description = "Minimum height of the world.")
|
||||
private int minHeight = -64;
|
||||
|
||||
@Option(names = { "--no-save"}, description = "Don't save the world to disk.")
|
||||
private boolean noSave = false;
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
Logger LOGGER = LoggerFactory.getLogger(TerraCLI.class);
|
||||
LOGGER.info("Starting Terra CLI...");
|
||||
|
||||
CLIPlatform platform = new CLIPlatform();
|
||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
|
||||
ConfigPack generate = platform.getConfigRegistry().getByID("OVERWORLD").orElseThrow(); // TODO: make this a cli argument
|
||||
ConfigPack generate = platform.getConfigRegistry().getByID(pack).orElseThrow();
|
||||
|
||||
CLIWorld world = new CLIWorld(2, 2, 384, -64, generate);
|
||||
CLIWorld world = new CLIWorld(size, seed, maxHeight, minHeight, generate, noSave);
|
||||
|
||||
world.generate();
|
||||
|
||||
world.serialize().parallel().forEach(mcaFile -> {
|
||||
Vector2Int pos = mcaFile.getLeft();
|
||||
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
|
||||
LOGGER.info("Writing region ({}, {}) to {}", pos.getX(), pos.getZ(), name);
|
||||
if(!noSave) {
|
||||
world.serialize().parallel().forEach(mcaFile -> {
|
||||
Vector2Int pos = mcaFile.getLeft();
|
||||
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
|
||||
LOGGER.info("Writing region ({}, {}) to {}", pos.getX(), pos.getZ(), name);
|
||||
|
||||
try {
|
||||
MCAUtil.write(mcaFile.getRight(), name);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LOGGER.info("Wrote region to file.");
|
||||
});
|
||||
try {
|
||||
MCAUtil.write(mcaFile.getRight(), name);
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LOGGER.info("Wrote region to file.");
|
||||
});
|
||||
}
|
||||
LOGGER.info("Done.");
|
||||
System.exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void main(String... args) {
|
||||
int exitCode = new CommandLine(new TerraCLI()).execute(args);
|
||||
System.exit(exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
private final ChunkGenerator chunkGenerator;
|
||||
private final BiomeProvider biomeProvider;
|
||||
private final ConfigPack pack;
|
||||
private final boolean noSave;
|
||||
private final AtomicInteger amount = new AtomicInteger(0);
|
||||
|
||||
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1);
|
||||
@@ -51,7 +52,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
long seed,
|
||||
int maxHeight,
|
||||
int minHeight,
|
||||
ConfigPack pack) {
|
||||
ConfigPack pack, boolean noSave) {
|
||||
this.size = size;
|
||||
this.maxHeight = maxHeight;
|
||||
this.minHeight = minHeight;
|
||||
@@ -59,6 +60,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
this.chunkGenerator = pack.getGeneratorProvider().newInstance(pack);
|
||||
this.biomeProvider = pack.getBiomeProvider();
|
||||
this.pack = pack;
|
||||
this.noSave = noSave;
|
||||
|
||||
|
||||
size += 1;
|
||||
@@ -73,6 +75,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
ArrayList<Double> CPSHistory = new ArrayList<>();
|
||||
int sizeChunks = size * 32;
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
final AtomicLong start = new AtomicLong(System.nanoTime());
|
||||
@@ -83,7 +86,13 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
futures.add(executor.submit(() -> {
|
||||
try {
|
||||
int num = amount.getAndIncrement();
|
||||
CLIChunk chunk = getChunkAt(finalX, finalZ);
|
||||
CLIChunk chunk;
|
||||
if (!noSave) {
|
||||
chunk = getChunkAt(finalX, finalZ);
|
||||
} else {
|
||||
chunk = new CLIChunk(Math.floorMod(finalX, 32), Math.floorMod(finalZ, 32), this);
|
||||
}
|
||||
|
||||
BiomeProvider cachingBiomeProvider = pack.getBiomeProvider();
|
||||
chunkGenerator.generateChunkData(chunk, this, cachingBiomeProvider, finalX, finalZ);
|
||||
CLIProtoWorld protoWorld = new CLIProtoWorld(this, cachingBiomeProvider, finalX, finalZ);
|
||||
@@ -91,6 +100,7 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
if(num % 240 == 239) {
|
||||
long time = System.nanoTime();
|
||||
double cps = num / ((double) (time - start.get()) / 1000000000);
|
||||
CPSHistory.add(cps);
|
||||
LOGGER.info("Generating chunk at ({}, {}), generated {} chunks at {}cps", finalX, finalZ, num, cps);
|
||||
amount.set(0);
|
||||
start.set(System.nanoTime());
|
||||
@@ -109,6 +119,8 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("Average CPS: {}", CPSHistory.stream().mapToDouble(d -> d).average().orElse(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,13 @@
|
||||
"name": "Terra",
|
||||
"description": "@DESCRIPTION@",
|
||||
"authors": [
|
||||
"dfsek"
|
||||
"dfsek",
|
||||
"duplexsystem",
|
||||
"Astrash",
|
||||
"solonovamax",
|
||||
"Sancires",
|
||||
"Aureus",
|
||||
"RogueShade"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "@WIKI@",
|
||||
@@ -28,7 +34,7 @@
|
||||
"depends": {
|
||||
"fabricloader": ">=0.16.5",
|
||||
"java": ">=21",
|
||||
"minecraft": ">=1.20.6",
|
||||
"minecraft": ">=1.21.1",
|
||||
"fabric": "*"
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.lifecycle;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import org.incendo.cloud.SenderMapper;
|
||||
import org.incendo.cloud.execution.ExecutionCoordinator;
|
||||
@@ -7,9 +10,6 @@ import org.incendo.cloud.fabric.FabricServerCommandManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.api.command.CommandSender;
|
||||
import com.dfsek.terra.api.event.events.platform.CommandRegistrationEvent;
|
||||
|
||||
|
||||
public final class LifecycleEntryPoint {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LifecycleEntryPoint.class);
|
||||
|
||||
+12
@@ -3,6 +3,9 @@ package com.dfsek.terra.lifecycle;
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.parser.tokenizer.ParseException;
|
||||
import ca.solostudios.strata.version.Version;
|
||||
|
||||
import com.dfsek.terra.api.util.reflection.ReflectionUtil;
|
||||
|
||||
import net.minecraft.MinecraftVersion;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.registry.Registry;
|
||||
@@ -37,8 +40,15 @@ public abstract class LifecyclePlatform extends ModPlatform {
|
||||
private static final AtomicReference<Registry<MultiNoiseBiomeSourceParameterList>> NOISE = new AtomicReference<>();
|
||||
private static final AtomicReference<Registry<Enchantment>> ENCHANTMENT = new AtomicReference<>();
|
||||
private static MinecraftServer server;
|
||||
private int generationThreads;
|
||||
|
||||
public LifecyclePlatform() {
|
||||
generationThreads = getGenerationThreadsWithReflection("com.ishland.c2me.base.common.GlobalExecutors", "GLOBAL_EXECUTOR_PARALLELISM", "C2ME");
|
||||
if (generationThreads == 0) {
|
||||
generationThreads = getGenerationThreadsWithReflection("ca.spottedleaf.moonrise.common.util.MoonriseCommon", "WORKER_THREADS", "Moonrise");
|
||||
} if (generationThreads == 0) {
|
||||
generationThreads = 1;
|
||||
}
|
||||
CommonPlatform.initialize(this);
|
||||
load();
|
||||
}
|
||||
@@ -55,6 +65,8 @@ public abstract class LifecyclePlatform extends ModPlatform {
|
||||
ENCHANTMENT.set(enchantmentRegistry);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public MinecraftServer getServer() {
|
||||
return server;
|
||||
|
||||
+1
@@ -18,6 +18,7 @@ import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
|
||||
import static com.dfsek.terra.lifecycle.util.LifecycleUtil.initialized;
|
||||
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MinecraftServerMixin {
|
||||
@Inject(method = "<init>(Ljava/lang/Thread;Lnet/minecraft/world/level/storage/LevelStorage$Session;" +
|
||||
|
||||
+1
@@ -13,6 +13,7 @@ import com.dfsek.terra.mod.CommonPlatform;
|
||||
|
||||
public final class LifecycleUtil {
|
||||
public static boolean initialized = false;
|
||||
|
||||
private LifecycleUtil() {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user