2022-06-08 07:02:19 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-06-11 10:30:20 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
|
|
|
|
index 3167f5c6be39757e3cc42cbb17ab0cf13a2fe470..3768a71491ef7836b9739bdaec7a077c523dbacd 100644
|
|
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java
|
|
|
|
@@ -5,7 +5,7 @@ import net.minecraft.world.phys.Vec3;
|
|
|
|
|
|
|
|
public class VecDeltaCodec {
|
|
|
|
private static final double TRUNCATION_STEPS = 4096.0D;
|
|
|
|
- private Vec3 base = Vec3.ZERO;
|
|
|
|
+ public Vec3 base = Vec3.ZERO; // Paper
|
|
|
|
|
|
|
|
private static long encode(double value) {
|
|
|
|
return Mth.lfloor(value * 4096.0D);
|
2022-06-08 07:02:19 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
2022-09-01 18:51:59 +02:00
|
|
|
index ea224e68b680c5e9ab38998f7709a4dbe3471b86..82eceddc15dcdf592dc5bbe6f1249f537be0a91e 100644
|
2022-06-08 07:02:19 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
2022-09-01 18:51:59 +02:00
|
|
|
@@ -2040,9 +2040,13 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
2022-06-08 07:02:19 +02:00
|
|
|
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());
|
|
|
|
+ // Paper start - remove allocation of Vec3D here
|
|
|
|
+ // Vec3 vec3d = player.position().subtract(this.entity.position());
|
|
|
|
+ double vec3d_dx = player.getX() - this.entity.getX();
|
|
|
|
+ double vec3d_dz = player.getZ() - this.entity.getZ();
|
|
|
|
+ // Paper end - remove allocation of Vec3D here
|
|
|
|
double d0 = (double) Math.min(this.getEffectiveRange(), (ChunkMap.this.viewDistance - 1) * 16);
|
|
|
|
- double d1 = vec3d.x * vec3d.x + vec3d.z * vec3d.z;
|
|
|
|
+ double d1 = vec3d_dx * vec3d_dx + vec3d_dz * vec3d_dz; // Paper
|
|
|
|
double d2 = d0 * d0;
|
|
|
|
boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(player);
|
|
|
|
|
2022-06-11 10:30:20 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
|
|
index 7881176a900daa3306c691454f688c1f79b73475..ddc5b4849939a96b76611cfa1cd34c06c7acc0f8 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
|
|
@@ -147,7 +147,13 @@ public class ServerEntity {
|
|
|
|
i = Mth.floor(this.entity.getYRot() * 256.0F / 360.0F);
|
|
|
|
j = Mth.floor(this.entity.getXRot() * 256.0F / 360.0F);
|
|
|
|
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 = Math.abs(i - this.yRotp) >= 1 || Math.abs(j - this.xRotp) >= 1;
|