scm loading

This commit is contained in:
Daniel Mills 2020-01-08 02:42:50 -05:00
parent d1925201ef
commit feb4f77e39
6 changed files with 222 additions and 88 deletions

View File

@ -1,18 +1,22 @@
package ninja.bytecode.iris; package ninja.bytecode.iris;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Enumeration;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function; import java.util.function.Function;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -31,7 +35,9 @@ import ninja.bytecode.iris.util.Direction;
import ninja.bytecode.shuriken.bench.Profiler; import ninja.bytecode.shuriken.bench.Profiler;
import ninja.bytecode.shuriken.collections.GMap; import ninja.bytecode.shuriken.collections.GMap;
import ninja.bytecode.shuriken.collections.GSet; import ninja.bytecode.shuriken.collections.GSet;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.execution.TaskExecutor; import ninja.bytecode.shuriken.execution.TaskExecutor;
import ninja.bytecode.shuriken.format.F;
import ninja.bytecode.shuriken.io.IO; import ninja.bytecode.shuriken.io.IO;
import ninja.bytecode.shuriken.json.JSONException; import ninja.bytecode.shuriken.json.JSONException;
import ninja.bytecode.shuriken.json.JSONObject; import ninja.bytecode.shuriken.json.JSONObject;
@ -60,16 +66,18 @@ public class Iris extends JavaPlugin implements Listener
values = new GMap<>(); values = new GMap<>();
instance = this; instance = this;
settings = new Settings(); settings = new Settings();
J.attempt(() -> createTempCache());
loadContent(); loadContent();
processContent();
gen = new IrisGenerator(); gen = new IrisGenerator();
genPool = new TaskExecutor(getTC(), settings.performance.threadPriority, "Iris Generator"); genPool = new TaskExecutor(getTC(), settings.performance.threadPriority, "Iris Generator");
getServer().getPluginManager().registerEvents((Listener) this, this); getServer().getPluginManager().registerEvents((Listener) this, this);
getCommand("iris").setExecutor(new CommandIris()); getCommand("iris").setExecutor(new CommandIris());
getCommand("ish").setExecutor(new CommandIsh()); getCommand("ish").setExecutor(new CommandIsh());
new WandManager(); new WandManager();
// Debug world regens // Debug world regens
if(settings.performance.loadonstart) if(settings.performance.loadonstart)
{ {
GSet<String> ws = new GSet<>(); GSet<String> ws = new GSet<>();
@ -90,25 +98,74 @@ public class Iris extends JavaPlugin implements Listener
} }
} }
} }
private void processContent()
{
L.v("Processing Content");
for(SchematicGroup i : schematics.v())
{
i.processVariants();
}
}
private static File internalResource(String resource)
{
return new File(System.getProperty("java.io.tmpdir") + "/Iris/" + resource);
}
private void createTempCache() throws Throwable
{
File temp = new File(System.getProperty("java.io.tmpdir") + "/Iris/");
temp.mkdirs();
L.i("Iris Cache: " + temp.getAbsolutePath());
ZipFile zipFile = new ZipFile(getFile());
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while(entries.hasMoreElements())
{
ZipEntry entry = entries.nextElement();
if(entry.getName().startsWith("pack/") && !entry.isDirectory())
{
File f = new File(temp, entry.getName());
f.getParentFile().mkdirs();
InputStream stream = zipFile.getInputStream(entry);
FileOutputStream fos = new FileOutputStream(f);
IO.fullTransfer(stream, fos, 16921);
fos.close();
stream.close();
}
}
zipFile.close();
}
private void loadContent() private void loadContent()
{ {
L.i("Loading Content"); L.i("Loading Content");
try try
{ {
IrisPack master = new IrisPack(loadJSON("pack/manifest.json")); IrisPack master = new IrisPack(loadJSON("pack/manifest.json"));
master.load(); master.load();
} }
catch(Throwable e) catch(Throwable e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
int m = 0;
for(SchematicGroup i : schematics.v())
{
m+=i.size();
}
L.i("Dimensions: " + dimensions.size()); L.i("Dimensions: " + dimensions.size());
L.i("Biomes: " + biomes.size()); L.i("Biomes: " + biomes.size());
L.i("Schematic Groups: " + schematics.size()); L.i("Object Groups: " + schematics.size());
L.i("Objects: " + F.f(m));
L.flush(); L.flush();
} }
@ -164,33 +221,74 @@ public class Iris extends JavaPlugin implements Listener
values.get(w).put(t, d); values.get(w).put(t, d);
} }
public static IrisDimension loadDimension(String s) throws JSONException, IOException public static IrisDimension loadDimension(String s) throws JSONException, IOException
{ {
L.i("Loading Iris Dimension " + s); L.i("Loading Iris Dimension " + s);
return new IrisDimension(loadJSON("pack/dimensions/" + s + ".json")); return new IrisDimension(loadJSON("pack/dimensions/" + s + ".json"));
} }
public static IrisBiome loadBiome(String s) throws JSONException, IOException public static IrisBiome loadBiome(String s) throws JSONException, IOException
{ {
L.i("Loading Iris Biome " + s); L.i("Loading Iris Biome " + s);
return new IrisBiome(loadJSON("pack/biomes/" + s + ".json")); return new IrisBiome(loadJSON("pack/biomes/" + s + ".json"));
} }
public static SchematicGroup loadSchematicGroup(String s)
{
SchematicGroup g = SchematicGroup.load("pack/objects/" + s);
if(g != null)
{
schematics.put(s, g);
L.i("Loaded Object Group: " + g.getName() + " (" + g.getSchematics().size() + " Objects)");
return g;
}
L.i("Cannot load Object Group: " + s);
return null;
}
public static Schematic loadSchematic(String s) throws IOException public static Schematic loadSchematic(String s) throws IOException
{ {
L.i("Loading Iris Object " + s); L.i("Loading Iris Object " + s);
return Schematic.load(loadResource("pack/objects/" + s + ".ish")); return Schematic.load(loadResource("pack/objects/" + s + ".ish"));
} }
public static JSONObject loadJSON(String s) throws JSONException, IOException public static JSONObject loadJSON(String s) throws JSONException, IOException
{ {
return new JSONObject(IO.readAll(loadResource(s))); return new JSONObject(IO.readAll(loadResource(s)));
} }
public static InputStream loadResource(String string) public static File loadFolder(String string)
{ {
L.v("Loading Resource: " + "Iris.jar/" + string); File internal = internalResource(string);
return Iris.class.getResourceAsStream("/" + string);
if(internal.exists())
{
L.v("Loading Group: " + string);
return internal;
}
L.f("Cannot find folder: " + internal.getAbsolutePath());
return null;
}
public static InputStream loadResource(String string) throws IOException
{
File internal = internalResource(string);
if(internal.exists())
{
L.v("Loading Resource: " + "Iris/" + string);
return new FileInputStream(internal);
}
else
{
L.f("Cannot find Resource: " + string);
return null;
}
} }
} }

View File

@ -1,7 +1,5 @@
package ninja.bytecode.iris.generator; package ninja.bytecode.iris.generator;
import java.io.File;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -34,8 +32,6 @@ import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.ParallelChunkGenerator; import ninja.bytecode.iris.util.ParallelChunkGenerator;
import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.collections.GList;
import ninja.bytecode.shuriken.collections.GMap; import ninja.bytecode.shuriken.collections.GMap;
import ninja.bytecode.shuriken.execution.J;
import ninja.bytecode.shuriken.io.IO;
import ninja.bytecode.shuriken.logging.L; import ninja.bytecode.shuriken.logging.L;
import ninja.bytecode.shuriken.math.M; import ninja.bytecode.shuriken.math.M;
import ninja.bytecode.shuriken.math.RNG; import ninja.bytecode.shuriken.math.RNG;
@ -260,73 +256,7 @@ public class IrisGenerator extends ParallelChunkGenerator
private SchematicGroup loadSchematics(String folder) private SchematicGroup loadSchematics(String folder)
{ {
if(schematicCache.containsKey(folder)) return Iris.schematics.get(folder);
{
return schematicCache.get(folder);
}
File f = new File(Iris.instance.getDataFolder(), "objects/" + folder);
GList<Schematic> s = new GList<>();
GList<String> flags = new GList<>();
if(f.exists() && f.isDirectory())
{
for(File i : f.listFiles())
{
if(i.isFile() && i.getName().endsWith(".ifl"))
{
try
{
flags.add(IO.readAll(i).split("\\Q\n\\E"));
}
catch(IOException e)
{
e.printStackTrace();
}
}
if(i.isFile() && i.getName().endsWith(".ish"))
{
J.attempt(() ->
{
Schematic sc = Schematic.load(i);
s.add(sc);
});
}
}
}
for(String i : flags)
{
String flag = i.trim().toLowerCase();
if(flag.equals("center"))
{
for(Schematic j : s)
{
j.setCenteredHeight();
}
L.i("Centered " + s.size() + " Schematics");
}
}
L.i("Loaded " + s.size() + " Schematics in " + folder);
SchematicGroup g = new SchematicGroup(folder);
g.setSchematics(s);
g.setFlags(flags);
for(String i : flags)
{
if(i.startsWith("priority="))
{
J.attempt(() -> g.setPriority(Integer.valueOf(i.split("\\Q=\\E")[1]).intValue()));
}
}
schematicCache.put(folder, g);
return g;
} }
private double getBiomedHeight(int x, int z, ChunkPlan plan) private double getBiomedHeight(int x, int z, ChunkPlan plan)

View File

@ -17,6 +17,7 @@ import org.bukkit.util.BlockVector;
import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.util.Catalyst12; import ninja.bytecode.iris.util.Catalyst12;
import ninja.bytecode.iris.util.MB; import ninja.bytecode.iris.util.MB;
import ninja.bytecode.shuriken.collections.GList;
import ninja.bytecode.shuriken.collections.GMap; import ninja.bytecode.shuriken.collections.GMap;
import ninja.bytecode.shuriken.io.CustomOutputStream; import ninja.bytecode.shuriken.io.CustomOutputStream;
import ninja.bytecode.shuriken.logging.L; import ninja.bytecode.shuriken.logging.L;
@ -28,6 +29,7 @@ public class Schematic
private int h; private int h;
private int d; private int d;
private final GMap<BlockVector, MB> s; private final GMap<BlockVector, MB> s;
private BlockVector mount;
public Schematic(int w, int h, int d) public Schematic(int w, int h, int d)
{ {
@ -38,6 +40,57 @@ public class Schematic
centeredHeight = false; centeredHeight = false;
} }
public void computeMountShift()
{
int ly = Integer.MAX_VALUE;
for(BlockVector i : s.k())
{
if(i.getBlockY() < ly)
{
ly = i.getBlockY();
}
}
GList<BlockVector> fmount = new GList<>();
for(BlockVector i : s.k())
{
if(i.getBlockY() == ly)
{
fmount.add(i);
}
}
double avx[] = new double[fmount.size()];
double avy[] = new double[fmount.size()];
double avz[] = new double[fmount.size()];
int c = 0;
for(BlockVector i : fmount)
{
avx[c] = i.getBlockX();
avy[c] = i.getBlockY();
avz[c] = i.getBlockZ();
c++;
}
mount = new BlockVector(avg(avx), avg(avy), avg(avz));
}
private int avg(double[] v)
{
double g = 0;
for(int i = 0; i < v.length; i++)
{
g+=v[i];
}
return (int) Math.round(g / (double) v.length);
}
public void setCenteredHeight() public void setCenteredHeight()
{ {
this.centeredHeight = true; this.centeredHeight = true;
@ -170,7 +223,7 @@ public class Schematic
} }
} }
} }
public static Schematic load(InputStream in) throws IOException public static Schematic load(InputStream in) throws IOException
{ {
Schematic s = new Schematic(1, 1, 1); Schematic s = new Schematic(1, 1, 1);
@ -185,7 +238,6 @@ public class Schematic
Schematic s = new Schematic(1, 1, 1); Schematic s = new Schematic(1, 1, 1);
FileInputStream fin = new FileInputStream(f); FileInputStream fin = new FileInputStream(f);
s.read(fin); s.read(fin);
L.i("Loaded Schematic: " + f.getPath() + " Size: " + s.getSchematic().size()); L.i("Loaded Schematic: " + f.getPath() + " Size: " + s.getSchematic().size());
return s; return s;

View File

@ -1,6 +1,11 @@
package ninja.bytecode.iris.schematic; package ninja.bytecode.iris.schematic;
import java.io.File;
import java.io.IOException;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.collections.GList;
import ninja.bytecode.shuriken.logging.L;
public class SchematicGroup public class SchematicGroup
{ {
@ -61,4 +66,41 @@ public class SchematicGroup
{ {
return getSchematics().size(); return getSchematics().size();
} }
public static SchematicGroup load(String string)
{
File folder = Iris.loadFolder(string);
if(folder != null)
{
SchematicGroup g = new SchematicGroup(string);
for(File i : folder.listFiles())
{
if(i.getName().endsWith(".ish"))
{
try
{
Schematic s = Schematic.load(i);
g.getSchematics().add(s);
}
catch(IOException e)
{
L.f("Cannot load Schematic: " + string + "/" + i.getName());
L.ex(e);
}
}
}
return g;
}
return null;
}
public void processVariants()
{
L.v("Processing " + name + " Objects");
}
} }

View File

@ -5,6 +5,7 @@ import java.lang.reflect.Field;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import ninja.bytecode.iris.Iris;
import ninja.bytecode.iris.util.MB; import ninja.bytecode.iris.util.MB;
import ninja.bytecode.iris.util.PolygonGenerator; import ninja.bytecode.iris.util.PolygonGenerator;
import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.collections.GList;
@ -97,7 +98,14 @@ public class IrisBiome
J.attempt(() -> scatterChance = scatterFromJSON(o.getJSONArray("scatter"))); J.attempt(() -> scatterChance = scatterFromJSON(o.getJSONArray("scatter")));
J.attempt(() -> simplexScatter = o.getString("surfaceType").equalsIgnoreCase("simplex")); J.attempt(() -> simplexScatter = o.getString("surfaceType").equalsIgnoreCase("simplex"));
J.attempt(() -> scatterSurface = o.getString("surfaceType").equalsIgnoreCase("scatter")); J.attempt(() -> scatterSurface = o.getString("surfaceType").equalsIgnoreCase("scatter"));
J.attempt(() -> schematicGroups = strFromJSON(o.getJSONArray("schematics"))); J.attempt(() -> {
schematicGroups = strFromJSON(o.getJSONArray("objects"));
for(String i : schematicGroups.k())
{
Iris.loadSchematicGroup(i);
}
});
} }
public JSONObject toJSON() public JSONObject toJSON()
@ -110,7 +118,7 @@ public class IrisBiome
J.attempt(() -> j.put("dirt", mbListToJSON(dirt))); J.attempt(() -> j.put("dirt", mbListToJSON(dirt)));
J.attempt(() -> j.put("scatter", scatterToJson(scatterChance))); J.attempt(() -> j.put("scatter", scatterToJson(scatterChance)));
J.attempt(() -> j.put("surfaceType", simplexScatter ? "simplex" : scatterSurface ? "scatter" : "na")); J.attempt(() -> j.put("surfaceType", simplexScatter ? "simplex" : scatterSurface ? "scatter" : "na"));
J.attempt(() -> j.put("schematics", strToJson(schematicGroups))); J.attempt(() -> j.put("objects", strToJson(schematicGroups)));
return j; return j;
} }

View File

@ -9,5 +9,9 @@
], ],
"scatter":[ "scatter":[
"DEAD_BUSH=0.008" "DEAD_BUSH=0.008"
],
"objects": [
"tree/palm/medium=0.25",
"tree/palm/small=2.5"
] ]
} }