Tweaking carves

This commit is contained in:
Daniel Mills
2020-01-14 01:16:33 -05:00
parent 8e28c59163
commit 90846401a5
18 changed files with 449 additions and 224 deletions

View File

@@ -0,0 +1,152 @@
package ninja.bytecode.iris.pack;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.function.Consumer;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import ninja.bytecode.iris.generator.genobject.GenObjectGroup;
import ninja.bytecode.shuriken.collections.GList;
import ninja.bytecode.shuriken.collections.GMap;
import ninja.bytecode.shuriken.io.CustomOutputStream;
import ninja.bytecode.shuriken.json.JSONObject;
import ninja.bytecode.shuriken.reaction.O;
public class CompiledDimension
{
private IrisDimension dimension;
private GList<IrisBiome> biomes;
private GMap<String, GenObjectGroup> objects;
public CompiledDimension(IrisDimension dimension)
{
this.dimension = dimension;
biomes = new GList<>();
objects = new GMap<>();
}
public void read(InputStream in) throws IOException
{
GZIPInputStream gin = new GZIPInputStream(in);
DataInputStream din = new DataInputStream(gin);
dimension = new IrisDimension();
dimension.fromJSON(new JSONObject(din.readUTF()), false);
int bi = din.readInt();
int ob = din.readInt();
for(int i = 0; i < bi; i++)
{
IrisBiome b = new IrisBiome("Loading", Biome.VOID);
b.fromJSON(new JSONObject(din.readUTF()), false);
}
for(int i = 0; i < ob; i++)
{
GenObjectGroup g = new GenObjectGroup("Loading");
g.read(din);
}
}
public void write(OutputStream out, Consumer<Double> progress) throws IOException
{
GZIPOutputStream gzo = new CustomOutputStream(out, 1);
DataOutputStream dos = new DataOutputStream(gzo);
dos.writeUTF(dimension.toJSON().toString(0));
dos.writeInt(biomes.size());
dos.writeInt(objects.size());
for(IrisBiome i : biomes)
{
dos.writeUTF(i.toJSON().toString(0));
}
O<Integer> tc = new O<>();
O<Integer> oc = new O<>();
O<Integer> cc = new O<>();
tc.set(0);
oc.set(0);
cc.set(0);
for(GenObjectGroup i : objects.v())
{
tc.set(tc.get() + i.size());
}
for(GenObjectGroup i : objects.v().shuffle())
{
i.write(dos, (o) ->
{
cc.set((int) (o * i.size()));
if(progress != null)
{
progress.accept((double) (oc.get() + cc.get()) / (double) tc.get());
}
});
oc.set(oc.get() + cc.get());
cc.set(0);
}
dos.close();
}
public void registerBiome(IrisBiome j)
{
biomes.add(j);
}
public void registerObject(GenObjectGroup g)
{
if(g.getName().startsWith("pack/objects/"))
{
g.setName(g.getName().replaceFirst("\\Qpack/objects/\\E", ""));
}
objects.put(g.getName(), g);
}
public String getName()
{
return dimension.getName();
}
public GList<IrisBiome> getBiomes()
{
return biomes;
}
public Environment getEnvironment()
{
return dimension.getEnvironment();
}
public GenObjectGroup getObjectGroup(String j)
{
return objects.get(j);
}
public int countObjects()
{
int m = 0;
for(GenObjectGroup i : objects.v())
{
m += i.size();
}
return m;
}
public void sort()
{
biomes.sort();
}
}

View File

@@ -158,6 +158,11 @@ public class IrisBiome
}
public void fromJSON(JSONObject o)
{
fromJSON(o, true);
}
public void fromJSON(JSONObject o, boolean chain)
{
name = o.getString("name");
realBiome = Biome.valueOf(o.getString("derivative").toUpperCase().replaceAll(" ", "_"));
@@ -173,9 +178,12 @@ public class IrisBiome
{
schematicGroups = strFromJSON(o.getJSONArray("objects"));
for(String i : schematicGroups.k())
if(chain)
{
Iris.getController(PackController.class).loadSchematicGroup(i);
for(String i : schematicGroups.k())
{
Iris.getController(PackController.class).loadSchematicGroup(i);
}
}
});
}

View File

@@ -20,93 +20,86 @@ public class IrisDimension
private String name;
private Environment environment;
GList<IrisBiome> biomes;
public IrisDimension(JSONObject o) throws JSONException, IOException
{
this();
fromJSON(o);
}
public IrisDimension()
{
biomes = new GList<IrisBiome>();
environment = Environment.NORMAL;
}
public void fromJSON(JSONObject o) throws JSONException, IOException
{
fromJSON(o, true);
}
public void fromJSON(JSONObject o, boolean chain) throws JSONException, IOException
{
name = o.getString("name");
J.attempt(() -> environment = Environment.valueOf(o.getString("environment").toUpperCase().replaceAll(" ", "_")));
try
{
biomes = biomesFromArray(o.getJSONArray("biomes"));
biomes = chain ? biomesFromArray(o.getJSONArray("biomes")) : new GList<>();
}
catch(Throwable e)
{
e.printStackTrace();
}
if(o.has("focus"))
{
String focus = o.getString("focus");
for(IrisBiome i : biomes.copy())
{
if(!i.getName().toLowerCase().replaceAll(" ", "_").equals(focus))
{
biomes.remove(i);
}
}
}
}
public JSONObject toJSON()
{
JSONObject o = new JSONObject();
o.put("name", name);
o.put("environment", environment.name().toLowerCase().replaceAll("_", " "));
o.put("biomes", biomesToArray(biomes));
return o;
}
private GList<IrisBiome> biomesFromArray(JSONArray a) throws JSONException, IOException
{
GList<IrisBiome> b = new GList<>();
TaskExecutor ex= new TaskExecutor(Iris.settings.performance.compilerThreads, Iris.settings.performance.compilerPriority, "Iris Loader");
TaskExecutor ex = new TaskExecutor(Iris.settings.performance.compilerThreads, Iris.settings.performance.compilerPriority, "Iris Loader");
TaskGroup g = ex.startWork();
ReentrantLock lock = new ReentrantLock();
for(int i = 0; i < a.length(); i++)
{
int ii = i;
g.queue(() -> {
g.queue(() ->
{
IrisBiome bb = Iris.getController(PackController.class).loadBiome(a.getString(ii));
lock.lock();
Iris.getController(PackController.class).getBiomes().put(a.getString(ii), bb);
Iris.getController(PackController.class).registerBiome(a.getString(ii), bb);
b.add(bb);
lock.unlock();
});
}
g.execute();
ex.close();
return b;
}
private JSONArray biomesToArray(GList<IrisBiome> b)
{
JSONArray a = new JSONArray();
for(IrisBiome i : b)
{
a.put(i.getName().toLowerCase().replaceAll(" ", "_"));
}
return a;
}

View File

@@ -75,13 +75,13 @@ public class IrisPack
for(String i : dimensions)
{
IrisDimension d = Iris.getController(PackController.class).loadDimension(i);
Iris.getController(PackController.class).getDimensions().put(i, d);
Iris.getController(PackController.class).registerDimension(i, d);
}
}
public void loadBiome(String s) throws JSONException, IOException
{
IrisBiome b = Iris.getController(PackController.class).loadBiome(s);
Iris.getController(PackController.class).getBiomes().put(s, b);
Iris.getController(PackController.class).registerBiome(s, b);
}
}