mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Fix locking
This commit is contained in:
parent
58a5aaed30
commit
ef5115b76c
@ -36,6 +36,7 @@ import com.volmit.iris.util.Desc;
|
||||
import com.volmit.iris.util.Form;
|
||||
import com.volmit.iris.util.GroupedExecutor;
|
||||
import com.volmit.iris.util.IO;
|
||||
import com.volmit.iris.util.IrisLock;
|
||||
import com.volmit.iris.util.IrisPostBlockFilter;
|
||||
import com.volmit.iris.util.J;
|
||||
import com.volmit.iris.util.JSONException;
|
||||
@ -64,6 +65,7 @@ public class Iris extends MortarPlugin implements BoardProvider
|
||||
private KList<String> lines = new KList<>();
|
||||
public RollingSequence hits = new RollingSequence(20);
|
||||
public RollingSequence tp = new RollingSequence(100);
|
||||
private static IrisLock lock = new IrisLock("Iris");
|
||||
public static KList<Class<? extends IrisPostBlockFilter>> postProcessors;
|
||||
|
||||
@Permission
|
||||
@ -97,6 +99,7 @@ public class Iris extends MortarPlugin implements BoardProvider
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
lock = new IrisLock("Iris");
|
||||
instance = this;
|
||||
hotloader = new IrisHotloadManager();
|
||||
data = new IrisDataManager(getDataFolder());
|
||||
@ -122,6 +125,7 @@ public class Iris extends MortarPlugin implements BoardProvider
|
||||
|
||||
public void onDisable()
|
||||
{
|
||||
lock.unlock();
|
||||
proj.close();
|
||||
|
||||
for(GroupedExecutor i : executors)
|
||||
@ -280,16 +284,18 @@ public class Iris extends MortarPlugin implements BoardProvider
|
||||
|
||||
public static void msg(String string)
|
||||
{
|
||||
lock.lock();
|
||||
String msg = ChatColor.GREEN + "[Iris]: " + ChatColor.GRAY + string;
|
||||
|
||||
if(last.equals(msg))
|
||||
{
|
||||
lock.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
last = msg;
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(msg);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> Bukkit.getConsoleSender().sendMessage(msg));
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
public static void warn(String string)
|
||||
|
@ -9,7 +9,7 @@ public class IrisSettings
|
||||
|
||||
@DontObfuscate
|
||||
@Desc("Iris generator threads (must be 2 or higher).")
|
||||
public int threads = 16;
|
||||
public int threads = 128;
|
||||
|
||||
@DontObfuscate
|
||||
@Desc("Compress parallax data in memory to reduce memory usage in exchange for more cpu usage.")
|
||||
|
@ -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];
|
||||
@ -118,6 +117,8 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
|
||||
protected double interpolateGenerator(double rx, double rz, IrisGenerator gen)
|
||||
{
|
||||
double hi = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) ->
|
||||
{
|
||||
try
|
||||
{
|
||||
IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome();
|
||||
|
||||
@ -129,10 +130,18 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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) ->
|
||||
{
|
||||
try
|
||||
{
|
||||
IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome();
|
||||
|
||||
@ -143,6 +152,12 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator
|
||||
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<>();
|
||||
|
||||
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());
|
||||
|
@ -5,19 +5,20 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
|
||||
public class GroupedExecutor
|
||||
{
|
||||
private int xc;
|
||||
private ExecutorService service;
|
||||
private ReentrantLock lock;
|
||||
private IrisLock lock;
|
||||
private KMap<String, Integer> mirror;
|
||||
|
||||
public GroupedExecutor(int threadLimit, int priority, String name)
|
||||
{
|
||||
xc = 1;
|
||||
lock = new ReentrantLock();
|
||||
lock = new IrisLock("GX");
|
||||
mirror = new KMap<String, Integer>();
|
||||
|
||||
if(threadLimit == 1)
|
||||
@ -74,14 +75,23 @@ public class GroupedExecutor
|
||||
return;
|
||||
}
|
||||
|
||||
PrecisionStopwatch s = PrecisionStopwatch.start();
|
||||
|
||||
while(true)
|
||||
{
|
||||
J.sleep(1);
|
||||
J.sleep(0);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject>
|
||||
{
|
||||
if(useFlip.flip())
|
||||
{
|
||||
unloadLast(60000);
|
||||
unloadLast(60000 * 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.Iris;
|
||||
@ -17,11 +16,11 @@ public class ResourceLoader<T extends IrisRegistrant>
|
||||
protected KList<File> folderCache;
|
||||
protected Class<? extends T> objectClass;
|
||||
protected String cname;
|
||||
protected ReentrantLock lock;
|
||||
protected IrisLock lock;
|
||||
|
||||
public ResourceLoader(File root, String folderName, String resourceTypeName, Class<? extends T> objectClass)
|
||||
{
|
||||
lock = new ReentrantLock();
|
||||
lock = new IrisLock("Res");
|
||||
folderMapCache = new KMap<>();
|
||||
this.objectClass = objectClass;
|
||||
cname = objectClass.getCanonicalName();
|
||||
|
Loading…
x
Reference in New Issue
Block a user