mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
PRegen tweaks
This commit is contained in:
parent
0ec2f68a96
commit
f263fe30a4
@ -41,7 +41,8 @@ import java.util.function.Consumer;
|
||||
|
||||
public class PregeneratorJob implements PregenListener {
|
||||
public static PregeneratorJob instance;
|
||||
private static final Color COLOR_GENERATING = parseColor("#346beb");
|
||||
private static final Color COLOR_EXISTS = parseColor("#4d7d5b");
|
||||
private static final Color COLOR_GENERATING = parseColor("#00ffdd");
|
||||
private static final Color COLOR_GENERATED = parseColor("#34eb93");
|
||||
private JFrame frame;
|
||||
private final PregenTask task;
|
||||
@ -61,7 +62,6 @@ public class PregeneratorJob implements PregenListener {
|
||||
info = new String[]{"Initializing..."};
|
||||
this.task = task;
|
||||
this.pregenerator = new IrisPregenerator(task, method, this);
|
||||
J.a(this.pregenerator::start);
|
||||
max = new Position2(0, 0);
|
||||
min = new Position2(0, 0);
|
||||
KList<Runnable> draw = new KList<>();
|
||||
@ -72,6 +72,7 @@ public class PregeneratorJob implements PregenListener {
|
||||
max.setZ(Math.max((zz << 5) + 31, max.getZ()));
|
||||
});
|
||||
open();
|
||||
J.a(this.pregenerator::start, 20);
|
||||
}
|
||||
|
||||
public PregeneratorJob onProgress(Consumer<Double> c)
|
||||
@ -248,6 +249,11 @@ public class PregeneratorJob implements PregenListener {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkExistsInRegionGen(int x, int z) {
|
||||
draw(x, z, COLOR_EXISTS);
|
||||
}
|
||||
|
||||
private Position2 getMax() {
|
||||
return max;
|
||||
}
|
||||
|
@ -18,7 +18,10 @@
|
||||
|
||||
package com.volmit.iris.core.pregenerator;
|
||||
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
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.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
@ -46,10 +49,12 @@ public class IrisPregenerator {
|
||||
private final AtomicLong startTime;
|
||||
private final ChronoLatch minuteLatch;
|
||||
private final AtomicReference<String> currentGeneratorMethod;
|
||||
private final KSet<Position2> generatedRegions;
|
||||
|
||||
public IrisPregenerator(PregenTask task, PregeneratorMethod generator, PregenListener listener)
|
||||
{
|
||||
this.listener = listenify(listener);
|
||||
generatedRegions = new KSet<>();
|
||||
this.shutdown = new AtomicBoolean(false);
|
||||
this.paused = new AtomicBoolean(false);
|
||||
this.task = task;
|
||||
@ -106,12 +111,19 @@ public class IrisPregenerator {
|
||||
{
|
||||
init();
|
||||
ticker.start();
|
||||
task.iterateRegions(this::visitRegion);
|
||||
checkRegions();
|
||||
task.iterateRegions((x,z) -> visitRegion(x, z, true));
|
||||
task.iterateRegions((x,z) -> visitRegion(x, z, false));
|
||||
shutdown();
|
||||
}
|
||||
|
||||
private void checkRegions() {
|
||||
task.iterateRegions(this::checkRegion);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
generator.init();
|
||||
generator.save();
|
||||
}
|
||||
|
||||
private void shutdown() {
|
||||
@ -121,7 +133,7 @@ public class IrisPregenerator {
|
||||
listener.onClose();
|
||||
}
|
||||
|
||||
private void visitRegion(int x, int z) {
|
||||
private void visitRegion(int x, int z, boolean regions) {
|
||||
while(paused.get() && !shutdown.get())
|
||||
{
|
||||
J.sleep(50);
|
||||
@ -133,22 +145,46 @@ public class IrisPregenerator {
|
||||
return;
|
||||
}
|
||||
|
||||
listener.onRegionGenerating(x, z);
|
||||
currentGeneratorMethod.set(generator.getMethod(x, z));
|
||||
Position2 pos = new Position2(x, z);
|
||||
|
||||
if(generator.supportsRegions(x, z))
|
||||
if(generatedRegions.contains(pos))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
currentGeneratorMethod.set(generator.getMethod(x, z));
|
||||
boolean hit = false;
|
||||
if(generator.supportsRegions(x, z, listener) && regions)
|
||||
{
|
||||
hit = true;
|
||||
listener.onRegionGenerating(x, z);
|
||||
generator.generateRegion(x, z, listener);
|
||||
}
|
||||
|
||||
else
|
||||
else if(!regions)
|
||||
{
|
||||
hit = true;
|
||||
listener.onRegionGenerating(x, z);
|
||||
PregenTask.iterateRegion(x, z, (xx, zz) -> generator.generateChunk(xx, zz, listener));
|
||||
}
|
||||
|
||||
listener.onRegionGenerated(x, z);
|
||||
listener.onSaving();
|
||||
generator.save();
|
||||
if(hit)
|
||||
{
|
||||
listener.onRegionGenerated(x, z);
|
||||
listener.onSaving();
|
||||
generator.save();
|
||||
generatedRegions.add(pos);
|
||||
checkRegions();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkRegion(int x, int z) {
|
||||
if(generatedRegions.contains(new Position2(x, z)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
generator.supportsRegions(x, z, listener);
|
||||
}
|
||||
|
||||
public void pause()
|
||||
@ -203,6 +239,11 @@ public class IrisPregenerator {
|
||||
public void onSaving() {
|
||||
listener.onSaving();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkExistsInRegionGen(int x, int z) {
|
||||
listener.onChunkExistsInRegionGen(x, z);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -34,4 +34,6 @@ public interface PregenListener {
|
||||
void onClose();
|
||||
|
||||
void onSaving();
|
||||
|
||||
void onChunkExistsInRegionGen(int x, int z);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public interface PregeneratorMethod {
|
||||
* @param x the x region
|
||||
* @param z the z region
|
||||
*/
|
||||
boolean supportsRegions(int x, int z);
|
||||
boolean supportsRegions(int x, int z, PregenListener listener);
|
||||
|
||||
/**
|
||||
* Return the name of the method being used
|
||||
|
@ -43,7 +43,7 @@ public class DummyPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRegions(int x, int z) {
|
||||
public boolean supportsRegions(int x, int z, PregenListener listener) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -22,9 +22,12 @@ import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||
import com.volmit.iris.engine.headless.HeadlessGenerator;
|
||||
import com.volmit.iris.engine.headless.HeadlessWorld;
|
||||
import lombok.Getter;
|
||||
|
||||
public class HeadlessPregenMethod implements PregeneratorMethod {
|
||||
private final HeadlessWorld world;
|
||||
|
||||
@Getter
|
||||
private final HeadlessGenerator generator;
|
||||
|
||||
public HeadlessPregenMethod(HeadlessWorld world)
|
||||
@ -54,7 +57,7 @@ public class HeadlessPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRegions(int x, int z) {
|
||||
public boolean supportsRegions(int x, int z, PregenListener listener) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,12 @@
|
||||
|
||||
package com.volmit.iris.core.pregenerator.methods;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||
import com.volmit.iris.core.tools.IrisWorlds;
|
||||
import com.volmit.iris.engine.headless.HeadlessWorld;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.File;
|
||||
@ -45,7 +47,7 @@ public class HybridPregenMethod implements PregeneratorMethod {
|
||||
|
||||
@Override
|
||||
public String getMethod(int x, int z) {
|
||||
return "Hybrid<" + ((supportsRegions(x, z) ? headless.getMethod(x, z) : inWorld.getMethod(x, z)) + ">");
|
||||
return "Hybrid<" + ((supportsRegions(x, z, null) ? headless.getMethod(x, z) : inWorld.getMethod(x, z)) + ">");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -67,12 +69,30 @@ public class HybridPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRegions(int x, int z) {
|
||||
public boolean supportsRegions(int x, int z, PregenListener listener) {
|
||||
if (headless instanceof DummyPregenMethod) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !new File(world.getWorldFolder(), "region/r." + x + "." + z + ".mca").exists();
|
||||
boolean r = !new File(world.getWorldFolder(), "region/r." + x + "." + z + ".mca").exists();
|
||||
|
||||
if(!r && listener != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
for(Position2 i : ((HeadlessPregenMethod) headless).getGenerator().getChunksInRegion(x, z))
|
||||
{
|
||||
listener.onChunkExistsInRegionGen((x << 5) + i.getX(), (z << 5) + i.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,13 +53,17 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
|
||||
private void unloadAndSaveAllChunks() {
|
||||
waitForChunks();
|
||||
J.s(() -> {
|
||||
for(Chunk i : world.getLoadedChunks())
|
||||
{
|
||||
i.unload(true);
|
||||
}
|
||||
world.save();
|
||||
});
|
||||
try {
|
||||
J.sfut(() -> {
|
||||
for(Chunk i : world.getLoadedChunks())
|
||||
{
|
||||
i.unload(true);
|
||||
}
|
||||
world.save();
|
||||
}).get();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,7 +82,7 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRegions(int x, int z) {
|
||||
public boolean supportsRegions(int x, int z, PregenListener listener) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
||||
private final World world;
|
||||
@ -47,13 +48,17 @@ public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
private void unloadAndSaveAllChunks() {
|
||||
J.s(() -> {
|
||||
for(Chunk i : world.getLoadedChunks())
|
||||
{
|
||||
i.unload(true);
|
||||
}
|
||||
world.save();
|
||||
});
|
||||
try {
|
||||
J.sfut(() -> {
|
||||
for(Chunk i : world.getLoadedChunks())
|
||||
{
|
||||
i.unload(true);
|
||||
}
|
||||
world.save();
|
||||
}).get();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void completeChunk(int x, int z, PregenListener listener) {
|
||||
@ -103,7 +108,7 @@ public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRegions(int x, int z) {
|
||||
public boolean supportsRegions(int x, int z, PregenListener listener) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -114,7 +119,7 @@ public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
if(future.size() > 128)
|
||||
if(future.size() > 16)
|
||||
{
|
||||
waitForChunks();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class PaperOrMedievalPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRegions(int x, int z) {
|
||||
public boolean supportsRegions(int x, int z, PregenListener listener) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user