Optimize set when not region restricted

This commit is contained in:
Jesse Boyd 2016-12-29 10:20:37 +11:00
parent 0c33e84e6b
commit 04bdec3e76
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
6 changed files with 44 additions and 8 deletions

View File

@ -111,10 +111,12 @@ public abstract class CharFaweChunk<T, V extends FaweQueue> extends FaweChunk<T>
* @param i
* @return
*/
@Override
public char[] getIdArray(final int i) {
return this.ids[i];
}
@Override
public char[][] getCombinedIdArrays() {
return this.ids;
}

View File

@ -27,6 +27,11 @@ public class NullFaweChunk extends FaweChunk<Void> {
return new char[16][];
}
@Override
public char[] getIdArray(int layer) {
return null;
}
@Override
public int getBitMask() {
return 0;

View File

@ -10,6 +10,7 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import javax.annotation.Nullable;
public abstract class FaweChunk<T> implements Callable<FaweChunk> {
@ -123,8 +124,28 @@ public abstract class FaweChunk<T> implements Callable<FaweChunk> {
}
}
/**
* Get the combined id array at a layer or null if it does not exist
* @param layer
* @return char[] or null
*/
public @Nullable char[] getIdArray(int layer) {
char[] ids = new char[4096];
int by = layer << 4;
int index = 0;
for (int y = 0; y < 16; y++) {
int yy = by + y;
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
ids[index++] = (char) getBlockCombinedId(x, yy, z);
}
}
}
return ids;
}
public char[][] getCombinedIdArrays() {
char[][] ids = new char[16][];
char[][] ids = new char[HEIGHT >> 4][];
for (int y = 0; y < HEIGHT >> 4; y++) {
int y4 = y >> 4;
short[][] i1 = FaweCache.CACHE_J[y];

View File

@ -33,6 +33,7 @@ public abstract class FaweChangeSet implements ChangeSet {
private final World world;
private final boolean mainThread;
private final int layers;
private AtomicInteger waitingCombined = new AtomicInteger(0);
private AtomicInteger waitingAsync = new AtomicInteger(0);
private Object lockCombined = new Object();
@ -49,6 +50,7 @@ public abstract class FaweChangeSet implements ChangeSet {
public FaweChangeSet(World world) {
this.world = world;
this.mainThread = Fawe.get().isMainThread();
this.layers = this.world.getMaxY() >> 4;
}
public World getWorld() {
@ -221,12 +223,12 @@ public abstract class FaweChangeSet implements ChangeSet {
// Block changes
{
// Current blocks
char[][] currentIds = next.getCombinedIdArrays();
// char[][] currentIds = next.getCombinedIdArrays();
// Previous blocks in modified sections (i.e. we skip sections that weren't modified)
char[][] previousIds = previous.getCombinedIdArrays();
for (int layer = 0; layer < currentIds.length; layer++) {
char[] currentLayer = currentIds[layer];
char[] previousLayer = previousIds[layer];
// char[][] previousIds = previous.getCombinedIdArrays();
for (int layer = 0; layer < layers; layer++) {
char[] currentLayer = next.getIdArray(layer);
char[] previousLayer = previous.getIdArray(layer);
if (currentLayer == null) {
continue;
}

View File

@ -524,6 +524,10 @@ public class EditSession extends AbstractWorld implements HasFaweQueue, Lighting
return history != null ? history.getChangeSet() : changeTask;
}
public FaweChangeSet getChangeTask() {
return changeTask;
}
/**
* Change the ChangeSet being used for this EditSession
* - If history is disabled, no changeset can be set

View File

@ -319,7 +319,7 @@ public class RegionCommands {
@CommandPermissions("worldedit.region.set")
@Logging(REGION)
public void set(Player player, LocalSession session, EditSession editSession, @Selection Region selection, Pattern to) throws WorldEditException {
if (selection instanceof CuboidRegion && editSession.hasFastMode() && to instanceof BlockPattern) {
if (selection instanceof CuboidRegion && (editSession.hasFastMode() || (editSession.getRegionExtent() == null && editSession.getChangeTask() != null)) && to instanceof BlockPattern) {
try {
CuboidRegion cuboid = (CuboidRegion) selection;
RegionWrapper current = new RegionWrapper(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
@ -363,9 +363,11 @@ public class RegionCommands {
newChunk.addToQueue();
}
});
int volume = cuboid.getArea();
editSession.setSize(volume);
queue.enqueue();
long start = System.currentTimeMillis();
BBC.OPERATION.send(player, BBC.VISITOR_BLOCK.format(cuboid.getArea()));
BBC.OPERATION.send(player, BBC.VISITOR_BLOCK.format(volume));
queue.flush();
BBC.ACTION_COMPLETE.send(player, (System.currentTimeMillis() - start) / 1000d);
return;