This commit is contained in:
Dan Macbook 2020-08-13 07:04:50 -04:00
parent 93866dc466
commit 887d355dea
8 changed files with 72 additions and 26 deletions

View File

@ -120,14 +120,14 @@ public abstract class DimensionChunkGenerator extends ContextualChunkGenerator
{
return (getDimension().cosRotate() * rx) + (-getDimension().sinRotate() * rz) +
getDimension().getCoordFracture(masterRandom, 39392).fitDoubleD(-getDimension().getCoordFractureDistance() / 2, getDimension().getCoordFractureDistance() / 2, rx, rz);
getDimension().getCoordFracture(masterRandom, 39392).fitDouble(-getDimension().getCoordFractureDistance() / 2, getDimension().getCoordFractureDistance() / 2, rx, rz);
}
public double getModifiedZ(int rx, int rz)
{
return (getDimension().sinRotate() * rx) + (getDimension().cosRotate() * rz) +
getDimension().getCoordFracture(masterRandom, 39392).fitDoubleD(-getDimension().getCoordFractureDistance() / 2, getDimension().getCoordFractureDistance() / 2, rx, rz);
getDimension().getCoordFracture(masterRandom, 39392).fitDouble(-getDimension().getCoordFractureDistance() / 2, getDimension().getCoordFractureDistance() / 2, rx, rz);
}
public double getZoomed(double modified)

View File

@ -60,7 +60,7 @@ public class GenLayerCave extends GenLayer
double distanceTake = 0.0022 * baseWidth;
double drop = (-i * 17) + 44 + iris.getDimension().getCaveShift();
double caveHeightNoise = incline * gincline.noise((wx + (10000 * i)), (wz - (10000 * i)));
caveHeightNoise += shuffle.fitDoubleD(-1, 1, wxx - caveHeightNoise, wzz + caveHeightNoise) * 3;
caveHeightNoise += shuffle.fitDouble(-1, 1, wxx - caveHeightNoise, wzz + caveHeightNoise) * 3;
int ceiling = -256;
int floor = 512;

View File

@ -2,6 +2,7 @@ package com.volmit.iris.noise;
import java.util.List;
import com.volmit.iris.util.IRare;
import com.volmit.iris.util.IrisInterpolation;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.NoiseInjector;
@ -21,6 +22,7 @@ public class CNG {
public static final NoiseInjector DST_MOD = (s, v) -> new double[] { v % s, 0 };
public static final NoiseInjector DST_POW = (s, v) -> new double[] { Math.pow(v, s), 0 };
private double scale;
private double bakedScale;
private double fscale;
private KList<CNG> children;
private CNG fracture;
@ -65,7 +67,8 @@ public class CNG {
new CNG(rng.nextParallelRNG(18), 1, 1).scale(0.9)
.fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.21)
.fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.9), 620), 145),
44);
44)
.bake();
// @done
}
@ -76,16 +79,20 @@ public class CNG {
new CNG(rng.nextParallelRNG(18), 1, 1).scale(0.5)
.fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.11)
.fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.4), 620), 145),
44);
44)
.bake();
// @done
}
public static CNG signatureHalf(RNG rng, NoiseType t) {
// @builder
return new CNG(rng.nextParallelRNG(127), t, 1D, 1).fractureWith(
new CNG(rng.nextParallelRNG(18), 1, 1).scale(0.9).fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1)
.scale(0.21).fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.9), 420), 99),
22);
return new CNG(rng.nextParallelRNG(127), t, 1D, 1)
.fractureWith(
new CNG(rng.nextParallelRNG(18), 1, 1).scale(0.9)
.fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.21)
.fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.9), 420), 99),
22)
.bake();
// @done
}
@ -108,6 +115,7 @@ public class CNG {
power = 1;
scale = 1;
patch = 1;
bakedScale = 1;
fscale = 1;
down = 0;
up = 0;
@ -121,6 +129,12 @@ public class CNG {
}
}
public CNG bake() {
bakedScale *= scale;
scale = 1;
return this;
}
public CNG child(CNG c) {
if (children == null) {
children = new KList<>();
@ -170,6 +184,47 @@ public class CNG {
return this;
}
public <T extends IRare> T fitRarity(List<T> l, double... dim) {
if (l.isEmpty()) {
return null;
}
if (l.size() == 1) {
return l.get(0);
}
int total = 0;
boolean allOne = true;
for (T i : l) {
int r = i.getRarity();
if (r > 1) {
allOne = false;
}
total += r;
}
int m = fit(0, total - 1, dim);
if (m == 0) {
return l.get(0);
}
if (allOne) {
return l.get(m);
}
T c = l.get(0);
while (m > 0) {
m -= c.getRarity();
}
return c;
}
public <T> T fit(T[] v, double... dim) {
if (v.length == 0) {
return null;
@ -204,7 +259,7 @@ public class CNG {
return (int) Math.round(IrisInterpolation.lerp(min, max, noise));
}
public int fitDouble(double min, double max, double... dim) {
public int fit(double min, double max, double... dim) {
if (min == max) {
return (int) Math.round(min);
}
@ -214,7 +269,7 @@ public class CNG {
return (int) Math.round(IrisInterpolation.lerp(min, max, noise));
}
public double fitDoubleD(double min, double max, double... dim) {
public double fitDouble(double min, double max, double... dim) {
if (min == max) {
return min;
}
@ -224,17 +279,8 @@ public class CNG {
return IrisInterpolation.lerp(min, max, noise);
}
public int fitDoubleExponent(double min, double max, double exponent, double... dim) {
if (min == max) {
return (int) Math.round(min);
}
double noise = noise(dim);
return (int) Math.round(IrisInterpolation.lerp(min, max, exponent == 1 ? noise : Math.pow(noise, exponent)));
}
public double noise(double... dim) {
double scale = this.bakedScale * this.scale;
double f = fracture != null ? (fracture.noise(dim) - 0.5) * fscale : 0D;
double x = dim.length > 0 ? dim[0] + f : 0D;
double y = dim.length > 1 ? dim[1] - f : 0D;

View File

@ -147,7 +147,7 @@ public class IrisBiomeDecorator {
xx /= getZoom();
zz /= getZoom();
if (getGenerator(rng).fitDoubleD(0D, 1D, xx, zz) <= chance) {
if (getGenerator(rng).fitDouble(0D, 1D, xx, zz) <= chance) {
if (getBlockData().size() == 1) {
return getBlockData().get(0);
}

View File

@ -126,7 +126,7 @@ public class IrisNoiseGenerator
g += 819;
}
double n = getGenerator(superSeed).fitDoubleD(0, opacity, (x / zoom) + offsetX, (z / zoom) + offsetZ);
double n = getGenerator(superSeed).fitDouble(0, opacity, (x / zoom) + offsetX, (z / zoom) + offsetZ);
n = negative ? (-n + opacity) : n;
n = (exponent != 1 ? n < 0 ? -Math.pow(-n, exponent) : Math.pow(n, exponent) : n) + offsetY;
n = parametric ? IrisInterpolation.parametric(n, 1) : n;

View File

@ -219,7 +219,7 @@ public class IrisRegion extends IrisRegistrant implements IRare
public double getShoreHeight(double x, double z)
{
return getShoreHeightGenerator().fitDoubleD(shoreHeightMin, shoreHeightMax, x / shoreHeightZoom, z / shoreHeightZoom);
return getShoreHeightGenerator().fitDouble(shoreHeightMin, shoreHeightMax, x / shoreHeightZoom, z / shoreHeightZoom);
}
public KList<IrisBiome> getAllBiomes(ContextualChunkGenerator g)

View File

@ -130,7 +130,7 @@ public class IrisStructure extends IrisRegistrant
}
BlockPosition p = asTileHorizon(new BlockPosition((int) x, (int) y, (int) z), face);
return (getWallGenerator(rng).fitDoubleD(0, 1, p.getX(), p.getY(), p.getZ()) < getWallChance());
return (getWallGenerator(rng).fitDouble(0, 1, p.getX(), p.getY(), p.getZ()) < getWallChance());
}
public int getTileHorizon(double v)

View File

@ -330,6 +330,6 @@ public enum NoiseStyle {
}
public CNG create(RNG seed) {
return f.create(seed);
return f.create(seed).bake();
}
}