This commit is contained in:
Daniel Mills 2020-01-19 02:45:28 -05:00
parent 1b9c7d48e4
commit 445ce46357
13 changed files with 391 additions and 109 deletions

View File

@ -9,10 +9,13 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import mortar.api.nms.NMP;
import mortar.util.text.C;
import ninja.bytecode.iris.controller.TimingsController;
import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.util.BiomeLayer;
import ninja.bytecode.shuriken.format.F;
import ninja.bytecode.shuriken.logging.L;
public class CommandIris implements CommandExecutor
{
@ -44,6 +47,46 @@ public class CommandIris implements CommandExecutor
msg(sender, " \\Decor: " + ChatColor.BOLD + ChatColor.WHITE + F.duration(d, 2));
}
if(args[0].equalsIgnoreCase("info"))
{
if(sender instanceof Player)
{
Player p = (Player) sender;
World w = p.getWorld();
if(w.getGenerator() instanceof IrisGenerator)
{
IrisGenerator g = (IrisGenerator) w.getGenerator();
IrisBiome biome = g.getBiome((int) g.getOffsetX(p.getLocation().getX()), (int) g.getOffsetZ(p.getLocation().getZ()));
BiomeLayer l = new BiomeLayer(g, biome);
msg(p, "Biome: " + C.BOLD + C.WHITE + biome.getName() + C.RESET + C.GRAY + " (" + C.GOLD + l.getBiome().getRarityString() + C.GRAY + ")");
for(String i : biome.getSchematicGroups().k())
{
String f = "";
double percent = biome.getSchematicGroups().get(i);
if(percent > 1D)
{
f = (int) percent + " + " + F.pc(percent - (int) percent, percent - (int) percent >= 0.01 ? 0 : 3);
}
else
{
f = F.pc(percent, percent >= 0.01 ? 0 : 3);
}
msg(p, "* " + C.DARK_GREEN + i + ": " + C.BOLD + C.WHITE + f + C.RESET + C.GRAY + " (" + F.f(g.getDimension().getObjectGroup(i).size()) + " variants)");
}
}
else
{
msg(sender, "Not in an Iris World");
}
}
}
if(args[0].equalsIgnoreCase("rtp"))
{
if(sender instanceof Player)
@ -118,6 +161,11 @@ public class CommandIris implements CommandExecutor
p.teleport(w.getHighestBlockAt(x, z).getLocation());
}
}
else
{
msg(sender, "Not in an Iris World");
}
}
}

View File

@ -3,6 +3,7 @@ package ninja.bytecode.iris;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
@ -56,9 +57,23 @@ public class Iris extends JavaPlugin implements Listener
public void onDisable()
{
getController(PackController.class).dispose();
controllerSet.stopControllers();
HandlerList.unregisterAll((Plugin) this);
Bukkit.getScheduler().cancelTasks(this);
if(Iris.settings.performance.debugMode)
{
for(World i : Bukkit.getWorlds())
{
if(i.getGenerator() instanceof IrisGenerator)
{
((IrisGenerator) i.getGenerator()).dispose();
}
}
System.gc();
}
}
public void reload()

View File

@ -1,5 +1,7 @@
package ninja.bytecode.iris.controller;
import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -12,6 +14,7 @@ import ninja.bytecode.iris.util.IrisController;
import ninja.bytecode.shuriken.collections.GList;
import ninja.bytecode.shuriken.collections.GSet;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.io.IO;
public class DebugController implements IrisController
{
@ -38,7 +41,7 @@ public class DebugController implements IrisController
{
GSet<String> ws = new GSet<>();
GList<World> destroy = new GList<>();
for(World i : Bukkit.getWorlds())
{
if(i.getGenerator() instanceof IrisGenerator)
@ -46,7 +49,7 @@ public class DebugController implements IrisController
destroy.add(i);
}
}
World w = Iris.getController(WorldController.class).createIrisWorld(null, 0, true);
for(Player i : Bukkit.getOnlinePlayers())
{
@ -61,8 +64,9 @@ public class DebugController implements IrisController
{
Bukkit.unloadWorld(i, false);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> {
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () ->
{
for(World i : destroy.copy())
{
Bukkit.unloadWorld(i, false);
@ -80,6 +84,24 @@ public class DebugController implements IrisController
@Override
public void onStop()
{
deleteOnExit(new File("iris-worlds"));
}
public static void deleteOnExit(File f)
{
if(f == null || !f.exists())
{
return;
}
if(f.isDirectory())
{
for(File i : f.listFiles())
{
deleteOnExit(i);
}
}
f.deleteOnExit();
}
}

View File

@ -105,15 +105,11 @@ public class PackController implements IrisController
}
L.v(ChatColor.LIGHT_PURPLE + "Processing Content");
TaskExecutor executor = new TaskExecutor(Runtime.getRuntime().availableProcessors() * 2, Thread.MIN_PRIORITY, "Schematic Processor");
TaskGroup gx = executor.startWork();
for(GenObjectGroup i : genObjectGroups.v())
{
gx.queue(i::processVariants);
i.processVariants();
}
gx.execute();
executor.close();
for(String i : dimensions.k())
{
@ -284,4 +280,12 @@ public class PackController implements IrisController
return biomes.get(id);
}
public void dispose()
{
compiledDimensions.clear();
dimensions.clear();
biomes.clear();
genObjectGroups.clear();
}
}

View File

@ -12,23 +12,13 @@ import ninja.bytecode.iris.generator.IrisGenerator;
import ninja.bytecode.iris.pack.CompiledDimension;
import ninja.bytecode.iris.util.IrisController;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.io.IO;
public class WorldController implements IrisController
{
@Override
public void onStart()
{
J.attemptAsync(() ->
{
for(File i : new File(Iris.instance.getDataFolder().getParentFile().getParentFile(), "iris-worlds").listFiles())
{
if(new File(i, ".garbage").exists())
{
IO.delete(i);
}
}
});
}
public boolean isChunkGenerated(World w, int x, int z)

View File

@ -8,7 +8,7 @@ import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import net.minecraft.server.v1_12_R1.CriterionTriggerBredAnimals.b;
import mortar.util.text.C;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.controller.PackController;
import ninja.bytecode.iris.generator.genobject.GenObjectDecorator;
@ -24,7 +24,6 @@ import ninja.bytecode.iris.pack.CompiledDimension;
import ninja.bytecode.iris.pack.IrisBiome;
import ninja.bytecode.iris.pack.IrisRegion;
import ninja.bytecode.iris.util.AtomicChunkData;
import ninja.bytecode.iris.util.BiomeLayer;
import ninja.bytecode.iris.util.ChunkPlan;
import ninja.bytecode.iris.util.IrisInterpolation;
import ninja.bytecode.iris.util.MB;
@ -56,6 +55,7 @@ public class IrisGenerator extends ParallelChunkGenerator
});
//@done
private boolean disposed;
private double[][][] scatterCache;
private CNG scatter;
private MB ICE = new MB(Material.ICE);
@ -81,6 +81,7 @@ public class IrisGenerator extends ParallelChunkGenerator
public IrisGenerator(CompiledDimension dim)
{
this.dim = dim;
disposed = false;
L.i("Preparing Dimension: " + dim.getName() + " With " + dim.getBiomes().size() + " Biomes...");
}
@ -102,6 +103,11 @@ public class IrisGenerator extends ParallelChunkGenerator
@Override
public void onInit(World world, Random random)
{
if(disposed)
{
return;
}
this.world = world;
rTerrain = new RNG(world.getSeed());
glLNoise = new GenLayerLayeredNoise(this, world, random, rTerrain.nextParallelRNG(2));
@ -233,6 +239,12 @@ public class IrisGenerator extends ParallelChunkGenerator
@Override
public Biome genColumn(int wxxf, int wzxf, int x, int z, ChunkPlan plan)
{
if(disposed)
{
setBlock(x, 0, z, Material.MAGENTA_GLAZED_TERRACOTTA);
return Biome.VOID;
}
double wx = getOffsetX(wxxf);
double wz = getOffsetZ(wzxf);
int wxx = (int) wx;
@ -374,4 +386,26 @@ public class IrisGenerator extends ParallelChunkGenerator
{
return dim;
}
public void dispose()
{
if(disposed)
{
return;
}
L.w(C.YELLOW + "Disposed Iris World " + C.RED + world.getName());
disposed = true;
dim = null;
glLNoise = null;
glCaves = null;
glCarving = null;
glCaverns = null;
glSnow = null;
glCliffs = null;
}
public boolean isDisposed()
{
return disposed;
}
}

View File

@ -22,6 +22,7 @@ import ninja.bytecode.iris.generator.placer.NMSPlacer;
import ninja.bytecode.iris.util.Direction;
import ninja.bytecode.iris.util.IPlacer;
import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.SBlockVector;
import ninja.bytecode.iris.util.VectorMath;
import ninja.bytecode.shuriken.collections.GList;
import ninja.bytecode.shuriken.collections.GMap;
@ -36,7 +37,7 @@ public class GenObject
private int h;
private int d;
private String name = "?";
private final GMap<BlockVector, MB> s;
private final GMap<SBlockVector, MB> s;
private BlockVector mount;
private int mountHeight;
private BlockVector shift;
@ -55,19 +56,19 @@ public class GenObject
{
int ly = Integer.MAX_VALUE;
for(BlockVector i : s.k())
for(SBlockVector i : s.keySet())
{
if(i.getBlockY() < ly)
if(i.getY() < ly)
{
ly = i.getBlockY();
ly = (int) i.getY();
}
}
GList<BlockVector> fmount = new GList<>();
GList<SBlockVector> fmount = new GList<>();
for(BlockVector i : s.k())
for(SBlockVector i : s.keySet())
{
if(i.getBlockY() == ly)
if(i.getY() == ly)
{
fmount.add(i);
}
@ -78,11 +79,11 @@ public class GenObject
double avz[] = new double[fmount.size()];
int c = 0;
for(BlockVector i : fmount)
for(SBlockVector i : fmount)
{
avx[c] = i.getBlockX();
avy[c] = i.getBlockY();
avz[c] = i.getBlockZ();
avx[c] = i.getX();
avy[c] = i.getY();
avz[c] = i.getZ();
c++;
}
@ -122,7 +123,7 @@ public class GenObject
return d;
}
public GMap<BlockVector, MB> getSchematic()
public GMap<SBlockVector, MB> getSchematic()
{
return s;
}
@ -157,7 +158,7 @@ public class GenObject
for(int i = 0; i < l; i++)
{
s.put(new BlockVector(din.readInt(), din.readInt(), din.readInt()), new MB(Material.getMaterial((int) din.readInt()), din.readInt()));
s.put(new SBlockVector(din.readInt(), din.readInt(), din.readInt()), new MB(Material.getMaterial((int) din.readInt()), din.readInt()));
}
}
@ -169,11 +170,11 @@ public class GenObject
dos.writeInt(d);
dos.writeInt(s.size());
for(BlockVector i : s.keySet())
for(SBlockVector i : s.keySet())
{
dos.writeInt(i.getBlockX());
dos.writeInt(i.getBlockY());
dos.writeInt(i.getBlockZ());
dos.writeInt((int) i.getX());
dos.writeInt((int) i.getY());
dos.writeInt((int) i.getZ());
dos.writeInt(s.get(i).material.getId());
dos.writeInt(s.get(i).data);
}
@ -189,17 +190,17 @@ public class GenObject
public MB get(int x, int y, int z)
{
return s.get(new BlockVector(x, y, z));
return s.get(new SBlockVector(x, y, z));
}
public boolean has(int x, int y, int z)
{
return s.contains(new BlockVector(x, y, z));
return s.containsKey(new SBlockVector(x, y, z));
}
public void put(int x, int y, int z, MB mb)
{
s.put(new BlockVector(x, y, z), mb);
s.put(new SBlockVector(x, y, z), mb);
}
public GenObject copy()
@ -216,10 +217,10 @@ public class GenObject
s.clear();
}
public void fill(GMap<BlockVector, MB> b)
public void fill(GMap<SBlockVector, MB> b)
{
clear();
s.put(b);
s.putAll(b);
}
public int sh(int g)
@ -259,7 +260,7 @@ public class GenObject
start.add(shift);
GMap<Location, MB> undo = new GMap<>();
for(BlockVector i : getSchematic().k())
for(SBlockVector i : s.keySet())
{
MB b = getSchematic().get(i);
@ -268,10 +269,10 @@ public class GenObject
continue;
}
Location f = start.clone().add(i);
Location f = start.clone().add(i.toBlockVector());
Material m = placer.get(f.clone().subtract(0, 1, 0)).material;
if(i.getBlockY() == mountHeight && (m.equals(Material.WATER) || m.equals(Material.STATIONARY_WATER) || m.equals(Material.LAVA) || m.equals(Material.STATIONARY_LAVA)))
if(i.getY() == mountHeight && (m.equals(Material.WATER) || m.equals(Material.STATIONARY_WATER) || m.equals(Material.LAVA) || m.equals(Material.STATIONARY_LAVA)))
{
for(Location j : undo.k())
{
@ -336,13 +337,14 @@ public class GenObject
public void rotate(Direction from, Direction to)
{
GMap<BlockVector, MB> g = s.copy();
GMap<SBlockVector, MB> g = new GMap<>();
g.putAll(s);
s.clear();
for(BlockVector i : g.k())
for(SBlockVector i : g.keySet())
{
MB mb = g.get(i);
s.put(VectorMath.rotate(from, to, i).toBlockVector(), mb);
s.put(new SBlockVector(VectorMath.rotate(from, to, i.toBlockVector()).toBlockVector()), mb);
}
name = name + "-rt" + to.name();
@ -358,10 +360,12 @@ public class GenObject
MB a = MB.of(g[1]);
boolean specific = g[1].contains(":");
MB b = MB.of(g[2]);
for(BlockVector i : s.k())
GMap<SBlockVector, MB> m = new GMap<>();
m.putAll(s);
s.clear();
for(SBlockVector i : m.keySet())
{
MB c = s.get(i);
MB c = m.get(i);
if((specific && c.equals(a)) || c.material.equals(a.material))
{
@ -394,36 +398,36 @@ public class GenObject
int maxZ = 0;
boolean added = false;
for(BlockVector i : getSchematic().k())
for(SBlockVector i : getSchematic().keySet())
{
if(i.getBlockX() > maxX)
if(i.getX() > maxX)
{
maxX = i.getBlockX();
maxX = (int) i.getX();
}
if(i.getBlockY() > maxY)
if(i.getY() > maxY)
{
maxY = i.getBlockY();
maxY = (int) i.getY();
}
if(i.getBlockZ() > maxZ)
if(i.getZ() > maxZ)
{
maxZ = i.getBlockZ();
maxZ = (int) i.getZ();
}
if(i.getBlockX() < minX)
if(i.getX() < minX)
{
minX = i.getBlockX();
minX = (int) i.getX();
}
if(i.getBlockY() < minY)
if(i.getY() < minY)
{
minY = i.getBlockY();
minY = (int) i.getY();
}
if(i.getBlockZ() < minZ)
if(i.getZ() < minZ)
{
minZ = i.getBlockZ();
minZ = (int) i.getZ();
}
}
@ -431,18 +435,18 @@ public class GenObject
{
for(int j = minZ; j <= maxZ; j++)
{
BlockVector highest = null;
SBlockVector highest = null;
for(BlockVector k : getSchematic().k())
for(SBlockVector k : getSchematic().keySet())
{
if(k.getBlockX() == i && k.getBlockZ() == j)
if(k.getX() == i && k.getZ() == j)
{
if(highest == null)
{
highest = k;
}
else if(highest.getBlockY() < k.getBlockY())
else if(highest.getY() < k.getY())
{
highest = k;
}
@ -451,9 +455,9 @@ public class GenObject
if(highest != null)
{
BlockVector mbv = highest.clone().add(new Vector(0, 1, 0)).toBlockVector();
BlockVector mbv = highest.toBlockVector().add(new Vector(0, 1, 0)).toBlockVector();
added = true;
getSchematic().put(mbv, MB.of(Material.SNOW, RNG.r.nextInt((int) M.clip(factor, 0, 8))));
getSchematic().put(new SBlockVector(mbv), MB.of(Material.SNOW, RNG.r.nextInt((int) M.clip(factor, 0, 8))));
}
}
}

View File

@ -84,6 +84,11 @@ public class GenObjectDecorator extends BlockPopulator
@Override
public void populate(World world, Random rnotusingyou, Chunk source)
{
if(g.isDisposed())
{
return;
}
ex.execute(() -> {
Random random = new Random(((source.getX() - 32) * (source.getZ() + 54)) + world.getSeed());
GSet<IrisBiome> hits = new GSet<>();

View File

@ -195,42 +195,29 @@ public class GenObjectGroup
public void processVariants()
{
TaskExecutor te = new TaskExecutor(Runtime.getRuntime().availableProcessors(), Thread.MAX_PRIORITY, "Variant Processor");
TaskGroup g = te.startWork();
GList<GenObject> inject = new GList<>();
for(GenObject i : getSchematics())
{
for(Direction j : new Direction[] {Direction.S, Direction.E, Direction.W})
{
g.queue(() ->
{
GenObject cp = i.copy();
GenObject f = cp;
f.rotate(Direction.N, j);
inject.add(f);
});
GenObject cp = i.copy();
GenObject f = cp;
f.rotate(Direction.N, j);
inject.add(f);
}
}
g.execute();
getSchematics().add(inject);
g = te.startWork();
for(GenObject i : getSchematics())
{
g.queue(() ->
i.recalculateMountShift();
for(String j : flags)
{
i.recalculateMountShift();
for(String j : flags)
{
i.computeFlag(j);
}
});
i.computeFlag(j);
}
}
g.execute();
te.close();
L.i(ChatColor.LIGHT_PURPLE + "Processed " + ChatColor.WHITE + F.f(schematics.size()) + ChatColor.LIGHT_PURPLE + " Schematics in " + ChatColor.WHITE + name);
}
}

View File

@ -72,7 +72,7 @@ public class GenLayerBiome extends GenLayer
}
master = BiomeLayer.compile(iris, 0.082 * Iris.settings.gen.biomeScale * 0.189, 1, factory);
if(Iris.settings.performance.verbose)
{
master.print(2);
@ -175,4 +175,9 @@ public class GenLayerBiome extends GenLayer
{
return regions.get(name);
}
public void compileInfo(BiomeLayer l)
{
l.compileChildren(0.082 * Iris.settings.gen.biomeScale * 0.189, 1, factory, true);
}
}

View File

@ -67,21 +67,14 @@ public class IrisDimension
private GList<IrisBiome> biomesFromArray(JSONArray a) throws JSONException, IOException
{
GList<IrisBiome> b = new GList<>();
TaskExecutor t = new TaskExecutor(Runtime.getRuntime().availableProcessors() * 2, Thread.MIN_PRIORITY, "Biome Loader");
TaskGroup g = t.startWork();
for(int i = 0; i < a.length(); i++)
{
int ii = i;
g.queue(() ->
{
IrisBiome bb = Iris.getController(PackController.class).loadBiome(a.getString(ii));
Iris.getController(PackController.class).registerBiome(a.getString(ii), bb);
b.add(bb);
});
IrisBiome bb = Iris.getController(PackController.class).loadBiome(a.getString(ii));
Iris.getController(PackController.class).registerBiome(a.getString(ii), bb);
b.add(bb);
}
g.execute();
t.close();
return b;
}

View File

@ -33,7 +33,7 @@ public class BiomeLayer
this.children = new GList<>();
}
private void compile(double scale, int octaves, Function<CNG, CNG> factory)
public void compileChildren(double scale, int octaves, Function<CNG, CNG> factory, boolean inf)
{
if(gen != null)
{
@ -61,7 +61,7 @@ public class BiomeLayer
for(BiomeLayer i : getChildren())
{
i.compile(scale, octaves, factory);
i.compileChildren(scale, octaves, factory, inf);
}
}
@ -160,6 +160,11 @@ public class BiomeLayer
}
public static BiomeLayer compile(IrisGenerator g, double scale, int octaves, Function<CNG, CNG> factory)
{
return compile(g, scale, octaves, factory, false);
}
public static BiomeLayer compile(IrisGenerator g, double scale, int octaves, Function<CNG, CNG> factory, boolean inf)
{
GMap<String, BiomeLayer> components = new GMap<>();
@ -204,7 +209,7 @@ public class BiomeLayer
master.addLayer(components.get(i));
}
master.compile(scale, octaves, factory);
master.compileChildren(scale, octaves, factory, inf);
return master;
}

View File

@ -0,0 +1,170 @@
package ninja.bytecode.iris.util;
import java.util.Map;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.util.BlockVector;
import org.bukkit.util.Vector;
/**
* A vector with a hash function that floors the X, Y, Z components, a la
* BlockVector in WorldEdit. BlockVectors can be used in hash sets and hash
* maps. Be aware that BlockVectors are mutable, but it is important that
* BlockVectors are never changed once put into a hash set or hash map.
*/
@SerializableAs("BlockVector")
public class SBlockVector
{
private short x;
private short y;
private short z;
/**
* Construct the vector with all components as 0.
*/
public SBlockVector()
{
this.x = 0;
this.y = 0;
this.z = 0;
}
/**
* Construct the vector with another vector.
*
* @param vec
* The other vector.
*/
public SBlockVector(Vector vec)
{
this.x = (short) vec.getX();
this.y = (short) vec.getY();
this.z = (short) vec.getZ();
}
/**
* Construct the vector with provided integer components.
*
* @param x
* X component
* @param y
* Y component
* @param z
* Z component
*/
public SBlockVector(int x, int y, int z)
{
this.x = (short) x;
this.y = (short) y;
this.z = (short) z;
}
/**
* Construct the vector with provided double components.
*
* @param x
* X component
* @param y
* Y component
* @param z
* Z component
*/
public SBlockVector(double x, double y, double z)
{
this.x = (short) x;
this.y = (short) y;
this.z = (short) z;
}
/**
* Construct the vector with provided float components.
*
* @param x
* X component
* @param y
* Y component
* @param z
* Z component
*/
public SBlockVector(float x, float y, float z)
{
this.x = (short) x;
this.y = (short) y;
this.z = (short) z;
}
/**
* Get a new block vector.
*
* @return vector
*/
@Override
public SBlockVector clone()
{
return new SBlockVector(x, y, z);
}
public double getX()
{
return x;
}
public void setX(double x)
{
this.x = (short) x;
}
public double getY()
{
return y;
}
public void setY(double y)
{
this.y = (short) y;
}
public double getZ()
{
return z;
}
public void setZ(double z)
{
this.z = (short) z;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + x;
result = prime * result + y;
result = prime * result + z;
return result;
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
SBlockVector other = (SBlockVector) obj;
if(x != other.x)
return false;
if(y != other.y)
return false;
if(z != other.z)
return false;
return true;
}
public BlockVector toBlockVector()
{
return new BlockVector(x, y, z);
}
}