diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2012-04-21 13:47:29 -0500 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-04-21 23:53:10 -0400 |
commit | e8459c1ff6a8e58f6d7578a99ea164deadc30884 (patch) | |
tree | 5e279538c8c5b3facf71314b69dc37427d6ef0c2 /src | |
parent | 343f39b2b3750036f3749a16cf06ae39d65e87db (diff) | |
download | craftbukkit-e8459c1ff6a8e58f6d7578a99ea164deadc30884.tar craftbukkit-e8459c1ff6a8e58f6d7578a99ea164deadc30884.tar.gz craftbukkit-e8459c1ff6a8e58f6d7578a99ea164deadc30884.tar.lz craftbukkit-e8459c1ff6a8e58f6d7578a99ea164deadc30884.tar.xz craftbukkit-e8459c1ff6a8e58f6d7578a99ea164deadc30884.zip |
Optimize AI and EntityLiving ticking
Reduce usage of getCubes as it is an expensive call.
Remove iterator usage and object creation from PathfinderGoalSelector
methods as these are called very often.
Update EntityLiving goal selectors less often as this is still quite an
expensive task.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/net/minecraft/server/EntityLiving.java | 46 | ||||
-rw-r--r-- | src/main/java/net/minecraft/server/PathfinderGoalSelector.java | 31 |
2 files changed, 47 insertions, 30 deletions
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index 8c279ec7..1f192275 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -1090,22 +1090,28 @@ public abstract class EntityLiving extends Entity { --this.aN; this.setPosition(d0, d1, d2); this.c(this.yaw, this.pitch); - List list = this.world.getCubes(this, this.boundingBox.shrink(0.03125D, 0.0D, 0.03125D)); + // CraftBukkit start - getCubes is expensive, use an approximation + if (this.world.getTypeId(MathHelper.floor(d0), MathHelper.floor(d1), MathHelper.floor(d2)) != 0) { + d1 += 1.0D; + this.setPosition(d0, d1, d2); + } + //List list = this.world.getCubes(this, this.boundingBox.shrink(0.03125D, 0.0D, 0.03125D)); - if (list.size() > 0) { - double d4 = 0.0D; + //if (list.size() > 0) { + // double d4 = 0.0D; - for (int i = 0; i < list.size(); ++i) { - AxisAlignedBB axisalignedbb = (AxisAlignedBB) list.get(i); + // for (int i = 0; i < list.size(); ++i) { + // AxisAlignedBB axisalignedbb = (AxisAlignedBB) list.get(i); - if (axisalignedbb.e > d4) { - d4 = axisalignedbb.e; - } - } + // if (axisalignedbb.e > d4) { + // d4 = axisalignedbb.e; + // } + // } - d1 += d4 - this.boundingBox.b; - this.setPosition(d0, d1, d2); - } + // d1 += d4 - this.boundingBox.b; + // this.setPosition(d0, d1, d2); + //} + // CraftBukkit end } // MethodProfiler.a("ai"); // CraftBukkit - not in production code @@ -1116,13 +1122,13 @@ public abstract class EntityLiving extends Entity { this.aY = 0.0F; } else if (this.aF()) { if (this.c_()) { - MethodProfiler.a("newAi"); + // MethodProfiler.a("newAi"); // CraftBukkit - not in production code this.z_(); - MethodProfiler.a(); + // MethodProfiler.a(); // CraftBukkit - not in production code } else { - MethodProfiler.a("oldAi"); + // MethodProfiler.a("oldAi"); // CraftBukkit - not in production code this.d_(); - MethodProfiler.a(); + // MethodProfiler.a(); // CraftBukkit - not in production code this.X = this.yaw; } } @@ -1234,10 +1240,14 @@ public abstract class EntityLiving extends Entity { this.m.a(); //MethodProfiler.a(); // CraftBukkit - not in production code //MethodProfiler.a("targetSelector"); // CraftBukkit - not in production code - this.targetSelector.a(); + // CraftBukkit start - run goal selectors every other tick + if ((this.aV & 1) == 0) { + this.targetSelector.a(); //MethodProfiler.a(); // CraftBukkit - not in production code //MethodProfiler.a("goalSelector"); // CraftBukkit - not in production code - this.goalSelector.a(); + this.goalSelector.a(); + } + // CraftBukkit end //MethodProfiler.a(); // CraftBukkit - not in production code //MethodProfiler.a("navigation"); // CraftBukkit - not in production code this.navigation.d(); diff --git a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java index 43dc1b9f..054777c4 100644 --- a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java +++ b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java @@ -7,6 +7,7 @@ public class PathfinderGoalSelector { private ArrayList a = new ArrayList(); private ArrayList b = new ArrayList(); + private ArrayList arraylist = new ArrayList(); // CraftBukkit - create list for object reuse public PathfinderGoalSelector() {} @@ -15,11 +16,12 @@ public class PathfinderGoalSelector { } public void a() { - ArrayList arraylist = new ArrayList(); - Iterator iterator = this.a.iterator(); + //ArrayList arraylist = new ArrayList(); // CraftBukkit + arraylist.clear(); // CraftBukkit - prepare reused list - while (iterator.hasNext()) { - PathfinderGoalSelectorItem pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next(); + // CraftBukkit start - don't use iterators for private fields + for (int i = 0; i < this.a.size(); i++) { + PathfinderGoalSelectorItem pathfindergoalselectoritem = (PathfinderGoalSelectorItem) this.a.get(i); boolean flag = this.b.contains(pathfindergoalselectoritem); if (flag) { @@ -36,6 +38,7 @@ public class PathfinderGoalSelector { this.b.add(pathfindergoalselectoritem); } } + // CraftBukkit end boolean flag1 = false; @@ -46,8 +49,10 @@ public class PathfinderGoalSelector { Iterator iterator1; PathfinderGoalSelectorItem pathfindergoalselectoritem1; - for (iterator1 = arraylist.iterator(); iterator1.hasNext(); pathfindergoalselectoritem1.a.c()) { - pathfindergoalselectoritem1 = (PathfinderGoalSelectorItem) iterator1.next(); + //CraftBukkit start - don't use iterators for private fields + for (int i = 0; i < arraylist.size(); i++) { + pathfindergoalselectoritem1 = (PathfinderGoalSelectorItem) arraylist.get(i); + pathfindergoalselectoritem1.a.c(); if (flag1) { System.out.println(pathfindergoalselectoritem1.a.toString() + ", "); } @@ -57,19 +62,20 @@ public class PathfinderGoalSelector { System.out.println("Running: "); } - for (iterator1 = this.b.iterator(); iterator1.hasNext(); pathfindergoalselectoritem1.a.e()) { - pathfindergoalselectoritem1 = (PathfinderGoalSelectorItem) iterator1.next(); + for (int i = 0; i < this.b.size(); i++) { + pathfindergoalselectoritem1 = (PathfinderGoalSelectorItem) this.b.get(i); + pathfindergoalselectoritem1.a.e(); if (flag1) { System.out.println(pathfindergoalselectoritem1.a.toString()); } } + // CraftBukkit end } private boolean a(PathfinderGoalSelectorItem pathfindergoalselectoritem) { - Iterator iterator = this.a.iterator(); - - while (iterator.hasNext()) { - PathfinderGoalSelectorItem pathfindergoalselectoritem1 = (PathfinderGoalSelectorItem) iterator.next(); + // CraftBukkit start - don't use iterators for private fields + for (int i = 0; i < this.a.size(); i++) { + PathfinderGoalSelectorItem pathfindergoalselectoritem1 = (PathfinderGoalSelectorItem) this.a.get(i); if (pathfindergoalselectoritem1 != pathfindergoalselectoritem) { if (pathfindergoalselectoritem.b >= pathfindergoalselectoritem1.b) { @@ -81,6 +87,7 @@ public class PathfinderGoalSelector { } } } + // CraftBukkit end return true; } |