mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-28 11:39:07 +00:00
f
This commit is contained in:
@@ -80,7 +80,7 @@ public class Mantle {
|
||||
unload = new KSet<>();
|
||||
loadedRegions = new KMap<>();
|
||||
lastUse = new KMap<>();
|
||||
ioBurst = new MultiBurst("Iris Mantle[" + dataFolder.hashCode() + "]", Thread.MIN_PRIORITY, Runtime.getRuntime().availableProcessors() / 2);
|
||||
ioBurst = MultiBurst.burst;
|
||||
Iris.debug("Opened The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
@@ -126,6 +126,19 @@ public class Mantle {
|
||||
get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31).flag(flag, flagged);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check very quickly if a tectonic plate exists via cached or the file system
|
||||
* @param x the x region coordinate
|
||||
* @param z the z region coordinate
|
||||
* @return true if it exists
|
||||
*/
|
||||
@RegionCoordinates
|
||||
public boolean hasTectonicPlate(int x, int z)
|
||||
{
|
||||
Long k = key(x, z);
|
||||
return loadedRegions.containsKey(k) || fileForRegion(dataFolder, k).exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate data in a chunk
|
||||
* @param x the chunk x
|
||||
@@ -137,6 +150,11 @@ public class Mantle {
|
||||
*/
|
||||
@ChunkCoordinates
|
||||
public <T> void iterateChunk(int x, int z, Class<T> type, Consumer4<Integer, Integer, Integer, T> iterator, MantleFlag... requiredFlags) {
|
||||
if(!hasTectonicPlate(x >> 5, z >> 5))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (MantleFlag i : requiredFlags) {
|
||||
if (!hasFlag(x, z, i)) {
|
||||
return;
|
||||
@@ -155,6 +173,11 @@ public class Mantle {
|
||||
*/
|
||||
@ChunkCoordinates
|
||||
public boolean hasFlag(int x, int z, MantleFlag flag) {
|
||||
if(!hasTectonicPlate(x >> 5, z >> 5))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31).isFlagged(flag);
|
||||
}
|
||||
|
||||
@@ -211,7 +234,12 @@ public class Mantle {
|
||||
throw new RuntimeException("The Mantle is closed");
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
if(!hasTectonicPlate(x >> 5, z >> 5))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (y < 0 || y >= worldHeight) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -263,7 +291,6 @@ public class Mantle {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
ioBurst.shutdownNow();
|
||||
Iris.debug("The Mantle has Closed " + C.DARK_AQUA + dataFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,9 @@
|
||||
package com.volmit.iris.util.parallel;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.service.PreservationSVC;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.io.InstanceState;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
@@ -33,66 +29,39 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MultiBurst {
|
||||
public static final MultiBurst burst = new MultiBurst("Iris", IrisSettings.get().getConcurrency().getMiscThreadPriority(), IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getMiscThreadCount()));
|
||||
public static final MultiBurst burst = new MultiBurst();
|
||||
private ExecutorService service;
|
||||
private final Looper heartbeat;
|
||||
private final AtomicLong last;
|
||||
private int tid;
|
||||
private final String name;
|
||||
private final int tc;
|
||||
private final int priority;
|
||||
private final int instance;
|
||||
|
||||
public MultiBurst(int tc) {
|
||||
this("Iris", 6, tc);
|
||||
public MultiBurst() {
|
||||
this("Iris", Thread.MIN_PRIORITY);
|
||||
}
|
||||
|
||||
public MultiBurst(String name, int priority, int tc) {
|
||||
public MultiBurst(String name, int priority) {
|
||||
this.name = name;
|
||||
this.priority = priority;
|
||||
this.tc = tc;
|
||||
instance = InstanceState.getInstanceId();
|
||||
last = new AtomicLong(M.ms());
|
||||
heartbeat = new Looper() {
|
||||
@Override
|
||||
protected long loop() {
|
||||
if (instance != InstanceState.getInstanceId()) {
|
||||
shutdownNow();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (M.ms() - last.get() > TimeUnit.MINUTES.toMillis(1) && service != null) {
|
||||
service.shutdown();
|
||||
service = null;
|
||||
Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resources.");
|
||||
}
|
||||
|
||||
return 30000;
|
||||
}
|
||||
};
|
||||
heartbeat.setName(name + " Monitor");
|
||||
heartbeat.start();
|
||||
Iris.service(PreservationSVC.class).register(this);
|
||||
}
|
||||
|
||||
private synchronized ExecutorService getService() {
|
||||
last.set(M.ms());
|
||||
if (service == null || service.isShutdown()) {
|
||||
service = Executors.newFixedThreadPool(Math.max(tc, 1), r -> {
|
||||
tid++;
|
||||
Thread t = new Thread(r);
|
||||
t.setName(name + " " + tid);
|
||||
t.setPriority(priority);
|
||||
t.setUncaughtExceptionHandler((et, e) ->
|
||||
{
|
||||
Iris.info("Exception encountered in " + et.getName());
|
||||
e.printStackTrace();
|
||||
});
|
||||
service = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
|
||||
new ForkJoinPool.ForkJoinWorkerThreadFactory() {
|
||||
int m = 0;
|
||||
|
||||
return t;
|
||||
});
|
||||
Iris.service(PreservationSVC.class).register(service);
|
||||
Iris.debug("Started MultiBurst Pool " + name + " with " + tc + " threads at " + priority + " priority.");
|
||||
@Override
|
||||
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
|
||||
final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
|
||||
worker.setPriority(priority);
|
||||
worker.setName(name + " " + ++m);
|
||||
return worker;
|
||||
}
|
||||
},
|
||||
(t, e) -> e.printStackTrace(), true);
|
||||
}
|
||||
|
||||
return service;
|
||||
@@ -146,56 +115,7 @@ public class MultiBurst {
|
||||
return CompletableFuture.supplyAsync(o, getService());
|
||||
}
|
||||
|
||||
public void shutdownNow() {
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
heartbeat.interrupt();
|
||||
|
||||
if (service != null) {
|
||||
service.shutdownNow().forEach(Runnable::run);
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
heartbeat.interrupt();
|
||||
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdownLater() {
|
||||
if (service != null) {
|
||||
try
|
||||
{
|
||||
service.submit(() -> {
|
||||
J.sleep(3000);
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
}
|
||||
});
|
||||
|
||||
heartbeat.interrupt();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
}
|
||||
|
||||
heartbeat.interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdownAndAwait() {
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
heartbeat.interrupt();
|
||||
public void close() {
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user