3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-07 12:00:07 +01:00

Add chunk batching flag, enable by default

Dieser Commit ist enthalten in:
Kenzie Togami 2018-10-04 10:37:58 -07:00
Ursprung ff391ca0b3
Commit 7d4906cfe9
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81
7 geänderte Dateien mit 58 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -272,7 +272,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
editSession.enableQueue();
editSession.enableStandardMode();
return editSession;
}

Datei anzeigen

@ -36,6 +36,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;
@ -151,6 +152,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;
@ -190,6 +192,7 @@ public class EditSession implements Extent {
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 @@ 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.
*
@ -378,6 +391,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.
*

Datei anzeigen

@ -226,7 +226,7 @@ public class LocalSession {
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 class LocalSession {
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;

Datei anzeigen

@ -72,7 +72,7 @@ public class SelectionCommand extends SimpleCommand<Operation> {
Region selection = session.getSelection(player.getWorld());
EditSession editSession = session.createEditSession(player);
editSession.enableQueue();
editSession.enableStandardMode();
locals.put(EditSession.class, editSession);
session.tellVersion(player);

Datei anzeigen

@ -54,13 +54,30 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent {
.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;
@ -68,6 +85,9 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent {
@Override
protected Operation commitBefore() {
if (!enabled) {
return null;
}
return new Operation() {
private final Iterator<LocatedBlockList> batchIterator = batches.values().iterator();
@ -78,6 +98,7 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent {
return null;
}
new SetLocatedBlocks(getExtent(), batchIterator.next()).resume(run);
batchIterator.remove();
return this;
}

Datei anzeigen

@ -103,7 +103,7 @@ public class WorldEditBinding extends BindingHelper {
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;

Datei anzeigen

@ -65,7 +65,7 @@ public class CraftScriptContext extends CraftScriptEnvironment {
EditSession editSession = controller.getEditSessionFactory()
.getEditSession(player.getWorld(),
session.getBlockChangeLimit(), session.getBlockBag(player), player);
editSession.enableQueue();
editSession.enableStandardMode();
editSessions.add(editSession);
return editSession;
}