Added an option to switch reorder modes

Dieser Commit ist enthalten in:
Matthew Miller 2018-12-04 20:20:27 +10:00
Ursprung b3f5bc030e
Commit 7f11b2800d
5 geänderte Dateien mit 145 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -149,6 +149,38 @@ public class EditSession implements Extent, AutoCloseable {
BEFORE_CHANGE BEFORE_CHANGE
} }
/**
* Reorder mode for {@link EditSession#setReorderMode(ReorderMode)}.
*
* MULTI_STAGE = Multi stage reorder, may not be great with mods.
* FAST = Use the fast mode. Good for mods.
* NONE = Place blocks without worrying about placement order.
*/
public enum ReorderMode {
MULTI_STAGE("multi"),
FAST("fast"),
NONE("none");
private String name;
ReorderMode(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public static ReorderMode getFromName(String name) {
for (ReorderMode mode : values()) {
if (mode.getName().equalsIgnoreCase(name)) {
return mode;
}
}
return null;
}
}
@SuppressWarnings("ProtectedField") @SuppressWarnings("ProtectedField")
protected final World world; protected final World world;
private final ChangeSet changeSet = new BlockOptimizedHistory(); private final ChangeSet changeSet = new BlockOptimizedHistory();
@ -170,7 +202,7 @@ public class EditSession implements Extent, AutoCloseable {
private final Extent bypassHistory; private final Extent bypassHistory;
private final Extent bypassNone; private final Extent bypassNone;
private final boolean useFastModeCorrections; private ReorderMode reorderMode = ReorderMode.MULTI_STAGE;
private Mask oldMask; private Mask oldMask;
@ -189,13 +221,12 @@ public class EditSession implements Extent, AutoCloseable {
checkNotNull(event); checkNotNull(event);
this.world = world; this.world = world;
this.useFastModeCorrections = false;
if (world != null) { if (world != null) {
Extent extent; Extent extent;
// These extents are ALWAYS used // These extents are ALWAYS used
extent = fastModeExtent = new FastModeExtent(world, useFastModeCorrections); extent = fastModeExtent = new FastModeExtent(world, false);
extent = survivalExtent = new SurvivalModeExtent(extent, world); extent = survivalExtent = new SurvivalModeExtent(extent, world);
extent = quirkExtent = new BlockQuirkExtent(extent, world); extent = quirkExtent = new BlockQuirkExtent(extent, world);
extent = chunkLoadingExtent = new ChunkLoadingExtent(extent, world); extent = chunkLoadingExtent = new ChunkLoadingExtent(extent, world);
@ -240,13 +271,13 @@ public class EditSession implements Extent, AutoCloseable {
// pkg private for TracedEditSession only, may later become public API // pkg private for TracedEditSession only, may later become public API
boolean commitRequired() { boolean commitRequired() {
if (isQueueEnabled() && reorderExtent.commitRequired()) { if (reorderExtent.commitRequired()) {
return true; return true;
} }
if (isBatchingChunks() && chunkBatchingExtent.commitRequired()) { if (isBatchingChunks() && chunkBatchingExtent.commitRequired()) {
return true; return true;
} }
if (hasFastMode() && fastModeExtent.commitRequired()) { if (fastModeExtent != null && fastModeExtent.commitRequired()) {
return true; return true;
} }
return false; return false;
@ -254,14 +285,60 @@ public class EditSession implements Extent, AutoCloseable {
/** /**
* Turns on specific features for a normal WorldEdit session, such as * Turns on specific features for a normal WorldEdit session, such as
* {@link #enableQueue() queuing} and {@link #setBatchingChunks(boolean) * {@link #setReorderMode(ReorderMode)} reordering} and {@link #setBatchingChunks(boolean)
* chunk batching}. * chunk batching}.
*/ */
public void enableStandardMode() { public void enableStandardMode() {
enableQueue(); setReorderMode(ReorderMode.MULTI_STAGE);
setBatchingChunks(true); setBatchingChunks(true);
} }
/**
* Sets the {@link ReorderMode} of this EditSession.
*
* @param reorderMode The reorder mode
*/
public void setReorderMode(ReorderMode reorderMode) {
if (reorderMode == ReorderMode.FAST && fastModeExtent == null) {
throw new IllegalArgumentException("An EditSession without a fast mode tried to use it for reordering!");
}
if (reorderMode == ReorderMode.MULTI_STAGE && reorderExtent == null) {
throw new IllegalArgumentException("An EditSession without a reorder extent tried to use it for reordering!");
}
this.reorderMode = reorderMode;
switch (reorderMode) {
case MULTI_STAGE:
if (fastModeExtent != null) {
fastModeExtent.setPostEditSimulationEnabled(false);
}
reorderExtent.setEnabled(true);
break;
case FAST:
fastModeExtent.setPostEditSimulationEnabled(true);
if (reorderExtent != null) {
reorderExtent.setEnabled(false);
}
break;
case NONE:
if (fastModeExtent != null) {
fastModeExtent.setPostEditSimulationEnabled(false);
}
if (reorderExtent != null) {
reorderExtent.setEnabled(false);
}
break;
}
}
/**
* Get the reorder mode.
*
* @return the reorder mode
*/
public ReorderMode getReorderMode() {
return reorderMode;
}
/** /**
* Get the world. * Get the world.
* *
@ -305,26 +382,31 @@ public class EditSession implements Extent, AutoCloseable {
* @return whether the queue is enabled * @return whether the queue is enabled
*/ */
public boolean isQueueEnabled() { public boolean isQueueEnabled() {
return !useFastModeCorrections && reorderExtent.isEnabled(); return reorderMode == ReorderMode.MULTI_STAGE && reorderExtent.isEnabled();
} }
/** /**
* Queue certain types of block for better reproduction of those blocks. * Queue certain types of block for better reproduction of those blocks.
*
* Uses {@link ReorderMode#MULTI_STAGE}
* @deprecated Use {@link EditSession#setReorderMode(ReorderMode)} with MULTI_STAGE instead.
*/ */
@Deprecated
public void enableQueue() { public void enableQueue() {
if (!useFastModeCorrections) { setReorderMode(ReorderMode.MULTI_STAGE);
reorderExtent.setEnabled(true);
}
} }
/** /**
* Disable the queue. This will {@linkplain #flushSession() flush the session}. * Disable the queue. This will {@linkplain #flushSession() flush the session}.
*
* @deprecated Use {@link EditSession#setReorderMode(ReorderMode)} with another mode instead.
*/ */
@Deprecated
public void disableQueue() { public void disableQueue() {
if (isQueueEnabled()) { if (isQueueEnabled()) {
flushSession(); flushSession();
} }
reorderExtent.setEnabled(false); setReorderMode(ReorderMode.NONE);
} }
/** /**
@ -369,14 +451,7 @@ public class EditSession implements Extent, AutoCloseable {
*/ */
public void setFastMode(boolean enabled) { public void setFastMode(boolean enabled) {
if (fastModeExtent != null) { if (fastModeExtent != null) {
// If fast mode corrections are enabled, we're using fast mode for fastModeExtent.setEnabled(enabled);
// multipass support. Thus, we do not actually ever turn the fast mode
// extent off, we instead toggle post edit simulation
if (useFastModeCorrections) {
fastModeExtent.setPostEditSimulationEnabled(!enabled);
} else {
fastModeExtent.setEnabled(enabled);
}
} }
} }
@ -451,16 +526,15 @@ public class EditSession implements Extent, AutoCloseable {
/** /**
* Disable all buffering extents. * Disable all buffering extents.
* *
* @see #disableQueue() * @see #setReorderMode(ReorderMode)
* @see #setBatchingChunks(boolean) * @see #setBatchingChunks(boolean)
*/ */
public void disableBuffering() { public void disableBuffering() {
// We optimize here to avoid repeated calls to flushSession. // We optimize here to avoid repeated calls to flushSession.
boolean needsFlush = isQueueEnabled() || isBatchingChunks(); if (commitRequired()) {
if (needsFlush) {
flushSession(); flushSession();
} }
reorderExtent.setEnabled(false); setReorderMode(ReorderMode.NONE);
if (chunkBatchingExtent != null) { if (chunkBatchingExtent != null) {
chunkBatchingExtent.setEnabled(false); chunkBatchingExtent.setEnabled(false);
} }

Datei anzeigen

@ -93,6 +93,7 @@ public class LocalSession {
private transient Mask mask; private transient Mask mask;
private transient TimeZone timezone = TimeZone.getDefault(); private transient TimeZone timezone = TimeZone.getDefault();
private transient BlockVector3 cuiTemporaryBlock; private transient BlockVector3 cuiTemporaryBlock;
private transient EditSession.ReorderMode reorderMode = EditSession.ReorderMode.MULTI_STAGE;
// Saved properties // Saved properties
private String lastScript; private String lastScript;
@ -877,6 +878,24 @@ public class LocalSession {
this.fastMode = fastMode; this.fastMode = fastMode;
} }
/**
* Gets the reorder mode of the session.
*
* @return The reorder mode
*/
public EditSession.ReorderMode getReorderMode() {
return reorderMode;
}
/**
* Sets the reorder mode of the session.
*
* @param reorderMode The reorder mode
*/
public void setReorderMode(EditSession.ReorderMode reorderMode) {
this.reorderMode = reorderMode;
}
/** /**
* Get the mask. * Get the mask.
* *

Datei anzeigen

@ -115,6 +115,30 @@ public class GeneralCommands {
} }
} }
@Command(
aliases = { "/reorder" },
usage = "[multi|fast|none]",
desc = "Sets the reorder mode of WorldEdit",
min = 0,
max = 1
)
@CommandPermissions("worldedit.reorder")
public void reorderMode(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
String newState = args.getString(0, null);
if (newState == null) {
player.print("The reorder mode is " + session.getReorderMode().getName());
} else {
EditSession.ReorderMode reorderMode = EditSession.ReorderMode.getFromName(newState);
if (reorderMode == null) {
player.printError("Unknown reorder mode!");
return;
}
session.setReorderMode(reorderMode);
player.print("The reorder mode is now " + session.getReorderMode().getName());
}
}
@Command( @Command(
aliases = { "/drawsel" }, aliases = { "/drawsel" },
usage = "[on|off]", usage = "[on|off]",

Datei anzeigen

@ -99,7 +99,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
} }
public boolean commitRequired() { public boolean commitRequired() {
return stages.stream().anyMatch(stage -> stage.size() > 0); return enabled && stages.stream().anyMatch(stage -> stage.size() > 0);
} }
/** /**

Datei anzeigen

@ -67,9 +67,6 @@ public class FastModeExtent extends AbstractDelegateExtent {
checkNotNull(world); checkNotNull(world);
this.world = world; this.world = world;
this.enabled = enabled; this.enabled = enabled;
if (enabled) {
this.postEditSimulation = true;
}
} }
/** /**
@ -100,11 +97,11 @@ public class FastModeExtent extends AbstractDelegateExtent {
@Override @Override
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
if (enabled) { if (enabled || postEditSimulation) {
dirtyChunks.add(BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4)); dirtyChunks.add(BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4));
if (world.setBlock(location, block, false)) { if (world.setBlock(location, block, false)) {
if (postEditSimulation) { if (!enabled && postEditSimulation) {
positions.add(location); positions.add(location);
} }
return true; return true;
@ -129,7 +126,7 @@ public class FastModeExtent extends AbstractDelegateExtent {
world.fixAfterFastMode(dirtyChunks); world.fixAfterFastMode(dirtyChunks);
} }
if (postEditSimulation) { if (!enabled && postEditSimulation) {
Iterator<BlockVector3> positionIterator = positions.iterator(); Iterator<BlockVector3> positionIterator = positions.iterator();
while (run.shouldContinue() && positionIterator.hasNext()) { while (run.shouldContinue() && positionIterator.hasNext()) {
BlockVector3 position = positionIterator.next(); BlockVector3 position = positionIterator.next();