Supercarves

This commit is contained in:
Daniel Mills
2020-09-03 03:59:03 -04:00
parent 3663b9f957
commit 607a7be337
13 changed files with 274 additions and 99 deletions

View File

@@ -1,37 +1,79 @@
package com.volmit.iris.gen.layer;
import com.volmit.iris.gen.DimensionChunkGenerator;
import com.volmit.iris.noise.CellGenerator;
import com.volmit.iris.object.IrisCarveLayer;
import com.volmit.iris.util.GenLayer;
import com.volmit.iris.util.IrisInterpolation;
import com.volmit.iris.util.M;
import com.volmit.iris.util.RNG;
public class GenLayerCarve extends GenLayer
{
private CellGenerator cell;
private boolean couldCarve;
private int minimum;
private int maximum;
public GenLayerCarve(DimensionChunkGenerator iris, RNG rng)
{
super(iris, rng);
cell = new CellGenerator(rng.nextParallelRNG(-135486678));
couldCarve = iris.getDimension().isCarving() && iris.getDimension().getCarveLayers().isNotEmpty();
minimum = 512;
maximum = -256;
for(IrisCarveLayer i : iris.getDimension().getCarveLayers())
{
minimum = i.getMinHeight() < minimum ? i.getMinHeight() : minimum;
maximum = i.getMaxHeight() > maximum ? i.getMaxHeight() : maximum;
}
}
public boolean couldCarve(int x, int y, int z)
{
return couldCarve && y >= minimum && y <= maximum;
}
public boolean couldCarveBelow(int x, int y, int z)
{
return couldCarve && y <= maximum;
}
public int getSurfaceCarve(int x, int y, int z)
{
if(couldCarveBelow(x, y, z))
{
int h = y;
while(isCarved(x, h, z))
{
if(h <= 0)
{
break;
}
h--;
}
return h;
}
return y;
}
public boolean isCarved(int xc, int y, int zc)
{
if(y > iris.getDimension().getCarvingMax() || y < iris.getDimension().getCarvingMin())
if(!couldCarve(xc, y, zc))
{
return false;
}
double x = ((double) xc / iris.getDimension().getCarvingZoom());
double z = ((double) zc / iris.getDimension().getCarvingZoom());
double x = ((double) xc);
double z = ((double) zc);
double opacity = Math.pow(IrisInterpolation.sinCenter(M.lerpInverse(iris.getDimension().getCarvingMin(), iris.getDimension().getCarvingMax(), y)), 4);
if(cell.getDistance(x - (Math.cos(y / iris.getDimension().getCarvingRippleThickness()) + 0.5D) / 2D, y / iris.getDimension().getCarvingSliverThickness(), z + (Math.sin(y / iris.getDimension().getCarvingRippleThickness()) + 0.5D) / 2D) < opacity * iris.getDimension().getCarvingEnvelope())
for(IrisCarveLayer i : iris.getDimension().getCarveLayers())
{
return true;
if(i.isCarved(rng, x, y, z))
{
return true;
}
}
return false;