Permalink
Browse files

Add chunk batching flag, enable by default

  • Loading branch information...
kenzierocks committed Oct 4, 2018
1 parent ff391ca commit 7d4906cfe9fc48ea125f967264e6258001f40ec7
@@ -272,7 +272,7 @@ public EditSession createEditSession(Player player) {
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
editSession.enableQueue();
editSession.enableStandardMode();
return editSession;
}
@@ -36,6 +36,7 @@
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;
@@ -151,6 +152,7 @@
private @Nullable FastModeExtent fastModeExtent;
private final SurvivalModeExtent survivalExtent;
private @Nullable ChunkBatchingExtent chunkBatchingExtent;
private @Nullable ChunkLoadingExtent chunkLoadingExtent;
private @Nullable LastAccessExtentCache cacheExtent;
private @Nullable BlockQuirkExtent quirkExtent;
@@ -190,6 +192,7 @@
extent = fastModeExtent = new FastModeExtent(world, false);
extent = survivalExtent = new SurvivalModeExtent(extent, world);
extent = quirkExtent = new BlockQuirkExtent(extent, world);
extent = chunkBatchingExtent = new ChunkBatchingExtent(extent);
extent = chunkLoadingExtent = new ChunkLoadingExtent(extent, world);
extent = cacheExtent = new LastAccessExtentCache(extent);
extent = wrapExtent(extent, eventBus, event, Stage.BEFORE_CHANGE);
@@ -229,6 +232,16 @@ private Extent wrapExtent(Extent extent, EventBus eventBus, EditSessionEvent eve
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.
*
@@ -378,6 +391,23 @@ public void setBlockBag(BlockBag blockBag) {
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.
*
@@ -226,7 +226,7 @@ public EditSession undo(@Nullable BlockBag newBlockBag, Player player) {
EditSession editSession = history.get(historyPointer);
EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(editSession.getWorld(), -1, newBlockBag, player);
newEditSession.enableQueue();
newEditSession.enableStandardMode();
newEditSession.setFastMode(fastMode);
editSession.undo(newEditSession);
return editSession;
@@ -249,7 +249,7 @@ public EditSession redo(@Nullable BlockBag newBlockBag, Player player) {
EditSession editSession = history.get(historyPointer);
EditSession newEditSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(editSession.getWorld(), -1, newBlockBag, player);
newEditSession.enableQueue();
newEditSession.enableStandardMode();
newEditSession.setFastMode(fastMode);
editSession.redo(newEditSession);
++historyPointer;
@@ -72,7 +72,7 @@ public Operation call(CommandArgs args, CommandLocals locals) throws CommandExce
Region selection = session.getSelection(player.getWorld());
EditSession editSession = session.createEditSession(player);
editSession.enableQueue();
editSession.enableStandardMode();
locals.put(EditSession.class, editSession);
session.tellVersion(player);
@@ -54,20 +54,40 @@
.thenComparing(Vector2D.COMPARING_GRID_ARRANGEMENT);
private final SortedMap<BlockVector2D, LocatedBlockList> batches = new TreeMap<>(REGION_OPTIMIZED_SORT);
private boolean enabled;
protected ChunkBatchingExtent(Extent extent) {
public ChunkBatchingExtent(Extent extent) {
this(extent, true);
}
public ChunkBatchingExtent(Extent extent, boolean enabled) {
super(extent);
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@Override
public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException {
if (!enabled) {
return getExtent().setBlock(location, block);
}
BlockVector2D chunkPos = new BlockVector2D(location.getBlockX() >> 4, location.getBlockZ() >> 4);
batches.computeIfAbsent(chunkPos, k -> new LocatedBlockList()).add(location, block);
return true;
}
@Override
protected Operation commitBefore() {
if (!enabled) {
return null;
}
return new Operation() {
private final Iterator<LocatedBlockList> batchIterator = batches.values().iterator();
@@ -78,6 +98,7 @@ public Operation resume(RunContext run) throws WorldEditException {
return null;
}
new SetLocatedBlocks(getExtent(), batchIterator.next()).resume(run);
batchIterator.remove();
return this;
}
@@ -103,7 +103,7 @@ public EditSession getEditSession(ArgumentStack context) throws ParameterExcepti
Player sender = getPlayer(context);
LocalSession session = worldEdit.getSessionManager().get(sender);
EditSession editSession = session.createEditSession(sender);
editSession.enableQueue();
editSession.enableStandardMode();
context.getContext().getLocals().put(EditSession.class, editSession);
session.tellVersion(sender);
return editSession;
@@ -65,7 +65,7 @@ public EditSession remember() {
EditSession editSession = controller.getEditSessionFactory()
.getEditSession(player.getWorld(),
session.getBlockChangeLimit(), session.getBlockBag(player), player);
editSession.enableQueue();
editSession.enableStandardMode();
editSessions.add(editSession);
return editSession;
}

0 comments on commit 7d4906c

Please sign in to comment.