Skip to content

Commit

Permalink
Flush or disable buffers in tools
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal committed Oct 21, 2018
1 parent dd2fcba commit 1fa1ff8
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 18 deletions.
Expand Up @@ -285,7 +285,7 @@ public void remember(Player player, EditSession editSession) {
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);

session.remember(editSession);
editSession.flushQueue();
editSession.flushSession();

WorldEdit.getInstance().flushBlockBag(wePlayer, editSession);
}
Expand Down
40 changes: 32 additions & 8 deletions worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java
Expand Up @@ -298,13 +298,13 @@ public void enableQueue() {
}

/**
* Disable the queue. This will flush the queue.
* Disable the queue. This will {@linkplain #flushSession() flush the session}.
*/
public void disableQueue() {
if (isQueueEnabled()) {
flushQueue();
flushSession();
}
reorderExtent.setEnabled(true);
reorderExtent.setEnabled(false);
}

/**
Expand Down Expand Up @@ -393,10 +393,21 @@ public Map<BlockType, Integer> popMissingBlocks() {
return blockBagExtent.popMissing();
}

/**
* Returns chunk batching status.
*
* @return whether chunk batching is enabled
*/
public boolean isBatchingChunks() {
return chunkBatchingExtent != null && chunkBatchingExtent.isEnabled();
}

/**
* Enable or disable chunk batching. Disabling will
* {@linkplain #flushSession() flush the session}.
*
* @param batchingChunks {@code true} to enable, {@code false} to disable
*/
public void setBatchingChunks(boolean batchingChunks) {
if (chunkBatchingExtent == null) {
if (batchingChunks) {
Expand All @@ -405,11 +416,23 @@ public void setBatchingChunks(boolean batchingChunks) {
return;
}
if (!batchingChunks) {
flushQueue();
flushSession();
}
chunkBatchingExtent.setEnabled(batchingChunks);
}

/**
* Disable all buffering extents.
*
* @see #disableQueue()
* @see #setBatchingChunks(boolean)
*/
public void disableBuffering() {
// We optimize here to avoid double calls to flushSession.
reorderExtent.setEnabled(false);
setBatchingChunks(false);
}

/**
* Get the number of blocks changed, including repeated block changes.
*
Expand Down Expand Up @@ -569,7 +592,7 @@ public void undo(EditSession editSession) {
UndoContext context = new UndoContext();
context.setExtent(editSession.bypassHistory);
Operations.completeBlindly(ChangeSetExecutor.createUndo(changeSet, context));
editSession.flushQueue();
editSession.flushSession();
}

/**
Expand All @@ -581,7 +604,7 @@ public void redo(EditSession editSession) {
UndoContext context = new UndoContext();
context.setExtent(editSession.bypassHistory);
Operations.completeBlindly(ChangeSetExecutor.createRedo(changeSet, context));
editSession.flushQueue();
editSession.flushSession();
}

/**
Expand Down Expand Up @@ -614,9 +637,10 @@ public List<? extends Entity> getEntities() {
}

/**
* Finish off the queue.
* Communicate to the EditSession that all block changes are complete,
* and that it should apply them to the world.
*/
public void flushQueue() {
public void flushSession() {
Operations.completeBlindly(commit());
}

Expand Down
Expand Up @@ -628,7 +628,7 @@ public void runScript(Player player, File f, String[] args) throws WorldEditExce
logger.log(Level.WARNING, "Failed to execute script", e);
} finally {
for (EditSession editSession : scriptContext.getEditSessions()) {
editSession.flushQueue();
editSession.flushSession();
session.remember(editSession);
}
}
Expand Down
Expand Up @@ -460,7 +460,7 @@ public void butcher(Actor actor, CommandContext args) throws WorldEditException

if (editSession != null) {
session.remember(editSession);
editSession.flushQueue();
editSession.flushSession();
}
}

Expand Down Expand Up @@ -520,7 +520,7 @@ public void remove(Actor actor, CommandContext args) throws WorldEditException,

if (editSession != null) {
session.remember(editSession);
editSession.flushQueue();
editSession.flushSession();
}
}

Expand Down
Expand Up @@ -83,7 +83,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
editSession.flushQueue();
editSession.flushSession();
session.remember(editSession);
}

Expand Down
Expand Up @@ -53,16 +53,17 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
BlockBag bag = session.getBlockBag(player);

EditSession editSession = session.createEditSession(player);
editSession.disableBuffering();

try {
Vector position = clicked.toVector();
editSession.setBlock(position, pattern.apply(position));
} catch (MaxChangedBlocksException ignored) {
} finally {
session.remember(editSession);
if (bag != null) {
bag.flushChanges();
}
session.remember(editSession);
}

return true;
Expand Down
Expand Up @@ -193,10 +193,11 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
session.remember(editSession);
editSession.flushSession();
if (bag != null) {
bag.flushChanges();
}
session.remember(editSession);
}

return true;
Expand Down
Expand Up @@ -75,7 +75,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
editSession.flushQueue();
editSession.flushSession();
session.remember(editSession);
}

Expand Down
Expand Up @@ -57,7 +57,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks change limit reached.");
} finally {
editSession.flushQueue();
editSession.flushSession();
}

world.playEffect(clicked.toVector(), 2001, blockType.getLegacyId());
Expand Down
Expand Up @@ -316,7 +316,7 @@ public void handleCommand(CommandEvent event) {

if (editSession != null) {
session.remember(editSession);
editSession.flushQueue();
editSession.flushSession();

if (config.profile) {
long time = System.currentTimeMillis() - start;
Expand Down

0 comments on commit 1fa1ff8

Please sign in to comment.