Reduce allocation of Vec3D by entity tracker

This commit is contained in:
Spottedleaf
2020-04-27 00:04:16 -07:00
parent 0449ede4a6
commit 46c2fbfb74
3 changed files with 39 additions and 14 deletions

View File

@@ -86,7 +86,22 @@
worldmap.tickCarriedBy(entityplayer, itemstack);
Packet<?> packet = worldmap.getUpdatePacket(mapid, entityplayer);
@@ -248,6 +258,27 @@
@@ -168,7 +178,13 @@
++this.teleportDelay;
Vec3 vec3d = this.entity.trackingPosition();
- boolean flag1 = this.positionCodec.delta(vec3d).lengthSqr() >= 7.62939453125E-6D;
+ // Paper start - reduce allocation of Vec3D here
+ Vec3 base = this.positionCodec.base;
+ double vec3d_dx = vec3d.x - base.x;
+ double vec3d_dy = vec3d.y - base.y;
+ double vec3d_dz = vec3d.z - base.z;
+ boolean flag1 = (vec3d_dx * vec3d_dx + vec3d_dy * vec3d_dy + vec3d_dz * vec3d_dz) >= 7.62939453125E-6D;
+ // Paper end - reduce allocation of Vec3D here
Packet<?> packet1 = null;
boolean flag2 = flag1 || this.tickCount % 60 == 0;
boolean flag3 = false;
@@ -248,6 +264,27 @@
++this.tickCount;
if (this.entity.hurtMarked) {
@@ -114,7 +129,7 @@
this.entity.hurtMarked = false;
this.broadcastAndSend(new ClientboundSetEntityMotionPacket(this.entity));
}
@@ -298,7 +329,10 @@
@@ -298,7 +335,10 @@
public void sendPairingData(ServerPlayer player, Consumer<Packet<ClientGamePacketListener>> sender) {
if (this.entity.isRemoved()) {
@@ -126,7 +141,7 @@
}
Packet<ClientGamePacketListener> packet = this.entity.getAddEntityPacket(this);
@@ -313,6 +347,12 @@
@@ -313,6 +353,12 @@
if (this.entity instanceof LivingEntity) {
Collection<AttributeInstance> collection = ((LivingEntity) this.entity).getAttributes().getSyncableAttributes();
@@ -139,7 +154,7 @@
if (!collection.isEmpty()) {
sender.accept(new ClientboundUpdateAttributesPacket(this.entity.getId(), collection));
}
@@ -344,6 +384,7 @@
@@ -344,6 +390,7 @@
if (!list.isEmpty()) {
sender.accept(new ClientboundSetEquipmentPacket(this.entity.getId(), list));
}
@@ -147,7 +162,7 @@
}
if (!this.entity.getPassengers().isEmpty()) {
@@ -396,6 +437,11 @@
@@ -396,6 +443,11 @@
Set<AttributeInstance> set = ((LivingEntity) this.entity).getAttributes().getAttributesToSync();
if (!set.isEmpty()) {