Various minor

Angle mask optimizations
- Fix and re-implement greedy height caching
- Use cached block mask for everything
Keep mask intersection insertion order
This commit is contained in:
Jesse Boyd 2017-11-12 16:28:22 +11:00
parent 6873e45b6f
commit f72aa7baf9
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 46 additions and 44 deletions

View File

@ -231,9 +231,6 @@ public class Fawe {
private DefaultTransformParser transformParser; private DefaultTransformParser transformParser;
private ChatManager chatManager = new PlainChatManager(); private ChatManager chatManager = new PlainChatManager();
// @Deprecated
// private boolean isJava8 = MainUtil.getJavaVersion() >= 1.8;
/** /**
* Get the implementation specific class * Get the implementation specific class
* *

View File

@ -2,7 +2,6 @@ package com.boydti.fawe.object.mask;
import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.MutableBlockVector;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.mask.Mask2D;
import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.mask.SolidBlockMask;
@ -47,7 +46,10 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
private transient int cacheBotX = Integer.MIN_VALUE; private transient int cacheBotX = Integer.MIN_VALUE;
private transient int cacheBotZ = Integer.MIN_VALUE; private transient int cacheBotZ = Integer.MIN_VALUE;
private transient int cacheCenterZ; private transient int cacheCenterZ;
private transient byte[] cacheHeights; private transient byte[] cacheHeights;
private transient byte[] cacheDistance;
private transient int lastY; private transient int lastY;
private transient int lastX = Integer.MIN_VALUE; private transient int lastX = Integer.MIN_VALUE;
private transient int lastZ = Integer.MIN_VALUE; private transient int lastZ = Integer.MIN_VALUE;
@ -55,34 +57,38 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
private transient boolean lastValue; private transient boolean lastValue;
public int getHeight(int x, int y, int z) { public int getHeight(int x, int y, int z) {
return getExtent().getNearestSurfaceTerrainBlock(x, z, y, 0, maxY); // return getExtent().getNearestSurfaceTerrainBlock(x, z, y, 0, maxY);
// try { try {
// int rx = x - cacheBotX + 16; int rx = x - cacheBotX + 16;
// int rz = z - cacheBotZ + 16; int rz = z - cacheBotZ + 16;
// int index; int index;
// if (((rx & 0xFF) != rx || (rz & 0xFF) != rz)) { if (((rx & 0xFF) != rx || (rz & 0xFF) != rz)) {
// cacheBotX = x - 16; cacheBotX = x - 16;
// cacheBotZ = z - 16; cacheBotZ = z - 16;
// rx = x - cacheBotX + 16; rx = x - cacheBotX + 16;
// rz = z - cacheBotZ + 16; rz = z - cacheBotZ + 16;
// index = rx + (rz << 8); index = rx + (rz << 8);
// if (cacheHeights == null) { if (cacheHeights == null) {
// cacheHeights = new byte[65536]; cacheHeights = new byte[65536];
// } else { cacheDistance = new byte[65536];
// Arrays.fill(cacheHeights, (byte) 0); } else {
// } Arrays.fill(cacheHeights, (byte) 0);
// } else { Arrays.fill(cacheDistance, (byte) 0);
// index = rx + (rz << 8); }
// } } else {
// int result = cacheHeights[index] & 0xFF; index = rx + (rz << 8);
// if (result == 0) { }
// cacheHeights[index] = (byte) (result = lastY = getExtent().getNearestSurfaceTerrainBlock(x, z, lastY, 0, maxY)); int result = cacheHeights[index] & 0xFF;
// } int distance = cacheDistance[index] & 0xFF;
// return result; if (result == 0 || distance < Math.abs(result - y)) {
// } catch (Throwable e) { cacheHeights[index] = (byte) (result = lastY = getExtent().getNearestSurfaceTerrainBlock(x, z, lastY, 0, maxY));
// e.printStackTrace(); cacheDistance[index] = (byte) Math.abs(result - y);
// throw e; }
// } return result;
} catch (Throwable e) {
e.printStackTrace();
throw e;
}
} }
private boolean testSlope(int x, int y, int z) { private boolean testSlope(int x, int y, int z) {
@ -105,22 +111,22 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
int x = v.getBlockX(); int x = v.getBlockX();
int y = v.getBlockY(); int y = v.getBlockY();
int z = v.getBlockZ(); int z = v.getBlockZ();
if (mask.test(x + 1, y, z)) { if (!mask.test(x + 1, y, z)) {
return true; return true;
} }
if (mask.test(x - 1, y, z)) { if (!mask.test(x - 1, y, z)) {
return true; return true;
} }
if (mask.test(x, y, z + 1)) { if (!mask.test(x, y, z + 1)) {
return true; return true;
} }
if (mask.test(x, y, z - 1)) { if (!mask.test(x, y, z - 1)) {
return true; return true;
} }
if (y < 256 && mask.test(x, y + 1, z)) { if (y < 255 && !mask.test(x, y + 1, z)) {
return true; return true;
} }
if (y > 0 && mask.test(x, y - 1, z)) { if (y > 0 && !mask.test(x, y - 1, z)) {
return true; return true;
} }
return false; return false;
@ -131,13 +137,11 @@ public class AngleMask extends SolidBlockMask implements ResettableMask {
int x = vector.getBlockX(); int x = vector.getBlockX();
int y = vector.getBlockY(); int y = vector.getBlockY();
int z = vector.getBlockZ(); int z = vector.getBlockZ();
BaseBlock block = getExtent().getLazyBlock(x, y, z); if (!mask.test(x, y, z)) {
if (!test(block.getId(), block.getData())) {
return false; return false;
} }
if (overlay) { if (overlay) {
block = getExtent().getLazyBlock(x, y + 1, z); if (y < 255 && !mask.test(x, y + 1, z)) return lastValue = false;
if (test(block.getId(), block.getData())) return lastValue = false;
} else if (!adjacentAir(vector)) { } else if (!adjacentAir(vector)) {
return false; return false;
} }

View File

@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -40,7 +41,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/ */
public class MaskIntersection extends AbstractMask implements Serializable { public class MaskIntersection extends AbstractMask implements Serializable {
private transient Set<Mask> masks = new HashSet<Mask>(); private transient Set<Mask> masks = new LinkedHashSet<>();
private Mask[] masksArray; private Mask[] masksArray;
/** /**
@ -100,7 +101,7 @@ public class MaskIntersection extends AbstractMask implements Serializable {
return masks; return masks;
} }
public Mask[] getMasksArray() { public final Mask[] getMasksArray() {
return masksArray; return masksArray;
} }