mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-30 04:29:05 +00:00
Fix locking
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package com.volmit.iris.gen;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
@@ -17,6 +15,7 @@ import com.volmit.iris.util.CNG;
|
||||
import com.volmit.iris.util.ChronoLatch;
|
||||
import com.volmit.iris.util.ChunkPosition;
|
||||
import com.volmit.iris.util.IrisInterpolation;
|
||||
import com.volmit.iris.util.IrisLock;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.M;
|
||||
@@ -29,7 +28,7 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
|
||||
{
|
||||
protected ReentrantLock regLock;
|
||||
protected IrisLock regLock;
|
||||
private KMap<String, IrisGenerator> generators;
|
||||
private KMap<String, IrisGenerator> ceilingGenerators;
|
||||
protected GenLayerBiome glBiome;
|
||||
@@ -44,7 +43,7 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
|
||||
super(dimensionName);
|
||||
generators = new KMap<>();
|
||||
ceilingGenerators = new KMap<>();
|
||||
regLock = new ReentrantLock();
|
||||
regLock = new IrisLock("BiomeChunkGenerator");
|
||||
biomeHitCache = new KMap<>();
|
||||
ceilingBiomeHitCache = new KMap<>();
|
||||
biomeCache = new IrisBiome[256];
|
||||
@@ -119,31 +118,47 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
|
||||
{
|
||||
double hi = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) ->
|
||||
{
|
||||
IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome();
|
||||
|
||||
for(IrisBiomeGeneratorLink i : b.getGenerators())
|
||||
try
|
||||
{
|
||||
if(i.getGenerator().equals(gen.getLoadKey()))
|
||||
IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome();
|
||||
|
||||
for(IrisBiomeGeneratorLink i : b.getGenerators())
|
||||
{
|
||||
return i.getMax();
|
||||
if(i.getGenerator().equals(gen.getLoadKey()))
|
||||
{
|
||||
return i.getMax();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " + gen.getLoadKey());
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
double lo = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) ->
|
||||
{
|
||||
IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome();
|
||||
|
||||
for(IrisBiomeGeneratorLink i : b.getGenerators())
|
||||
try
|
||||
{
|
||||
if(i.getGenerator().equals(gen.getLoadKey()))
|
||||
IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome();
|
||||
|
||||
for(IrisBiomeGeneratorLink i : b.getGenerators())
|
||||
{
|
||||
return i.getMin();
|
||||
if(i.getGenerator().equals(gen.getLoadKey()))
|
||||
{
|
||||
return i.getMin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " + gen.getLoadKey());
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.volmit.iris.gen;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
@@ -15,6 +14,7 @@ import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.IrisRegion;
|
||||
import com.volmit.iris.util.BiomeResult;
|
||||
import com.volmit.iris.util.CNG;
|
||||
import com.volmit.iris.util.IrisLock;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
@@ -26,13 +26,13 @@ import lombok.EqualsAndHashCode;
|
||||
public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisContext
|
||||
{
|
||||
private Method initLighting;
|
||||
private ReentrantLock lock;
|
||||
private IrisLock lock;
|
||||
private KMap<Player, IrisBiome> b = new KMap<>();
|
||||
|
||||
public IrisChunkGenerator(String dimensionName, int threads)
|
||||
{
|
||||
super(dimensionName, threads);
|
||||
lock = new ReentrantLock();
|
||||
lock = new IrisLock("IrisChunkGenerator");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +77,7 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon
|
||||
@Override
|
||||
protected void onTick(int ticks)
|
||||
{
|
||||
super.onTick(ticks);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.volmit.iris.gen;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -19,6 +18,7 @@ import com.volmit.iris.util.CaveResult;
|
||||
import com.volmit.iris.util.ChunkPosition;
|
||||
import com.volmit.iris.util.HeightMap;
|
||||
import com.volmit.iris.util.IObjectPlacer;
|
||||
import com.volmit.iris.util.IrisLock;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.NastyRunnable;
|
||||
@@ -37,8 +37,8 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
|
||||
protected KMap<ChunkPosition, AtomicSliver> ceilingSliverCache;
|
||||
protected AtomicWorldData ceilingParallaxMap;
|
||||
private MasterLock masterLock;
|
||||
private ReentrantLock lock = new ReentrantLock();
|
||||
private ReentrantLock lockq = new ReentrantLock();
|
||||
private IrisLock lock = new IrisLock("ParallaxLock");
|
||||
private IrisLock lockq = new IrisLock("ParallaxQueueLock");
|
||||
private int sliverBuffer;
|
||||
|
||||
public ParallaxChunkGenerator(String dimensionName, int threads)
|
||||
@@ -190,6 +190,8 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
|
||||
p.end();
|
||||
getMetrics().getParallax().put(p.getMilliseconds());
|
||||
super.onPostParallaxPostGenerate(random, x, z, data, grid, height, biomeMap);
|
||||
getParallaxMap().clean(ticks);
|
||||
Iris.data.getObjectLoader().clean();
|
||||
}
|
||||
|
||||
protected void injectBiomeSky(int x, int z, BiomeGrid grid)
|
||||
@@ -370,13 +372,6 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTick(int ticks)
|
||||
{
|
||||
getParallaxMap().clean(ticks);
|
||||
Iris.data.getObjectLoader().clean();
|
||||
}
|
||||
|
||||
public AtomicSliver sampleSliver(int x, int z)
|
||||
{
|
||||
ChunkPosition key = new ChunkPosition(x, z);
|
||||
@@ -387,7 +382,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
|
||||
}
|
||||
|
||||
AtomicSliver s = new AtomicSliver(x & 15, z & 15);
|
||||
onGenerateColumn(x >> 4, z >> 4, x, z, x & 15, z & 15, s, null);
|
||||
onGenerateColumn(x >> 4, z >> 4, x, z, x & 15, z & 15, s, null, true);
|
||||
getSliverCache().put(key, s);
|
||||
|
||||
return s;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.volmit.iris.gen;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
@@ -10,6 +8,7 @@ import com.volmit.iris.gen.atomics.AtomicSliverMap;
|
||||
import com.volmit.iris.util.BiomeMap;
|
||||
import com.volmit.iris.util.GroupedExecutor;
|
||||
import com.volmit.iris.util.HeightMap;
|
||||
import com.volmit.iris.util.IrisLock;
|
||||
import com.volmit.iris.util.PrecisionStopwatch;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
@@ -25,7 +24,7 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator
|
||||
protected boolean unsafe;
|
||||
protected int cacheX;
|
||||
protected int cacheZ;
|
||||
private ReentrantLock genlock;
|
||||
private IrisLock genlock;
|
||||
protected boolean cachingAllowed;
|
||||
|
||||
public ParallelChunkGenerator(String dimensionName, int threads)
|
||||
@@ -35,7 +34,7 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator
|
||||
cacheX = 0;
|
||||
cacheZ = 0;
|
||||
this.threads = threads;
|
||||
genlock = new ReentrantLock();
|
||||
genlock = new IrisLock("ParallelGenLock");
|
||||
}
|
||||
|
||||
public void changeThreadCount(int tc)
|
||||
@@ -51,11 +50,11 @@ public abstract class ParallelChunkGenerator extends BiomeChunkGenerator
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, int onlyY);
|
||||
protected abstract void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled);
|
||||
|
||||
protected void onGenerateColumn(int cx, int cz, int wx, int wz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap)
|
||||
{
|
||||
onGenerateColumn(cx, cz, wx, wz, x, z, sliver, biomeMap, -1);
|
||||
onGenerateColumn(cx, cz, wx, wz, x, z, sliver, biomeMap, false);
|
||||
}
|
||||
|
||||
protected abstract int onSampleColumnHeight(int cx, int cz, int wx, int wz, int x, int z);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.volmit.iris.gen;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
@@ -9,6 +7,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
import com.volmit.iris.util.CaveResult;
|
||||
import com.volmit.iris.util.IPostBlockAccess;
|
||||
import com.volmit.iris.util.IrisLock;
|
||||
import com.volmit.iris.util.IrisPostBlockFilter;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.PrecisionStopwatch;
|
||||
@@ -30,7 +29,7 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
|
||||
private ChunkData currentData;
|
||||
private KList<IrisPostBlockFilter> availableFilters;
|
||||
private String postKey;
|
||||
private ReentrantLock lock;
|
||||
private IrisLock lock;
|
||||
private int minPhase;
|
||||
private int maxPhase;
|
||||
|
||||
@@ -39,7 +38,7 @@ public abstract class PostBlockChunkGenerator extends ParallaxChunkGenerator imp
|
||||
super(dimensionName, threads);
|
||||
availableFilters = new KList<>();
|
||||
postKey = "post-" + dimensionName;
|
||||
lock = new ReentrantLock();
|
||||
lock = new IrisLock("PostChunkGenerator");
|
||||
}
|
||||
|
||||
public void onInit(World world, RNG rng)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.volmit.iris.gen;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
@@ -23,6 +21,7 @@ import com.volmit.iris.util.BiomeResult;
|
||||
import com.volmit.iris.util.BlockDataTools;
|
||||
import com.volmit.iris.util.CaveResult;
|
||||
import com.volmit.iris.util.HeightMap;
|
||||
import com.volmit.iris.util.IrisLock;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.M;
|
||||
import com.volmit.iris.util.RNG;
|
||||
@@ -41,7 +40,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
|
||||
private RNG rockRandom;
|
||||
private int[] cacheHeightMap;
|
||||
private BiomeResult[] cacheTrueBiome;
|
||||
private ReentrantLock cacheLock;
|
||||
private IrisLock cacheLock;
|
||||
|
||||
public TerrainChunkGenerator(String dimensionName, int threads)
|
||||
{
|
||||
@@ -49,7 +48,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
|
||||
cacheHeightMap = new int[256];
|
||||
cacheTrueBiome = new BiomeResult[256];
|
||||
cachingAllowed = true;
|
||||
cacheLock = new ReentrantLock();
|
||||
cacheLock = new IrisLock("TerrainCacheLock");
|
||||
}
|
||||
|
||||
public void onInit(World world, RNG rng)
|
||||
@@ -66,7 +65,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onGenerateColumn(int cx, int cz, int rx, int rz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, int onlyY)
|
||||
protected void onGenerateColumn(int cx, int cz, int rx, int rz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled)
|
||||
{
|
||||
if(x > 15 || x < 0 || z > 15 || z < 0)
|
||||
{
|
||||
@@ -96,7 +95,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
|
||||
throw new RuntimeException("Null Biome!");
|
||||
}
|
||||
|
||||
if(cachingAllowed)
|
||||
if(cachingAllowed && !sampled)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -112,7 +111,12 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
|
||||
|
||||
KList<BlockData> layers = biome.generateLayers(wx, wz, masterRandom, height, height - getFluidHeight());
|
||||
KList<BlockData> seaLayers = biome.isSea() ? biome.generateSeaLayers(wx, wz, masterRandom, fluidHeight - height) : new KList<>();
|
||||
cacheInternalBiome(x, z, biome);
|
||||
|
||||
if(cachingAllowed && !sampled)
|
||||
{
|
||||
cacheInternalBiome(x, z, biome);
|
||||
}
|
||||
|
||||
boolean caverning = false;
|
||||
KList<Integer> cavernHeights = new KList<>();
|
||||
int lastCavernHeight = -1;
|
||||
@@ -252,7 +256,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
|
||||
}
|
||||
}
|
||||
|
||||
if(cachingAllowed && highestPlaced < height)
|
||||
if(!sampled && cachingAllowed && highestPlaced < height)
|
||||
{
|
||||
cacheHeightMap[(z << 4) | x] = highestPlaced;
|
||||
}
|
||||
@@ -327,6 +331,14 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
|
||||
}
|
||||
}
|
||||
|
||||
if(d.getMaterial().equals(Material.WHEAT) || d.getMaterial().equals(Material.CARROTS) || d.getMaterial().equals(Material.POTATOES) || d.getMaterial().equals(Material.MELON_STEM) || d.getMaterial().equals(Material.PUMPKIN_STEM))
|
||||
{
|
||||
if(!block.getMaterial().equals(Material.FARMLAND))
|
||||
{
|
||||
sliver.set(k, BlockDataTools.getBlockData("FARMLAND"));
|
||||
}
|
||||
}
|
||||
|
||||
if(d instanceof Bisected && k < 254)
|
||||
{
|
||||
Bisected t = ((Bisected) d.clone());
|
||||
|
||||
Reference in New Issue
Block a user