mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 13:06:02 +01:00
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.
This commit is contained in:
parent
858d36efc9
commit
d628c886d2
@ -470,7 +470,7 @@ public abstract class EntityLiving extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.av += (f3 - this.av) * 0.3F;
|
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()) {
|
if (this.aV()) {
|
||||||
this.senses.a();
|
this.senses.a();
|
||||||
} else {
|
} else {
|
||||||
@ -498,8 +498,8 @@ public abstract class EntityLiving extends Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.world.methodProfiler.b();
|
// this.world.methodProfiler.b(); // CraftBukkit - not in production code
|
||||||
this.world.methodProfiler.a("rangeChecks");
|
// this.world.methodProfiler.a("rangeChecks"); // CraftBukkit - not in production code
|
||||||
|
|
||||||
while (this.yaw - this.lastYaw < -180.0F) {
|
while (this.yaw - this.lastYaw < -180.0F) {
|
||||||
this.lastYaw -= 360.0F;
|
this.lastYaw -= 360.0F;
|
||||||
@ -533,7 +533,7 @@ public abstract class EntityLiving extends Entity {
|
|||||||
this.at += 360.0F;
|
this.at += 360.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.world.methodProfiler.b();
|
// this.world.methodProfiler.b(); // CraftBukkit - not in production code
|
||||||
this.aw += f2;
|
this.aw += f2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ public class PathfinderGoalSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void a() {
|
public void a() {
|
||||||
UnsafeList arraylist = new UnsafeList(); // CraftBukkit - ArrayList -> UnsafeList
|
// ArrayList arraylist = new ArrayList(); // CraftBukkit - remove usage
|
||||||
Iterator iterator;
|
Iterator iterator;
|
||||||
PathfinderGoalSelectorItem pathfindergoalselectoritem;
|
PathfinderGoalSelectorItem pathfindergoalselectoritem;
|
||||||
|
|
||||||
@ -46,7 +46,10 @@ public class PathfinderGoalSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.b(pathfindergoalselectoritem) && pathfindergoalselectoritem.a.a()) {
|
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);
|
this.b.add(pathfindergoalselectoritem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,40 +65,42 @@ public class PathfinderGoalSelector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.c.a("goalStart");
|
// this.c.a("goalStart"); // CraftBukkit - not in production code
|
||||||
iterator = arraylist.iterator();
|
// CraftBukkit start - removed usage of arraylist
|
||||||
|
/*iterator = arraylist.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next();
|
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();
|
pathfindergoalselectoritem.a.e();
|
||||||
this.c.b();
|
// this.c.b(); // CraftBukkit - not in production code
|
||||||
}
|
}*/
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
this.c.b();
|
// this.c.b(); // CraftBukkit - not in production code
|
||||||
this.c.a("goalTick");
|
// this.c.a("goalTick"); // CraftBukkit - not in production code
|
||||||
iterator = this.b.iterator();
|
iterator = this.b.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
pathfindergoalselectoritem = (PathfinderGoalSelectorItem) iterator.next();
|
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();
|
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) {
|
private boolean a(PathfinderGoalSelectorItem pathfindergoalselectoritem) {
|
||||||
this.c.a("canContinue");
|
// this.c.a("canContinue"); // CraftBukkit - not in production code
|
||||||
boolean flag = pathfindergoalselectoritem.a.b();
|
boolean flag = pathfindergoalselectoritem.a.b();
|
||||||
|
|
||||||
this.c.b();
|
// this.c.b(); // CraftBukkit - not in production code
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean b(PathfinderGoalSelectorItem pathfindergoalselectoritem) {
|
private boolean b(PathfinderGoalSelectorItem pathfindergoalselectoritem) {
|
||||||
this.c.a("canUse");
|
// this.c.a("canUse"); // CraftBukkit - not in production code
|
||||||
Iterator iterator = this.a.iterator();
|
Iterator iterator = this.a.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@ -103,18 +108,20 @@ public class PathfinderGoalSelector {
|
|||||||
|
|
||||||
if (pathfindergoalselectoritem1 != pathfindergoalselectoritem) {
|
if (pathfindergoalselectoritem1 != pathfindergoalselectoritem) {
|
||||||
if (pathfindergoalselectoritem.b >= pathfindergoalselectoritem1.b) {
|
if (pathfindergoalselectoritem.b >= pathfindergoalselectoritem1.b) {
|
||||||
if (this.b.contains(pathfindergoalselectoritem1) && !this.a(pathfindergoalselectoritem, pathfindergoalselectoritem1)) {
|
// CraftBukkit - switch order
|
||||||
this.c.b();
|
if (!this.a(pathfindergoalselectoritem, pathfindergoalselectoritem1) && this.b.contains(pathfindergoalselectoritem1)) {
|
||||||
|
// this.c.b(); // CraftBukkit - not in production code
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (this.b.contains(pathfindergoalselectoritem1) && !pathfindergoalselectoritem1.a.g()) {
|
// CraftBukkit - switch order
|
||||||
this.c.b();
|
} else if (!pathfindergoalselectoritem1.a.g() && this.b.contains(pathfindergoalselectoritem1)) {
|
||||||
|
// this.c.b(); // CraftBukkit - not in production code
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.c.b();
|
// this.c.b(); // CraftBukkit - not in production code
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user