mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 13:06:02 +01:00
Use TrigMath in hotspots
Use our implementation of atan2 in AI routines as profiling shows these are hotspots and (for these cases) our implementation is much faster.
This commit is contained in:
parent
8219081385
commit
7b20caf8fe
@ -1,5 +1,7 @@
|
|||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.TrigMath; // CraftBukkit
|
||||||
|
|
||||||
public class ControllerLook {
|
public class ControllerLook {
|
||||||
|
|
||||||
private EntityLiving a;
|
private EntityLiving a;
|
||||||
@ -45,8 +47,10 @@ public class ControllerLook {
|
|||||||
double d1 = this.f - (this.a.locY + (double) this.a.getHeadHeight());
|
double d1 = this.f - (this.a.locY + (double) this.a.getHeadHeight());
|
||||||
double d2 = this.g - this.a.locZ;
|
double d2 = this.g - this.a.locZ;
|
||||||
double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
|
double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
|
||||||
float f = (float) (Math.atan2(d2, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
|
// CraftBukkit start - Math -> TrigMath
|
||||||
float f1 = (float) (-(Math.atan2(d1, d3) * 180.0D / 3.1415927410125732D));
|
float f = (float) (TrigMath.atan2(d2, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
|
||||||
|
float f1 = (float) (-(TrigMath.atan2(d1, d3) * 180.0D / 3.1415927410125732D));
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
this.a.pitch = this.a(this.a.pitch, f1, this.c);
|
this.a.pitch = this.a(this.a.pitch, f1, this.c);
|
||||||
this.a.as = this.a(this.a.as, f, this.b);
|
this.a.as = this.a(this.a.as, f, this.b);
|
||||||
|
@ -43,7 +43,8 @@ public class ControllerMove {
|
|||||||
double d3 = d0 * d0 + d2 * d2 + d1 * d1;
|
double d3 = d0 * d0 + d2 * d2 + d1 * d1;
|
||||||
|
|
||||||
if (d3 >= 2.500000277905201E-7D) {
|
if (d3 >= 2.500000277905201E-7D) {
|
||||||
float f = (float) (Math.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
|
// CraftBukkit - Math -> TrigMath
|
||||||
|
float f = (float) (org.bukkit.craftbukkit.TrigMath.atan2(d1, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
|
||||||
|
|
||||||
this.a.yaw = this.a(this.a.yaw, f, 30.0F);
|
this.a.yaw = this.a(this.a.yaw, f, 30.0F);
|
||||||
this.a.e(this.e);
|
this.a.e(this.e);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.minecraft.server;
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.TrigMath; // CraftBukkit
|
||||||
|
|
||||||
public class EntitySquid extends EntityWaterAnimal {
|
public class EntitySquid extends EntityWaterAnimal {
|
||||||
|
|
||||||
public float d = 0.0F;
|
public float d = 0.0F;
|
||||||
@ -104,10 +106,12 @@ public class EntitySquid extends EntityWaterAnimal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
f = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
|
f = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
|
||||||
this.aq += (-((float) Math.atan2(this.motX, this.motZ)) * 180.0F / 3.1415927F - this.aq) * 0.1F;
|
// CraftBukkit - Math -> TrigMath
|
||||||
|
this.aq += (-((float) TrigMath.atan2(this.motX, this.motZ)) * 180.0F / 3.1415927F - this.aq) * 0.1F;
|
||||||
this.yaw = this.aq;
|
this.yaw = this.aq;
|
||||||
this.f += 3.1415927F * this.bB * 1.5F;
|
this.f += 3.1415927F * this.bB * 1.5F;
|
||||||
this.d += (-((float) Math.atan2((double) f, this.motY)) * 180.0F / 3.1415927F - this.d) * 0.1F;
|
// CraftBukkit - Math -> TrigMath
|
||||||
|
this.d += (-((float) TrigMath.atan2((double) f, this.motY)) * 180.0F / 3.1415927F - this.d) * 0.1F;
|
||||||
} else {
|
} else {
|
||||||
this.j = MathHelper.abs(MathHelper.sin(this.h)) * 3.1415927F * 0.25F;
|
this.j = MathHelper.abs(MathHelper.sin(this.h)) * 3.1415927F * 0.25F;
|
||||||
if (!this.world.isStatic) {
|
if (!this.world.isStatic) {
|
||||||
|
Loading…
Reference in New Issue
Block a user