PaperMC/patches/server-remapped/0481-Reduce-allocation-of-Vec3D-by-entity-tracker.patch
Mariell Hoversholm a207d14a0e
Rename all patches to correct numbering scheme
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
2021-06-11 15:46:44 +02:00

69 lines
5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <spottedleaf@spottedleaf.dev>
Date: Mon, 27 Apr 2020 00:04:16 -0700
Subject: [PATCH] Reduce allocation of Vec3D by entity tracker
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 67f748d5955453ba4873b0c9bb741b5bfe52d655..738f1183ce663db7c67d2f0289823390a7f06a0e 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -95,7 +95,6 @@ import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.storage.DimensionDataStorage;
import net.minecraft.world.level.storage.LevelStorageSource;
-import net.minecraft.world.phys.Vec3;
import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet; // Paper
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.logging.log4j.LogManager;
@@ -2233,9 +2232,14 @@ Sections go from 0..16. Now whenever a section is not empty, it can potentially
public void updatePlayer(ServerPlayer player) {
org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
if (player != this.entity) {
- Vec3 vec3d = player.position().subtract(this.entity.position()); // MC-155077, SPIGOT-5113
+ // Paper start - remove allocation of Vec3D here
+ //Vec3D vec3d = entityplayer.getPositionVector().d(this.tracker.getPositionVector()); // MC-155077, SPIGOT-5113
+ double vec3d_dx = player.getX() - this.entity.getX();
+ double vec3d_dy = player.getY() - this.entity.getY();
+ double vec3d_dz = player.getZ() - this.entity.getZ();
+ // Paper end - remove allocation of Vec3D here
int i = Math.min(this.getEffectiveRange(), (ChunkMap.this.viewDistance - 1) * 16);
- boolean flag = vec3d.x >= (double) (-i) && vec3d.x <= (double) i && vec3d.z >= (double) (-i) && vec3d.z <= (double) i && this.entity.broadcastToPlayer(player);
+ boolean flag = vec3d_dx >= (double) (-i) && vec3d_dx <= (double) i && vec3d_dz >= (double) (-i) && vec3d_dz <= (double) i && this.entity.broadcastToPlayer(player); // Paper - remove allocation of Vec3D here
if (flag) {
boolean flag1 = this.entity.forcedLoading;
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
index d797873db52ba265ac4478f9f3c6344badd4739e..75e2274578c2c28de3d786372df0b4102337a2cc 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
@@ -154,8 +154,12 @@ public class ServerEntity {
++this.teleportDelay;
i = Mth.floor(this.entity.yRot * 256.0F / 360.0F);
j = Mth.floor(this.entity.xRot * 256.0F / 360.0F);
- Vec3 vec3d = this.entity.position().subtract(ClientboundMoveEntityPacket.packetToEntity(this.xp, this.yp, this.zp));
- boolean flag1 = vec3d.lengthSqr() >= 7.62939453125E-6D;
+ // Paper start - reduce allocation of Vec3D here
+ double vec3d_dx = this.entity.getX() - 2.44140625E-4D*(this.xp);
+ double vec3d_dy = this.entity.getY() - 2.44140625E-4D*(this.yp);
+ double vec3d_dz = this.entity.getZ() - 2.44140625E-4D*(this.zp);
+ 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 = Math.abs(i - this.yRotp) >= 1 || Math.abs(j - this.xRotp) >= 1;
@@ -172,9 +176,11 @@ public class ServerEntity {
// CraftBukkit end
if (this.tickCount > 0 || this.entity instanceof AbstractArrow) {
- long k = ClientboundMoveEntityPacket.entityToPacket(vec3d.x);
- long l = ClientboundMoveEntityPacket.entityToPacket(vec3d.y);
- long i1 = ClientboundMoveEntityPacket.entityToPacket(vec3d.z);
+ // Paper start - remove allocation of Vec3D here
+ long k = ClientboundMoveEntityPacket.entityToPacket(vec3d_dx);
+ long l = ClientboundMoveEntityPacket.entityToPacket(vec3d_dy);
+ long i1 = ClientboundMoveEntityPacket.entityToPacket(vec3d_dz);
+ // Paper end - remove allocation of Vec3D here
boolean flag4 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i1 < -32768L || i1 > 32767L;
if (!flag4 && this.teleportDelay <= 400 && !this.wasRiding && this.wasOnGround == this.entity.isOnGround()) {