Skip to content

Commit

Permalink
Speedup BlockPos by fixing inlining
Browse files Browse the repository at this point in the history
  • Loading branch information
Techcable authored and Zach Brown committed Jan 29, 2016
1 parent 972d71a commit bb17101
Show file tree
Hide file tree
Showing 2 changed files with 515 additions and 2 deletions.
361 changes: 359 additions & 2 deletions Spigot-Server-Patches/0003-mc-dev-imports.patch
@@ -1,9 +1,100 @@
From ce5da7df48c5505249c2b932b66d5b45558c01c8 Mon Sep 17 00:00:00 2001
From ef451696bb6004f2d3467750038f2010f52a04b2 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Mon, 25 May 2015 15:37:00 -0500
Subject: [PATCH] mc-dev imports


diff --git a/src/main/java/net/minecraft/server/BaseBlockPosition.java b/src/main/java/net/minecraft/server/BaseBlockPosition.java
new file mode 100644
index 0000000..0b2277c
--- /dev/null
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
@@ -0,0 +1,85 @@
+package net.minecraft.server;
+
+import com.google.common.base.Objects;
+
+public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
+
+ public static final BaseBlockPosition ZERO = new BaseBlockPosition(0, 0, 0);
+ private final int a;
+ private final int c;
+ private final int d;
+
+ public BaseBlockPosition(int i, int j, int k) {
+ this.a = i;
+ this.c = j;
+ this.d = k;
+ }
+
+ public BaseBlockPosition(double d0, double d1, double d2) {
+ this(MathHelper.floor(d0), MathHelper.floor(d1), MathHelper.floor(d2));
+ }
+
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ } else if (!(object instanceof BaseBlockPosition)) {
+ return false;
+ } else {
+ BaseBlockPosition baseblockposition = (BaseBlockPosition) object;
+
+ return this.getX() != baseblockposition.getX() ? false : (this.getY() != baseblockposition.getY() ? false : this.getZ() == baseblockposition.getZ());
+ }
+ }
+
+ public int hashCode() {
+ return (this.getY() + this.getZ() * 31) * 31 + this.getX();
+ }
+
+ public int g(BaseBlockPosition baseblockposition) {
+ return this.getY() == baseblockposition.getY() ? (this.getZ() == baseblockposition.getZ() ? this.getX() - baseblockposition.getX() : this.getZ() - baseblockposition.getZ()) : this.getY() - baseblockposition.getY();
+ }
+
+ public int getX() {
+ return this.a;
+ }
+
+ public int getY() {
+ return this.c;
+ }
+
+ public int getZ() {
+ return this.d;
+ }
+
+ public BaseBlockPosition d(BaseBlockPosition baseblockposition) {
+ return new BaseBlockPosition(this.getY() * baseblockposition.getZ() - this.getZ() * baseblockposition.getY(), this.getZ() * baseblockposition.getX() - this.getX() * baseblockposition.getZ(), this.getX() * baseblockposition.getY() - this.getY() * baseblockposition.getX());
+ }
+
+ public double c(double d0, double d1, double d2) {
+ double d3 = (double) this.getX() - d0;
+ double d4 = (double) this.getY() - d1;
+ double d5 = (double) this.getZ() - d2;
+
+ return d3 * d3 + d4 * d4 + d5 * d5;
+ }
+
+ public double d(double d0, double d1, double d2) {
+ double d3 = (double) this.getX() + 0.5D - d0;
+ double d4 = (double) this.getY() + 0.5D - d1;
+ double d5 = (double) this.getZ() + 0.5D - d2;
+
+ return d3 * d3 + d4 * d4 + d5 * d5;
+ }
+
+ public double i(BaseBlockPosition baseblockposition) {
+ return this.c((double) baseblockposition.getX(), (double) baseblockposition.getY(), (double) baseblockposition.getZ());
+ }
+
+ public String toString() {
+ return Objects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).toString();
+ }
+
+ public int compareTo(Object object) {
+ return this.g((BaseBlockPosition) object);
+ }
+}
diff --git a/src/main/java/net/minecraft/server/BiomeBase.java b/src/main/java/net/minecraft/server/BiomeBase.java
new file mode 100644
index 0000000..b1ae67a
Expand Down Expand Up @@ -1529,6 +1620,272 @@ index 0000000..b610450
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
new file mode 100644
index 0000000..2bd5499
--- /dev/null
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
@@ -0,0 +1,260 @@
+package net.minecraft.server;
+
+import com.google.common.collect.AbstractIterator;
+import java.util.Iterator;
+
+public class BlockPosition extends BaseBlockPosition {
+
+ public static final BlockPosition ZERO = new BlockPosition(0, 0, 0);
+ private static final int c = 1 + MathHelper.c(MathHelper.b(30000000));
+ private static final int d = BlockPosition.c;
+ private static final int e = 64 - BlockPosition.c - BlockPosition.d;
+ private static final int f = 0 + BlockPosition.d;
+ private static final int g = BlockPosition.f + BlockPosition.e;
+ private static final long h = (1L << BlockPosition.c) - 1L;
+ private static final long i = (1L << BlockPosition.e) - 1L;
+ private static final long j = (1L << BlockPosition.d) - 1L;
+
+ public BlockPosition(int i, int j, int k) {
+ super(i, j, k);
+ }
+
+ public BlockPosition(double d0, double d1, double d2) {
+ super(d0, d1, d2);
+ }
+
+ public BlockPosition(Entity entity) {
+ this(entity.locX, entity.locY, entity.locZ);
+ }
+
+ public BlockPosition(Vec3D vec3d) {
+ this(vec3d.a, vec3d.b, vec3d.c);
+ }
+
+ public BlockPosition(BaseBlockPosition baseblockposition) {
+ this(baseblockposition.getX(), baseblockposition.getY(), baseblockposition.getZ());
+ }
+
+ public BlockPosition a(double d0, double d1, double d2) {
+ return d0 == 0.0D && d1 == 0.0D && d2 == 0.0D ? this : new BlockPosition((double) this.getX() + d0, (double) this.getY() + d1, (double) this.getZ() + d2);
+ }
+
+ public BlockPosition a(int i, int j, int k) {
+ return i == 0 && j == 0 && k == 0 ? this : new BlockPosition(this.getX() + i, this.getY() + j, this.getZ() + k);
+ }
+
+ public BlockPosition a(BaseBlockPosition baseblockposition) {
+ return baseblockposition.getX() == 0 && baseblockposition.getY() == 0 && baseblockposition.getZ() == 0 ? this : new BlockPosition(this.getX() + baseblockposition.getX(), this.getY() + baseblockposition.getY(), this.getZ() + baseblockposition.getZ());
+ }
+
+ public BlockPosition b(BaseBlockPosition baseblockposition) {
+ return baseblockposition.getX() == 0 && baseblockposition.getY() == 0 && baseblockposition.getZ() == 0 ? this : new BlockPosition(this.getX() - baseblockposition.getX(), this.getY() - baseblockposition.getY(), this.getZ() - baseblockposition.getZ());
+ }
+
+ public BlockPosition up() {
+ return this.up(1);
+ }
+
+ public BlockPosition up(int i) {
+ return this.shift(EnumDirection.UP, i);
+ }
+
+ public BlockPosition down() {
+ return this.down(1);
+ }
+
+ public BlockPosition down(int i) {
+ return this.shift(EnumDirection.DOWN, i);
+ }
+
+ public BlockPosition north() {
+ return this.north(1);
+ }
+
+ public BlockPosition north(int i) {
+ return this.shift(EnumDirection.NORTH, i);
+ }
+
+ public BlockPosition south() {
+ return this.south(1);
+ }
+
+ public BlockPosition south(int i) {
+ return this.shift(EnumDirection.SOUTH, i);
+ }
+
+ public BlockPosition west() {
+ return this.west(1);
+ }
+
+ public BlockPosition west(int i) {
+ return this.shift(EnumDirection.WEST, i);
+ }
+
+ public BlockPosition east() {
+ return this.east(1);
+ }
+
+ public BlockPosition east(int i) {
+ return this.shift(EnumDirection.EAST, i);
+ }
+
+ public BlockPosition shift(EnumDirection enumdirection) {
+ return this.shift(enumdirection, 1);
+ }
+
+ public BlockPosition shift(EnumDirection enumdirection, int i) {
+ return i == 0 ? this : new BlockPosition(this.getX() + enumdirection.getAdjacentX() * i, this.getY() + enumdirection.getAdjacentY() * i, this.getZ() + enumdirection.getAdjacentZ() * i);
+ }
+
+ public BlockPosition c(BaseBlockPosition baseblockposition) {
+ return new BlockPosition(this.getY() * baseblockposition.getZ() - this.getZ() * baseblockposition.getY(), this.getZ() * baseblockposition.getX() - this.getX() * baseblockposition.getZ(), this.getX() * baseblockposition.getY() - this.getY() * baseblockposition.getX());
+ }
+
+ public long asLong() {
+ return ((long) this.getX() & BlockPosition.h) << BlockPosition.g | ((long) this.getY() & BlockPosition.i) << BlockPosition.f | ((long) this.getZ() & BlockPosition.j) << 0;
+ }
+
+ public static BlockPosition fromLong(long i) {
+ int j = (int) (i << 64 - BlockPosition.g - BlockPosition.c >> 64 - BlockPosition.c);
+ int k = (int) (i << 64 - BlockPosition.f - BlockPosition.e >> 64 - BlockPosition.e);
+ int l = (int) (i << 64 - BlockPosition.d >> 64 - BlockPosition.d);
+
+ return new BlockPosition(j, k, l);
+ }
+
+ public static Iterable<BlockPosition> a(BlockPosition blockposition, BlockPosition blockposition1) {
+ final BlockPosition blockposition2 = new BlockPosition(Math.min(blockposition.getX(), blockposition1.getX()), Math.min(blockposition.getY(), blockposition1.getY()), Math.min(blockposition.getZ(), blockposition1.getZ()));
+ final BlockPosition blockposition3 = new BlockPosition(Math.max(blockposition.getX(), blockposition1.getX()), Math.max(blockposition.getY(), blockposition1.getY()), Math.max(blockposition.getZ(), blockposition1.getZ()));
+
+ return new Iterable() {
+ public Iterator<BlockPosition> iterator() {
+ return new AbstractIterator() {
+ private BlockPosition b = null;
+
+ protected BlockPosition a() {
+ if (this.b == null) {
+ this.b = blockposition;
+ return this.b;
+ } else if (this.b.equals(blockposition1)) {
+ return (BlockPosition) this.endOfData();
+ } else {
+ int i = this.b.getX();
+ int j = this.b.getY();
+ int k = this.b.getZ();
+
+ if (i < blockposition1.getX()) {
+ ++i;
+ } else if (j < blockposition1.getY()) {
+ i = blockposition.getX();
+ ++j;
+ } else if (k < blockposition1.getZ()) {
+ i = blockposition.getX();
+ j = blockposition.getY();
+ ++k;
+ }
+
+ this.b = new BlockPosition(i, j, k);
+ return this.b;
+ }
+ }
+
+ protected Object computeNext() {
+ return this.a();
+ }
+ };
+ }
+ };
+ }
+
+ public static Iterable<BlockPosition.MutableBlockPosition> b(BlockPosition blockposition, BlockPosition blockposition1) {
+ final BlockPosition blockposition2 = new BlockPosition(Math.min(blockposition.getX(), blockposition1.getX()), Math.min(blockposition.getY(), blockposition1.getY()), Math.min(blockposition.getZ(), blockposition1.getZ()));
+ final BlockPosition blockposition3 = new BlockPosition(Math.max(blockposition.getX(), blockposition1.getX()), Math.max(blockposition.getY(), blockposition1.getY()), Math.max(blockposition.getZ(), blockposition1.getZ()));
+
+ return new Iterable() {
+ public Iterator<BlockPosition.MutableBlockPosition> iterator() {
+ return new AbstractIterator() {
+ private BlockPosition.MutableBlockPosition b = null;
+
+ protected BlockPosition.MutableBlockPosition a() {
+ if (this.b == null) {
+ this.b = new BlockPosition.MutableBlockPosition(blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ return this.b;
+ } else if (this.b.equals(blockposition1)) {
+ return (BlockPosition.MutableBlockPosition) this.endOfData();
+ } else {
+ int i = this.b.getX();
+ int j = this.b.getY();
+ int k = this.b.getZ();
+
+ if (i < blockposition1.getX()) {
+ ++i;
+ } else if (j < blockposition1.getY()) {
+ i = blockposition.getX();
+ ++j;
+ } else if (k < blockposition1.getZ()) {
+ i = blockposition.getX();
+ j = blockposition.getY();
+ ++k;
+ }
+
+ this.b.c = i;
+ this.b.d = j;
+ this.b.e = k;
+ return this.b;
+ }
+ }
+
+ protected Object computeNext() {
+ return this.a();
+ }
+ };
+ }
+ };
+ }
+
+ public BaseBlockPosition d(BaseBlockPosition baseblockposition) {
+ return this.c(baseblockposition);
+ }
+
+ public static final class MutableBlockPosition extends BlockPosition {
+
+ private int c;
+ private int d;
+ private int e;
+
+ public MutableBlockPosition() {
+ this(0, 0, 0);
+ }
+
+ public MutableBlockPosition(int i, int j, int k) {
+ super(0, 0, 0);
+ this.c = i;
+ this.d = j;
+ this.e = k;
+ }
+
+ public int getX() {
+ return this.c;
+ }
+
+ public int getY() {
+ return this.d;
+ }
+
+ public int getZ() {
+ return this.e;
+ }
+
+ public BlockPosition.MutableBlockPosition c(int i, int j, int k) {
+ this.c = i;
+ this.d = j;
+ this.e = k;
+ return this;
+ }
+
+ public BaseBlockPosition d(BaseBlockPosition baseblockposition) {
+ return super.c(baseblockposition);
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/server/ChunkProviderFlat.java b/src/main/java/net/minecraft/server/ChunkProviderFlat.java
new file mode 100644
index 0000000..d1e10c6
Expand Down Expand Up @@ -2966,5 +3323,5 @@ index 0000000..f75e2de
+ }
+}
--
2.7.0.windows.1
2.7.0

0 comments on commit bb17101

Please sign in to comment.