This commit is contained in:
Daniel Mills 2020-01-24 14:19:52 -05:00
parent 7b8b8d6b75
commit 08159923d6
8 changed files with 180 additions and 23 deletions

View File

@ -1,15 +1,26 @@
package ninja.bytecode.iris;
import java.io.File;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Difficulty;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import mortar.api.rift.Rift;
import mortar.api.sched.J;
import mortar.bukkit.command.Command;
import mortar.bukkit.plugin.Control;
import mortar.bukkit.plugin.Instance;
import mortar.bukkit.plugin.Mortar;
import mortar.bukkit.plugin.MortarPlugin;
import mortar.lib.control.RiftController;
import mortar.util.text.C;
import ninja.bytecode.iris.command.CommandIris;
import ninja.bytecode.iris.controller.ExecutionController;
@ -24,13 +35,11 @@ public class Iris extends MortarPlugin
public static Thread primaryThread;
public static Settings settings;
public static IrisMetrics metrics;
private ExecutionController executionController;
@Instance
public static Iris instance;
@Control
private ExecutionController executionController;
@Control
private PackController packController;
@ -40,6 +49,22 @@ public class Iris extends MortarPlugin
@Command
private CommandIris commandIris;
private Rift r;
@Override
public void onEnable()
{
instance = this;
executionController = new ExecutionController();
executionController.start();
super.onEnable();
}
public File getCacheFolder()
{
return getDataFolder("cache", "object");
}
@Override
public void start()
{
@ -50,13 +75,60 @@ public class Iris extends MortarPlugin
settings = new Settings();
getServer().getPluginManager().registerEvents((Listener) this, this);
packController.compile();
J.s(() ->
{
if(settings.performance.debugMode)
{
try
{
r = Mortar.getController(RiftController.class).createRift("iris/" + UUID.randomUUID().toString());
r.setGenerator(IrisGenerator.class);
r.setDifficulty(Difficulty.NORMAL);
r.setTemporary(true);
r.setSeed(0);
r.setViewDistance(10);
r.setTileTickLimit(0.1);
r.setEntityTickLimit(0.1);
r.setPhysicsThrottle(5);
r.setMonsterActivationRange(5);
r.setArrowDespawnRate(1);
r.load();
for(Player i : Bukkit.getOnlinePlayers())
{
i.teleport(r.getSpawn());
}
}
catch(Throwable e)
{
e.printStackTrace();
}
}
}, 10);
}
@Override
public void stop()
{
if(settings.performance.debugMode && r != null)
{
r.colapse();
}
HandlerList.unregisterAll((Plugin) this);
Bukkit.getScheduler().cancelTasks(this);
executionController.stop();
}
@EventHandler
public void on(PlayerJoinEvent e)
{
if(settings.performance.debugMode && r != null)
{
e.getPlayer().teleport(r.getSpawn());
}
}
public void reload()

View File

@ -2,22 +2,19 @@ package ninja.bytecode.iris.controller;
import org.bukkit.World;
import mortar.bukkit.plugin.Controller;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.execution.TaskExecutor;
public class ExecutionController extends Controller
public class ExecutionController
{
KMap<String, TaskExecutor> executors;
@Override
public void start()
{
executors = new KMap<>();
}
@Override
public void stop()
{
for(TaskExecutor i : executors.v())
@ -28,12 +25,6 @@ public class ExecutionController extends Controller
executors.clear();
}
@Override
public void tick()
{
}
public TaskExecutor getExecutor(World world, String f)
{
String k = world.getWorldFolder().getAbsolutePath() + " (" + world + ") " + f;

View File

@ -5,6 +5,7 @@ import java.lang.reflect.Field;
import sun.misc.Unsafe;
@SuppressWarnings("restriction")
public class AtomicCharArray implements Serializable
{
private static final long serialVersionUID = 2862133569453604235L;

View File

@ -4,6 +4,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -35,6 +36,7 @@ import ninja.bytecode.iris.util.VectorMath;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
import ninja.bytecode.shuriken.io.CustomOutputStream;
import ninja.bytecode.shuriken.io.IO;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.RNG;
@ -52,6 +54,62 @@ public class GenObject
private int mountHeight;
private BlockVector shift;
@SuppressWarnings("deprecation")
public void perfectRead(File folder, String name) throws IOException
{
File file = new File(folder, IO.hash(name));
FileInputStream fin = new FileInputStream(file);
DataInputStream din = new DataInputStream(fin);
centeredHeight = din.readBoolean();
w = din.readShort();
h = din.readShort();
d = din.readShort();
name = din.readUTF();
int size = din.readInt();
s.clear();
for(int i = 0; i < size; i++)
{
s.put(new SBlockVector(din.readShort(), din.readShort(), din.readShort()), MB.of(Material.getMaterial(din.readInt()), din.readByte()));
}
mount = new BlockVector(din.readShort(), din.readShort(), din.readShort());
mountHeight = din.readShort();
shift = new BlockVector(din.readShort(), din.readShort(), din.readShort());
din.close();
}
@SuppressWarnings("deprecation")
public void perfectWrite(File folder) throws IOException
{
File file = new File(folder, IO.hash(name));
FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBoolean(centeredHeight);
dos.writeShort(w);
dos.writeShort(h);
dos.writeShort(d);
dos.writeUTF(name);
dos.writeInt(s.size());
for(SBlockVector i : s.keySet())
{
dos.writeShort((short) i.getX());
dos.writeShort((short) i.getY());
dos.writeShort((short) i.getZ());
dos.writeInt(s.get(i).material.getId());
dos.writeByte(s.get(i).data);
}
dos.writeShort(mount.getBlockX());
dos.writeShort(mount.getBlockY());
dos.writeShort(mount.getBlockZ());
dos.writeShort(mountHeight);
dos.writeShort(shift.getBlockX());
dos.writeShort(shift.getBlockY());
dos.writeShort(shift.getBlockZ());
dos.close();
}
public GenObject(int w, int h, int d)
{
this.w = w;

View File

@ -0,0 +1,13 @@
package ninja.bytecode.iris.generator.genobject;
public class PhantomGenObject
{
private GenObject object;
private String name;
public PhantomGenObject(GenObject object)
{
this.object = object;
this.name = object.getName();
}
}

View File

@ -3,7 +3,6 @@ package ninja.bytecode.iris.generator.parallax;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.event.EventHandler;
@ -21,8 +20,6 @@ import ninja.bytecode.iris.util.IrisWorldData;
import ninja.bytecode.iris.util.ObjectMode;
import ninja.bytecode.iris.util.SChunkVector;
import ninja.bytecode.shuriken.bench.PrecisionStopwatch;
import ninja.bytecode.shuriken.collections.KSet;
import ninja.bytecode.shuriken.execution.ChronoLatch;
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup;
import ninja.bytecode.shuriken.math.RNG;
@ -32,8 +29,6 @@ public abstract class ParallaxWorldGenerator extends ParallelChunkGenerator impl
private IrisWorldData data;
private RNG rMaster;
private AtomicChunkData buffer;
private KSet<Chunk> fix;
private ChronoLatch cl;
protected boolean saving;
@Override
@ -41,8 +36,6 @@ public abstract class ParallaxWorldGenerator extends ParallelChunkGenerator impl
{
this.world = world;
saving = true;
cl = new ChronoLatch(3000);
fix = new KSet<>();
buffer = new AtomicChunkData(world);
this.data = new IrisWorldData(world);
this.rMaster = new RNG(world.getSeed() + 1);

View File

@ -8,12 +8,15 @@ import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.generator.atomics.AtomicChunkData;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.ChunkSpliceListener;
import ninja.bytecode.shuriken.execution.TaskExecutor;
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup;
import ninja.bytecode.shuriken.execution.TaskExecutor.TaskResult;
import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.RollingSequence;
import ninja.bytecode.shuriken.reaction.O;
@ -24,6 +27,7 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator
private int wx;
private int wz;
private ReentrantLock biomeLock;
private TaskExecutor backupService;
private TaskGroup tg;
private boolean ready = false;
int cg = 0;
@ -46,14 +50,38 @@ public abstract class ParallelChunkGenerator extends ChunkGenerator
return genColumn(a, b, c, d, p, data, false);
}
private TaskGroup work(String n)
{
if(Iris.instance == null || Iris.exec() == null)
{
if(backupService == null)
{
L.f(C.RED + "Cannot contact ExecutionController!" + C.YELLOW + " Did you reload iris?");
L.w(C.YELLOW + "Spinning up a temporary backup service until the issue resolves...");
backupService = new TaskExecutor(4, Thread.MAX_PRIORITY, "Iris Backup Handover");
Iris.instance.reload();
}
return backupService.startWork();
}
else if(backupService != null)
{
L.i(C.GREEN + "Reconnected to the execution service. Closing backup service now...");
backupService.close();
}
return Iris.exec().getExecutor(world, n).startWork();
}
public TaskGroup startParallaxWork()
{
return Iris.exec().getExecutor(world, "Parallax").startWork();
return work("Parallax");
}
public TaskGroup startWork()
{
return Iris.exec().getExecutor(world, "Generator").startWork();
return work("Generator");
}
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)

View File

@ -3,3 +3,4 @@ version: ${project.version}
main: ninja.bytecode.iris.Iris
load: STARTUP
depend: [Mortar]
hotload-dependencies: false