mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Engine provider
This commit is contained in:
parent
79b3d7359a
commit
eb4b42c089
@ -28,8 +28,10 @@ import com.volmit.iris.engine.object.common.IrisWorld;
|
|||||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
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.IO;
|
||||||
import com.volmit.iris.util.io.ReactiveFolder;
|
import com.volmit.iris.util.io.ReactiveFolder;
|
||||||
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.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -50,8 +52,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
|
|
||||||
public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChunkGenerator {
|
public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChunkGenerator {
|
||||||
private static final BlockData ERROR_BLOCK = Material.RED_GLAZED_TERRACOTTA.createBlockData();
|
private static final BlockData ERROR_BLOCK = Material.RED_GLAZED_TERRACOTTA.createBlockData();
|
||||||
private final AtomicReference<CompletableFuture<Engine>> engine = new AtomicReference<>();
|
private final EngineProvider provider;
|
||||||
private final AtomicBoolean busy = new AtomicBoolean(false);
|
|
||||||
private final IrisWorld world;
|
private final IrisWorld world;
|
||||||
private final File dataLocation;
|
private final File dataLocation;
|
||||||
private final String dimensionKey;
|
private final String dimensionKey;
|
||||||
@ -67,18 +68,13 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
this.dataLocation = dataLocation;
|
this.dataLocation = dataLocation;
|
||||||
this.dimensionKey = dimensionKey;
|
this.dimensionKey = dimensionKey;
|
||||||
this.folder = new ReactiveFolder(dataLocation, (_a, _b, _c) -> initialize());
|
this.folder = new ReactiveFolder(dataLocation, (_a, _b, _c) -> initialize());
|
||||||
|
this.provider = new EngineProvider();
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Engine getEngine()
|
public Engine getEngine()
|
||||||
{
|
{
|
||||||
try {
|
return provider.getEngine();
|
||||||
return engine.get().get();
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,7 +84,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
getEngine().close();
|
provider.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,17 +100,10 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
|
|
||||||
private void initialize()
|
private void initialize()
|
||||||
{
|
{
|
||||||
engine.set(MultiBurst.burst.completeValue(() -> createEngine(world, dimensionKey, dataLocation)));
|
provider.provideEngine(world, dimensionKey, dataLocation, isStudio(), (e) -> {
|
||||||
}
|
populators.clear();
|
||||||
|
populators.add((BlockPopulator) e);
|
||||||
private Engine createEngine(IrisWorld world, String dimension, File dataLocation) {
|
});
|
||||||
IrisData data = new IrisData(dataLocation);
|
|
||||||
IrisDimension realDimension = data.getDimensionLoader().load(dimension);
|
|
||||||
EngineTarget target = new EngineTarget(world, realDimension, data);
|
|
||||||
Engine engine = new IrisEngine(target, isStudio());
|
|
||||||
populators.clear();
|
|
||||||
populators.add((BlockPopulator) engine);
|
|
||||||
return engine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -126,7 +115,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
|||||||
Hunk<BlockData> blocks = Hunk.view((ChunkData) tc);
|
Hunk<BlockData> blocks = Hunk.view((ChunkData) tc);
|
||||||
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
||||||
this.world.bind(world);
|
this.world.bind(world);
|
||||||
engine.get().get().generate(x * 16, z * 16, blocks, biomes, true);
|
getEngine().generate(x * 16, z * 16, blocks, biomes, true);
|
||||||
return tc.getRaw();
|
return tc.getRaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* 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.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 org.bukkit.generator.BlockPopulator;
|
||||||
|
|
||||||
|
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 = new IrisData(dataLocation);
|
||||||
|
IrisDimension realDimension = data.getDimensionLoader().load(dimension);
|
||||||
|
EngineTarget target = new EngineTarget(world, realDimension, data);
|
||||||
|
Engine engine = new IrisEngine(target, studio);
|
||||||
|
post.accept(engine);
|
||||||
|
return engine;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Engine getEngine()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return engine.get().get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
if(engine.get() != null && engine.get().isDone())
|
||||||
|
{
|
||||||
|
Engine e = getEngine();
|
||||||
|
|
||||||
|
if(e != null)
|
||||||
|
{
|
||||||
|
e.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -54,13 +54,14 @@ 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 Engine engine;
|
private final EngineProvider provider;
|
||||||
|
|
||||||
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());
|
||||||
engine = new IrisEngine(new EngineTarget(world.getWorld(),world.getDimension(), world.getDimension().getLoader()), isStudio());
|
provider = new EngineProvider();
|
||||||
|
provider.provideEngine(world.getWorld(), world.getDimension().getLoadKey(), world.getDimension().getLoader().getDataFolder(), isStudio(), (e) -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ChunkCoordinates
|
@ChunkCoordinates
|
||||||
@ -76,7 +77,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
|||||||
.injector((xx, yy, zz, biomeBase) -> chunk.setBiomeAt(ox + xx, yy, oz + zz,
|
.injector((xx, yy, zz, biomeBase) -> chunk.setBiomeAt(ox + xx, yy, oz + zz,
|
||||||
INMS.get().getTrueBiomeBaseId(biomeBase)))
|
INMS.get().getTrueBiomeBaseId(biomeBase)))
|
||||||
.build();
|
.build();
|
||||||
engine.generate(x * 16, z * 16,
|
getEngine().generate(x * 16, z * 16,
|
||||||
Hunk.view((ChunkGenerator.ChunkData) tc), Hunk.view((ChunkGenerator.BiomeGrid) tc),
|
Hunk.view((ChunkGenerator.ChunkData) tc), Hunk.view((ChunkGenerator.BiomeGrid) tc),
|
||||||
false);
|
false);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -132,7 +133,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
|||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
burst.shutdownAndAwait();
|
burst.shutdownAndAwait();
|
||||||
engine.close();
|
provider.close();
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +152,11 @@ 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