mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-15 07:05:52 +01:00
ChunkLoader can now indicate that they support parallel loading or saving
This commit is contained in:
parent
69654d05de
commit
dfdf93bfc4
@ -5,4 +5,20 @@ import java.util.function.Consumer;
|
|||||||
public interface IChunkLoader {
|
public interface IChunkLoader {
|
||||||
boolean loadChunk(Instance instance, int chunkX, int chunkZ, Consumer<Chunk> callback);
|
boolean loadChunk(Instance instance, int chunkX, int chunkZ, Consumer<Chunk> callback);
|
||||||
void saveChunk(Chunk chunk, Runnable callback);
|
void saveChunk(Chunk chunk, Runnable callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this ChunkLoader allow for multithreaded saving of chunks?
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
default boolean supportsParallelSaving() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this ChunkLoader allow for multithreaded loading of chunks?
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
default boolean supportsParallelLoading() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -374,11 +374,18 @@ public class InstanceContainer extends Instance {
|
|||||||
@Override
|
@Override
|
||||||
public void saveChunksToStorageFolder(Runnable callback) {
|
public void saveChunksToStorageFolder(Runnable callback) {
|
||||||
Check.notNull(getStorageFolder(), "You cannot save the instance if no StorageFolder has been defined");
|
Check.notNull(getStorageFolder(), "You cannot save the instance if no StorageFolder has been defined");
|
||||||
Iterator<Chunk> chunks = getChunks().iterator();
|
if(chunkLoader.supportsParallelSaving()) {
|
||||||
while (chunks.hasNext()) {
|
getChunks().parallelStream().forEach(c -> {
|
||||||
Chunk chunk = chunks.next();
|
saveChunkToStorageFolder(c, null);
|
||||||
boolean isLast = !chunks.hasNext();
|
});
|
||||||
saveChunkToStorageFolder(chunk, isLast ? callback : null);
|
callback.run();
|
||||||
|
} else {
|
||||||
|
Iterator<Chunk> chunks = getChunks().iterator();
|
||||||
|
while (chunks.hasNext()) {
|
||||||
|
Chunk chunk = chunks.next();
|
||||||
|
boolean isLast = !chunks.hasNext();
|
||||||
|
saveChunkToStorageFolder(chunk, isLast ? callback : null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user