Move vectors to static creators, for caching

This commit is contained in:
Kenzie Togami
2018-10-19 13:13:32 -07:00
committed by IronApollo
parent a9919d130c
commit 4d6045813c
138 changed files with 670 additions and 531 deletions

View File

@ -163,12 +163,16 @@ public class ExtentEntityCopy implements EntityFunction {
boolean hasFacing = tag.containsKey("Facing");
if (hasTilePosition) {
<<<<<<< HEAD
//<<<<<<< HEAD
changed = true;
// Vector tilePosition = new Vector(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
// Vector newTilePosition = transform.apply(tilePosition.subtract(from)).add(to);
//=======
Vector3 tilePosition = new Vector3(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
=======
Vector3 tilePosition = Vector3.at(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ"));
>>>>>>> 2c8b2fe0... Move vectors to static creators, for caching
BlockVector3 newTilePosition = transform.apply(tilePosition.subtract(from)).add(to).toBlockPoint();
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner

View File

@ -43,14 +43,14 @@ public class BackwardsExtentBlockCopy implements Operation {
}
private CuboidRegion transform(Transform transform, Region region) {
BlockVector3 min = new BlockVector3(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
BlockVector3 max = new BlockVector3(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
BlockVector3 min = BlockVector3.at(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
BlockVector3 max = BlockVector3.at(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
BlockVector3 pos1 = region.getMinimumPoint();
BlockVector3 pos2 = region.getMaximumPoint();
for (int x : new int[] { pos1.getBlockX(), pos2.getBlockX() }) {
for (int y : new int[] { pos1.getBlockY(), pos2.getBlockY() }) {
for (int z : new int[] { pos1.getBlockZ(), pos2.getBlockZ() }) {
BlockVector3 pt = transform(transform, new BlockVector3(x, y, z));
BlockVector3 pt = transform(transform, BlockVector3.at(x, y, z));
min = min.getMinimum(pt);
max = max.getMaximum(pt);
}
@ -68,7 +68,7 @@ public class BackwardsExtentBlockCopy implements Operation {
// tmp.mutY((tmp.getBlockY() + origin.getBlockY()));
// tmp.mutZ((tmp.getBlockZ() + origin.getBlockZ()));
// return tmp;
return transform.apply(new Vector3(pt.getBlockX() - origin.getBlockX(), pt.getBlockY() - origin.getBlockY(), pt.getBlockZ() - origin.getBlockZ())).toBlockPoint().add(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
return transform.apply(Vector3.at(pt.getBlockX() - origin.getBlockX(), pt.getBlockY() - origin.getBlockY(), pt.getBlockZ() - origin.getBlockZ())).toBlockPoint().add(origin.getBlockX(), origin.getBlockY(), origin.getBlockZ());
}
@Override

View File

@ -48,7 +48,6 @@ import com.sk89q.worldedit.function.visitor.IntersectRegionFunction;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.Identity;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.Region;
@ -322,7 +321,7 @@ public class ForwardExtentCopy implements Operation {
int z = translation.getBlockZ();
maskFunc = position -> {
BlockVector3 bv = new BlockVector3(position.getBlockX() + x, position.getBlockY() + y, position.getBlockZ() + z);
BlockVector3 bv = BlockVector3.at(position.getBlockX() + x, position.getBlockY() + y, position.getBlockZ() + z);
if (region.contains(bv)) {
return sourceFunction.apply(bv);
}
@ -330,7 +329,7 @@ public class ForwardExtentCopy implements Operation {
};
copySrcFunc = position -> {
BlockVector3 bv = new BlockVector3(position.getBlockX() - x, position.getBlockY() - y, position.getBlockZ() - z);
BlockVector3 bv = BlockVector3.at(position.getBlockX() - x, position.getBlockY() - y, position.getBlockZ() - z);
if (!region.contains(bv)) {
return sourceFunction.apply(position);
}

View File

@ -45,7 +45,7 @@ public class ClipboardPattern extends AbstractPattern {
if (xp < 0) xp += sx;
if (yp < 0) yp += sy;
if (zp < 0) zp += sz;
return clipboard.getBlock(new BlockVector3(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
return clipboard.getBlock(BlockVector3.at(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
//=======
// public BlockStateHolder apply(BlockVector3 position) {
// int xp = Math.abs(position.getBlockX()) % size.getBlockX();

View File

@ -46,7 +46,7 @@ public interface Pattern extends com.sk89q.worldedit.patterns.Pattern{
@Override
default BaseBlock next(int x, int y, int z) {
return new BaseBlock(apply(new BlockVector3(x, y, z)));
return new BaseBlock(apply(BlockVector3.at(x, y, z)));
}
/**

View File

@ -93,10 +93,6 @@ public class RepeatingExtentPattern extends AbstractPattern {
int x = base.getBlockX() % size.getBlockX();
int y = base.getBlockY() % size.getBlockY();
int z = base.getBlockZ() % size.getBlockZ();
//<<<<<<< HEAD
// return extent.getBlock(new Vector(x, y, z));
//=======
return extent.getFullBlock(new BlockVector3(x, y, z));
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
return extent.getFullBlock(BlockVector3.at(x, y, z));
}
}

View File

@ -44,18 +44,18 @@ public abstract class BreadthFirstSearch implements Operation {
public static final BlockVector3[] DIAGONAL_DIRECTIONS;
static {
DEFAULT_DIRECTIONS[0] = (new BlockVector3(0, -1, 0));
DEFAULT_DIRECTIONS[1] = (new BlockVector3(0, 1, 0));
DEFAULT_DIRECTIONS[2] = (new BlockVector3(-1, 0, 0));
DEFAULT_DIRECTIONS[3] = (new BlockVector3(1, 0, 0));
DEFAULT_DIRECTIONS[4] = (new BlockVector3(0, 0, -1));
DEFAULT_DIRECTIONS[5] = (new BlockVector3(0, 0, 1));
DEFAULT_DIRECTIONS[0] = (BlockVector3.at(0, -1, 0));
DEFAULT_DIRECTIONS[1] = (BlockVector3.at(0, 1, 0));
DEFAULT_DIRECTIONS[2] = (BlockVector3.at(-1, 0, 0));
DEFAULT_DIRECTIONS[3] = (BlockVector3.at(1, 0, 0));
DEFAULT_DIRECTIONS[4] = (BlockVector3.at(0, 0, -1));
DEFAULT_DIRECTIONS[5] = (BlockVector3.at(0, 0, 1));
List<BlockVector3> list = new ArrayList<>();
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
if (x != 0 || y != 0 || z != 0) {
BlockVector3 pos = new BlockVector3(x, y, z);
BlockVector3 pos = BlockVector3.at(x, y, z);
if (!list.contains(pos)) {
list.add(pos);
}
@ -100,10 +100,6 @@ public abstract class BreadthFirstSearch implements Operation {
this.maxDepth = maxDepth;
}
public Collection<BlockVector3> getDirections() {
return this.directions;
}
public void setDirections(List<BlockVector3> directions) {
this.directions = directions;
}
@ -116,6 +112,44 @@ public abstract class BreadthFirstSearch implements Operation {
}
return array;
}
/**
* Get the list of directions will be visited.
*
* <p>Directions are {@link BlockVector3}s that determine
* what adjacent points area available. Vectors should not be
* unit vectors. An example of a valid direction is
* {@code BlockVector3.at(1, 0, 1)}.</p>
*
* <p>The list of directions can be cleared.</p>
*
* @return the list of directions
*/
protected Collection<BlockVector3> getDirections() {
return directions;
}
/**
* Add the directions along the axes as directions to visit.
*/
protected void addAxes() {
directions.add(BlockVector3.at(0, -1, 0));
directions.add(BlockVector3.at(0, 1, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, 0, 1));
}
/**
* Add the diagonal directions as directions to visit.
*/
protected void addDiagonal() {
directions.add(BlockVector3.at(1, 0, 1));
directions.add(BlockVector3.at(-1, 0, -1));
directions.add(BlockVector3.at(1, 0, -1));
directions.add(BlockVector3.at(-1, 0, 1));
}
public void visit(final BlockVector3 pos) {
if (!isVisited(pos)) {
@ -223,7 +257,7 @@ public abstract class BreadthFirstSearch implements Operation {
int x = from.getBlockX() + direction.x;
int z = from.getBlockZ() + direction.z;
if (!visited.contains(x, y, z)) {
if (isVisitable(from, new BlockVector3(x, y, z))) {
if (isVisitable(from, BlockVector3.at(x, y, z))) {
j++;
visited.add(x, y, z);
tempQueue.add(x, y, z);

View File

@ -53,12 +53,12 @@ public class DirectionalVisitor extends RecursiveVisitor {
this.dirVec = direction;
final Collection<BlockVector3> directions = this.getDirections();
directions.clear();
directions.add(new BlockVector3(1, 0, 0));
directions.add(new BlockVector3(-1, 0, 0));
directions.add(new BlockVector3(0, 0, 1));
directions.add(new BlockVector3(0, 0, -1));
directions.add(new BlockVector3(0, -1, 0));
directions.add(new BlockVector3(0, 1, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, -1, 0));
directions.add(BlockVector3.at(0, 1, 0));
}
@Override

View File

@ -62,11 +62,11 @@ public class DownwardVisitor extends RecursiveVisitor {
Collection<BlockVector3> directions = getDirections();
directions.clear();
directions.add(new BlockVector3(1, 0, 0));
directions.add(new BlockVector3(-1, 0, 0));
directions.add(new BlockVector3(0, 0, 1));
directions.add(new BlockVector3(0, 0, -1));
directions.add(new BlockVector3(0, -1, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, -1, 0));
}
@Override

View File

@ -48,11 +48,11 @@ public class NonRisingVisitor extends RecursiveVisitor {
super(mask, function, depth, hasFaweQueue);
Collection<BlockVector3> directions = getDirections();
directions.clear();
directions.add(new BlockVector3(1, 0, 0));
directions.add(new BlockVector3(-1, 0, 0));
directions.add(new BlockVector3(0, 0, 1));
directions.add(new BlockVector3(0, 0, -1));
directions.add(new BlockVector3(0, -1, 0));
directions.add(BlockVector3.at(1, 0, 0));
directions.add(BlockVector3.at(-1, 0, 0));
directions.add(BlockVector3.at(0, 0, 1));
directions.add(BlockVector3.at(0, 0, -1));
directions.add(BlockVector3.at(0, -1, 0));
}