mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
A less garbage hotloader
This commit is contained in:
parent
fc5763c8e8
commit
e279dc4cea
@ -22,6 +22,7 @@ import com.google.common.util.concurrent.AtomicDouble;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
|
import com.volmit.iris.core.events.IrisEngineHotloadEvent;
|
||||||
import com.volmit.iris.engine.actuator.IrisBiomeActuator;
|
import com.volmit.iris.engine.actuator.IrisBiomeActuator;
|
||||||
import com.volmit.iris.engine.actuator.IrisDecorantActuator;
|
import com.volmit.iris.engine.actuator.IrisDecorantActuator;
|
||||||
import com.volmit.iris.engine.actuator.IrisTerrainIslandActuator;
|
import com.volmit.iris.engine.actuator.IrisTerrainIslandActuator;
|
||||||
@ -81,11 +82,11 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
|||||||
private final AtomicLong lastGPS;
|
private final AtomicLong lastGPS;
|
||||||
private final EngineTarget target;
|
private final EngineTarget target;
|
||||||
private final IrisContext context;
|
private final IrisContext context;
|
||||||
private final EngineEffects effects;
|
private EngineEffects effects;
|
||||||
private final EngineMantle mantle;
|
private final EngineMantle mantle;
|
||||||
private final ChronoLatch perSecondLatch;
|
private final ChronoLatch perSecondLatch;
|
||||||
private final EngineExecutionEnvironment execution;
|
private EngineExecutionEnvironment execution;
|
||||||
private final EngineWorldManager worldManager;
|
private EngineWorldManager worldManager;
|
||||||
private volatile int parallelism;
|
private volatile int parallelism;
|
||||||
private final EngineMetrics metrics;
|
private final EngineMetrics metrics;
|
||||||
private volatile int minHeight;
|
private volatile int minHeight;
|
||||||
@ -98,58 +99,94 @@ public class IrisEngine extends BlockPopulator implements Engine {
|
|||||||
private double maxBiomeObjectDensity;
|
private double maxBiomeObjectDensity;
|
||||||
private double maxBiomeLayerDensity;
|
private double maxBiomeLayerDensity;
|
||||||
private double maxBiomeDecoratorDensity;
|
private double maxBiomeDecoratorDensity;
|
||||||
private final IrisComplex complex;
|
private IrisComplex complex;
|
||||||
private final EngineActuator<BlockData> terrainNormalActuator;
|
private EngineActuator<BlockData> terrainNormalActuator;
|
||||||
private final EngineActuator<BlockData> terrainIslandActuator;
|
private EngineActuator<BlockData> terrainIslandActuator;
|
||||||
private final EngineActuator<BlockData> decorantActuator;
|
private EngineActuator<BlockData> decorantActuator;
|
||||||
private final EngineActuator<Biome> biomeActuator;
|
private EngineActuator<Biome> biomeActuator;
|
||||||
private final EngineModifier<BlockData> depositModifier;
|
private EngineModifier<BlockData> depositModifier;
|
||||||
private final EngineModifier<BlockData> caveModifier;
|
private EngineModifier<BlockData> caveModifier;
|
||||||
private final EngineModifier<BlockData> ravineModifier;
|
private EngineModifier<BlockData> ravineModifier;
|
||||||
private final EngineModifier<BlockData> postModifier;
|
private EngineModifier<BlockData> postModifier;
|
||||||
private final AtomicCache<IrisEngineData> engineData = new AtomicCache<>();
|
private final AtomicCache<IrisEngineData> engineData = new AtomicCache<>();
|
||||||
private final AtomicBoolean cleaning;
|
private final AtomicBoolean cleaning;
|
||||||
private final ChronoLatch cleanLatch;
|
private final ChronoLatch cleanLatch;
|
||||||
|
|
||||||
public IrisEngine(EngineTarget target, boolean studio) {
|
public IrisEngine(EngineTarget target, boolean studio) {
|
||||||
target.getData().dump();
|
|
||||||
this.studio = studio;
|
this.studio = studio;
|
||||||
|
this.target = target;
|
||||||
|
metrics = new EngineMetrics(32);
|
||||||
|
cleanLatch = new ChronoLatch(Math.max(10000, Math.min(IrisSettings.get().getParallax()
|
||||||
|
.getParallaxChunkEvictionMS(), IrisSettings.get().getParallax().getParallaxRegionEvictionMS())));
|
||||||
generatedLast = new AtomicInteger(0);
|
generatedLast = new AtomicInteger(0);
|
||||||
perSecond = new AtomicDouble(0);
|
perSecond = new AtomicDouble(0);
|
||||||
perSecondLatch = new ChronoLatch(1000, false);
|
perSecondLatch = new ChronoLatch(1000, false);
|
||||||
wallClock = new AtomicRollingSequence(32);
|
wallClock = new AtomicRollingSequence(32);
|
||||||
lastGPS = new AtomicLong(M.ms());
|
lastGPS = new AtomicLong(M.ms());
|
||||||
generated = new AtomicInteger(0);
|
generated = new AtomicInteger(0);
|
||||||
execution = new IrisExecutionEnvironment(this);
|
mantle = new IrisEngineMantle(this);
|
||||||
// TODO: HEIGHT ------------------------------------------------------------------------------------------------------>
|
context = new IrisContext(this);
|
||||||
|
cleaning = new AtomicBoolean(false);
|
||||||
|
context.touch();
|
||||||
Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + 256 + " height)");
|
Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + 256 + " height)");
|
||||||
metrics = new EngineMetrics(32);
|
|
||||||
this.target = target;
|
|
||||||
getData().setEngine(this);
|
getData().setEngine(this);
|
||||||
getEngineData();
|
getEngineData();
|
||||||
worldManager = new IrisWorldManager(this);
|
|
||||||
minHeight = 0;
|
minHeight = 0;
|
||||||
failing = false;
|
failing = false;
|
||||||
closed = false;
|
closed = false;
|
||||||
|
art = J.ar(this::tickRandomPlayer, 0);
|
||||||
|
setupEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tickRandomPlayer() {
|
||||||
|
if(effects != null) {
|
||||||
|
effects.tickRandomPlayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prehotload()
|
||||||
|
{
|
||||||
|
worldManager.close();
|
||||||
|
complex.close();
|
||||||
|
execution.close();
|
||||||
|
terrainNormalActuator.close();
|
||||||
|
terrainIslandActuator.close();
|
||||||
|
decorantActuator.close();
|
||||||
|
biomeActuator.close();
|
||||||
|
depositModifier.close();
|
||||||
|
ravineModifier.close();
|
||||||
|
caveModifier.close();
|
||||||
|
postModifier.close();
|
||||||
|
effects.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupEngine()
|
||||||
|
{
|
||||||
cacheId = RNG.r.nextInt();
|
cacheId = RNG.r.nextInt();
|
||||||
|
worldManager = new IrisWorldManager(this);
|
||||||
|
complex = new IrisComplex(this);
|
||||||
|
execution = new IrisExecutionEnvironment(this);
|
||||||
|
terrainNormalActuator = new IrisTerrainNormalActuator(this);
|
||||||
|
terrainIslandActuator = new IrisTerrainIslandActuator(this);
|
||||||
|
decorantActuator = new IrisDecorantActuator(this);
|
||||||
|
biomeActuator = new IrisBiomeActuator(this);
|
||||||
|
depositModifier = new IrisDepositModifier(this);
|
||||||
|
ravineModifier = new IrisRavineModifier(this);
|
||||||
|
caveModifier = new IrisCaveModifier(this);
|
||||||
|
postModifier = new IrisPostModifier(this);
|
||||||
effects = new IrisEngineEffects(this);
|
effects = new IrisEngineEffects(this);
|
||||||
art = J.ar(effects::tickRandomPlayer, 0);
|
|
||||||
J.a(this::computeBiomeMaxes);
|
J.a(this::computeBiomeMaxes);
|
||||||
context = new IrisContext(this);
|
}
|
||||||
context.touch();
|
|
||||||
this.complex = new IrisComplex(this);
|
@Override
|
||||||
this.terrainNormalActuator = new IrisTerrainNormalActuator(this);
|
public void hotload() {
|
||||||
this.terrainIslandActuator = new IrisTerrainIslandActuator(this);
|
Iris.info("Hotload ENGINE");
|
||||||
this.decorantActuator = new IrisDecorantActuator(this);
|
getData().dump();
|
||||||
this.biomeActuator = new IrisBiomeActuator(this);
|
getData().clearLists();
|
||||||
this.depositModifier = new IrisDepositModifier(this);
|
getTarget().setDimension(getData().getDimensionLoader().load(getDimension().getLoadKey()));
|
||||||
this.ravineModifier = new IrisRavineModifier(this);
|
prehotload();
|
||||||
this.caveModifier = new IrisCaveModifier(this);
|
setupEngine();
|
||||||
this.postModifier = new IrisPostModifier(this);
|
Iris.callEvent(new IrisEngineHotloadEvent(this));
|
||||||
cleaning = new AtomicBoolean(false);
|
|
||||||
cleanLatch = new ChronoLatch(Math.max(10000, Math.min(IrisSettings.get().getParallax()
|
|
||||||
.getParallaxChunkEvictionMS(), IrisSettings.get().getParallax().getParallaxRegionEvictionMS())));
|
|
||||||
mantle = new IrisEngineMantle(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,6 +57,7 @@ import java.util.stream.Stream;
|
|||||||
@Data
|
@Data
|
||||||
public class IrisWorldManager extends EngineAssignedWorldManager {
|
public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||||
private final Looper looper;
|
private final Looper looper;
|
||||||
|
private final int id;
|
||||||
private final KMap<Long, Long> chunkCooldowns;
|
private final KMap<Long, Long> chunkCooldowns;
|
||||||
private double energy = 25;
|
private double energy = 25;
|
||||||
private int entityCount = 0;
|
private int entityCount = 0;
|
||||||
@ -75,6 +76,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
|||||||
cln = null;
|
cln = null;
|
||||||
chunkCooldowns = null;
|
chunkCooldowns = null;
|
||||||
looper = null;
|
looper = null;
|
||||||
|
id = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IrisWorldManager(Engine engine) {
|
public IrisWorldManager(Engine engine) {
|
||||||
@ -83,11 +85,12 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
|||||||
cl = new ChronoLatch(3000);
|
cl = new ChronoLatch(3000);
|
||||||
ecl = new ChronoLatch(250);
|
ecl = new ChronoLatch(250);
|
||||||
chunkCooldowns = new KMap<>();
|
chunkCooldowns = new KMap<>();
|
||||||
|
id = engine.getCacheID();
|
||||||
energy = 25;
|
energy = 25;
|
||||||
looper = new Looper() {
|
looper = new Looper() {
|
||||||
@Override
|
@Override
|
||||||
protected long loop() {
|
protected long loop() {
|
||||||
if (getEngine().isClosed()) {
|
if (getEngine().isClosed() || getEngine().getCacheID() != id) {
|
||||||
interrupt();
|
interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdater, Renderer {
|
public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdater, Renderer, Hotloadable {
|
||||||
IrisComplex getComplex();
|
IrisComplex getComplex();
|
||||||
|
|
||||||
void printMetrics(CommandSender sender);
|
void printMetrics(CommandSender sender);
|
||||||
|
@ -28,7 +28,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class EngineTarget {
|
public class EngineTarget {
|
||||||
private final MultiBurst burster;
|
private final MultiBurst burster;
|
||||||
private final IrisDimension dimension;
|
private IrisDimension dimension;
|
||||||
private IrisWorld world;
|
private IrisWorld world;
|
||||||
private final IrisData data;
|
private final IrisData data;
|
||||||
|
|
||||||
|
@ -19,17 +19,22 @@
|
|||||||
package com.volmit.iris.engine.platform;
|
package com.volmit.iris.engine.platform;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.project.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.IrisEngine;
|
||||||
import com.volmit.iris.engine.data.chunk.TerrainChunk;
|
import com.volmit.iris.engine.data.chunk.TerrainChunk;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
|
import com.volmit.iris.engine.framework.EngineTarget;
|
||||||
import com.volmit.iris.engine.framework.WrongEngineBroException;
|
import com.volmit.iris.engine.framework.WrongEngineBroException;
|
||||||
import com.volmit.iris.engine.object.common.IrisWorld;
|
import com.volmit.iris.engine.object.common.IrisWorld;
|
||||||
|
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.hunk.Hunk;
|
import com.volmit.iris.util.hunk.Hunk;
|
||||||
import com.volmit.iris.util.io.ReactiveFolder;
|
import com.volmit.iris.util.io.ReactiveFolder;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
|
||||||
import com.volmit.iris.util.scheduling.Looper;
|
import com.volmit.iris.util.scheduling.Looper;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -44,9 +49,10 @@ import java.util.List;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChunkGenerator {
|
public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChunkGenerator {
|
||||||
private static final int HOTLOAD_LOCKS = 1000000;
|
private final Engine engine;
|
||||||
private final EngineProvider provider;
|
|
||||||
private final IrisWorld world;
|
private final IrisWorld world;
|
||||||
private final File dataLocation;
|
private final File dataLocation;
|
||||||
private final String dimensionKey;
|
private final String dimensionKey;
|
||||||
@ -54,21 +60,20 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
private final KList<BlockPopulator> populators;
|
private final KList<BlockPopulator> populators;
|
||||||
private final ChronoLatch hotloadChecker;
|
private final ChronoLatch hotloadChecker;
|
||||||
private final Looper hotloader;
|
private final Looper hotloader;
|
||||||
private final Semaphore hotloadLock;
|
|
||||||
private final boolean studio;
|
private final boolean studio;
|
||||||
|
|
||||||
public BukkitChunkGenerator(IrisWorld world, boolean studio, File dataLocation, String dimensionKey) {
|
public BukkitChunkGenerator(IrisWorld world, boolean studio, File dataLocation, String dimensionKey) {
|
||||||
populators = new KList<>();
|
populators = new KList<>();
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.hotloadLock = new Semaphore(HOTLOAD_LOCKS);
|
|
||||||
this.hotloadChecker = new ChronoLatch(1000, false);
|
this.hotloadChecker = new ChronoLatch(1000, false);
|
||||||
this.studio = studio;
|
this.studio = studio;
|
||||||
this.dataLocation = dataLocation;
|
this.dataLocation = dataLocation;
|
||||||
this.dimensionKey = dimensionKey;
|
this.dimensionKey = dimensionKey;
|
||||||
this.folder = new ReactiveFolder(dataLocation, (_a, _b, _c) -> hotload());
|
this.folder = new ReactiveFolder(dataLocation, (_a, _b, _c) -> hotload());
|
||||||
this.provider = new EngineProvider();
|
IrisData data = IrisData.get(dataLocation);
|
||||||
initialize();
|
IrisDimension dimension = data.getDimensionLoader().load(dimensionKey);
|
||||||
|
this.engine = new IrisEngine(new EngineTarget(world, dimension, data), studio);
|
||||||
|
populators.add((BlockPopulator) engine);
|
||||||
this.hotloader = new Looper() {
|
this.hotloader = new Looper() {
|
||||||
@Override
|
@Override
|
||||||
protected long loop() {
|
protected long loop() {
|
||||||
@ -84,13 +89,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
hotloader.setName(getTarget().getWorld().name() + " Hotloader");
|
hotloader.setName(getTarget().getWorld().name() + " Hotloader");
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Engine getEngine() {
|
|
||||||
synchronized (provider)
|
|
||||||
{
|
|
||||||
return provider.getEngine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHeadless() {
|
public boolean isHeadless() {
|
||||||
return false;
|
return false;
|
||||||
@ -98,11 +96,8 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
synchronized (provider)
|
|
||||||
{
|
|
||||||
hotloader.interrupt();
|
hotloader.interrupt();
|
||||||
provider.close();
|
getEngine().close();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -112,38 +107,12 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hotload() {
|
public void hotload() {
|
||||||
J.aBukkit(this::hotloadBLOCKING);
|
getEngine().hotload();
|
||||||
}
|
Iris.info("Hotload BKG");
|
||||||
|
|
||||||
public void hotloadBLOCKING() {
|
|
||||||
try {
|
|
||||||
hotloadLock.acquire(HOTLOAD_LOCKS);
|
|
||||||
initialize();
|
|
||||||
hotloadLock.release(HOTLOAD_LOCKS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initialize() {
|
|
||||||
synchronized (provider)
|
|
||||||
{
|
|
||||||
provider.provideEngine(world, dimensionKey, dataLocation, isStudio(), (e) -> {
|
|
||||||
populators.clear();
|
|
||||||
populators.add((BlockPopulator) e);
|
|
||||||
folder.checkIgnore();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
||||||
try {
|
|
||||||
hotloadLock.acquire();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Iris.debug("Generated " + x + " " + z);
|
Iris.debug("Generated " + x + " " + z);
|
||||||
PrecisionStopwatch ps = PrecisionStopwatch.start();
|
PrecisionStopwatch ps = PrecisionStopwatch.start();
|
||||||
@ -152,17 +121,9 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
||||||
this.world.bind(world);
|
this.world.bind(world);
|
||||||
getEngine().generate(x * 16, z * 16, blocks, biomes, true);
|
getEngine().generate(x * 16, z * 16, blocks, biomes, true);
|
||||||
hotloadLock.release();
|
|
||||||
return tc.getRaw();
|
return tc.getRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(WrongEngineBroException e)
|
|
||||||
{
|
|
||||||
hotloadLock.release();
|
|
||||||
hotloadBLOCKING();
|
|
||||||
return generateChunkData(world, ignored, x, z, biome);
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
Iris.error("======================================");
|
Iris.error("======================================");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -177,10 +138,8 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hotloadLock.release();
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
|
||||||
* Copyright (c) 2021 Arcane Arts (Volmit Software)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.volmit.iris.engine.platform;
|
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.core.events.IrisEngineHotloadEvent;
|
|
||||||
import com.volmit.iris.core.project.loader.IrisData;
|
|
||||||
import com.volmit.iris.engine.IrisEngine;
|
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
|
||||||
import com.volmit.iris.engine.framework.EngineTarget;
|
|
||||||
import com.volmit.iris.engine.object.common.IrisWorld;
|
|
||||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class EngineProvider {
|
|
||||||
private final AtomicReference<CompletableFuture<Engine>> engine = new AtomicReference<>();
|
|
||||||
|
|
||||||
public void provideEngine(IrisWorld world, String dimension, File dataLocation, boolean studio, Consumer<Engine> post) {
|
|
||||||
close();
|
|
||||||
engine.set(MultiBurst.burst.completeValue(() -> {
|
|
||||||
IrisData data = IrisData.get(dataLocation);
|
|
||||||
IrisDimension realDimension = data.getDimensionLoader().load(dimension);
|
|
||||||
|
|
||||||
if (realDimension == null) {
|
|
||||||
throw new RuntimeException("Cannot find dimension in " + data.getDataFolder().getAbsolutePath() + " with key " + dimension);
|
|
||||||
}
|
|
||||||
|
|
||||||
EngineTarget target = new EngineTarget(world, realDimension, data);
|
|
||||||
Engine engine = new IrisEngine(target, studio);
|
|
||||||
post.accept(engine);
|
|
||||||
return engine;
|
|
||||||
}));
|
|
||||||
engine.get().whenComplete((e, x) -> Iris.callEvent(new IrisEngineHotloadEvent(e)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Engine getEngine() {
|
|
||||||
try {
|
|
||||||
Engine e = engine.get().get();
|
|
||||||
|
|
||||||
if (e == null) {
|
|
||||||
throw new RuntimeException("NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
return e;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new RuntimeException("INTERRUPTED");
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new RuntimeException("EXECUTION ERROR");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
if (engine.get() != null && engine.get().isDone()) {
|
|
||||||
Engine e = getEngine();
|
|
||||||
|
|
||||||
if (e != null) {
|
|
||||||
e.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,9 +23,11 @@ import com.volmit.iris.core.IrisSettings;
|
|||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||||
import com.volmit.iris.core.pregenerator.PregenTask;
|
import com.volmit.iris.core.pregenerator.PregenTask;
|
||||||
|
import com.volmit.iris.engine.IrisEngine;
|
||||||
import com.volmit.iris.engine.data.chunk.MCATerrainChunk;
|
import com.volmit.iris.engine.data.chunk.MCATerrainChunk;
|
||||||
import com.volmit.iris.engine.data.chunk.TerrainChunk;
|
import com.volmit.iris.engine.data.chunk.TerrainChunk;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
|
import com.volmit.iris.engine.framework.EngineTarget;
|
||||||
import com.volmit.iris.engine.object.common.HeadlessWorld;
|
import com.volmit.iris.engine.object.common.HeadlessWorld;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
@ -52,15 +54,13 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
|||||||
private final HeadlessWorld world;
|
private final HeadlessWorld world;
|
||||||
private final NBTWorld writer;
|
private final NBTWorld writer;
|
||||||
private final MultiBurst burst;
|
private final MultiBurst burst;
|
||||||
private final EngineProvider provider;
|
private final Engine engine;
|
||||||
|
|
||||||
public HeadlessGenerator(HeadlessWorld world) {
|
public HeadlessGenerator(HeadlessWorld world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
burst = new MultiBurst("Iris Headless Generator", 9, IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getPregenThreadCount()));
|
burst = new MultiBurst("Iris Headless Generator", 9, IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getPregenThreadCount()));
|
||||||
writer = new NBTWorld(world.getWorld().worldFolder());
|
writer = new NBTWorld(world.getWorld().worldFolder());
|
||||||
provider = new EngineProvider();
|
engine = new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), isStudio());
|
||||||
provider.provideEngine(world.getWorld(), world.getDimension().getLoadKey(), world.getDimension().getLoader().getDataFolder(), isStudio(), (e) -> {
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
@ -132,7 +132,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
|||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
burst.shutdownAndAwait();
|
burst.shutdownAndAwait();
|
||||||
provider.close();
|
getEngine().close();
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,11 +151,6 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
|||||||
return EMPTYPOINTS;
|
return EMPTYPOINTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Engine getEngine() {
|
|
||||||
return provider.getEngine();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHeadless() {
|
public boolean isHeadless() {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user