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

@@ -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)