ATOMIC MAYHEM

This commit is contained in:
Daniel Mills 2020-08-03 10:44:34 -04:00
parent b6592582b3
commit 58a5aaed30
17 changed files with 424 additions and 476 deletions

View File

@ -0,0 +1,77 @@
package com.volmit.iris.gen.atomics;
import java.util.function.Supplier;
import com.volmit.iris.util.IrisLock;
import com.volmit.iris.util.M;
public class AtomicCache<T>
{
private transient volatile T t;
private transient volatile long a;
private transient volatile int validations;
private final IrisLock check;
private final IrisLock time;
private final IrisLock write;
public AtomicCache()
{
check = new IrisLock("Check");
write = new IrisLock("Write");
time = new IrisLock("Time");
validations = 0;
a = -1;
t = null;
}
public void reset()
{
check.lock();
write.lock();
time.lock();
a = -1;
t = null;
time.unlock();
write.unlock();
check.unlock();
}
public T aquire(Supplier<T> t)
{
if(this.t != null && validations > 1000)
{
return this.t;
}
if(this.t != null && M.ms() - a > 1000)
{
if(this.t != null)
{
validations++;
}
return this.t;
}
check.lock();
if(this.t == null)
{
write.lock();
this.t = t.get();
time.lock();
if(a == -1)
{
a = M.ms();
}
time.unlock();
write.unlock();
}
check.unlock();
return this.t;
}
}

View File

@ -3,7 +3,6 @@ package com.volmit.iris.gen.atomics;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Material;
import org.bukkit.block.Biome;
@ -14,6 +13,7 @@ import org.bukkit.generator.ChunkGenerator.ChunkData;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.util.BlockDataTools;
import com.volmit.iris.util.HeightMap;
import com.volmit.iris.util.IrisLock;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import com.volmit.iris.util.M;
@ -27,7 +27,7 @@ public class AtomicSliver
private KMap<Integer, BlockData> block;
private KMap<Integer, IrisBiome> truebiome;
private KMap<Integer, Biome> biome;
private ReentrantLock lock = new ReentrantLock();
private IrisLock lock = new IrisLock("Sliver");
private int highestBlock = 0;
private int highestBiome = 0;
private long last = M.ms();
@ -37,6 +37,7 @@ public class AtomicSliver
public AtomicSliver(int x, int z)
{
lock.setDisabled(true);
this.x = x;
this.z = z;
this.block = new KMap<>();
@ -71,14 +72,15 @@ public class AtomicSliver
lock.lock();
block.put(h, d);
lock.unlock();
modified = true;
if(d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR))
{
lock.unlock();
return;
}
lock.lock();
highestBlock = h > highestBlock ? h : highestBlock;
lock.unlock();
}
@ -167,7 +169,7 @@ public class AtomicSliver
height.setHeight(x, z, highestBlock);
lock.unlock();
}
public void read(DataInputStream din) throws IOException
{
lock.lock();
@ -176,12 +178,12 @@ public class AtomicSliver
int p = din.readByte() - Byte.MIN_VALUE;
KList<BlockData> palette = new KList<BlockData>();
highestBlock = h;
for(int i = 0; i < p; i++)
{
palette.add(BlockDataTools.getBlockData(din.readUTF()));
}
for(int i = 0; i <= h; i++)
{
block.put(i, palette.get(din.readByte() - Byte.MIN_VALUE).clone());
@ -189,38 +191,38 @@ public class AtomicSliver
modified = false;
lock.unlock();
}
public void write(DataOutputStream dos) throws IOException
{
lock.lock();
dos.writeByte(highestBlock + Byte.MIN_VALUE);
KList<String> palette = new KList<>();
for(int i = 0; i <= highestBlock; i++)
{
BlockData dat = block.get(i);
String d = (dat == null ? AIR : dat).getAsString(true);
if(!palette.contains(d))
{
palette.add(d);
}
}
dos.writeByte(palette.size() + Byte.MIN_VALUE);
for(String i : palette)
{
dos.writeUTF(i);
}
for(int i = 0; i <= highestBlock; i++)
{
BlockData dat = block.get(i);
String d = (dat == null ? AIR : dat).getAsString(true);
dos.writeByte(palette.indexOf(d) + Byte.MIN_VALUE);
}
lock.unlock();
}

View File

@ -338,7 +338,7 @@ public class AtomicWorldData
private int getUnloadBatchSize()
{
return Math.max(3, getLoadedRegions().size() / 125);
return Math.max(3, getLoadedRegions().size() / 85);
}
private int getUnloadBatchSpeed()

View File

@ -1,18 +1,17 @@
package com.volmit.iris.gen.atomics;
import java.util.concurrent.locks.ReentrantLock;
import com.volmit.iris.util.IrisLock;
import com.volmit.iris.util.KMap;
public class MasterLock
{
private KMap<String, ReentrantLock> locks;
private ReentrantLock lock;
private KMap<String, IrisLock> locks;
private IrisLock lock;
public MasterLock()
{
locks = new KMap<>();
lock = new ReentrantLock();
lock = new IrisLock("MasterLock");
}
public void clear()
@ -25,10 +24,10 @@ public class MasterLock
lock.lock();
if(!locks.containsKey(key))
{
locks.put(key, new ReentrantLock());
locks.put(key, new IrisLock("Locker"));
}
ReentrantLock l = locks.get(key);
IrisLock l = locks.get(key);
lock.unlock();
l.lock();
}
@ -38,10 +37,10 @@ public class MasterLock
lock.lock();
if(!locks.containsKey(key))
{
locks.put(key, new ReentrantLock());
locks.put(key, new IrisLock("Unlocker"));
}
ReentrantLock l = locks.get(key);
IrisLock l = locks.get(key);
lock.unlock();
l.unlock();
}

View File

@ -1,11 +1,10 @@
package com.volmit.iris.object;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.BiomeRarityCellGenerator;
import com.volmit.iris.util.CNG;
import com.volmit.iris.util.Desc;
@ -95,17 +94,13 @@ public class IrisBiome extends IrisRegistrant
@Desc("Define biome deposit generators that add onto the existing regional and global deposit generators")
private KList<IrisDepositGenerator> deposits = new KList<>();
private transient ReentrantLock lock = new ReentrantLock();
private transient BiomeRarityCellGenerator childrenCell;
private transient InferredType inferredType;
private transient CNG biomeGenerator;
private transient int maxHeight = Integer.MIN_VALUE;
private transient KList<BlockData> fullLayerSpec;
private transient KList<CNG> layerHeightGenerators;
private transient KList<CNG> layerSeaHeightGenerators;
private transient KList<CNG> layerSurfaceGenerators;
private transient KList<CNG> layerSeaSurfaceGenerators;
private transient KList<IrisBiome> realChildren;
private transient AtomicCache<BiomeRarityCellGenerator> childrenCell = new AtomicCache<>();
private transient AtomicCache<CNG> biomeGenerator = new AtomicCache<>();
private transient AtomicCache<Integer> maxHeight = new AtomicCache<>();
private transient AtomicCache<KList<IrisBiome>> realChildren = new AtomicCache<>();
private transient AtomicCache<KList<CNG>> layerHeightGenerators = new AtomicCache<>();
private transient AtomicCache<KList<CNG>> layerSeaHeightGenerators = new AtomicCache<>();
public IrisBiome()
{
@ -126,23 +121,20 @@ public class IrisBiome extends IrisRegistrant
public CNG getBiomeGenerator(RNG random)
{
if(biomeGenerator == null)
return biomeGenerator.aquire(() ->
{
biomeGenerator = CNG.signature(random.nextParallelRNG(213949 + 228888 + getRarity() + getName().length())).scale(biomeDispersion.equals(Dispersion.SCATTER) ? 1000D : 0.1D);
}
return biomeGenerator;
return CNG.signature(random.nextParallelRNG(213949 + 228888 + getRarity() + getName().length())).scale(biomeDispersion.equals(Dispersion.SCATTER) ? 1000D : 0.1D);
});
}
public BiomeRarityCellGenerator getChildrenGenerator(RNG random, int sig, double scale)
{
if(childrenCell == null)
return childrenCell.aquire(() ->
{
childrenCell = new BiomeRarityCellGenerator(random.nextParallelRNG(sig * 2137));
BiomeRarityCellGenerator childrenCell = new BiomeRarityCellGenerator(random.nextParallelRNG(sig * 2137));
childrenCell.setCellScale(scale);
}
return childrenCell;
return childrenCell;
});
}
public KList<BlockData> generateLayers(double wx, double wz, RNG random, int maxDepth, int height)
@ -247,21 +239,17 @@ public class IrisBiome extends IrisRegistrant
private int getMaxHeight()
{
if(maxHeight == Integer.MIN_VALUE)
return maxHeight.aquire(() ->
{
lock.lock();
maxHeight = 0;
int maxHeight = 0;
for(IrisBiomeGeneratorLink i : getGenerators())
{
maxHeight += i.getMax();
}
lock.unlock();
}
return maxHeight;
return maxHeight;
});
}
public IrisBiome infer(InferredType t, InferredType type)
@ -313,10 +301,9 @@ public class IrisBiome extends IrisRegistrant
public KList<CNG> getLayerHeightGenerators(RNG rng)
{
lock.lock();
if(layerHeightGenerators == null)
return layerHeightGenerators.aquire(() ->
{
layerHeightGenerators = new KList<>();
KList<CNG> layerHeightGenerators = new KList<>();
int m = 7235;
@ -324,18 +311,16 @@ public class IrisBiome extends IrisRegistrant
{
layerHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m)));
}
}
lock.unlock();
return layerHeightGenerators;
return layerHeightGenerators;
});
}
public KList<CNG> getLayerSeaHeightGenerators(RNG rng)
{
lock.lock();
if(layerSeaHeightGenerators == null)
return layerSeaHeightGenerators.aquire(() ->
{
layerSeaHeightGenerators = new KList<>();
KList<CNG> layerSeaHeightGenerators = new KList<>();
int m = 7735;
@ -343,10 +328,9 @@ public class IrisBiome extends IrisRegistrant
{
layerSeaHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m)));
}
}
lock.unlock();
return layerSeaHeightGenerators;
return layerSeaHeightGenerators;
});
}
public boolean isLand()
@ -394,21 +378,17 @@ public class IrisBiome extends IrisRegistrant
public KList<IrisBiome> getRealChildren()
{
lock.lock();
if(realChildren == null)
return realChildren.aquire(() ->
{
realChildren = new KList<>();
KList<IrisBiome> realChildren = new KList<>();
for(String i : getChildren())
{
realChildren.add(Iris.data.getBiomeLoader().load(i));
}
}
lock.unlock();
return realChildren;
return realChildren;
});
}
public KList<String> getAllChildren(int limit)

View File

@ -2,6 +2,7 @@ package com.volmit.iris.object;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.BlockDataTools;
import com.volmit.iris.util.CNG;
import com.volmit.iris.util.Desc;
@ -57,8 +58,8 @@ public class IrisBiomeDecorator
private KList<String> palette = new KList<String>().qadd("GRASS");
private transient KMap<Long, CNG> layerGenerators;
private transient CNG heightGenerator;
private transient KList<BlockData> blockData;
private transient AtomicCache<CNG> heightGenerator = new AtomicCache<>();
private transient AtomicCache<KList<BlockData>> blockData = new AtomicCache<>();
public int getHeight(RNG rng, double x, double z)
{
@ -72,12 +73,10 @@ public class IrisBiomeDecorator
public CNG getHeightGenerator(RNG rng)
{
if(heightGenerator == null)
return heightGenerator.aquire(() ->
{
heightGenerator = CNG.signature(rng.nextParallelRNG(getBlockData().size() + stackMax + stackMin)).scale(1D / verticalZoom);
}
return heightGenerator;
return CNG.signature(rng.nextParallelRNG(getBlockData().size() + stackMax + stackMin)).scale(1D / verticalZoom);
});
}
public CNG getGenerator(RNG rng)
@ -141,9 +140,9 @@ public class IrisBiomeDecorator
public KList<BlockData> getBlockData()
{
if(blockData == null)
return blockData.aquire(() ->
{
blockData = new KList<>();
KList<BlockData> blockData = new KList<>();
for(String i : palette)
{
BlockData bx = BlockDataTools.getBlockData(i);
@ -152,8 +151,8 @@ public class IrisBiomeDecorator
blockData.add(bx);
}
}
}
return blockData;
return blockData;
});
}
}

View File

@ -1,6 +1,7 @@
package com.volmit.iris.object;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
import com.volmit.iris.util.IrisInterpolation;
@ -23,7 +24,7 @@ public class IrisBiomeGeneratorLink
@Desc("The max block value (value + fluidHeight)")
private int max = 0;
private transient IrisGenerator gen;
private transient AtomicCache<IrisGenerator> gen = new AtomicCache<>();
public IrisBiomeGeneratorLink()
{
@ -32,17 +33,17 @@ public class IrisBiomeGeneratorLink
public IrisGenerator getCachedGenerator()
{
if(gen == null)
return gen.aquire(() ->
{
gen = Iris.data.getGeneratorLoader().load(getGenerator());
IrisGenerator gen = Iris.data.getGeneratorLoader().load(getGenerator());
if(gen == null)
{
gen = new IrisGenerator();
}
}
return gen;
return gen;
});
}
public double getHeight(double x, double z, long seed)

View File

@ -1,6 +1,7 @@
package com.volmit.iris.object;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
import com.volmit.iris.util.KList;
@ -32,27 +33,17 @@ public class IrisBiomeMutation
@Desc("Objects define what schematics (iob files) iris will place in this biome mutation")
private KList<IrisObjectPlacement> objects = new KList<IrisObjectPlacement>();
private transient KList<String> sideACache;
private transient KList<String> sideBCache;
private transient AtomicCache<KList<String>> sideACache = new AtomicCache<>();
private transient AtomicCache<KList<String>> sideBCache = new AtomicCache<>();
public KList<String> getRealSideA()
{
if(sideACache == null)
{
sideACache = processList(getSideA());
}
return sideACache;
return sideACache.aquire(() -> processList(getSideA()));
}
public KList<String> getRealSideB()
{
if(sideBCache == null)
{
sideBCache = processList(getSideB());
}
return sideBCache;
return sideBCache.aquire(() -> processList(getSideB()));
}
public KList<String> processList(KList<String> s)

View File

@ -1,9 +1,8 @@
package com.volmit.iris.object;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.BlockDataTools;
import com.volmit.iris.util.CNG;
import com.volmit.iris.util.Desc;
@ -37,28 +36,17 @@ public class IrisBiomePaletteLayer
@Desc("The palette of blocks to be used in this layer")
private KList<String> palette = new KList<String>().qadd("GRASS_BLOCK");
private transient ReentrantLock lock = new ReentrantLock();
private transient KList<BlockData> blockData;
private transient CNG layerGenerator;
private transient CNG heightGenerator;
private transient AtomicCache<KList<BlockData>> blockData = new AtomicCache<>();
private transient AtomicCache<CNG> layerGenerator = new AtomicCache<>();
private transient AtomicCache<CNG> heightGenerator = new AtomicCache<>();
public CNG getHeightGenerator(RNG rng)
{
if(heightGenerator == null)
{
heightGenerator = CNG.signature(rng.nextParallelRNG(minHeight * maxHeight + getBlockData().size()));
}
return heightGenerator;
return heightGenerator.aquire(() -> CNG.signature(rng.nextParallelRNG(minHeight * maxHeight + getBlockData().size())));
}
public BlockData get(RNG rng, double x, double y, double z)
{
if(layerGenerator == null)
{
cacheGenerator(rng);
}
if(getBlockData().isEmpty())
{
return null;
@ -69,35 +57,36 @@ public class IrisBiomePaletteLayer
return getBlockData().get(0);
}
if(layerGenerator != null)
if(dispersion.equals(Dispersion.SCATTER))
{
if(dispersion.equals(Dispersion.SCATTER))
{
return getBlockData().get(layerGenerator.fit(0, 30000000, x, y, z) % getBlockData().size());
}
else
{
return getBlockData().get(layerGenerator.fit(0, getBlockData().size() - 1, x, y, z));
}
return getBlockData().get(getLayerGenerator(rng).fit(0, 30000000, x, y, z) % getBlockData().size());
}
return getBlockData().get(0);
else
{
return getBlockData().get(getLayerGenerator(rng).fit(0, getBlockData().size() - 1, x, y, z));
}
}
public void cacheGenerator(RNG rng)
public CNG getLayerGenerator(RNG rng)
{
RNG rngx = rng.nextParallelRNG(minHeight + maxHeight + getBlockData().size());
switch(dispersion)
return layerGenerator.aquire(() ->
{
case SCATTER:
layerGenerator = CNG.signature(rngx).freq(1000000);
break;
case WISPY:
layerGenerator = CNG.signature(rngx);
break;
}
CNG layerGenerator = new CNG(rng);
RNG rngx = rng.nextParallelRNG(minHeight + maxHeight + getBlockData().size());
switch(dispersion)
{
case SCATTER:
layerGenerator = CNG.signature(rngx).freq(1000000);
break;
case WISPY:
layerGenerator = CNG.signature(rngx);
break;
}
return layerGenerator;
});
}
public KList<String> add(String b)
@ -109,10 +98,9 @@ public class IrisBiomePaletteLayer
public KList<BlockData> getBlockData()
{
lock.lock();
if(blockData == null)
return blockData.aquire(() ->
{
blockData = new KList<>();
KList<BlockData> blockData = new KList<>();
for(String ix : palette)
{
BlockData bx = BlockDataTools.getBlockData(ix);
@ -121,10 +109,9 @@ public class IrisBiomePaletteLayer
blockData.add(bx);
}
}
}
lock.unlock();
return blockData;
return blockData;
});
}
public IrisBiomePaletteLayer zero()

View File

@ -1,13 +1,12 @@
package com.volmit.iris.object;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.util.BlockVector;
import com.volmit.iris.gen.TerrainChunkGenerator;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.BlockDataTools;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
@ -51,54 +50,26 @@ public class IrisDepositGenerator
@Desc("Ore varience is how many different objects clumps iris will create")
private int varience = 8;
private transient IrisObjectPlacement config = createDepositConfig();
private transient ReentrantLock lock = new ReentrantLock();
private transient KList<IrisObject> objects;
private transient KList<BlockData> blockData;
private transient AtomicCache<KList<IrisObject>> objects = new AtomicCache<>();
private transient AtomicCache<KList<BlockData>> blockData = new AtomicCache<>();
public IrisObject getClump(RNG rng)
{
lock.lock();
if(objects == null)
KList<IrisObject> objects = this.objects.aquire(() ->
{
RNG rngv = rng.nextParallelRNG(3957778);
objects = new KList<>();
KList<IrisObject> objectsf = new KList<>();
for(int i = 0; i < varience; i++)
{
objects.add(generateClumpObject(rngv.nextParallelRNG(2349 * i + 3598)));
objectsf.add(generateClumpObject(rngv.nextParallelRNG(2349 * i + 3598)));
}
}
lock.unlock();
return objectsf;
});
return objects.get(rng.i(0, objects.size() - 1));
}
private IrisObjectPlacement createDepositConfig()
{
IrisObjectPlacement p = new IrisObjectPlacement();
IrisObjectRotation rot = new IrisObjectRotation();
rot.setEnabled(true);
IrisAxisRotationClamp xc = new IrisAxisRotationClamp();
IrisAxisRotationClamp yc = new IrisAxisRotationClamp();
IrisAxisRotationClamp zc = new IrisAxisRotationClamp();
xc.setEnabled(true);
xc.setInterval(45);
yc.setEnabled(true);
yc.setInterval(45);
zc.setEnabled(true);
zc.setInterval(45);
rot.setXAxis(xc);
rot.setYAxis(yc);
rot.setZAxis(zc);
p.setRotation(rot);
p.setUnderwater(true);
p.setMeld(true);
return p;
}
public int getMaxDimension()
{
return Math.min(11, (int) Math.round(Math.pow(maxSize, 1D / 3D)));
@ -137,11 +108,9 @@ public class IrisDepositGenerator
public KList<BlockData> getBlockData()
{
lock.lock();
if(blockData == null)
return blockData.aquire(() ->
{
blockData = new KList<>();
KList<BlockData> blockData = new KList<>();
for(String ix : palette)
{
@ -152,11 +121,9 @@ public class IrisDepositGenerator
blockData.add(bx);
}
}
}
lock.unlock();
return blockData;
return blockData;
});
}
public void generate(ChunkData data, RNG rng, TerrainChunkGenerator g)

View File

@ -1,13 +1,13 @@
package com.volmit.iris.object;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Material;
import org.bukkit.World.Environment;
import org.bukkit.block.data.BlockData;
import org.bukkit.util.BlockVector;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.PostBlockChunkGenerator;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.BlockDataTools;
import com.volmit.iris.util.CNG;
import com.volmit.iris.util.ChunkPosition;
@ -26,6 +26,9 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = false)
public class IrisDimension extends IrisRegistrant
{
public static final BlockData STONE = Material.STONE.createBlockData();
public static final BlockData WATER = Material.WATER.createBlockData();
@DontObfuscate
@Desc("The human readable name of this dimension")
private String name = "A Dimension";
@ -206,26 +209,23 @@ public class IrisDimension extends IrisRegistrant
@Desc("Define biome mutations for this dimension")
private KList<IrisBiomeMutation> mutations = new KList<>();
private transient ChunkPosition parallaxSize;
private transient ReentrantLock rockLock = new ReentrantLock();
private transient ReentrantLock parLock = new ReentrantLock();
private transient ReentrantLock fluidLock = new ReentrantLock();
private transient KList<BlockData> rockData;
private transient KList<BlockData> fluidData;
private transient KList<IrisPostBlockFilter> cacheFilters;
private transient CNG rockLayerGenerator;
private transient CNG fluidLayerGenerator;
private transient CNG coordFracture;
private transient Double sinr;
private transient Double cosr;
private transient Double rad;
private transient boolean inverted;
private transient AtomicCache<ChunkPosition> parallaxSize = new AtomicCache<>();
private transient AtomicCache<KList<BlockData>> rockData = new AtomicCache<>();
private transient AtomicCache<KList<BlockData>> fluidData = new AtomicCache<>();
private transient AtomicCache<KList<IrisPostBlockFilter>> cacheFilters = new AtomicCache<>();
private transient AtomicCache<CNG> rockLayerGenerator = new AtomicCache<>();
private transient AtomicCache<CNG> fluidLayerGenerator = new AtomicCache<>();
private transient AtomicCache<CNG> coordFracture = new AtomicCache<>();
private transient AtomicCache<Double> sinr = new AtomicCache<>();
private transient AtomicCache<Double> cosr = new AtomicCache<>();
private transient AtomicCache<Double> rad = new AtomicCache<>();
private transient boolean inverted = false;
public KList<IrisPostBlockFilter> getPostBlockProcessors(PostBlockChunkGenerator g)
{
if(cacheFilters == null)
return cacheFilters.aquire(() ->
{
cacheFilters = new KList<>();
KList<IrisPostBlockFilter> cacheFilters = new KList<>();
for(IrisPostProcessor i : getPostProcessors())
{
@ -242,20 +242,18 @@ public class IrisDimension extends IrisRegistrant
}
Iris.info("Post Processing: " + cacheFilters.size() + " filters. Phases: " + g.getMinPhase() + " - " + g.getMaxPhase());
}
return cacheFilters;
return cacheFilters;
});
}
public CNG getCoordFracture(RNG rng, int signature)
{
if(coordFracture == null)
return coordFracture.aquire(() ->
{
coordFracture = CNG.signature(rng.nextParallelRNG(signature));
CNG coordFracture = CNG.signature(rng.nextParallelRNG(signature));
coordFracture.scale(0.012 / coordFractureZoom);
}
return coordFracture;
return coordFracture;
});
}
private KList<IrisPostProcessor> getDefaultPostProcessors()
@ -274,54 +272,52 @@ public class IrisDimension extends IrisRegistrant
public BlockData getRock(RNG rng, double x, double y, double z)
{
if(getRockData().isEmpty())
{
return STONE;
}
if(getRockData().size() == 1)
{
return getRockData().get(0);
}
if(rockLayerGenerator == null)
if(dispersion.equals(Dispersion.SCATTER))
{
cacheRockGenerator(rng);
return getRockData().get(getRockGenerator(rng).fit(0, 30000000, x, y, z) % getRockData().size());
}
if(rockLayerGenerator != null)
else
{
if(dispersion.equals(Dispersion.SCATTER))
{
return getRockData().get(rockLayerGenerator.fit(0, 30000000, x, y, z) % getRockData().size());
}
else
{
return getRockData().get(rockLayerGenerator.fit(0, getRockData().size() - 1, x, y, z));
}
return getRockData().get(getRockGenerator(rng).fit(0, getRockData().size() - 1, x, y, z));
}
return getRockData().get(0);
}
public void cacheRockGenerator(RNG rng)
public CNG getRockGenerator(RNG rng)
{
RNG rngx = rng.nextParallelRNG((int) (getRockData().size() * getRegions().size() * getCaveScale() * getLandZoom() * 10357));
switch(dispersion)
return rockLayerGenerator.aquire(() ->
{
case SCATTER:
rockLayerGenerator = CNG.signature(rngx).freq(1000000);
break;
case WISPY:
rockLayerGenerator = CNG.signature(rngx);
break;
}
RNG rngx = rng.nextParallelRNG((int) (getRockData().size() * getRegions().size() * getCaveScale() * getLandZoom() * 10357));
CNG rockLayerGenerator = new CNG(rng);
switch(dispersion)
{
case SCATTER:
rockLayerGenerator = CNG.signature(rngx).freq(1000000);
break;
case WISPY:
rockLayerGenerator = CNG.signature(rngx);
break;
}
return rockLayerGenerator;
});
}
public KList<BlockData> getRockData()
{
rockLock.lock();
if(rockData == null)
return rockData.aquire(() ->
{
rockData = new KList<>();
KList<BlockData> rockData = new KList<>();
for(String ix : rockPalette)
{
BlockData bx = BlockDataTools.getBlockData(ix);
@ -330,63 +326,59 @@ public class IrisDimension extends IrisRegistrant
rockData.add(bx);
}
}
}
rockLock.unlock();
return rockData;
return rockData;
});
}
public BlockData getFluid(RNG rng, double x, double y, double z)
{
if(getFluidData().isEmpty())
{
return WATER;
}
if(getFluidData().size() == 1)
{
return getFluidData().get(0);
}
if(fluidLayerGenerator == null)
if(dispersion.equals(Dispersion.SCATTER))
{
cacheFluidGenerator(rng);
return getFluidData().get(getFluidGenerator(rng).fit(0, 30000000, x, y, z) % getFluidData().size());
}
if(fluidLayerGenerator != null)
else
{
if(dispersion.equals(Dispersion.SCATTER))
{
return getFluidData().get(fluidLayerGenerator.fit(0, 30000000, x, y, z) % getFluidData().size());
}
else
{
return getFluidData().get(fluidLayerGenerator.fit(0, getFluidData().size() - 1, x, y, z));
}
return getFluidData().get(getFluidGenerator(rng).fit(0, getFluidData().size() - 1, x, y, z));
}
return getFluidData().get(0);
}
public void cacheFluidGenerator(RNG rng)
public CNG getFluidGenerator(RNG rng)
{
RNG rngx = rng.nextParallelRNG(getFluidData().size() * (int) (getRockData().size() * getRegions().size() * getCaveScale() * getLandZoom() * 10357));
switch(dispersion)
return fluidLayerGenerator.aquire(() ->
{
case SCATTER:
fluidLayerGenerator = CNG.signature(rngx).freq(1000000);
break;
case WISPY:
fluidLayerGenerator = CNG.signature(rngx);
break;
}
RNG rngx = rng.nextParallelRNG(getFluidData().size() * (int) (getRockData().size() * getRegions().size() * getCaveScale() * getLandZoom() * 10357));
CNG fluidLayerGenerator = new CNG(rng);
switch(dispersion)
{
case SCATTER:
fluidLayerGenerator = CNG.signature(rngx).freq(1000000);
break;
case WISPY:
fluidLayerGenerator = CNG.signature(rngx);
break;
}
return fluidLayerGenerator;
});
}
public KList<BlockData> getFluidData()
{
fluidLock.lock();
if(fluidData == null)
return fluidData.aquire(() ->
{
fluidData = new KList<>();
KList<BlockData> fluidData = new KList<>();
for(String ix : fluidPalette)
{
BlockData bx = BlockDataTools.getBlockData(ix);
@ -395,41 +387,24 @@ public class IrisDimension extends IrisRegistrant
fluidData.add(bx);
}
}
}
fluidLock.unlock();
return fluidData;
return fluidData;
});
}
public double getDimensionAngle()
{
if(rad == null)
{
rad = Math.toRadians(dimensionAngleDeg);
}
return rad;
return rad.aquire(() -> Math.toRadians(dimensionAngleDeg));
}
public double sinRotate()
{
if(sinr == null)
{
sinr = Math.sin(getDimensionAngle());
}
return sinr;
return sinr.aquire(() -> Math.sin(getDimensionAngle()));
}
public double cosRotate()
{
if(cosr == null)
{
cosr = Math.cos(getDimensionAngle());
}
return cosr;
return cosr.aquire(() -> Math.cos(getDimensionAngle()));
}
public KList<IrisRegion> getAllRegions()
@ -458,9 +433,7 @@ public class IrisDimension extends IrisRegistrant
public ChunkPosition getParallaxSize()
{
parLock.lock();
if(parallaxSize == null)
return parallaxSize.aquire(() ->
{
int x = 0;
int z = 0;
@ -523,11 +496,8 @@ public class IrisDimension extends IrisRegistrant
z = (Math.max(z, 16) + 16) >> 4;
x = x % 2 == 0 ? x + 1 : x;
z = z % 2 == 0 ? z + 1 : z;
parallaxSize = new ChunkPosition(x, z);
Iris.info("Parallax Size: " + x + ", " + z);
}
parLock.unlock();
return parallaxSize;
return new ChunkPosition(x, z);
});
}
}

View File

@ -1,7 +1,6 @@
package com.volmit.iris.object;
import java.util.concurrent.locks.ReentrantLock;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.CNG;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
@ -71,12 +70,11 @@ public class IrisNoiseGenerator
@Desc("Apply a child noise generator to fracture the input coordinates of this generator")
private KList<IrisNoiseGenerator> fracture = new KList<>();
private transient ReentrantLock lock;
private transient CNG generator;
private transient AtomicCache<CNG> generator = new AtomicCache<>();
public IrisNoiseGenerator()
{
lock = new ReentrantLock();
}
public IrisNoiseGenerator(boolean enabled)
@ -87,14 +85,7 @@ public class IrisNoiseGenerator
protected CNG getGenerator(long superSeed)
{
if(generator == null)
{
lock.lock();
generator = irisBased ? CNG.signature(new RNG(superSeed + 33955677 - seed)) : new CNG(new RNG(superSeed + 33955677 - seed), 1D, octaves);
lock.unlock();
}
return generator;
return generator.aquire(() -> irisBased ? CNG.signature(new RNG(superSeed + 33955677 - seed)) : new CNG(new RNG(superSeed + 33955677 - seed), 1D, octaves));
}
public double getMax()

View File

@ -1,9 +1,8 @@
package com.volmit.iris.object;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.BlockDataTools;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
@ -23,9 +22,8 @@ public class IrisObjectReplace
@DontObfuscate
private boolean exact = false;
private transient ReentrantLock lock = new ReentrantLock();
private transient BlockData findData;
private transient BlockData replaceData;
private transient AtomicCache<BlockData> findData = new AtomicCache<>();
private transient AtomicCache<BlockData> replaceData = new AtomicCache<>();
public IrisObjectReplace()
{
@ -34,21 +32,11 @@ public class IrisObjectReplace
public BlockData getFind()
{
if(findData == null)
{
findData = BlockDataTools.getBlockData(find);
}
return findData;
return findData.aquire(() -> BlockDataTools.getBlockData(find));
}
public BlockData getReplace()
{
if(replaceData == null)
{
replaceData = BlockDataTools.getBlockData(replace);
}
return replaceData;
return replaceData.aquire(() -> BlockDataTools.getBlockData(replace));
}
}

View File

@ -1,8 +1,7 @@
package com.volmit.iris.object;
import java.util.concurrent.locks.ReentrantLock;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.CNG;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
@ -102,17 +101,15 @@ public class IrisRegion extends IrisRegistrant
@Desc("Define regional deposit generators that add onto the global deposit generators")
private KList<IrisDepositGenerator> deposits = new KList<>();
private transient KList<String> cacheRidge;
private transient KList<String> cacheSpot;
private transient CNG shoreHeightGenerator;
private transient ReentrantLock lock = new ReentrantLock();
private transient KList<IrisBiome> realLandBiomes;
private transient KList<IrisBiome> realSeaBiomes;
private transient KList<IrisBiome> realShoreBiomes;
private transient KList<IrisBiome> realIslandBiomes;
private transient KList<IrisBiome> realSkylandBiomes;
private transient KList<IrisBiome> realCaveBiomes;
private transient AtomicCache<KList<String>> cacheRidge = new AtomicCache<>();
private transient AtomicCache<KList<String>> cacheSpot = new AtomicCache<>();
private transient AtomicCache<CNG> shoreHeightGenerator = new AtomicCache<>();
private transient AtomicCache<KList<IrisBiome>> realLandBiomes = new AtomicCache<>();
private transient AtomicCache<KList<IrisBiome>> realSeaBiomes = new AtomicCache<>();
private transient AtomicCache<KList<IrisBiome>> realShoreBiomes = new AtomicCache<>();
private transient AtomicCache<KList<IrisBiome>> realIslandBiomes = new AtomicCache<>();
private transient AtomicCache<KList<IrisBiome>> realSkylandBiomes = new AtomicCache<>();
private transient AtomicCache<KList<IrisBiome>> realCaveBiomes = new AtomicCache<>();
public double getBiomeZoom(InferredType t)
{
@ -139,44 +136,36 @@ public class IrisRegion extends IrisRegistrant
public KList<String> getRidgeBiomeKeys()
{
lock.lock();
if(cacheRidge == null)
return cacheRidge.aquire(() ->
{
cacheRidge = new KList<String>();
KList<String> cacheRidge = new KList<String>();
ridgeBiomes.forEach((i) -> cacheRidge.add(i.getBiome()));
}
lock.unlock();
return cacheRidge;
return cacheRidge;
});
}
public KList<String> getSpotBiomeKeys()
{
lock.lock();
if(cacheSpot == null)
return cacheSpot.aquire(() ->
{
cacheSpot = new KList<String>();
KList<String> cacheSpot = new KList<String>();
spotBiomes.forEach((i) -> cacheSpot.add(i.getBiome()));
}
return cacheSpot;
});
}
lock.unlock();
return cacheSpot;
public CNG getShoreHeightGenerator()
{
return shoreHeightGenerator.aquire(() ->
{
return CNG.signature(new RNG((long) (getName().length() + getIslandBiomes().size() + getLandBiomeZoom() + getLandBiomes().size() + 3458612)));
});
}
public double getShoreHeight(double x, double z)
{
if(shoreHeightGenerator == null)
{
lock.lock();
shoreHeightGenerator = CNG.signature(new RNG((long) (getName().length() + getIslandBiomes().size() + getLandBiomeZoom() + getLandBiomes().size() + 3458612)));
lock.unlock();
}
return shoreHeightGenerator.fitDoubleD(shoreHeightMin, shoreHeightMax, x / shoreHeightZoom, z / shoreHeightZoom);
return getShoreHeightGenerator().fitDoubleD(shoreHeightMin, shoreHeightMax, x / shoreHeightZoom, z / shoreHeightZoom);
}
public KList<IrisBiome> getAllBiomes()
@ -246,115 +235,91 @@ public class IrisRegion extends IrisRegistrant
public KList<IrisBiome> getRealCaveBiomes()
{
lock.lock();
if(realCaveBiomes == null)
return realCaveBiomes.aquire(() ->
{
realCaveBiomes = new KList<>();
KList<IrisBiome> realCaveBiomes = new KList<>();
for(String i : getCaveBiomes())
{
realCaveBiomes.add(Iris.data.getBiomeLoader().load(i));
}
}
lock.unlock();
return realCaveBiomes;
return realCaveBiomes;
});
}
public KList<IrisBiome> getRealSkylandBiomes()
{
lock.lock();
if(realSkylandBiomes == null)
return realSkylandBiomes.aquire(() ->
{
realSkylandBiomes = new KList<>();
KList<IrisBiome> realSkylandBiomes = new KList<>();
for(String i : getSkylandBiomes())
{
realSkylandBiomes.add(Iris.data.getBiomeLoader().load(i));
}
}
lock.unlock();
return realSkylandBiomes;
return realSkylandBiomes;
});
}
public KList<IrisBiome> getRealIslandBiomes()
{
lock.lock();
if(realIslandBiomes == null)
return realIslandBiomes.aquire(() ->
{
realIslandBiomes = new KList<>();
KList<IrisBiome> realIslandBiomes = new KList<>();
for(String i : getIslandBiomes())
{
realIslandBiomes.add(Iris.data.getBiomeLoader().load(i));
}
}
lock.unlock();
return realIslandBiomes;
return realIslandBiomes;
});
}
public KList<IrisBiome> getRealShoreBiomes()
{
lock.lock();
if(realShoreBiomes == null)
return realShoreBiomes.aquire(() ->
{
realShoreBiomes = new KList<>();
KList<IrisBiome> realShoreBiomes = new KList<>();
for(String i : getShoreBiomes())
{
realShoreBiomes.add(Iris.data.getBiomeLoader().load(i));
}
}
lock.unlock();
return realShoreBiomes;
return realShoreBiomes;
});
}
public KList<IrisBiome> getRealSeaBiomes()
{
lock.lock();
if(realSeaBiomes == null)
return realSeaBiomes.aquire(() ->
{
realSeaBiomes = new KList<>();
KList<IrisBiome> realSeaBiomes = new KList<>();
for(String i : getSeaBiomes())
{
realSeaBiomes.add(Iris.data.getBiomeLoader().load(i));
}
}
lock.unlock();
return realSeaBiomes;
return realSeaBiomes;
});
}
public KList<IrisBiome> getRealLandBiomes()
{
lock.lock();
if(realLandBiomes == null)
return realLandBiomes.aquire(() ->
{
realLandBiomes = new KList<>();
KList<IrisBiome> realLandBiomes = new KList<>();
for(String i : getLandBiomes())
{
realLandBiomes.add(Iris.data.getBiomeLoader().load(i));
}
}
lock.unlock();
return realLandBiomes;
return realLandBiomes;
});
}
}

View File

@ -1,5 +1,6 @@
package com.volmit.iris.object;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.CellGenerator;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
@ -55,14 +56,36 @@ public class IrisRegionRidge
@Desc("If the noise multiplier is below zero, what should the air be filled with?")
private IrisBiomePaletteLayer air = new IrisBiomePaletteLayer().zero();
private transient CellGenerator spot;
private transient CellGenerator ridge;
private transient AtomicCache<CellGenerator> spot = new AtomicCache<>();
private transient AtomicCache<CellGenerator> ridge = new AtomicCache<>();
public IrisRegionRidge()
{
}
public CellGenerator getSpotGenerator(RNG rng)
{
return spot.aquire(() ->
{
CellGenerator spot = new CellGenerator(rng.nextParallelRNG((int) (198523 * getChance())));
spot.setCellScale(chanceScale);
spot.setShuffle(shuffle);
return spot;
});
}
public CellGenerator getRidgeGenerator(RNG rng)
{
return spot.aquire(() ->
{
CellGenerator ridge = new CellGenerator(rng.nextParallelRNG((int) (465583 * getChance())));
ridge.setCellScale(scale);
ridge.setShuffle(shuffle);
return ridge;
});
}
public double getRidgeHeight(RNG rng, double x, double z)
{
if(getNoiseMultiplier() == 0)
@ -70,48 +93,20 @@ public class IrisRegionRidge
return 0;
}
if(ridge == null)
{
ridge = new CellGenerator(rng.nextParallelRNG((int) (465583 * getChance())));
ridge.setCellScale(scale);
ridge.setShuffle(shuffle);
}
if(spot == null)
{
spot = new CellGenerator(rng.nextParallelRNG((int) (198523 * getChance())));
spot.setCellScale(chanceScale);
spot.setShuffle(shuffle);
}
return spot.getDistance(x, z) * ridge.getDistance(x, z) * getNoiseMultiplier();
return getSpotGenerator(rng).getDistance(x, z) * getRidgeGenerator(rng).getDistance(x, z) * getNoiseMultiplier();
}
public boolean isRidge(RNG rng, double x, double z)
{
if(ridge == null)
{
ridge = new CellGenerator(rng.nextParallelRNG((int) (465583 * getChance())));
ridge.setCellScale(scale);
ridge.setShuffle(shuffle);
}
if(spot == null)
{
spot = new CellGenerator(rng.nextParallelRNG((int) (198523 * getChance())));
spot.setCellScale(chanceScale);
spot.setShuffle(shuffle);
}
if(chance < 1)
{
if(spot.getIndex(x, z, 1000) > chance * 1000)
if(getSpotGenerator(rng).getIndex(x, z, 1000) > chance * 1000)
{
return false;
}
}
if(ridge.getDistance(x, z) <= thickness)
if(getRidgeGenerator(rng).getDistance(x, z) <= thickness)
{
return true;
}

View File

@ -1,5 +1,6 @@
package com.volmit.iris.object;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.util.CellGenerator;
import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate;
@ -43,13 +44,24 @@ public class IrisRegionSpot
@Desc("If the noise multiplier is below zero, what should the air be filled with?")
private IrisBiomePaletteLayer air = new IrisBiomePaletteLayer().zero();
private transient CellGenerator spot;
private transient AtomicCache<CellGenerator> spot = new AtomicCache<>();
public IrisRegionSpot()
{
}
public CellGenerator getSpotGenerator(RNG rng)
{
return spot.aquire(() ->
{
CellGenerator spot = new CellGenerator(rng.nextParallelRNG((int) (168583 * (shuffle + 102) + rarity + (scale * 10465) + biome.length() + type.ordinal() + as.ordinal())));
spot.setCellScale(scale);
spot.setShuffle(shuffle);
return spot;
});
}
public double getSpotHeight(RNG rng, double x, double z)
{
if(getNoiseMultiplier() == 0)
@ -57,26 +69,12 @@ public class IrisRegionSpot
return 0;
}
if(spot == null)
{
spot = new CellGenerator(rng.nextParallelRNG((int) (168583 * (shuffle + 102) + rarity + (scale * 10465) + biome.length() + type.ordinal() + as.ordinal())));
spot.setCellScale(scale);
spot.setShuffle(shuffle);
}
return spot.getDistance(x, z) * getNoiseMultiplier();
return getSpotGenerator(rng).getDistance(x, z) * getNoiseMultiplier();
}
public boolean isSpot(RNG rng, double x, double z)
{
if(spot == null)
{
spot = new CellGenerator(rng.nextParallelRNG((int) (168583 * (shuffle + 102) + rarity + (scale * 10465) + biome.length() + type.ordinal() + as.ordinal())));
spot.setCellScale(scale);
spot.setShuffle(shuffle);
}
if(spot.getIndex(x, z, (int) (Math.round(rarity) + 8)) == (int) ((Math.round(rarity) + 8) / 2))
if(getSpotGenerator(rng).getIndex(x, z, (int) (Math.round(rarity) + 8)) == (int) ((Math.round(rarity) + 8) / 2))
{
return true;
}

View File

@ -0,0 +1,38 @@
package com.volmit.iris.util;
import java.util.concurrent.locks.ReentrantLock;
import lombok.Data;
@Data
public class IrisLock
{
private final ReentrantLock lock;
private final String name;
private boolean disabled = false;
public IrisLock(String name)
{
this.name = name;
lock = new ReentrantLock(false);
}
public void lock()
{
if(disabled)
{
return;
}
lock.lock();
}
public void unlock()
{
if(disabled)
{
return;
}
lock.unlock();
}
}