mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-03 16:36:00 +00:00
Iris but forkjoin
This commit is contained in:
parent
72b4c9c6ab
commit
d686d07d53
@ -27,7 +27,6 @@ import com.volmit.iris.core.link.MultiverseCoreLink;
|
||||
import com.volmit.iris.core.link.MythicMobsLink;
|
||||
import com.volmit.iris.core.link.OraxenLink;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.project.IrisProject;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
@ -49,6 +48,7 @@ import com.volmit.iris.util.io.InstanceState;
|
||||
import com.volmit.iris.util.io.JarScanner;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.plugin.*;
|
||||
import com.volmit.iris.util.reflect.ShadeFix;
|
||||
@ -165,6 +165,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
HandlerList.unregisterAll((Plugin) this);
|
||||
postShutdown.forEach(Runnable::run);
|
||||
services.clear();
|
||||
MultiBurst.burst.close();
|
||||
super.onDisable();
|
||||
}
|
||||
|
||||
@ -604,14 +605,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
}
|
||||
|
||||
public static void verbose(String string) {
|
||||
try {
|
||||
if (IrisSettings.get().getGeneral().isVerbose()) {
|
||||
msg(C.GRAY + string);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
msg(C.GRAY + string);
|
||||
Iris.reportError(e);
|
||||
}
|
||||
debug(string);
|
||||
}
|
||||
|
||||
public static void success(String string) {
|
||||
|
@ -66,7 +66,7 @@ public class CommandIrisStudioUpdate extends MortarCommand {
|
||||
IrisData data = IrisData.get(Iris.service(StudioSVC.class).getWorkspaceFolder(args[0]));
|
||||
int t = data.getObjectLoader().getPossibleKeys().length;
|
||||
ChronoLatch cl = new ChronoLatch(250, false);
|
||||
MultiBurst bx = new MultiBurst("Object Rewriter", Thread.MIN_PRIORITY, Runtime.getRuntime().availableProcessors());
|
||||
MultiBurst bx = MultiBurst.burst;
|
||||
BurstExecutor b = bx.burst();
|
||||
int g = 0;
|
||||
for (String f : data.getObjectLoader().getPossibleKeys()) {
|
||||
@ -102,7 +102,6 @@ public class CommandIrisStudioUpdate extends MortarCommand {
|
||||
int finalG = g;
|
||||
J.a(() -> {
|
||||
b.complete();
|
||||
bx.shutdownNow();
|
||||
sender.sendMessage("Done! Rewrote " + Form.f(finalG) + " Objects!");
|
||||
});
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true)
|
||||
@ -133,7 +134,7 @@ public class DecStudio implements DecreeExecutor {
|
||||
KList<Job> jobs = new KList<>();
|
||||
KList<File> files = new KList<File>();
|
||||
files(Iris.instance.getDataFolder("packs", project.getLoadKey()), files);
|
||||
MultiBurst burst = new MultiBurst("Cleaner", Thread.MIN_PRIORITY, Runtime.getRuntime().availableProcessors() * 2);
|
||||
MultiBurst burst = MultiBurst.burst;
|
||||
|
||||
jobs.add(new SingleJob("Updating Workspace", () -> {
|
||||
if (!new IrisProject(Iris.service(StudioSVC.class).getWorkspaceFolder(project.getLoadKey())).updateWorkspace()) {
|
||||
@ -208,7 +209,7 @@ public class DecStudio implements DecreeExecutor {
|
||||
|
||||
IrisData data = IrisData.get(Iris.service(StudioSVC.class).getWorkspaceFolder(project.getLoadKey()));
|
||||
for (String f : data.getObjectLoader().getPossibleKeys()) {
|
||||
CompletableFuture<?> gg = burst.complete(() -> {
|
||||
Future<?> gg = burst.complete(() -> {
|
||||
File ff = data.getObjectLoader().findFile(f);
|
||||
IrisObject oo = new IrisObject(0, 0, 0);
|
||||
try {
|
||||
@ -237,8 +238,6 @@ public class DecStudio implements DecreeExecutor {
|
||||
jobs.add(q);
|
||||
}
|
||||
|
||||
jobs.add(new SingleJob("Finishing Up", burst::shutdownNow));
|
||||
|
||||
new JobCollection("Cleaning", jobs).execute(sender());
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List
|
||||
static double ascale = 10;
|
||||
CNG cng = NoiseStyle.STATIC.create(new RNG(RNG.r.nextLong()));
|
||||
@SuppressWarnings("CanBeFinal")
|
||||
MultiBurst gx = new MultiBurst("Iris Noise Renderer", Thread.MAX_PRIORITY, Runtime.getRuntime().availableProcessors());
|
||||
MultiBurst gx = MultiBurst.burst;
|
||||
ReentrantLock l = new ReentrantLock();
|
||||
BufferedImage img;
|
||||
int w = 0;
|
||||
@ -299,7 +299,6 @@ public class NoiseExplorerGUI extends JPanel implements MouseWheelListener, List
|
||||
frame.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
||||
nv.gx.shutdownLater();
|
||||
Iris.instance.unregisterListener(nv);
|
||||
}
|
||||
});
|
||||
|
@ -29,11 +29,12 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
private final World world;
|
||||
private final MultiBurst burst;
|
||||
private final KList<CompletableFuture<?>> future;
|
||||
private final KList<Future<?>> future;
|
||||
|
||||
public AsyncPregenMethod(World world, int threads) {
|
||||
if (!PaperLib.isPaper()) {
|
||||
@ -41,7 +42,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
this.world = world;
|
||||
burst = new MultiBurst("Iris Async Pregenerator", IrisSettings.get().getConcurrency().getPregenThreadPriority(), threads);
|
||||
burst = MultiBurst.burst;
|
||||
future = new KList<>(1024);
|
||||
}
|
||||
|
||||
@ -69,7 +70,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
private void waitForChunks() {
|
||||
for (CompletableFuture<?> i : future.copy()) {
|
||||
for (Future<?> i : future.copy()) {
|
||||
try {
|
||||
i.get();
|
||||
future.remove(i);
|
||||
@ -92,7 +93,6 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
@Override
|
||||
public void close() {
|
||||
waitForChunks();
|
||||
burst.shutdownAndAwait();
|
||||
unloadAndSaveAllChunks();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@ import java.util.concurrent.ExecutorService;
|
||||
public class PreservationSVC implements IrisService
|
||||
{
|
||||
private KList<Thread> threads = new KList<>();
|
||||
private KList<MultiBurst> bursts = new KList<>();
|
||||
private KList<ExecutorService> services = new KList<>();
|
||||
private Looper dereferencer;
|
||||
|
||||
@ -42,7 +41,7 @@ public class PreservationSVC implements IrisService
|
||||
|
||||
public void register(MultiBurst burst)
|
||||
{
|
||||
bursts.add(burst);
|
||||
|
||||
}
|
||||
|
||||
public void register(ExecutorService service)
|
||||
@ -94,20 +93,6 @@ public class PreservationSVC implements IrisService
|
||||
}
|
||||
}
|
||||
|
||||
for(MultiBurst i : bursts)
|
||||
{
|
||||
try
|
||||
{
|
||||
i.shutdownNow();
|
||||
Iris.info("Shutdown Multiburst " + i);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
for(ExecutorService i : services)
|
||||
{
|
||||
try
|
||||
|
@ -132,6 +132,7 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
closed = false;
|
||||
art = J.ar(this::tickRandomPlayer, 0);
|
||||
setupEngine();
|
||||
Iris.debug("Engine Initialized " + getCacheID());
|
||||
}
|
||||
|
||||
private void tickRandomPlayer() {
|
||||
@ -158,6 +159,9 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
|
||||
private void setupEngine()
|
||||
{
|
||||
try
|
||||
{
|
||||
Iris.debug("Setup Engine " + getCacheID());
|
||||
cacheId = RNG.r.nextInt();
|
||||
worldManager = new IrisWorldManager(this);
|
||||
complex = new IrisComplex(this);
|
||||
@ -174,6 +178,15 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
||||
J.a(this::computeBiomeMaxes);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
Iris.error("FAILED TO SETUP ENGINE!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Iris.debug("Engine Setup Complete " + getCacheID());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hotload() {
|
||||
getData().dump();
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.engine;
|
||||
|
||||
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||
@ -27,6 +28,7 @@ import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
|
||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
||||
import com.volmit.iris.engine.object.biome.IrisBiome;
|
||||
import com.volmit.iris.engine.object.deposits.IrisDepositGenerator;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePositional;
|
||||
import com.volmit.iris.engine.object.feature.IrisFeaturePotential;
|
||||
import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement;
|
||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||
@ -36,9 +38,15 @@ import com.volmit.iris.engine.object.regional.IrisRegion;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
||||
import com.volmit.iris.util.stream.utility.CachedStream2D;
|
||||
import lombok.Data;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
@ -46,6 +54,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Data
|
||||
@ -53,7 +62,9 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
private final Engine engine;
|
||||
private final Mantle mantle;
|
||||
private final KList<MantleComponent> components;
|
||||
private final CompletableFuture<Integer> radius;
|
||||
private final Future<Integer> radius;
|
||||
private ProceduralStream<KList<IrisFeaturePositional>> featureChunkStream;
|
||||
private ProceduralStream<KList<IrisFeaturePositional>> featureStream;
|
||||
|
||||
public IrisEngineMantle(Engine engine) {
|
||||
this.engine = engine;
|
||||
@ -63,6 +74,21 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
registerComponent(new MantleFeatureComponent(this));
|
||||
registerComponent(new MantleJigsawComponent(this));
|
||||
registerComponent(new MantleObjectComponent(this));
|
||||
featureChunkStream = ProceduralStream.of((x, z)
|
||||
-> EngineMantle.super.getFeaturesInChunk(x.intValue(), z.intValue()),
|
||||
Interpolated.of((i) -> 0D, (i) -> new KList<IrisFeaturePositional>())).cache2D(2048);
|
||||
featureStream = ProceduralStream.of(EngineMantle.super::forEachFeature,
|
||||
Interpolated.of((i) -> 0D, (i) -> new KList<IrisFeaturePositional>())).cache2D(8192);
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
public KList<IrisFeaturePositional> getFeaturesInChunk(int x, int z) {
|
||||
return featureChunkStream.get(x, z);
|
||||
}
|
||||
|
||||
@BlockCoordinates
|
||||
public KList<IrisFeaturePositional> forEachFeature(double x, double z) {
|
||||
return featureStream.get(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +69,6 @@ public class IrisBiomeActuator extends EngineAssignedActuator<Biome> {
|
||||
public void onActuate(int x, int z, Hunk<Biome> h, boolean multicore) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
BurstExecutor burst = burst().burst();
|
||||
burst.setMulticore(multicore);
|
||||
|
||||
for (int xf = 0; xf < h.getWidth(); xf++) {
|
||||
int finalXf = xf;
|
||||
|
@ -91,7 +91,6 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
|
||||
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
BurstExecutor burst = burst().burst();
|
||||
burst.setMulticore(multicore);
|
||||
|
||||
for (int i = 0; i < output.getWidth(); i++) {
|
||||
int finalI = i;
|
||||
|
@ -56,7 +56,6 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<BlockData>
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
|
||||
BurstExecutor e = getEngine().burst().burst(h.getWidth());
|
||||
e.setMulticore(multicore);
|
||||
for (int xf = 0; xf < h.getWidth(); xf++) {
|
||||
int finalXf = xf;
|
||||
e.queue(() -> terrainSliver(x, z, finalXf, h));
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.engine.framework;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
@ -31,6 +32,7 @@ public abstract class EngineAssignedActuator<T> extends EngineAssignedComponent
|
||||
@BlockCoordinates
|
||||
@Override
|
||||
public void actuate(int x, int z, Hunk<T> output, boolean multicore) {
|
||||
Iris.debug("Engine Actuator[" + getName() + "] " + x + " " + z);
|
||||
onActuate(x, z, output, multicore);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.engine.framework;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.math.RollingSequence;
|
||||
import lombok.Data;
|
||||
|
||||
@ -28,6 +29,7 @@ public class EngineAssignedComponent implements EngineComponent {
|
||||
private final String name;
|
||||
|
||||
public EngineAssignedComponent(Engine engine, String name) {
|
||||
Iris.debug("Engine: " + engine.getCacheID() + " Starting " + name);
|
||||
this.engine = engine;
|
||||
this.metrics = new RollingSequence(16);
|
||||
this.name = name;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.engine.framework;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
@ -32,6 +33,7 @@ public abstract class EngineAssignedModifier<T> extends EngineAssignedComponent
|
||||
@BlockCoordinates
|
||||
@Override
|
||||
public void modify(int x, int z, Hunk<T> output, boolean multicore) {
|
||||
Iris.debug("Engine Modifier[" + getName() + "] " + x + " " + z);
|
||||
onModify(x, z, output, multicore);
|
||||
}
|
||||
}
|
||||
|
@ -36,9 +36,7 @@ public class EngineTarget {
|
||||
this.world = world;
|
||||
this.dimension = dimension;
|
||||
this.data = data;
|
||||
this.burster = new MultiBurst("Iris Engine " + dimension.getName(),
|
||||
IrisSettings.get().getConcurrency().getEngineThreadPriority(),
|
||||
IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getEngineThreadCount()));
|
||||
this.burster = MultiBurst.burst;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
@ -46,6 +44,6 @@ public class EngineTarget {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
burster.shutdownLater();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -36,16 +36,11 @@ import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
// TODO: MOVE PLACER OUT OF MATTER INTO ITS OWN THING
|
||||
@ -56,7 +51,7 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
|
||||
Engine getEngine();
|
||||
|
||||
CompletableFuture<Integer> getRadius();
|
||||
Future<Integer> getRadius();
|
||||
|
||||
KList<MantleComponent> getComponents();
|
||||
|
||||
@ -189,7 +184,6 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
return;
|
||||
}
|
||||
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
KList<Runnable> post = new KList<>();
|
||||
Consumer<Runnable> c = (i) -> {
|
||||
synchronized (post)
|
||||
@ -199,7 +193,6 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
};
|
||||
int s = getRealRadius();
|
||||
BurstExecutor burst = burst().burst();
|
||||
burst.setMulticore(multicore);
|
||||
|
||||
for (int i = -s; i <= s; i++) {
|
||||
int xx = i + x;
|
||||
@ -217,17 +210,8 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
{
|
||||
KList<Runnable> px = post.copy();
|
||||
post.clear();
|
||||
|
||||
if(multicore)
|
||||
{
|
||||
burst().burst(px);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
burst().sync(px);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default void generateMantleComponent(int x, int z, MantleComponent c, Consumer<Runnable> post) {
|
||||
@ -240,6 +224,7 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
return;
|
||||
}
|
||||
|
||||
Iris.debug("Engine Matter Insert " + x + " " + z);
|
||||
getMantle().iterateChunk(x, z, t, blocks::set);
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class IrisDepositModifier extends EngineAssignedModifier<BlockData> {
|
||||
IrisRegion region = getComplex().getRegionStream().get((x * 16) + 7, (z * 16) + 7);
|
||||
IrisBiome biome = getComplex().getTrueBiomeStream().get((x * 16) + 7, (z * 16) + 7);
|
||||
BurstExecutor burst = burst().burst();
|
||||
burst.setMulticore(multicore);
|
||||
|
||||
for (IrisDepositGenerator k : getDimension().getDeposits()) {
|
||||
burst.queue(() -> generate(k, terrain, ro, x, z, false));
|
||||
}
|
||||
|
@ -65,7 +65,6 @@ public class IrisPostModifier extends EngineAssignedModifier<BlockData> {
|
||||
AtomicInteger i = new AtomicInteger();
|
||||
AtomicInteger j = new AtomicInteger();
|
||||
BurstExecutor burst = burst().burst();
|
||||
burst.setMulticore(multicore);
|
||||
Hunk<BlockData> sync = output.synchronize();
|
||||
for (i.set(0); i.get() < output.getWidth(); i.getAndIncrement()) {
|
||||
burst.queue(() -> {
|
||||
|
@ -177,6 +177,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
|
||||
@Override
|
||||
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
||||
Iris.debug("Generate Request " + world.getName() + " at: " + x + ", " + z);
|
||||
try {
|
||||
if(lastSeed != world.getSeed())
|
||||
{
|
||||
@ -187,12 +188,14 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
Iris.success("Updated Engine seed to " + lastSeed);
|
||||
}
|
||||
|
||||
Iris.debug("Generate Request [LOCKING] at: " + x + ", " + z);
|
||||
loadLock.acquire();
|
||||
PrecisionStopwatch ps = PrecisionStopwatch.start();
|
||||
Iris.debug("Generate Request [LOCKED] at: " + x + ", " + z);
|
||||
TerrainChunk tc = TerrainChunk.create(world, biome);
|
||||
Hunk<BlockData> blocks = Hunk.view((ChunkData) tc);
|
||||
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
||||
this.world.bind(world);
|
||||
Iris.debug("Generate Request [ENGINE] at: " + x + ", " + z);
|
||||
getEngine().generate(x * 16, z * 16, blocks, biomes, true);
|
||||
ChunkData c = tc.getRaw();
|
||||
Iris.debug("Generated " + x + " " + z);
|
||||
|
@ -58,7 +58,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
|
||||
public HeadlessGenerator(HeadlessWorld world) {
|
||||
this.world = world;
|
||||
burst = new MultiBurst("Iris Headless Generator", 9, IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getPregenThreadCount()));
|
||||
burst = MultiBurst.burst;
|
||||
writer = new NBTWorld(world.getWorld().worldFolder());
|
||||
engine = new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), isStudio());
|
||||
}
|
||||
@ -131,7 +131,6 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
burst.shutdownAndAwait();
|
||||
getEngine().close();
|
||||
writer.close();
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
@ -386,7 +387,7 @@ public class Mantle {
|
||||
* @return the future of a tectonic plate.
|
||||
*/
|
||||
@RegionCoordinates
|
||||
private CompletableFuture<TectonicPlate> getSafe(int x, int z) {
|
||||
private Future<TectonicPlate> getSafe(int x, int z) {
|
||||
Long k = key(x, z);
|
||||
TectonicPlate p = loadedRegions.get(k);
|
||||
|
||||
@ -449,7 +450,10 @@ public class Mantle {
|
||||
public static File fileForRegion(File folder, Long key) {
|
||||
String id = UUID.nameUUIDFromBytes(("TectonicPlate:" + key).getBytes(StandardCharsets.UTF_8)).toString();
|
||||
File f = new File(folder, id.substring(0, 2) + "/" + id.split("\\Q-\\E")[3] + "/" + id + ".ttp");
|
||||
if(!f.getParentFile().exists())
|
||||
{
|
||||
f.getParentFile().mkdirs();
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
|
@ -28,45 +28,27 @@ import java.util.concurrent.*;
|
||||
@SuppressWarnings("ALL")
|
||||
public class BurstExecutor {
|
||||
private final ExecutorService executor;
|
||||
private final KList<CompletableFuture<Void>> futures;
|
||||
@Setter
|
||||
private boolean multicore = true;
|
||||
private final KList<Future<?>> futures;
|
||||
|
||||
public BurstExecutor(ExecutorService executor, int burstSizeEstimate) {
|
||||
this.executor = executor;
|
||||
futures = new KList<CompletableFuture<Void>>(burstSizeEstimate);
|
||||
futures = new KList<Future<?>>(burstSizeEstimate);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public CompletableFuture<Void> queue(Runnable r) {
|
||||
if(!multicore)
|
||||
{
|
||||
r.run();
|
||||
return null;
|
||||
}
|
||||
|
||||
public Future<?> queue(Runnable r) {
|
||||
synchronized (futures) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(r, executor);
|
||||
|
||||
Future<?> c = executor.submit(r);
|
||||
futures.add(c);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
public BurstExecutor queue(List<Runnable> r) {
|
||||
if(!multicore)
|
||||
{
|
||||
for(Runnable i : r)
|
||||
{
|
||||
i.run();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
for (Runnable i : new KList<>(r)) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
|
||||
futures.add(c);
|
||||
queue(i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,20 +56,9 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public BurstExecutor queue(Runnable[] r) {
|
||||
if(!multicore)
|
||||
{
|
||||
for(Runnable i : r)
|
||||
{
|
||||
i.run();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
for (Runnable i : r) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
|
||||
futures.add(c);
|
||||
queue(i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,18 +66,17 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public void complete() {
|
||||
if(!multicore)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
if (futures.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get();
|
||||
for(Future<?> i : futures)
|
||||
{
|
||||
i.get();
|
||||
}
|
||||
|
||||
futures.clear();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
Iris.reportError(e);
|
||||
@ -115,11 +85,6 @@ public class BurstExecutor {
|
||||
}
|
||||
|
||||
public boolean complete(long maxDur) {
|
||||
if(!multicore)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
synchronized (futures) {
|
||||
if (futures.isEmpty()) {
|
||||
return true;
|
||||
|
@ -19,13 +19,10 @@
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
@ -33,66 +30,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;
|
||||
@ -138,64 +108,15 @@ public class MultiBurst {
|
||||
return getService().submit(o);
|
||||
}
|
||||
|
||||
public CompletableFuture<?> complete(Runnable o) {
|
||||
return CompletableFuture.runAsync(o, getService());
|
||||
public Future<?> complete(Runnable o) {
|
||||
return getService().submit(o);
|
||||
}
|
||||
|
||||
public <T> CompletableFuture<T> completeValue(Supplier<T> o) {
|
||||
return CompletableFuture.supplyAsync(o, getService());
|
||||
public <T> Future<T> completeValue(Callable<T> o) {
|
||||
return getService().submit(o);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user