mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-26 18:49:06 +00:00
dev shit
This commit is contained in:
@@ -179,10 +179,15 @@ public class CommandDeveloper implements DecreeExecutor {
|
||||
}
|
||||
|
||||
@Decree(description = "test")
|
||||
public void javafx () {
|
||||
public void devtest () {
|
||||
try {
|
||||
VMJavaFX javaFX = new VMJavaFX(sender());
|
||||
javaFX.start();
|
||||
|
||||
for (File mcafile : new File("rrtrender1/region").listFiles()) {
|
||||
MCAFile mca = MCAUtil.read(mcafile);
|
||||
int c = 0;
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -33,14 +33,24 @@ import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RollingSequence;
|
||||
import com.volmit.iris.util.misc.E;
|
||||
import com.volmit.iris.util.nbt.mca.Chunk;
|
||||
import com.volmit.iris.util.nbt.mca.MCAFile;
|
||||
import com.volmit.iris.util.nbt.mca.MCAUtil;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class IrisPregenerator {
|
||||
@@ -68,9 +78,10 @@ public class IrisPregenerator {
|
||||
private final ChronoLatch saveLatch = new ChronoLatch(30000);
|
||||
|
||||
public IrisPregenerator(PregenTask task, PregeneratorMethod generator, PregenListener listener) {
|
||||
Iris.info("Initializing Pregenerator");
|
||||
generatedRegions = new KSet<>();
|
||||
this.listener = listenify(listener);
|
||||
cl = new ChronoLatch(5000);
|
||||
generatedRegions = new KSet<>();
|
||||
this.shutdown = new AtomicBoolean(false);
|
||||
this.paused = new AtomicBoolean(false);
|
||||
this.task = task;
|
||||
@@ -87,7 +98,9 @@ public class IrisPregenerator {
|
||||
generatedLast = new AtomicInteger(0);
|
||||
generatedLastMinute = new AtomicInteger(0);
|
||||
totalChunks = new AtomicInteger(0);
|
||||
IrisToolbelt.access(generator.getWorld()).getEngine().saveEngineData();
|
||||
task.iterateRegions((_a, _b) -> totalChunks.addAndGet(1024));
|
||||
Iris.info("Initialization Completed!");
|
||||
startTime = new AtomicLong(M.ms());
|
||||
ticker = new Looper() {
|
||||
@Override
|
||||
@@ -173,6 +186,43 @@ public class IrisPregenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private void getGeneratedRegions() {
|
||||
World world = generator.getWorld();
|
||||
File[] region = new File(world.getWorldFolder(), "region").listFiles();
|
||||
BurstExecutor b = MultiBurst.burst.burst(region.length);
|
||||
b.setMulticore(true);
|
||||
b.queue(() -> {
|
||||
for (File file : region) {
|
||||
try {
|
||||
String regex = "r\\.(\\d+)\\.(-?\\d+)\\.mca";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(file.getName());
|
||||
if (!matcher.find()) continue;
|
||||
int x = Integer.parseInt(matcher.group(1));
|
||||
int z = Integer.parseInt(matcher.group(2));
|
||||
Position2 pos = new Position2(x,z);
|
||||
generatedRegions.add(pos);
|
||||
|
||||
MCAFile mca = MCAUtil.read(file, 0);
|
||||
|
||||
boolean notFull = false;
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
Chunk chunk = mca.getChunk(i);
|
||||
if (chunk == null) {
|
||||
generatedRegions.remove(pos);
|
||||
notFull = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Iris.info("Completed MCA region: " + file.getName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
b.complete();
|
||||
}
|
||||
|
||||
private void visitRegion(int x, int z, boolean regions) {
|
||||
while (paused.get() && !shutdown.get()) {
|
||||
J.sleep(50);
|
||||
|
||||
@@ -19,9 +19,12 @@
|
||||
package com.volmit.iris.core.pregenerator.methods;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.IHeadless;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
@@ -42,6 +45,7 @@ import java.util.concurrent.Future;
|
||||
|
||||
public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
private final World world;
|
||||
private final Engine engine;
|
||||
private final MultiBurst burst;
|
||||
private final KList<Future<?>> future;
|
||||
private final Map<Chunk, Long> lastUse;
|
||||
@@ -50,8 +54,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
if (!PaperLib.isPaper()) {
|
||||
throw new UnsupportedOperationException("Cannot use PaperAsync on non paper!");
|
||||
}
|
||||
|
||||
this.world = world;
|
||||
this.engine = IrisToolbelt.access(world).getEngine();
|
||||
burst = MultiBurst.burst;
|
||||
future = new KList<>(1024);
|
||||
this.lastUse = new KMap<>();
|
||||
@@ -81,13 +85,15 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
|
||||
private void completeChunk(int x, int z, PregenListener listener) {
|
||||
try {
|
||||
future.add(PaperLib.getChunkAtAsync(world, x, z, true).thenApply((i) -> {
|
||||
if (i == null) return 0;
|
||||
lastUse.put(i, M.ms());
|
||||
listener.onChunkGenerated(x, z);
|
||||
listener.onChunkCleaned(x, z);
|
||||
return 0;
|
||||
}));
|
||||
if (!engine.exists(x,z)) {
|
||||
future.add(PaperLib.getChunkAtAsync(world, x, z, true).thenApply((i) -> {
|
||||
if (i == null) return 0;
|
||||
lastUse.put(i, M.ms());
|
||||
listener.onChunkGenerated(x, z);
|
||||
listener.onChunkCleaned(x, z);
|
||||
return 0;
|
||||
}));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -54,8 +54,6 @@ public class IrisEngineSVC implements IrisService {
|
||||
private AtomicBoolean IsTrimAlive;
|
||||
ChronoLatch cl;
|
||||
|
||||
public List<World> corruptedIrisWorlds = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.cl = new ChronoLatch(5000);
|
||||
|
||||
@@ -45,6 +45,7 @@ import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.MatterStructurePOI;
|
||||
import com.volmit.iris.util.misc.E;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
@@ -60,14 +61,17 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(exclude = "context")
|
||||
@ToString(exclude = "context")
|
||||
public class IrisEngine implements Engine {
|
||||
private Set<String> chunks = ConcurrentHashMap.newKeySet();
|
||||
private final AtomicInteger bud;
|
||||
private final AtomicInteger buds;
|
||||
private final AtomicInteger generated;
|
||||
@@ -100,6 +104,7 @@ public class IrisEngine implements Engine {
|
||||
private double maxBiomeLayerDensity;
|
||||
private double maxBiomeDecoratorDensity;
|
||||
private IrisComplex complex;
|
||||
private final ReentrantLock dataLock;
|
||||
|
||||
public IrisEngine(EngineTarget target, boolean studio) {
|
||||
this.studio = studio;
|
||||
@@ -107,6 +112,7 @@ public class IrisEngine implements Engine {
|
||||
getEngineData();
|
||||
verifySeed();
|
||||
this.seedManager = new SeedManager(target.getWorld().getRawWorldSeed());
|
||||
dataLock = new ReentrantLock();
|
||||
bud = new AtomicInteger(0);
|
||||
buds = new AtomicInteger(0);
|
||||
metrics = new EngineMetrics(32);
|
||||
@@ -129,6 +135,7 @@ public class IrisEngine implements Engine {
|
||||
failing = false;
|
||||
closed = false;
|
||||
art = J.ar(this::tickRandomPlayer, 0);
|
||||
chunks = getEngineData().getGeneratedChunks();
|
||||
setupEngine();
|
||||
Iris.debug("Engine Initialized " + getCacheID());
|
||||
}
|
||||
@@ -249,10 +256,10 @@ public class IrisEngine implements Engine {
|
||||
try {
|
||||
f.getParentFile().mkdirs();
|
||||
IrisEngineData data = new IrisEngineData();
|
||||
data.getStatistics().setVersion(Iris.instance.getIrisVersion());
|
||||
data.getStatistics().setIrisCreationVersion(Iris.instance.getIrisVersion());
|
||||
data.getStatistics().setMCVersion(Iris.instance.getMCVersion());
|
||||
data.getStatistics().setUpgradedVersion(Iris.instance.getIrisVersion());
|
||||
if (data.getStatistics().getVersion() == -1 || data.getStatistics().getMCVersion() == -1 ) {
|
||||
data.getStatistics().setIrisToUpgradedVersion(Iris.instance.getIrisVersion());
|
||||
if (data.getStatistics().getIrisCreationVersion() == -1 || data.getStatistics().getMCVersion() == -1 ) {
|
||||
Iris.error("Failed to setup Engine Data!");
|
||||
}
|
||||
IO.writeAll(f, new Gson().toJson(data));
|
||||
@@ -271,15 +278,43 @@ public class IrisEngine implements Engine {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveEngineData() {
|
||||
//TODO: Method this file
|
||||
if (dataLock.tryLock()) {
|
||||
try {
|
||||
File f = new File(getWorld().worldFolder(), "iris/engine-data/" + getDimension().getLoadKey() + ".json");
|
||||
f.getParentFile().mkdirs();
|
||||
try {
|
||||
getEngineData().addGeneratedChunk(chunks);
|
||||
IO.writeAll(f, new Gson().toJson(getEngineData()));
|
||||
Iris.debug("Saved Engine Data");
|
||||
} catch (IOException e) {
|
||||
Iris.error("Failed to save Engine Data");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} finally {
|
||||
dataLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenerated() {
|
||||
return generated.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGenerated() {
|
||||
if (generated.incrementAndGet() == 661) {
|
||||
J.a(() -> getData().savePrefetch(this));
|
||||
public void addGenerated(int x, int z) {
|
||||
try {
|
||||
File f = new File(getWorld().worldFolder(), "iris/engine-data/" + getDimension().getLoadKey() + ".json");
|
||||
chunks.add(x + "," + z);
|
||||
if (generated.incrementAndGet() == 661) {
|
||||
J.a(() -> getData().savePrefetch(this));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Iris.error("Failed to add generated chunk!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,7 +500,7 @@ public class IrisEngine implements Engine {
|
||||
|
||||
getMantle().getMantle().flag(x >> 4, z >> 4, MantleFlag.REAL, true);
|
||||
getMetrics().getTotal().put(p.getMilliseconds());
|
||||
addGenerated();
|
||||
addGenerated(x,z);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
fail("Failed to generate " + x + ", " + z, e);
|
||||
@@ -473,22 +508,13 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveEngineData() {
|
||||
//TODO: Method this file
|
||||
File f = new File(getWorld().worldFolder(), "iris/engine-data/" + getDimension().getLoadKey() + ".json");
|
||||
f.getParentFile().mkdirs();
|
||||
try {
|
||||
IO.writeAll(f, new Gson().toJson(getEngineData()));
|
||||
Iris.debug("Saved Engine Data");
|
||||
} catch (IOException e) {
|
||||
Iris.error("Failed to save Engine Data");
|
||||
e.printStackTrace();
|
||||
}
|
||||
public void blockUpdatedMetric() {
|
||||
bud.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blockUpdatedMetric() {
|
||||
bud.incrementAndGet();
|
||||
public boolean exists(int x, int z) {
|
||||
return chunks.contains(x + "," + z);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -529,7 +555,7 @@ public class IrisEngine implements Engine {
|
||||
private boolean EngineSafe() {
|
||||
// Todo: this has potential if done right
|
||||
int EngineMCVersion = getEngineData().getStatistics().getMCVersion();
|
||||
int EngineIrisVersion = getEngineData().getStatistics().getVersion();
|
||||
int EngineIrisVersion = getEngineData().getStatistics().getIrisCreationVersion();
|
||||
int MinecraftVersion = Iris.instance.getMCVersion();
|
||||
int IrisVersion = Iris.instance.getIrisVersion();
|
||||
if (EngineIrisVersion != IrisVersion) {
|
||||
|
||||
@@ -266,6 +266,8 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
|
||||
void blockUpdatedMetric();
|
||||
|
||||
boolean exists(int x, int z);
|
||||
|
||||
@ChunkCoordinates
|
||||
@Override
|
||||
default void updateChunk(Chunk c) {
|
||||
@@ -580,7 +582,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
|
||||
int getGenerated();
|
||||
|
||||
void addGenerated();
|
||||
void addGenerated(int x, int z);
|
||||
|
||||
default <T> IrisPosition lookForStreamResult(T find, ProceduralStream<T> stream, Function2<T, T, Boolean> matcher, long timeout) {
|
||||
AtomicInteger checked = new AtomicInteger();
|
||||
|
||||
@@ -23,13 +23,31 @@ import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Data
|
||||
public class IrisEngineData {
|
||||
private IrisEngineStatistics statistics = new IrisEngineStatistics();
|
||||
private KList<IrisEngineSpawnerCooldown> spawnerCooldowns = new KList<>();
|
||||
private Set<String> generatedChunks = ConcurrentHashMap.newKeySet();
|
||||
private KList<IrisEngineChunkData> chunks = new KList<>();
|
||||
private Long seed = null;
|
||||
|
||||
public void addGeneratedChunk(int x, int z) {
|
||||
getGeneratedChunks().add(x + "," + z);
|
||||
}
|
||||
|
||||
public void addGeneratedChunk(Set<String> chunks) {
|
||||
chunks.forEach(getGeneratedChunks()::add);
|
||||
}
|
||||
|
||||
|
||||
public boolean isChunkGenerated(int x, int z) {
|
||||
return getGeneratedChunks().contains(x + "," + z);
|
||||
}
|
||||
|
||||
public void removeChunk(int x, int z) {
|
||||
long k = Cache.key(x, z);
|
||||
chunks.removeWhere((i) -> i.getChunk() == k);
|
||||
|
||||
@@ -20,41 +20,22 @@ package com.volmit.iris.engine.object;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
@Data
|
||||
public class IrisEngineStatistics {
|
||||
private int totalHotloads = 0;
|
||||
private int chunksGenerated = 0;
|
||||
private int IrisToUpgradedVersion = 0;
|
||||
private int IrisCreationVersion = 0;
|
||||
private int MinecraftVersion = 0;
|
||||
private int MCVersion = 0;
|
||||
|
||||
public void generatedChunk() {
|
||||
chunksGenerated++;
|
||||
}
|
||||
|
||||
public void setUpgradedVersion(int i) {
|
||||
IrisToUpgradedVersion = i;
|
||||
}
|
||||
public int getUpgradedVersion() {
|
||||
return IrisToUpgradedVersion;
|
||||
}
|
||||
public void setVersion(int i) {
|
||||
IrisCreationVersion = i;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return IrisCreationVersion;
|
||||
}
|
||||
|
||||
public void setMCVersion(int i) {
|
||||
MinecraftVersion = i;
|
||||
}
|
||||
|
||||
public int getMCVersion() {
|
||||
return MinecraftVersion;
|
||||
}
|
||||
|
||||
public void hotloaded() {
|
||||
totalHotloads++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,6 +76,13 @@ public class Headless implements IHeadless, LevelHeightAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the mca plate is fully generated or not.
|
||||
*
|
||||
* @param x coord of the chunk
|
||||
* @param z coord of the chunk
|
||||
* @return true if the chunk exists in .mca
|
||||
*/
|
||||
@Override
|
||||
public boolean exists(int x, int z) {
|
||||
if (closed) return false;
|
||||
@@ -190,7 +197,7 @@ public class Headless implements IHeadless, LevelHeightAccessor {
|
||||
|
||||
engine.getMantle().getMantle().flag(x >> 4, z >> 4, MantleFlag.REAL, true);
|
||||
engine.getMetrics().getTotal().put(p.getMilliseconds());
|
||||
engine.addGenerated();
|
||||
engine.addGenerated(x,z);
|
||||
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
|
||||
@@ -757,6 +757,7 @@ public class NMSBinding implements INMSBinding {
|
||||
public void injectBukkit() {
|
||||
try {
|
||||
Iris.info("Injecting Bukkit");
|
||||
|
||||
new ByteBuddy()
|
||||
.redefine(CraftServer.class)
|
||||
.visit(Advice.to(CraftServerAdvice.class).on(ElementMatchers.isMethod().and(ElementMatchers.takesArguments(WorldCreator.class))))
|
||||
|
||||
Reference in New Issue
Block a user