mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-02 16:07:06 +00:00
potential fix for pregen deadlock
This commit is contained in:
parent
414f46a08d
commit
38ad345f85
@ -93,7 +93,12 @@ public class PregeneratorJob implements PregenListener {
|
|||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
|
|
||||||
J.a(this.pregenerator::start, 20);
|
var t = new Thread(() -> {
|
||||||
|
J.sleep(1000);
|
||||||
|
this.pregenerator.start();
|
||||||
|
}, "Iris Pregenerator");
|
||||||
|
t.setPriority(Thread.MIN_PRIORITY);
|
||||||
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shutdownInstance() {
|
public static boolean shutdownInstance() {
|
||||||
|
@ -29,15 +29,11 @@ import com.volmit.iris.util.math.M;
|
|||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.ForkJoinPool;
|
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public class AsyncPregenMethod implements PregeneratorMethod {
|
public class AsyncPregenMethod implements PregeneratorMethod {
|
||||||
@ -52,8 +48,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.world = world;
|
this.world = world;
|
||||||
burst = MultiBurst.burst;
|
burst = new MultiBurst("Iris Async Pregen", Thread.NORM_PRIORITY);
|
||||||
future = new KList<>(1024);
|
future = new KList<>(256);
|
||||||
this.lastUse = new KMap<>();
|
this.lastUse = new KMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,24 +77,17 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
|
|
||||||
private void completeChunk(int x, int z, PregenListener listener) {
|
private void completeChunk(int x, int z, PregenListener listener) {
|
||||||
try {
|
try {
|
||||||
future.add(PaperLib.getChunkAtAsync(world, x, z, true).thenApply((i) -> {
|
PaperLib.getChunkAtAsync(world, x, z, true).thenAccept((i) -> {
|
||||||
if (i == null) {
|
lastUse.put(i, M.ms());
|
||||||
|
|
||||||
}
|
|
||||||
Chunk c = Bukkit.getWorld(world.getUID()).getChunkAt(x, z);
|
|
||||||
lastUse.put(c, M.ms());
|
|
||||||
listener.onChunkGenerated(x, z);
|
listener.onChunkGenerated(x, z);
|
||||||
listener.onChunkCleaned(x, z);
|
listener.onChunkCleaned(x, z);
|
||||||
return 0;
|
}).join();
|
||||||
}));
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitForChunksPartial(int maxWaiting) {
|
private void waitForChunksPartial(int maxWaiting) {
|
||||||
future.removeWhere(Objects::isNull);
|
|
||||||
|
|
||||||
while (future.size() > maxWaiting) {
|
while (future.size() > maxWaiting) {
|
||||||
try {
|
try {
|
||||||
Future<?> i = future.remove(0);
|
Future<?> i = future.remove(0);
|
||||||
@ -127,8 +116,6 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
future.removeWhere(Objects::isNull);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -145,6 +132,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
public void close() {
|
public void close() {
|
||||||
waitForChunks();
|
waitForChunks();
|
||||||
unloadAndSaveAllChunks();
|
unloadAndSaveAllChunks();
|
||||||
|
burst.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -169,7 +157,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
if (future.size() > 256) {
|
if (future.size() > 256) {
|
||||||
waitForChunksPartial(256);
|
waitForChunksPartial(256);
|
||||||
}
|
}
|
||||||
future.add(burst.complete(() -> completeChunk(x, z, listener)));
|
burst.complete(() -> completeChunk(x, z, listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user