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
|
* 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 x the x
|
||||||
* @param z the z
|
* @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
|
@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
|
@Override
|
||||||
public void generateChunk(int x, int z) {
|
public void generateChunk(int x, int z, PregenListener listener) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ public class HybridPregenMethod implements PregeneratorMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateChunk(int x, int z) {
|
public void generateChunk(int x, int z, PregenListener listener) {
|
||||||
inWorld.generateChunk(x, z);
|
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.PregenListener;
|
||||||
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class MedievalPregenMethod implements PregeneratorMethod {
|
public class MedievalPregenMethod implements PregeneratorMethod {
|
||||||
private final World world;
|
private final World world;
|
||||||
|
private final KList<CompletableFuture<?>> futures;
|
||||||
|
|
||||||
public MedievalPregenMethod(World world)
|
public MedievalPregenMethod(World world)
|
||||||
{
|
{
|
||||||
this.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() {
|
private void unloadAndSaveAllChunks() {
|
||||||
|
waitForChunks();
|
||||||
J.s(() -> {
|
J.s(() -> {
|
||||||
for(Chunk i : world.getLoadedChunks())
|
for(Chunk i : world.getLoadedChunks())
|
||||||
{
|
{
|
||||||
i.unload(true);
|
i.unload(true);
|
||||||
}
|
}
|
||||||
|
world.save();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,13 +70,11 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
|||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
unloadAndSaveAllChunks();
|
unloadAndSaveAllChunks();
|
||||||
world.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
unloadAndSaveAllChunks();
|
unloadAndSaveAllChunks();
|
||||||
world.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,7 +93,16 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateChunk(int x, int 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);
|
world.getChunkAt(x, z);
|
||||||
|
listener.onChunkGenerated(x, z);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,12 +52,14 @@ public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
|||||||
{
|
{
|
||||||
i.unload(true);
|
i.unload(true);
|
||||||
}
|
}
|
||||||
|
world.save();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void completeChunk(int x, int z) {
|
private void completeChunk(int x, int z, PregenListener listener) {
|
||||||
try {
|
try {
|
||||||
PaperLib.getChunkAtAsync(world, x, z, true).get();
|
PaperLib.getChunkAtAsync(world, x, z, true).get();
|
||||||
|
listener.onChunkGenerated(x, z);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -92,14 +94,12 @@ public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
|||||||
waitForChunks();
|
waitForChunks();
|
||||||
burst.shutdownAndAwait();
|
burst.shutdownAndAwait();
|
||||||
unloadAndSaveAllChunks();
|
unloadAndSaveAllChunks();
|
||||||
world.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
waitForChunks();
|
waitForChunks();
|
||||||
unloadAndSaveAllChunks();
|
unloadAndSaveAllChunks();
|
||||||
world.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -113,7 +113,13 @@ public class PaperAsyncPregenMethod implements PregeneratorMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateChunk(int x, int z) {
|
public void generateChunk(int x, int z, PregenListener listener) {
|
||||||
future.add(burst.complete(() -> completeChunk(x, z)));
|
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
|
@Override
|
||||||
public void generateChunk(int x, int z) {
|
public void generateChunk(int x, int z, PregenListener listener) {
|
||||||
method.generateChunk(x, z);
|
method.generateChunk(x, z, listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user