mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Fix parallax deadlocking
This commit is contained in:
parent
5b74f8f836
commit
73360bb66c
@ -3,8 +3,6 @@ package com.volmit.iris.generator;
|
|||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.scaffold.engine.*;
|
import com.volmit.iris.scaffold.engine.*;
|
||||||
import com.volmit.iris.scaffold.hunk.Hunk;
|
import com.volmit.iris.scaffold.hunk.Hunk;
|
||||||
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
|
||||||
import com.volmit.iris.util.ChronoLatch;
|
|
||||||
import com.volmit.iris.util.J;
|
import com.volmit.iris.util.J;
|
||||||
import com.volmit.iris.util.PrecisionStopwatch;
|
import com.volmit.iris.util.PrecisionStopwatch;
|
||||||
import com.volmit.iris.util.RNG;
|
import com.volmit.iris.util.RNG;
|
||||||
@ -52,7 +50,6 @@ public class IrisEngine extends BlockPopulator implements Engine
|
|||||||
private volatile int minHeight;
|
private volatile int minHeight;
|
||||||
private int permits;
|
private int permits;
|
||||||
private boolean failing;
|
private boolean failing;
|
||||||
private ChronoLatch cl = new ChronoLatch(10000);
|
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
private int cacheId;
|
private int cacheId;
|
||||||
private Semaphore s;
|
private Semaphore s;
|
||||||
@ -62,7 +59,7 @@ public class IrisEngine extends BlockPopulator implements Engine
|
|||||||
{
|
{
|
||||||
Iris.info("Initializing Engine: " + target.getWorld().getName() + "/" + target.getDimension().getLoadKey() + " (" + target.getHeight() + " height)");
|
Iris.info("Initializing Engine: " + target.getWorld().getName() + "/" + target.getDimension().getLoadKey() + " (" + target.getHeight() + " height)");
|
||||||
metrics = new EngineMetrics(32);
|
metrics = new EngineMetrics(32);
|
||||||
permits = 1000;
|
permits = 10000;
|
||||||
this.s = new Semaphore(permits);
|
this.s = new Semaphore(permits);
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.framework = new IrisEngineFramework(this);
|
this.framework = new IrisEngineFramework(this);
|
||||||
@ -127,19 +124,7 @@ public class IrisEngine extends BlockPopulator implements Engine
|
|||||||
getFramework().getEngineParallax().insertParallax(x, z, fringe);
|
getFramework().getEngineParallax().insertParallax(x, z, fringe);
|
||||||
getMetrics().getTotal().put(p.getMilliseconds());
|
getMetrics().getTotal().put(p.getMilliseconds());
|
||||||
s.release(1);
|
s.release(1);
|
||||||
|
|
||||||
if(cl.flip())
|
|
||||||
{
|
|
||||||
MultiBurst.burst.lazy(() -> {
|
|
||||||
try {
|
|
||||||
s.acquire(permits);
|
|
||||||
getFramework().recycle();
|
getFramework().recycle();
|
||||||
s.release(permits);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(Throwable e)
|
catch(Throwable e)
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
package com.volmit.iris.generator;
|
package com.volmit.iris.generator;
|
||||||
|
|
||||||
import com.volmit.iris.generator.actuator.*;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.IrisSettings;
|
||||||
|
import com.volmit.iris.generator.actuator.IrisBiomeActuator;
|
||||||
|
import com.volmit.iris.generator.actuator.IrisDecorantActuator;
|
||||||
|
import com.volmit.iris.generator.actuator.IrisTerrainActuator;
|
||||||
import com.volmit.iris.generator.modifier.IrisCaveModifier;
|
import com.volmit.iris.generator.modifier.IrisCaveModifier;
|
||||||
import com.volmit.iris.generator.modifier.IrisDepositModifier;
|
import com.volmit.iris.generator.modifier.IrisDepositModifier;
|
||||||
import com.volmit.iris.generator.modifier.IrisPostModifier;
|
import com.volmit.iris.generator.modifier.IrisPostModifier;
|
||||||
import com.volmit.iris.generator.modifier.IrisRavineModifier;
|
import com.volmit.iris.generator.modifier.IrisRavineModifier;
|
||||||
import com.volmit.iris.scaffold.engine.*;
|
import com.volmit.iris.scaffold.engine.*;
|
||||||
|
import com.volmit.iris.util.ChronoLatch;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class IrisEngineFramework implements EngineFramework {
|
public class IrisEngineFramework implements EngineFramework {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -42,6 +49,9 @@ public class IrisEngineFramework implements EngineFramework {
|
|||||||
@Getter
|
@Getter
|
||||||
private final EngineModifier<BlockData> postModifier;
|
private final EngineModifier<BlockData> postModifier;
|
||||||
|
|
||||||
|
private final AtomicBoolean cleaning;
|
||||||
|
private final ChronoLatch cleanLatch;
|
||||||
|
|
||||||
public IrisEngineFramework(Engine engine)
|
public IrisEngineFramework(Engine engine)
|
||||||
{
|
{
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
@ -54,6 +64,39 @@ public class IrisEngineFramework implements EngineFramework {
|
|||||||
this.ravineModifier = new IrisRavineModifier(getEngine());
|
this.ravineModifier = new IrisRavineModifier(getEngine());
|
||||||
this.caveModifier = new IrisCaveModifier(engine);
|
this.caveModifier = new IrisCaveModifier(engine);
|
||||||
this.postModifier = new IrisPostModifier(engine);
|
this.postModifier = new IrisPostModifier(engine);
|
||||||
|
cleaning = new AtomicBoolean(false);
|
||||||
|
cleanLatch = new ChronoLatch(Math.max(10000, Math.min(IrisSettings.get().parallaxChunkEvictionMS, IrisSettings.get().parallaxRegionEvictionMS)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void recycle() {
|
||||||
|
if(!cleanLatch.flip())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cleaning.get())
|
||||||
|
{
|
||||||
|
cleanLatch.flipDown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleaning.set(true);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getEngine().getParallax().cleanup();
|
||||||
|
getData().getObjectLoader().clean();
|
||||||
|
Iris.verbose("Ran Cleanup");
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
Iris.error("Cleanup failed!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
cleaning.lazySet(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,7 +3,6 @@ package com.volmit.iris.scaffold.engine;
|
|||||||
import com.volmit.iris.generator.IrisComplex;
|
import com.volmit.iris.generator.IrisComplex;
|
||||||
import com.volmit.iris.manager.IrisDataManager;
|
import com.volmit.iris.manager.IrisDataManager;
|
||||||
import com.volmit.iris.scaffold.data.DataProvider;
|
import com.volmit.iris.scaffold.data.DataProvider;
|
||||||
import com.volmit.iris.util.M;
|
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
@ -20,17 +19,10 @@ public interface EngineFramework extends DataProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
default void recycle()
|
default void recycle()
|
||||||
{
|
|
||||||
if(M.r(0.1))
|
|
||||||
{
|
|
||||||
synchronized (getEngine().getParallax())
|
|
||||||
{
|
{
|
||||||
getEngine().getParallax().cleanup();
|
getEngine().getParallax().cleanup();
|
||||||
}
|
|
||||||
|
|
||||||
getData().getObjectLoader().clean();
|
getData().getObjectLoader().clean();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public EngineActuator<BlockData> getTerrainActuator();
|
public EngineActuator<BlockData> getTerrainActuator();
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class HunkRegionSlice<T>
|
public class HunkRegionSlice<T>
|
||||||
{
|
{
|
||||||
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata");
|
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newAtomicHunk, new BlockDataHunkIOAdapter(), c, "blockdata");
|
||||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t);
|
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newAtomicHunk, new StringHunkIOAdapter(), c, t);
|
||||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t);
|
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newAtomicHunk, new BooleanHunkIOAdapter(), c, t);
|
||||||
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
|
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
|
||||||
private final HunkIOAdapter<T> adapter;
|
private final HunkIOAdapter<T> adapter;
|
||||||
private final CompoundTag compound;
|
private final CompoundTag compound;
|
||||||
|
@ -90,7 +90,7 @@ public class ParallaxRegion extends HunkRegion
|
|||||||
return getMetaHunkR();
|
return getMetaHunkR();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Hunk<ParallaxChunkMeta> loadMetaHunk()
|
public Hunk<ParallaxChunkMeta> loadMetaHunk()
|
||||||
{
|
{
|
||||||
lastUse = M.ms();
|
lastUse = M.ms();
|
||||||
if(meta == null)
|
if(meta == null)
|
||||||
@ -115,7 +115,7 @@ public class ParallaxRegion extends HunkRegion
|
|||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void unloadMetaHunk()
|
public void unloadMetaHunk()
|
||||||
{
|
{
|
||||||
if(dirtyMeta)
|
if(dirtyMeta)
|
||||||
{
|
{
|
||||||
@ -126,7 +126,7 @@ public class ParallaxRegion extends HunkRegion
|
|||||||
meta = null;
|
meta = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void saveMetaHunk()
|
public void saveMetaHunk()
|
||||||
{
|
{
|
||||||
if(meta != null && dirtyMeta)
|
if(meta != null && dirtyMeta)
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,7 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void close()
|
public void close()
|
||||||
{
|
{
|
||||||
for(ParallaxRegion i : loadedRegions.v())
|
for(ParallaxRegion i : loadedRegions.v())
|
||||||
{
|
{
|
||||||
@ -65,7 +65,7 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
loadedRegions.clear();
|
loadedRegions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void save(ParallaxRegion region)
|
public void save(ParallaxRegion region)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -83,7 +83,7 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
return loadedRegions.containsKey(key(x, z));
|
return loadedRegions.containsKey(key(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void save(int x, int z)
|
public void save(int x, int z)
|
||||||
{
|
{
|
||||||
if(isLoaded(x, z))
|
if(isLoaded(x, z))
|
||||||
{
|
{
|
||||||
@ -91,7 +91,7 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void unload(int x, int z)
|
public void unload(int x, int z)
|
||||||
{
|
{
|
||||||
long key = key(x, z);
|
long key = key(x, z);
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized ParallaxRegion load(int x, int z)
|
public ParallaxRegion load(int x, int z)
|
||||||
{
|
{
|
||||||
if(isLoaded(x, z))
|
if(isLoaded(x, z))
|
||||||
{
|
{
|
||||||
@ -157,7 +157,7 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Hunk<BlockData> getBlocksRW(int x, int z)
|
public Hunk<BlockData> getBlocksRW(int x, int z)
|
||||||
{
|
{
|
||||||
return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31);
|
return getRW(x >> 5, z >> 5).getBlockSlice().getRW(x & 31, z & 31);
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Hunk<String> getObjectsRW(int x, int z)
|
public Hunk<String> getObjectsRW(int x, int z)
|
||||||
{
|
{
|
||||||
return getRW(x >> 5, z >> 5).getObjectSlice().getRW(x & 31, z & 31);
|
return getRW(x >> 5, z >> 5).getObjectSlice().getRW(x & 31, z & 31);
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Hunk<Boolean> getUpdatesRW(int x, int z)
|
public Hunk<Boolean> getUpdatesRW(int x, int z)
|
||||||
{
|
{
|
||||||
return getRW(x >> 5, z >> 5).getUpdateSlice().getRW(x & 31, z & 31);
|
return getRW(x >> 5, z >> 5).getUpdateSlice().getRW(x & 31, z & 31);
|
||||||
}
|
}
|
||||||
@ -227,10 +227,8 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void saveAllNOW() {
|
public void saveAllNOW() {
|
||||||
for(ParallaxRegion i : loadedRegions.v())
|
for(ParallaxRegion i : loadedRegions.v())
|
||||||
{
|
|
||||||
synchronized (save)
|
|
||||||
{
|
{
|
||||||
if(save.contains(key(i.getX(), i.getZ())))
|
if(save.contains(key(i.getX(), i.getZ())))
|
||||||
{
|
{
|
||||||
@ -238,5 +236,4 @@ public class ParallaxWorld implements ParallaxAccess
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user