diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2012-08-17 16:25:19 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2012-08-19 09:50:57 -0500 |
commit | d628c886d2c96c0bc8cd67bb3cd7cfba0b96f1a8 (patch) | |
tree | 1bddda313ef6f9213382a1abbc9849f71d765ad3 /src/main/java/net/minecraft | |
parent | 858d36efc9045d952af21ca4c33ad2756a05f8ae (diff) | |
download | craftbukkit-d628c886d2c96c0bc8cd67bb3cd7cfba0b96f1a8.tar craftbukkit-d628c886d2c96c0bc8cd67bb3cd7cfba0b96f1a8.tar.gz craftbukkit-d628c886d2c96c0bc8cd67bb3cd7cfba0b96f1a8.tar.lz craftbukkit-d628c886d2c96c0bc8cd67bb3cd7cfba0b96f1a8.tar.xz craftbukkit-d628c886d2c96c0bc8cd67bb3cd7cfba0b96f1a8.zip |
Optimize entity AI goal selector
Remove redundant ArrayList to avoid excessive object creation and CPU
overhead, the entries are added to the list then immediately iterated through
to run so just run them directly.
Swap order of some conditionals to perform the more efficient check first
as if it fails the list lookup will not be executed.
Remove profiling hooks including some rather expensive calls to getSimpleName.
Diffstat (limited to 'src/main/java/net/minecraft')
-rw-r--r-- | src/main/java/net/minecraft/server/EntityLiving.java | 8 | ||||
-rw-r--r-- | src/main/java/net/minecraft/server/PathfinderGoalSelector.java | 47 |
2 files changed, 31 insertions, 24 deletions
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index 7844e6a8..a62c98fc 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -470,7 +470,7 @@ public abstract class EntityLiving extends Entity { } this.av += (f3 - this.av) * 0.3F; - this.world.methodProfiler.a("headTurn"); + // this.world.methodProfiler.a("headTurn"); // CraftBukkit - not in production code if (this.aV()) { this.senses.a(); } else { @@ -498,8 +498,8 @@ public abstract class EntityLiving extends Entity { } } - this.world.methodProfiler.b(); - this.world.methodProfiler.a("rangeChecks"); + // this.world.methodProfiler.b(); // CraftBukkit - not in production code + // this.world.methodProfiler.a("rangeChecks"); // CraftBukkit - not in production code while (this.yaw - this.lastYaw < -180.0F) { this.lastYaw -= 360.0F; @@ -533,7 +533,7 @@ public abstract class EntityLiving extends Entity { this.at += 360.0F; } - this.world.methodProfiler.b(); + // this.world.methodProfiler.b(); // CraftBukkit - not in production code this.aw += f2; } diff --git a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java index 9ef8ec76..02f6e46b 100644 --- a/src/main/java/net/minecraft/server/PathfinderGoalSelector.java +++ b/src/main/java/net/minecraft/server/PathfinderGoalSelector.java @@ -25,7 +25,7 @@ public class PathfinderGoalSelector { } public void a() { - UnsafeList arraylist = new UnsafeList(); // CraftBukkit - ArrayList -> UnsafeList + // ArrayList arraylist = new ArrayList(); // CraftBukkit - remove usage Iterator iterator; PathfinderGoalSelectorItem pathfindergoalselectoritem; @@ -46,7 +46,10 @@ public class PathfinderGoalSelector { } if (this.b(pathfindergoalselectoritem) && pathfindergoalselectoritem.a.a()) { - arraylist.add(pathfindergoalselectoritem); + // CraftBukkit start - call method now instead of queueing + // arraylist.add(pathfindergoalselectoritem); + pathfindergoalselectoritem.a.e(); + // CraftBukkit end this.b.add(pathfindergoalselectoritem); } } @@ -62,40 +65,42 @@ public class PathfinderGoalSelector { } } - this.c.a("goalStart"); - iterator = arraylist.iterator(); + // this.c.a("goalStart"); // CraftBukkit - not in production code + // CraftBukkit start - removed usage of arraylist + /*iterator = arraylist.iterator(); while (iterator.hasNext()) { pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next(); - this.c.a(pathfindergoalselectoritem.a.getClass().getSimpleName()); + // this.c.a(pathfindergoalselectoritem.a.getClass().getSimpleName()); // CraftBukkit - not in production code pathfindergoalselectoritem.a.e(); - this.c.b(); - } + // this.c.b(); // CraftBukkit - not in production code + }*/ + // CraftBukkit end - this.c.b(); - this.c.a("goalTick"); + // this.c.b(); // CraftBukkit - not in production code + // this.c.a("goalTick"); // CraftBukkit - not in production code iterator = this.b.iterator(); while (iterator.hasNext()) { pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next(); - this.c.a(pathfindergoalselectoritem.a.getClass().getSimpleName()); + // this.c.a(pathfindergoalselectoritem.a.getClass().getSimpleName()); // CraftBukkit - not in production code pathfindergoalselectoritem.a.d(); - this.c.b(); + // this.c.b(); // CraftBukkit - not in production code } - this.c.b(); + // this.c.b(); // CraftBukkit - not in production code } private boolean a(PathfinderGoalSelectorItem pathfindergoalselectoritem) { - this.c.a("canContinue"); + // this.c.a("canContinue"); // CraftBukkit - not in production code boolean flag = pathfindergoalselectoritem.a.b(); - this.c.b(); + // this.c.b(); // CraftBukkit - not in production code return flag; } private boolean b(PathfinderGoalSelectorItem pathfindergoalselectoritem) { - this.c.a("canUse"); + // this.c.a("canUse"); // CraftBukkit - not in production code Iterator iterator = this.a.iterator(); while (iterator.hasNext()) { @@ -103,18 +108,20 @@ public class PathfinderGoalSelector { if (pathfindergoalselectoritem1 != pathfindergoalselectoritem) { if (pathfindergoalselectoritem.b >= pathfindergoalselectoritem1.b) { - if (this.b.contains(pathfindergoalselectoritem1) && !this.a(pathfindergoalselectoritem, pathfindergoalselectoritem1)) { - this.c.b(); + // CraftBukkit - switch order + if (!this.a(pathfindergoalselectoritem, pathfindergoalselectoritem1) && this.b.contains(pathfindergoalselectoritem1)) { + // this.c.b(); // CraftBukkit - not in production code return false; } - } else if (this.b.contains(pathfindergoalselectoritem1) && !pathfindergoalselectoritem1.a.g()) { - this.c.b(); + // CraftBukkit - switch order + } else if (!pathfindergoalselectoritem1.a.g() && this.b.contains(pathfindergoalselectoritem1)) { + // this.c.b(); // CraftBukkit - not in production code return false; } } } - this.c.b(); + // this.c.b(); // CraftBukkit - not in production code return true; } |