This commit is contained in:
Daniel Mills 2020-11-10 02:54:06 -05:00
parent 9ba47c1b6a
commit c60a772e84
7 changed files with 250 additions and 102 deletions

View File

@ -89,7 +89,7 @@ public class IrisBoardManager implements BoardProvider, Listener
int y = player.getLocation().getBlockY(); int y = player.getLocation().getBlockY();
int z = player.getLocation().getBlockZ(); int z = player.getLocation().getBlockZ();
Engine engine = g.getCompound().getEngine(y); Engine engine = g.getCompound().getEngineForHeight(y);
int parallaxChunks=0; int parallaxChunks=0;
int parallaxRegions=0; int parallaxRegions=0;
@ -102,8 +102,8 @@ public class IrisBoardManager implements BoardProvider, Listener
parallaxChunks += g.getCompound().getEngine(i).getParallax().getChunkCount(); parallaxChunks += g.getCompound().getEngine(i).getParallax().getChunkCount();
loadedObjects+= g.getCompound().getData().getObjectLoader().getSize(); loadedObjects+= g.getCompound().getData().getObjectLoader().getSize();
memoryGuess += g.getCompound().getData().getObjectLoader().getTotalStorage() * 225; memoryGuess += g.getCompound().getData().getObjectLoader().getTotalStorage() * 225;
memoryGuess+= parallaxChunks += 3500; memoryGuess+= parallaxChunks * 3500;
memoryGuess += parallaxRegions += 1700000; memoryGuess += parallaxRegions * 1700000;
} }
tp.put(0); // TODO: CHUNK SPEED tp.put(0); // TODO: CHUNK SPEED
@ -117,7 +117,7 @@ public class IrisBoardManager implements BoardProvider, Listener
if(engine != null) if(engine != null)
{ {
v.add("&7&m------------------"); v.add("&7&m------------------");
v.add(C.AQUA + "Engine" + C.GRAY + ": " + engine.getName() + " (" + engine.getMinHeight() + " - " + engine.getMaxHeight() + ")"); v.add(C.AQUA + "Engine" + C.GRAY + ": " + engine.getName() + " " + engine.getMinHeight() + "-" + engine.getMaxHeight());
v.add(C.AQUA + "Region" + C.GRAY + ": " + engine.getRegion(x, z).getName()); v.add(C.AQUA + "Region" + C.GRAY + ": " + engine.getRegion(x, z).getName());
v.add(C.AQUA + "Biome" + C.GRAY + ": " + engine.getBiome(x, y, z).getName()); v.add(C.AQUA + "Biome" + C.GRAY + ": " + engine.getBiome(x, y, z).getName());
v.add(C.AQUA + "Height" + C.GRAY + ": " + Math.round(engine.getHeight(x, z))); v.add(C.AQUA + "Height" + C.GRAY + ": " + Math.round(engine.getHeight(x, z)));

View File

@ -2,12 +2,10 @@ package com.volmit.iris.manager.command;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.object.IrisBiome; import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.scaffold.IrisWorlds; import com.volmit.iris.scaffold.IrisWorlds;
import com.volmit.iris.scaffold.engine.IrisAccess; import com.volmit.iris.scaffold.engine.IrisAccess;
import com.volmit.iris.util.KList; import com.volmit.iris.util.*;
import com.volmit.iris.util.MortarCommand;
import com.volmit.iris.util.MortarSender;
import com.volmit.iris.util.RNG;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -53,79 +51,49 @@ public class CommandIrisStudioGoto extends MortarCommand
} }
IrisAccess g = IrisWorlds.access(world); IrisAccess g = IrisWorlds.access(world);
int tries = 10000; IrisBiome b = Iris.globaldata.getBiomeLoader().load(args[0], false);
boolean cave = false; IrisRegion r = Iris.globaldata.getRegionLoader().load(args[0], false);
IrisBiome biome2 = null;
if(args.length > 1) if(b != null)
{ {
if(args[1].equalsIgnoreCase("-cave")) J.a(() -> {
Location l = g.lookForBiome(b, 10000, (v) -> sender.sendMessage("Looking for " + C.BOLD + C.WHITE + b.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places"));
if(l == null)
{ {
cave = true; sender.sendMessage("Couldn't find " + b.getName() + ".");
} }
else else
{ {
biome2 = g.getData().getBiomeLoader().load(args[1]); sender.sendMessage("Found " + b.getName() + "!");
J.s(() -> sender.player().teleport(l));
if(biome2 == null)
{
sender.sendMessage(args[1] + " is not a biome. Use the file name (without extension)");
return true;
}
} }
});
} }
for(String i : args) else if(r != null)
{ {
if(i.equalsIgnoreCase("-cave")) J.a(() -> {
{ Location l = g.lookForRegion(r, 10000, (v) -> sender.sendMessage("Looking for " + C.BOLD + C.WHITE + r.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places"));
cave = true;
}
}
IrisBiome biome = args[0].equals("this") ? g.getBiome(p.getLocation().getBlockX(), p.getLocation().getBlockZ()) : g.getData().getBiomeLoader().load(args[0]); if(l == null)
if(biome == null)
{ {
sender.sendMessage(args[0] + " is not a biome. Use the file name (without extension)"); sender.sendMessage("Couldn't find " + r.getName() + ".");
return true;
}
while(tries > 0)
{
tries--;
int xx = (int) (RNG.r.i(-29999970, 29999970));
int zz = (int) (RNG.r.i(-29999970, 29999970));
if((cave ? g.getCaveBiome(xx, zz) : g.getBiome(xx, zz)).getLoadKey().equals(biome.getLoadKey()))
{
if(biome2 != null)
{
for(int i = 0; i < 64; i++)
{
int ax = xx + RNG.r.i(-64, 32);
int az = zz + RNG.r.i(-64, 32);
if((cave ? g.getBiome(ax, az) : g.getBiome(ax, az)).getLoadKey().equals(biome2.getLoadKey()))
{
tries--;
p.teleport(new Location(world, xx, world.getHighestBlockYAt(xx, zz), zz));
sender.sendMessage("Found border in " + (10000 - tries) + " tries!");
return true;
}
}
} }
else else
{ {
p.teleport(new Location(world, xx, world.getHighestBlockYAt(xx, zz), zz)); sender.sendMessage("Found " + r.getName() + "!");
sender.sendMessage("Found in " + (10000 - tries) + " tries!"); J.s(() -> sender.player().teleport(l));
return true;
}
} }
});
} }
sender.sendMessage("Tried to find " + biome.getName() + " looked in 10,000 places no dice."); else
{
sender.sendMessage(args[0] + " is not a biome or region in this dimension.");
}
return true; return true;
} }
@ -149,6 +117,6 @@ public class CommandIrisStudioGoto extends MortarCommand
@Override @Override
protected String getArgsUsage() protected String getArgsUsage()
{ {
return "[biome] [otherbiome] [-cave]"; return "[biome/region]";
} }
} }

View File

@ -21,7 +21,7 @@ public class IrisWorldCreator
public IrisWorldCreator dimension(String loadKey) public IrisWorldCreator dimension(String loadKey)
{ {
this.dimensionName = dimensionName; this.dimensionName = loadKey;
return this; return this;
} }

View File

@ -10,6 +10,7 @@ import com.volmit.iris.scaffold.hunk.Hunk;
import com.volmit.iris.util.Form; import com.volmit.iris.util.Form;
import com.volmit.iris.util.KList; import com.volmit.iris.util.KList;
import com.volmit.iris.util.M; import com.volmit.iris.util.M;
import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -69,6 +70,8 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
if (hint == null) { if (hint == null) {
File iris = new File(world.getWorldFolder(), "iris"); File iris = new File(world.getWorldFolder(), "iris");
if(iris.exists() && iris.isDirectory())
{
searching: searching:
for (File i : iris.listFiles()) { for (File i : iris.listFiles()) {
// Look for v1 location // Look for v1 location
@ -89,6 +92,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
} }
} }
} }
}
if (hint == null) { if (hint == null) {
throw new RuntimeException("Cannot find iris dimension data for world: " + world.getName() + "! FAILED"); throw new RuntimeException("Cannot find iris dimension data for world: " + world.getName() + "! FAILED");
@ -272,6 +276,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
@Override @Override
public void close() { public void close() {
getComposite().close(); getComposite().close();
Bukkit.unloadWorld(getComposite().getWorld(), !isStudio());
} }
@Override @Override

View File

@ -2,7 +2,15 @@ package com.volmit.iris.scaffold.engine;
import com.volmit.iris.manager.IrisDataManager; import com.volmit.iris.manager.IrisDataManager;
import com.volmit.iris.object.IrisBiome; import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.scaffold.data.DataProvider; import com.volmit.iris.scaffold.data.DataProvider;
import com.volmit.iris.util.*;
import org.bukkit.Location;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
public interface IrisAccess extends Hotloadable, DataProvider { public interface IrisAccess extends Hotloadable, DataProvider {
@ -41,4 +49,163 @@ public interface IrisAccess extends Hotloadable, DataProvider {
public boolean isFailing(); public boolean isFailing();
public boolean isStudio(); public boolean isStudio();
public default Location lookForBiome(IrisBiome biome, long timeout, Consumer<Integer> triesc)
{
ChronoLatch cl = new ChronoLatch(250, false);
long s = M.ms();
int cpus = 2+(Runtime.getRuntime().availableProcessors()/2);
KList<Engine> engines = new KList<>();
for(int i = 0; i < getCompound().getSize(); i++)
{
Engine e = getCompound().getEngine(i);
if(e.getDimension().getAllBiomes(e).contains(biome))
{
engines.add(e);
}
}
AtomicInteger tries = new AtomicInteger(0);
AtomicBoolean found = new AtomicBoolean(false);
AtomicReference<Location> location = new AtomicReference<>();
for(int i = 0; i < cpus; i++)
{
J.a(() -> {
try
{
Engine e;
IrisBiome b;
int x,y,z;
while(!found.get())
{
try {
synchronized (engines) {
e = engines.getRandom();
x = RNG.r.i(-29999970, 29999970);
y = RNG.r.i(0, e.getHeight()-1);
z = RNG.r.i(-29999970, 29999970);
b = e.getBiome(x, y, z);
}
if(b != null && b.getLoadKey() == null)
{
continue;
}
if(b != null && b.getLoadKey().equals(biome.getLoadKey()))
{
found.lazySet(true);
location.lazySet(new Location(e.getWorld(), x,y,z));
}
tries.getAndIncrement();
}
catch(Throwable ex)
{
ex.printStackTrace();
return;
}
}
}
catch(Throwable e)
{
e.printStackTrace();
}
});
}
while(!found.get() || location.get() == null)
{
J.sleep(50);
if(cl.flip())
{
triesc.accept(tries.get());
}
if(M.ms() - s > timeout)
{
return null;
}
}
return location.get();
}
public default Location lookForRegion(IrisRegion reg, long timeout, Consumer<Integer> triesc)
{
ChronoLatch cl = new ChronoLatch(250, false);
long s = M.ms();
int cpus = 2+(Runtime.getRuntime().availableProcessors()/2);
KList<Engine> engines = new KList<>();
for(int i = 0; i < getCompound().getSize(); i++)
{
Engine e = getCompound().getEngine(i);
if(e.getDimension().getAllRegions(e).contains(reg))
{
engines.add(e);
}
}
AtomicInteger tries = new AtomicInteger(0);
AtomicBoolean found = new AtomicBoolean(false);
AtomicReference<Location> location = new AtomicReference<>();
for(int i = 0; i < cpus; i++)
{
J.a(() -> {
Engine e;
IrisRegion b;
int x,z;
while(!found.get())
{
try {
e = engines.getRandom();
x = RNG.r.i(-29999970, 29999970);
z = RNG.r.i(-29999970, 29999970);
b = e.getRegion(x, z);
if(b != null && b.getLoadKey().equals(reg.getLoadKey()))
{
found.lazySet(true);
location.lazySet(new Location(e.getWorld(), x, e.getHeight(x, z) + e.getMinHeight() ,z));
}
tries.getAndIncrement();
}
catch(Throwable xe)
{
xe.printStackTrace();
return;
}
}
});
}
while(!found.get() || location.get() != null)
{
J.sleep(50);
if(cl.flip())
{
triesc.accept(tries.get());
}
if(M.ms() - s > timeout)
{
triesc.accept(tries.get());
return null;
}
}
triesc.accept(tries.get());
return location.get();
}
} }

View File

@ -1,13 +1,15 @@
package com.volmit.iris.scaffold.parallax; package com.volmit.iris.scaffold.parallax;
import com.volmit.iris.scaffold.hunk.Hunk;
import com.volmit.iris.util.ChronoLatch;
import com.volmit.iris.util.J;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.KMap;
import org.bukkit.block.data.BlockData;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import com.volmit.iris.util.*;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.scaffold.hunk.Hunk;
public class ParallaxWorld implements ParallaxAccess public class ParallaxWorld implements ParallaxAccess
{ {
private final KMap<Long, ParallaxRegion> loadedRegions; private final KMap<Long, ParallaxRegion> loadedRegions;
@ -192,7 +194,7 @@ public class ParallaxWorld implements ParallaxAccess
public void cleanup() public void cleanup()
{ {
cleanup(10000, 5000); cleanup(10000, 1000);
} }
@Override @Override

View File

@ -1,19 +1,15 @@
package com.volmit.iris.scaffold.stream; package com.volmit.iris.scaffold.stream;
import java.util.List;
import java.util.function.Function;
import com.volmit.iris.scaffold.hunk.Hunk; import com.volmit.iris.scaffold.hunk.Hunk;
import com.volmit.iris.scaffold.stream.arithmetic.*; import com.volmit.iris.scaffold.stream.arithmetic.*;
import com.volmit.iris.scaffold.stream.convert.*; import com.volmit.iris.scaffold.stream.convert.*;
import com.volmit.iris.scaffold.stream.interpolation.Interpolated; import com.volmit.iris.scaffold.stream.interpolation.Interpolated;
import com.volmit.iris.scaffold.stream.sources.FunctionStream; import com.volmit.iris.scaffold.stream.sources.FunctionStream;
import com.volmit.iris.scaffold.stream.utility.*; import com.volmit.iris.scaffold.stream.utility.*;
import com.volmit.iris.util.Function2; import com.volmit.iris.util.*;
import com.volmit.iris.util.Function3;
import com.volmit.iris.util.Function4; import java.util.List;
import com.volmit.iris.util.IRare; import java.util.function.Function;
import com.volmit.iris.util.KList;
public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T>
{ {
@ -338,7 +334,17 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T>
default <V> ProceduralStream<V> selectRarity(List<V> types) default <V> ProceduralStream<V> selectRarity(List<V> types)
{ {
KList<V> rarityTypes = new KList<>(); KList<V> rarityTypes = new KList<>();
types.forEach((i) -> rarityTypes.addMultiple(i, IRare.get(i))); int totalRarity = 0;
for(V i : types)
{
totalRarity += IRare.get(i);
}
for(V i : types)
{
rarityTypes.addMultiple(i, Math.max(1, (IRare.get(i) / totalRarity)));
}
return new SelectionStream<V>(this, rarityTypes); return new SelectionStream<V>(this, rarityTypes);
} }