Optimization

This commit is contained in:
Daniel Mills 2020-09-02 21:06:01 -04:00
parent e6b59bc16d
commit 9aa6d1c0fc
19 changed files with 242 additions and 307 deletions

View File

@ -28,7 +28,6 @@ import com.volmit.iris.util.IrisLock;
import com.volmit.iris.util.IrisStructureResult;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.NastyRunnable;
import com.volmit.iris.util.PrecisionStopwatch;
import com.volmit.iris.util.RNG;
@ -45,7 +44,6 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
private MasterLock masterLock;
private IrisLock flock = new IrisLock("ParallaxLock");
private IrisLock lock = new IrisLock("ParallaxLock");
private IrisLock lockq = new IrisLock("ParallaxQueueLock");
private GenLayerUpdate glUpdate;
private GenLayerText glText;
private int sliverBuffer;
@ -230,7 +228,6 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
{
String key = "par." + x + "." + z;
ChunkPosition rad = getDimension().getParallaxSize(this);
KList<NastyRunnable> q = new KList<>();
for(int ii = x - (rad.getX() / 2); ii <= x + (rad.getX() / 2); ii++)
{
@ -275,12 +272,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
for(IrisObjectPlacement m : k.getObjects())
{
int gg = g++;
lockq.lock();
q.add(() ->
{
placeObject(m, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1569962));
});
lockq.unlock();
}
continue searching;
@ -291,64 +283,34 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
IrisRegion r = sampleRegion((i * 16) + 7, (j * 16) + 7);
for(IrisTextPlacement k : getDimension().getText())
{
lockq.lock();
q.add(() ->
{
k.place(this, random.nextParallelRNG(-7228 + (34 * ((i * 30) + (j * 30)) * i * j) + i - j + 1569962), i, j);
});
lockq.unlock();
}
for(IrisTextPlacement k : r.getText())
{
lockq.lock();
q.add(() ->
{
k.place(this, random.nextParallelRNG(-4228 + -7228 + (34 * ((i * 30) + (j * 30)) * i * j) + i - j + 1569962), i, j);
});
lockq.unlock();
}
for(IrisTextPlacement k : b.getText())
{
lockq.lock();
q.add(() ->
{
k.place(this, random.nextParallelRNG(-22228 + -4228 + -7228 + (34 * ((i * 30) + (j * 30)) * i * j) + i - j + 1569962), i, j);
});
lockq.unlock();
}
for(IrisStructurePlacement k : r.getStructures())
{
lockq.lock();
q.add(() ->
{
k.place(this, random.nextParallelRNG(2228), i, j);
});
lockq.unlock();
}
for(IrisStructurePlacement k : b.getStructures())
{
lockq.lock();
q.add(() ->
{
k.place(this, random.nextParallelRNG(-22228), i, j);
});
lockq.unlock();
}
for(IrisObjectPlacement k : b.getObjects())
{
int gg = g++;
lockq.lock();
q.add(() ->
{
placeObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 3569222));
});
lockq.unlock();
}
if(getDimension().isCaves())
@ -371,12 +333,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
for(IrisObjectPlacement k : biome.getObjects())
{
int gg = g++;
lockq.lock();
q.add(() ->
{
placeCaveObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + gg) * i * j) + i - j + 1869322));
});
lockq.unlock();
}
}
});
@ -386,14 +343,6 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
}
getAccelerant().waitFor(key);
lockq.lock();
for(NastyRunnable i : q)
{
getAccelerant().queue(key + "-obj", i);
}
lockq.unlock();
getAccelerant().waitFor(key + "-obj");
}
public void placeObject(IrisObjectPlacement o, int x, int z, RNG rng)

View File

@ -37,7 +37,7 @@ public abstract class ParallelChunkGenerator extends DimensionChunkGenerator
{
threads = tc;
GroupedExecutor e = accelerant;
accelerant = new GroupedExecutor(threads, Thread.NORM_PRIORITY, "Iris Generator - " + world.getName());
accelerant = new GroupedExecutor(threads, Thread.MAX_PRIORITY, "Iris Generator - " + world.getName());
Iris.executors.add(accelerant);
if(e != null)
@ -90,8 +90,7 @@ public abstract class ParallelChunkGenerator extends DimensionChunkGenerator
int j = jj;
int wz = (z * 16) + j;
AtomicSliver sliver = map.getSliver(i, j);
accelerant.queue(key, () ->
getAccelerant().queue(key, () ->
{
try
{

View File

@ -200,10 +200,10 @@ public class GenLayerBiome extends GenLayer
double x = bx / iris.getDimension().getBiomeZoom();
double z = bz / iris.getDimension().getBiomeZoom();
if(!parent.getRealChildren(iris).isEmpty())
if(parent.getRealChildren(iris).isNotEmpty())
{
CNG childCell = parent.getChildrenGenerator(rng, 123, parent.getChildShrinkFactor());
KList<IrisBiome> chx = parent.getRealChildren(iris).copy(); // TODO Cache
KList<IrisBiome> chx = parent.getRealChildren(iris).copy();
chx.add(parent);
IrisBiome biome = childCell.fitRarity(chx, x, z);
biome.setInferredType(parent.getInferredType());

View File

@ -40,9 +40,9 @@ public class GenLayerCave extends GenLayer
}
KList<CaveResult> result = new KList<>();
gg.SetNoiseType(NoiseType.Cellular);
gg.SetCellularReturnType(CellularReturnType.Distance2Sub);
gg.SetCellularDistanceFunction(CellularDistanceFunction.Natural);
gg.setNoiseType(NoiseType.Cellular);
gg.setCellularReturnType(CellularReturnType.Distance2Sub);
gg.setCellularDistanceFunction(CellularDistanceFunction.Natural);
for(int i = 0; i < iris.getDimension().getCaveLayers().size(); i++)
{

View File

@ -27,13 +27,13 @@ public class CellGenerator
RNG rx = rng.nextParallelRNG(8735652);
int s = rx.nextInt();
fn = new FastNoise(s);
fn.SetNoiseType(FastNoise.NoiseType.Cellular);
fn.SetCellularReturnType(FastNoise.CellularReturnType.CellValue);
fn.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
fn.setNoiseType(FastNoise.NoiseType.Cellular);
fn.setCellularReturnType(FastNoise.CellularReturnType.CellValue);
fn.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
fd = new FastNoise(s);
fd.SetNoiseType(FastNoise.NoiseType.Cellular);
fd.SetCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
fd.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
fd.setNoiseType(FastNoise.NoiseType.Cellular);
fd.setCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
fd.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
}
public float getDistance(double x, double z)

View File

@ -7,9 +7,9 @@ public class CellHeightNoise implements NoiseGenerator {
public CellHeightNoise(long seed) {
this.n = new FastNoise((int) seed);
n.SetNoiseType(FastNoise.NoiseType.Cellular);
n.SetCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
n.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
n.setNoiseType(FastNoise.NoiseType.Cellular);
n.setCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
n.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
}
private double filter(double noise) {

View File

@ -1,27 +1,32 @@
package com.volmit.iris.noise;
public class CellularNoise implements NoiseGenerator {
public class CellularNoise implements NoiseGenerator
{
private final FastNoise n;
public CellularNoise(long seed) {
public CellularNoise(long seed)
{
this.n = new FastNoise((int) seed);
n.SetNoiseType(FastNoise.NoiseType.Cellular);
n.SetCellularReturnType(FastNoise.CellularReturnType.CellValue);
n.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
n.setNoiseType(FastNoise.NoiseType.Cellular);
n.setCellularReturnType(FastNoise.CellularReturnType.CellValue);
n.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
}
@Override
public double noise(double x) {
public double noise(double x)
{
return (n.GetCellular((float) x, 0) / 2D) + 0.5D;
}
@Override
public double noise(double x, double z) {
public double noise(double x, double z)
{
return (n.GetCellular((float) x, (float) z) / 2D) + 0.5D;
}
@Override
public double noise(double x, double y, double z) {
public double noise(double x, double y, double z)
{
return (n.GetCellular((float) x, (float) y, (float) z) / 2D) + 0.5D;
}
}

File diff suppressed because one or more lines are too long

View File

@ -8,8 +8,8 @@ public class FractalBillowPerlinNoise implements NoiseGenerator, OctaveNoise {
public FractalBillowPerlinNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
n.SetFractalOctaves(1);
n.SetFractalType(FractalType.Billow);
n.setFractalOctaves(1);
n.setFractalType(FractalType.Billow);
}
public double f(double v) {
@ -33,6 +33,6 @@ public class FractalBillowPerlinNoise implements NoiseGenerator, OctaveNoise {
@Override
public void setOctaves(int o) {
n.SetFractalOctaves(o);
n.setFractalOctaves(o);
}
}

View File

@ -8,8 +8,8 @@ public class FractalBillowSimplexNoise implements NoiseGenerator, OctaveNoise {
public FractalBillowSimplexNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
n.SetFractalOctaves(1);
n.SetFractalType(FractalType.Billow);
n.setFractalOctaves(1);
n.setFractalType(FractalType.Billow);
}
public double f(double v) {
@ -33,6 +33,6 @@ public class FractalBillowSimplexNoise implements NoiseGenerator, OctaveNoise {
@Override
public void setOctaves(int o) {
n.SetFractalOctaves(o);
n.setFractalOctaves(o);
}
}

View File

@ -7,7 +7,7 @@ public class FractalCubicNoise implements NoiseGenerator {
public FractalCubicNoise(long seed) {
this.n = new FastNoise((int) seed);
n.SetFractalType(FractalType.Billow);
n.setFractalType(FractalType.Billow);
}
private double f(double n) {

View File

@ -8,8 +8,8 @@ public class FractalFBMSimplexNoise implements NoiseGenerator, OctaveNoise {
public FractalFBMSimplexNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
n.SetFractalOctaves(1);
n.SetFractalType(FractalType.FBM);
n.setFractalOctaves(1);
n.setFractalType(FractalType.FBM);
}
public double f(double v) {
@ -33,6 +33,6 @@ public class FractalFBMSimplexNoise implements NoiseGenerator, OctaveNoise {
@Override
public void setOctaves(int o) {
n.SetFractalOctaves(o);
n.setFractalOctaves(o);
}
}

View File

@ -8,8 +8,8 @@ public class FractalRigidMultiSimplexNoise implements NoiseGenerator, OctaveNois
public FractalRigidMultiSimplexNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
n.SetFractalOctaves(1);
n.SetFractalType(FractalType.RigidMulti);
n.setFractalOctaves(1);
n.setFractalType(FractalType.RigidMulti);
}
public double f(double v) {
@ -33,6 +33,6 @@ public class FractalRigidMultiSimplexNoise implements NoiseGenerator, OctaveNois
@Override
public void setOctaves(int o) {
n.SetFractalOctaves(o);
n.setFractalOctaves(o);
}
}

View File

@ -5,9 +5,9 @@ public class GlobNoise implements NoiseGenerator {
public GlobNoise(long seed) {
this.n = new FastNoise((int) seed);
n.SetNoiseType(FastNoise.NoiseType.Cellular);
n.SetCellularReturnType(FastNoise.CellularReturnType.Distance2Div);
n.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
n.setNoiseType(FastNoise.NoiseType.Cellular);
n.setCellularReturnType(FastNoise.CellularReturnType.Distance2Div);
n.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
}
private double f(double n)

View File

@ -8,7 +8,7 @@ public class PerlinNoise implements NoiseGenerator, OctaveNoise {
public PerlinNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
n.SetNoiseType(FastNoise.NoiseType.Perlin);
n.setNoiseType(FastNoise.NoiseType.Perlin);
octaves = 1;
}

View File

@ -8,7 +8,7 @@ public class SimplexNoise implements NoiseGenerator, OctaveNoise {
public SimplexNoise(long seed) {
this.n = new FastNoise(new RNG(seed).imax());
n.SetNoiseType(FastNoise.NoiseType.Simplex);
n.setNoiseType(FastNoise.NoiseType.Simplex);
octaves = 1;
}

View File

@ -7,9 +7,9 @@ public class VascularNoise implements NoiseGenerator {
public VascularNoise(long seed) {
this.n = new FastNoise((int) seed);
n.SetNoiseType(FastNoise.NoiseType.Cellular);
n.SetCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
n.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
n.setNoiseType(FastNoise.NoiseType.Cellular);
n.setCellularReturnType(FastNoise.CellularReturnType.Distance2Sub);
n.setCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
}
private double filter(double noise) {

View File

@ -31,7 +31,6 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = false)
public class IrisObject extends IrisRegistrant
{
private static final Material SNOW = Material.SNOW;
private static final BlockData AIR = B.getBlockData("CAVE_AIR");
private static final BlockData[] SNOW_LAYERS = new BlockData[] {B.getBlockData("minecraft:snow[layers=1]"), B.getBlockData("minecraft:snow[layers=2]"), B.getBlockData("minecraft:snow[layers=3]"), B.getBlockData("minecraft:snow[layers=4]"), B.getBlockData("minecraft:snow[layers=5]"), B.getBlockData("minecraft:snow[layers=6]"), B.getBlockData("minecraft:snow[layers=7]"), B.getBlockData("minecraft:snow[layers=8]")};
public static boolean shitty = false;
@ -469,12 +468,6 @@ public class IrisObject extends IrisRegistrant
if(config.getSnow() > 0)
{
BlockData bd = placer.get(vx, vy, vz);
if(bd != null && bd.getMaterial().equals(SNOW))
{
continue;
}
int height = rngx.i(0, (int) (config.getSnow() * 7));
placer.set(vx, vy + 1, vz, SNOW_LAYERS[Math.max(Math.min(height, 7), 0)]);
}

View File

@ -6,8 +6,6 @@ import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;
import java.util.concurrent.ForkJoinWorkerThread;
import com.volmit.iris.Iris;
public class GroupedExecutor
{
private int xc;
@ -73,21 +71,12 @@ public class GroupedExecutor
return;
}
PrecisionStopwatch s = PrecisionStopwatch.start();
while(true)
{
if(mirror.get(g) == 0)
{
break;
}
if(s.getMilliseconds() > 30000)
{
Iris.warn("Couldn't unlock grouped task: " + g + "! Clearing Task Group Forcibly and timing out!");
mirror.remove(g);
break;
}
}
}