Skip to content

Commit

Permalink
Few fixes for FastModeExtent.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Nov 15, 2018
1 parent 38e1e16 commit 0e48590
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Expand Up @@ -246,6 +246,9 @@ boolean commitRequired() {
if (isBatchingChunks() && chunkBatchingExtent.commitRequired()) {
return true;
}
if (hasFastMode() && fastModeExtent.commitRequired()) {
return true;
}
return false;
}

Expand Down
Expand Up @@ -31,10 +31,9 @@
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;

import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import java.util.Set;

/**
Expand All @@ -43,7 +42,7 @@
public class FastModeExtent extends AbstractDelegateExtent {

private final World world;
private final Queue<BlockVector3> positions = new ArrayDeque<>();
private final Set<BlockVector3> positions = new HashSet<>();
private final Set<BlockVector2> dirtyChunks = new HashSet<>();
private boolean enabled = true;
private boolean postEditSimulation;
Expand Down Expand Up @@ -106,7 +105,7 @@ public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws Wo

if (world.setBlock(location, block, false)) {
if (postEditSimulation) {
positions.offer(location);
positions.add(location);
}
return true;
}
Expand All @@ -117,6 +116,10 @@ public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws Wo
}
}

public boolean commitRequired() {
return !dirtyChunks.isEmpty() || !positions.isEmpty();
}

@Override
protected Operation commitBefore() {
return new Operation() {
Expand All @@ -127,9 +130,11 @@ public Operation resume(RunContext run) throws WorldEditException {
}

if (postEditSimulation) {
while (run.shouldContinue() && !positions.isEmpty()) {
BlockVector3 position = positions.poll(); // Remove from queue
Iterator<BlockVector3> positionIterator = positions.iterator();
while (run.shouldContinue() && positionIterator.hasNext()) {
BlockVector3 position = positionIterator.next();
world.notifyAndLightBlock(position, BlockTypes.AIR.getDefaultState());
positionIterator.remove();
}

return !positions.isEmpty() ? this : null;
Expand Down

0 comments on commit 0e48590

Please sign in to comment.