Merge pull request #430 from sk89q/feature/chunk-batching-mode

Chunk Batching
This commit is contained in:
Matthew Miller
2018-10-15 13:50:10 +10:00
committed by GitHub
15 changed files with 370 additions and 274 deletions

View File

@ -38,6 +38,7 @@ import com.sk89q.worldedit.extent.buffer.ForgetfulExtentBuffer;
import com.sk89q.worldedit.extent.cache.LastAccessExtentCache;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.inventory.BlockBagExtent;
import com.sk89q.worldedit.extent.reorder.ChunkBatchingExtent;
import com.sk89q.worldedit.extent.reorder.MultiStageReorder;
import com.sk89q.worldedit.extent.validation.BlockChangeLimiter;
import com.sk89q.worldedit.extent.validation.DataValidatorExtent;
@ -153,6 +154,7 @@ public class EditSession implements Extent {
private @Nullable FastModeExtent fastModeExtent;
private final SurvivalModeExtent survivalExtent;
private @Nullable ChunkBatchingExtent chunkBatchingExtent;
private @Nullable ChunkLoadingExtent chunkLoadingExtent;
private @Nullable LastAccessExtentCache cacheExtent;
private @Nullable BlockQuirkExtent quirkExtent;
@ -200,6 +202,7 @@ public class EditSession implements Extent {
// This extent can be skipped by calling rawSetBlock()
extent = reorderExtent = new MultiStageReorder(extent, false);
extent = chunkBatchingExtent = new ChunkBatchingExtent(extent);
extent = wrapExtent(extent, eventBus, event, Stage.BEFORE_REORDER);
// These extents can be skipped by calling smartSetBlock()
@ -231,6 +234,16 @@ public class EditSession implements Extent {
return event.getExtent();
}
/**
* Turns on specific features for a normal WorldEdit session, such as
* {@link #enableQueue() queuing} and {@link #setBatchingChunks(boolean)
* chunk batching}.
*/
public void enableStandardMode() {
enableQueue();
setBatchingChunks(true);
}
/**
* Get the world.
*
@ -380,6 +393,23 @@ public class EditSession implements Extent {
return blockBagExtent.popMissing();
}
public boolean isBatchingChunks() {
return chunkBatchingExtent != null && chunkBatchingExtent.isEnabled();
}
public void setBatchingChunks(boolean batchingChunks) {
if (chunkBatchingExtent == null) {
if (batchingChunks) {
throw new UnsupportedOperationException("Chunk batching not supported by this session.");
}
return;
}
if (!batchingChunks) {
flushQueue();
}
chunkBatchingExtent.setEnabled(batchingChunks);
}
/**
* Get the number of blocks changed, including repeated block changes.
*