mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Stop blowing up the VM when looking for biomes
This commit is contained in:
parent
e5cc9a3cbf
commit
9c376183e0
@ -28,7 +28,7 @@ import com.volmit.iris.util.collection.KList;
|
|||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.plugin.MortarCommand;
|
import com.volmit.iris.util.plugin.MortarCommand;
|
||||||
import com.volmit.iris.util.plugin.MortarSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -37,8 +37,11 @@ import org.bukkit.entity.Player;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class CommandIrisStudioGoto extends MortarCommand {
|
public class CommandIrisStudioGoto extends MortarCommand {
|
||||||
|
private static final AtomicBoolean looking = new AtomicBoolean(false);
|
||||||
|
|
||||||
public CommandIrisStudioGoto() {
|
public CommandIrisStudioGoto() {
|
||||||
super("goto", "find", "g");
|
super("goto", "find", "g");
|
||||||
setDescription("Find any region or biome");
|
setDescription("Find any region or biome");
|
||||||
@ -47,7 +50,7 @@ public class CommandIrisStudioGoto extends MortarCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTabOptions(MortarSender sender, String[] args, KList<String> list) {
|
public void addTabOptions(VolmitSender sender, String[] args, KList<String> list) {
|
||||||
if (args.length == 0 && sender.isPlayer() && IrisWorlds.isIrisWorld(sender.player().getWorld())) {
|
if (args.length == 0 && sender.isPlayer() && IrisWorlds.isIrisWorld(sender.player().getWorld())) {
|
||||||
IrisDataManager data = IrisWorlds.access(sender.player().getWorld()).getData();
|
IrisDataManager data = IrisWorlds.access(sender.player().getWorld()).getData();
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
@ -61,7 +64,7 @@ public class CommandIrisStudioGoto extends MortarCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(MortarSender sender, String[] args) {
|
public boolean handle(VolmitSender sender, String[] args) {
|
||||||
try {
|
try {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
sender.sendMessage("/iris std goto " + getArgsUsage());
|
sender.sendMessage("/iris std goto " + getArgsUsage());
|
||||||
@ -69,6 +72,11 @@ public class CommandIrisStudioGoto extends MortarCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sender.isPlayer()) {
|
if (sender.isPlayer()) {
|
||||||
|
if(looking.get())
|
||||||
|
{
|
||||||
|
sender.sendMessage("A Search is already running, please wait!");
|
||||||
|
}
|
||||||
|
|
||||||
Player p = sender.player();
|
Player p = sender.player();
|
||||||
World world = p.getWorld();
|
World world = p.getWorld();
|
||||||
|
|
||||||
@ -81,10 +89,12 @@ public class CommandIrisStudioGoto extends MortarCommand {
|
|||||||
IrisBiome b = IrisDataManager.loadAnyBiome(args[0]);
|
IrisBiome b = IrisDataManager.loadAnyBiome(args[0]);
|
||||||
IrisRegion r = IrisDataManager.loadAnyRegion(args[0]);
|
IrisRegion r = IrisDataManager.loadAnyRegion(args[0]);
|
||||||
|
|
||||||
|
looking.set(true);
|
||||||
if (b != null) {
|
if (b != null) {
|
||||||
J.a(() -> {
|
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"));
|
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"));
|
||||||
|
|
||||||
|
looking.set(false);
|
||||||
if (l == null) {
|
if (l == null) {
|
||||||
sender.sendMessage("Couldn't find " + b.getName() + ".");
|
sender.sendMessage("Couldn't find " + b.getName() + ".");
|
||||||
} else {
|
} else {
|
||||||
@ -96,6 +106,7 @@ public class CommandIrisStudioGoto extends MortarCommand {
|
|||||||
J.a(() -> {
|
J.a(() -> {
|
||||||
Location l = g.lookForRegion(r, 60000, (v) -> sender.sendMessage(C.BOLD + "" + C.WHITE + r.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places"));
|
Location l = g.lookForRegion(r, 60000, (v) -> sender.sendMessage(C.BOLD + "" + C.WHITE + r.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places"));
|
||||||
|
|
||||||
|
looking.set(false);
|
||||||
if (l == null) {
|
if (l == null) {
|
||||||
sender.sendMessage("Couldn't find " + r.getName() + ".");
|
sender.sendMessage("Couldn't find " + r.getName() + ".");
|
||||||
} else {
|
} else {
|
||||||
|
@ -39,8 +39,11 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class IrisComplex implements DataProvider {
|
public class IrisComplex implements DataProvider {
|
||||||
|
public static AtomicBoolean cacheLock = new AtomicBoolean(false);
|
||||||
private RNG rng;
|
private RNG rng;
|
||||||
private double fluidHeight;
|
private double fluidHeight;
|
||||||
private IrisDataManager data;
|
private IrisDataManager data;
|
||||||
@ -100,7 +103,7 @@ public class IrisComplex implements DataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IrisComplex(Engine engine, boolean simple) {
|
public IrisComplex(Engine engine, boolean simple) {
|
||||||
int cacheSize = IrisSettings.get().getCache().getStreamingCacheSize();
|
int cacheSize = 1024;
|
||||||
this.rng = new RNG(engine.getWorld().getSeed());
|
this.rng = new RNG(engine.getWorld().getSeed());
|
||||||
this.data = engine.getData();
|
this.data = engine.getData();
|
||||||
double height = engine.getHeight();
|
double height = engine.getHeight();
|
||||||
|
@ -40,7 +40,7 @@ import com.volmit.iris.util.collection.KMap;
|
|||||||
import com.volmit.iris.util.fakenews.FakeWorld;
|
import com.volmit.iris.util.fakenews.FakeWorld;
|
||||||
import com.volmit.iris.util.io.ReactiveFolder;
|
import com.volmit.iris.util.io.ReactiveFolder;
|
||||||
import com.volmit.iris.util.math.M;
|
import com.volmit.iris.util.math.M;
|
||||||
import com.volmit.iris.util.plugin.MortarSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import com.volmit.iris.util.reflect.V;
|
import com.volmit.iris.util.reflect.V;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
@ -117,7 +117,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
|||||||
J.s(() -> {
|
J.s(() -> {
|
||||||
try {
|
try {
|
||||||
for (Player i : getTarget().getWorld().getPlayers()) {
|
for (Player i : getTarget().getWorld().getPlayers()) {
|
||||||
new MortarSender(i, Iris.instance.getTag()).sendMessage("Dimension Hotloaded");
|
new VolmitSender(i, Iris.instance.getTag()).sendMessage("Dimension Hotloaded");
|
||||||
i.playSound(i.getLocation(), Sound.BLOCK_COPPER_PLACE, 1f, 1.25f);
|
i.playSound(i.getLocation(), Sound.BLOCK_COPPER_PLACE, 1f, 1.25f);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -195,7 +195,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
|||||||
dim = IrisDataManager.loadAnyDimension(query);
|
dim = IrisDataManager.loadAnyDimension(query);
|
||||||
|
|
||||||
if (dim == null) {
|
if (dim == null) {
|
||||||
Iris.proj.downloadSearch(new MortarSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), query, false);
|
Iris.proj.downloadSearch(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), query, false);
|
||||||
dim = IrisDataManager.loadAnyDimension(query);
|
dim = IrisDataManager.loadAnyDimension(query);
|
||||||
|
|
||||||
if (dim == null) {
|
if (dim == null) {
|
||||||
@ -211,7 +211,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
|||||||
|
|
||||||
if (dim == null) {
|
if (dim == null) {
|
||||||
Iris.info("Installing Iris pack " + od.getName() + " into world " + world.getName() + "...");
|
Iris.info("Installing Iris pack " + od.getName() + " into world " + world.getName() + "...");
|
||||||
Iris.proj.installIntoWorld(new MortarSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), od.getLoadKey(), world.getWorldFolder());
|
Iris.proj.installIntoWorld(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), od.getLoadKey(), world.getWorldFolder());
|
||||||
dim = new IrisDataManager(getDataFolder(world)).getDimensionLoader().load(od.getLoadKey());
|
dim = new IrisDataManager(getDataFolder(world)).getDimensionLoader().load(od.getLoadKey());
|
||||||
|
|
||||||
if (dim == null) {
|
if (dim == null) {
|
||||||
@ -261,7 +261,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
|||||||
dim = IrisDataManager.loadAnyDimension(query);
|
dim = IrisDataManager.loadAnyDimension(query);
|
||||||
|
|
||||||
if (dim == null) {
|
if (dim == null) {
|
||||||
Iris.proj.downloadSearch(new MortarSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), query, false);
|
Iris.proj.downloadSearch(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), query, false);
|
||||||
dim = IrisDataManager.loadAnyDimension(query);
|
dim = IrisDataManager.loadAnyDimension(query);
|
||||||
|
|
||||||
if (dim == null) {
|
if (dim == null) {
|
||||||
@ -277,7 +277,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
|||||||
|
|
||||||
if (dim == null) {
|
if (dim == null) {
|
||||||
Iris.info("Installing Iris pack " + od.getName() + " into world " + world + "...");
|
Iris.info("Installing Iris pack " + od.getName() + " into world " + world + "...");
|
||||||
Iris.proj.installIntoWorld(new MortarSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), od.getLoadKey(), new File(world));
|
Iris.proj.installIntoWorld(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), od.getLoadKey(), new File(world));
|
||||||
dim = new IrisDataManager(getDataFolder(world)).getDimensionLoader().load(od.getLoadKey());
|
dim = new IrisDataManager(getDataFolder(world)).getDimensionLoader().load(od.getLoadKey());
|
||||||
|
|
||||||
if (dim == null) {
|
if (dim == null) {
|
||||||
|
@ -20,6 +20,7 @@ package com.volmit.iris.engine.framework;
|
|||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.IrisDataManager;
|
import com.volmit.iris.core.IrisDataManager;
|
||||||
|
import com.volmit.iris.engine.IrisComplex;
|
||||||
import com.volmit.iris.engine.data.DataProvider;
|
import com.volmit.iris.engine.data.DataProvider;
|
||||||
import com.volmit.iris.engine.data.DirectWorldWriter;
|
import com.volmit.iris.engine.data.DirectWorldWriter;
|
||||||
import com.volmit.iris.engine.object.IrisBiome;
|
import com.volmit.iris.engine.object.IrisBiome;
|
||||||
@ -86,9 +87,10 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
|||||||
boolean isStudio();
|
boolean isStudio();
|
||||||
|
|
||||||
default Location lookForBiome(IrisBiome biome, long timeout, Consumer<Integer> triesc) {
|
default Location lookForBiome(IrisBiome biome, long timeout, Consumer<Integer> triesc) {
|
||||||
|
IrisComplex.cacheLock.set(true);
|
||||||
ChronoLatch cl = new ChronoLatch(250, false);
|
ChronoLatch cl = new ChronoLatch(250, false);
|
||||||
long s = M.ms();
|
long s = M.ms();
|
||||||
int cpus = 2 + (Runtime.getRuntime().availableProcessors() / 2);
|
int cpus = (Runtime.getRuntime().availableProcessors());
|
||||||
KList<Engine> engines = new KList<>();
|
KList<Engine> engines = new KList<>();
|
||||||
for (int i = 0; i < getCompound().getSize(); i++) {
|
for (int i = 0; i < getCompound().getSize(); i++) {
|
||||||
Engine e = getCompound().getEngine(i);
|
Engine e = getCompound().getEngine(i);
|
||||||
@ -98,29 +100,28 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (engines.isEmpty()) {
|
if (engines.isEmpty()) {
|
||||||
|
IrisComplex.cacheLock.set(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomicInteger tries = new AtomicInteger(0);
|
AtomicInteger tries = new AtomicInteger(0);
|
||||||
AtomicBoolean found = new AtomicBoolean(false);
|
AtomicBoolean found = new AtomicBoolean(false);
|
||||||
|
AtomicBoolean running = new AtomicBoolean(true);
|
||||||
AtomicReference<Location> location = new AtomicReference<>();
|
AtomicReference<Location> location = new AtomicReference<>();
|
||||||
|
|
||||||
for (int i = 0; i < cpus; i++) {
|
for (int i = 0; i < cpus; i++) {
|
||||||
J.a(() -> {
|
J.a(() -> {
|
||||||
try {
|
try {
|
||||||
Engine e;
|
Engine e;
|
||||||
IrisBiome b;
|
IrisBiome b;
|
||||||
int x, y, z;
|
int x, z;
|
||||||
|
|
||||||
while (!found.get()) {
|
while (!found.get() && running.get()) {
|
||||||
try {
|
try {
|
||||||
synchronized (engines) {
|
synchronized (engines) {
|
||||||
e = engines.getRandom();
|
e = engines.getRandom();
|
||||||
x = RNG.r.i(-29999970, 29999970);
|
x = RNG.r.i(-29999970, 29999970);
|
||||||
y = RNG.r.i(0, e.getHeight() - 1);
|
|
||||||
z = RNG.r.i(-29999970, 29999970);
|
z = RNG.r.i(-29999970, 29999970);
|
||||||
|
b = e.getSurfaceBiome(x, z);
|
||||||
b = e.getBiome(x, y, z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b != null && b.getLoadKey() == null) {
|
if (b != null && b.getLoadKey() == null) {
|
||||||
@ -129,7 +130,7 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
|||||||
|
|
||||||
if (b != null && b.getLoadKey().equals(biome.getLoadKey())) {
|
if (b != null && b.getLoadKey().equals(biome.getLoadKey())) {
|
||||||
found.lazySet(true);
|
found.lazySet(true);
|
||||||
location.lazySet(new Location(e.getWorld(), x, y, z));
|
location.lazySet(new Location(e.getWorld(), x, e.getHeight(x, z), z));
|
||||||
}
|
}
|
||||||
|
|
||||||
tries.getAndIncrement();
|
tries.getAndIncrement();
|
||||||
@ -154,17 +155,22 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (M.ms() - s > timeout) {
|
if (M.ms() - s > timeout) {
|
||||||
|
running.set(false);
|
||||||
|
IrisComplex.cacheLock.set(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IrisComplex.cacheLock.set(false);
|
||||||
|
running.set(false);
|
||||||
return location.get();
|
return location.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
default Location lookForRegion(IrisRegion reg, long timeout, Consumer<Integer> triesc) {
|
default Location lookForRegion(IrisRegion reg, long timeout, Consumer<Integer> triesc) {
|
||||||
|
IrisComplex.cacheLock.set(true);
|
||||||
ChronoLatch cl = new ChronoLatch(3000, false);
|
ChronoLatch cl = new ChronoLatch(3000, false);
|
||||||
long s = M.ms();
|
long s = M.ms();
|
||||||
int cpus = 2 + (Runtime.getRuntime().availableProcessors() / 2);
|
int cpus = (Runtime.getRuntime().availableProcessors());
|
||||||
KList<Engine> engines = new KList<>();
|
KList<Engine> engines = new KList<>();
|
||||||
for (int i = 0; i < getCompound().getSize(); i++) {
|
for (int i = 0; i < getCompound().getSize(); i++) {
|
||||||
Engine e = getCompound().getEngine(i);
|
Engine e = getCompound().getEngine(i);
|
||||||
@ -174,11 +180,13 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (engines.isEmpty()) {
|
if (engines.isEmpty()) {
|
||||||
|
IrisComplex.cacheLock.set(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomicInteger tries = new AtomicInteger(0);
|
AtomicInteger tries = new AtomicInteger(0);
|
||||||
AtomicBoolean found = new AtomicBoolean(false);
|
AtomicBoolean found = new AtomicBoolean(false);
|
||||||
|
AtomicBoolean running = new AtomicBoolean(true);
|
||||||
AtomicReference<Location> location = new AtomicReference<>();
|
AtomicReference<Location> location = new AtomicReference<>();
|
||||||
|
|
||||||
for (int i = 0; i < cpus; i++) {
|
for (int i = 0; i < cpus; i++) {
|
||||||
@ -187,7 +195,7 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
|||||||
IrisRegion b;
|
IrisRegion b;
|
||||||
int x, z;
|
int x, z;
|
||||||
|
|
||||||
while (!found.get()) {
|
while (!found.get() && running.get()) {
|
||||||
try {
|
try {
|
||||||
e = engines.getRandom();
|
e = engines.getRandom();
|
||||||
x = RNG.r.i(-29999970, 29999970);
|
x = RNG.r.i(-29999970, 29999970);
|
||||||
@ -218,11 +226,15 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
|||||||
|
|
||||||
if (M.ms() - s > timeout) {
|
if (M.ms() - s > timeout) {
|
||||||
triesc.accept(tries.get());
|
triesc.accept(tries.get());
|
||||||
|
running.set(false);
|
||||||
|
IrisComplex.cacheLock.set(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
triesc.accept(tries.get());
|
triesc.accept(tries.get());
|
||||||
|
IrisComplex.cacheLock.set(false);
|
||||||
|
running.set(false);
|
||||||
return location.get();
|
return location.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package com.volmit.iris.engine.stream.utility;
|
package com.volmit.iris.engine.stream.utility;
|
||||||
|
|
||||||
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||||
|
import com.volmit.iris.engine.IrisComplex;
|
||||||
import com.volmit.iris.engine.cache.Cache;
|
import com.volmit.iris.engine.cache.Cache;
|
||||||
import com.volmit.iris.engine.stream.BasicStream;
|
import com.volmit.iris.engine.stream.BasicStream;
|
||||||
import com.volmit.iris.engine.stream.ProceduralStream;
|
import com.volmit.iris.engine.stream.ProceduralStream;
|
||||||
@ -49,6 +50,11 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T get(double x, double z) {
|
public T get(double x, double z) {
|
||||||
|
if(IrisComplex.cacheLock.get())
|
||||||
|
{
|
||||||
|
return stream.get((int) x, (int) z);
|
||||||
|
}
|
||||||
|
|
||||||
return cache.compute(Cache.key((int) x, (int) z), (k, v) -> v != null ? v : stream.get((int) x, (int) z));
|
return cache.compute(Cache.key((int) x, (int) z), (k, v) -> v != null ? v : stream.get((int) x, (int) z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user