mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Method api & impl changes
This commit is contained in:
parent
90d2cf4970
commit
756f395158
@ -67,6 +67,7 @@ public interface PregeneratorMethod {
|
||||
* Called to generate a chunk. You can go async so long as save will wait on the threads to finish
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
* @param listener
|
||||
*/
|
||||
void generateChunk(int x, int z);
|
||||
void generateChunk(int x, int z, PregenListener listener);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class DummyPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z) {
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class HeadlessPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z) {
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class HybridPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z) {
|
||||
inWorld.generateChunk(x, z);
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
inWorld.generateChunk(x, z, listener);
|
||||
}
|
||||
}
|
||||
|
@ -20,24 +20,45 @@ package com.volmit.iris.core.pregenerator.methods;
|
||||
|
||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
private final World world;
|
||||
private final KList<CompletableFuture<?>> futures;
|
||||
|
||||
public MedievalPregenMethod(World world)
|
||||
{
|
||||
this.world = world;
|
||||
futures = new KList<>();
|
||||
}
|
||||
|
||||
private void waitForChunks()
|
||||
{
|
||||
for(CompletableFuture<?> i : futures)
|
||||
{
|
||||
try {
|
||||
i.get();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
futures.clear();
|
||||
}
|
||||
|
||||
private void unloadAndSaveAllChunks() {
|
||||
waitForChunks();
|
||||
J.s(() -> {
|
||||
for(Chunk i : world.getLoadedChunks())
|
||||
{
|
||||
i.unload(true);
|
||||
}
|
||||
world.save();
|
||||
});
|
||||
}
|
||||
|
||||
@ -49,13 +70,11 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
@Override
|
||||
public void close() {
|
||||
unloadAndSaveAllChunks();
|
||||
world.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
unloadAndSaveAllChunks();
|
||||
world.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +93,16 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z) {
|
||||
world.getChunkAt(x, z);
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
if(futures.size() > 32)
|
||||
{
|
||||
waitForChunks();
|
||||
}
|
||||
|
||||
listener.onChunkGenerating(x, z);
|
||||
futures.add(J.sfut(() -> {
|
||||
world.getChunkAt(x, z);
|
||||
listener.onChunkGenerated(x, z);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -52,12 +52,14 @@ public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
||||
{
|
||||
i.unload(true);
|
||||
}
|
||||
world.save();
|
||||
});
|
||||
}
|
||||
|
||||
private void completeChunk(int x, int z) {
|
||||
private void completeChunk(int x, int z, PregenListener listener) {
|
||||
try {
|
||||
PaperLib.getChunkAtAsync(world, x, z, true).get();
|
||||
listener.onChunkGenerated(x, z);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -92,14 +94,12 @@ public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
||||
waitForChunks();
|
||||
burst.shutdownAndAwait();
|
||||
unloadAndSaveAllChunks();
|
||||
world.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
waitForChunks();
|
||||
unloadAndSaveAllChunks();
|
||||
world.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,7 +113,13 @@ public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z) {
|
||||
future.add(burst.complete(() -> completeChunk(x, z)));
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
if(future.size() > 32)
|
||||
{
|
||||
waitForChunks();
|
||||
}
|
||||
|
||||
listener.onChunkGenerating(x, z);
|
||||
future.add(burst.complete(() -> completeChunk(x, z, listener)));
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class PaperOrMedievalPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z) {
|
||||
method.generateChunk(x, z);
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
method.generateChunk(x, z, listener);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user