diff options
author | Jake Potrebic <[email protected]> | 2024-04-26 11:39:20 -0700 |
---|---|---|
committer | Jake Potrebic <[email protected]> | 2024-04-26 11:39:20 -0700 |
commit | 44e68c301a66443d6af95a832792a9d25f873b0b (patch) | |
tree | 8d3f3c3d646f702a797853ef4868ff7c8d2d8b5a /patches/server/0953-Reduce-allocation-of-Vec3D-by-entity-tracker.patch | |
parent | cc81668863edd8ed6b382a59dd6fc002df14dea9 (diff) | |
download | Paper-44e68c301a66443d6af95a832792a9d25f873b0b.tar.gz Paper-44e68c301a66443d6af95a832792a9d25f873b0b.zip |
fix some more issues
Diffstat (limited to 'patches/server/0953-Reduce-allocation-of-Vec3D-by-entity-tracker.patch')
-rw-r--r-- | patches/server/0953-Reduce-allocation-of-Vec3D-by-entity-tracker.patch | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/patches/server/0953-Reduce-allocation-of-Vec3D-by-entity-tracker.patch b/patches/server/0953-Reduce-allocation-of-Vec3D-by-entity-tracker.patch new file mode 100644 index 0000000000..dc2cbd7a08 --- /dev/null +++ b/patches/server/0953-Reduce-allocation-of-Vec3D-by-entity-tracker.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Spottedleaf <[email protected]> +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/network/protocol/game/VecDeltaCodec.java b/src/main/java/net/minecraft/network/protocol/game/VecDeltaCodec.java +index a3d247c93ac1a2d872ff0e3841efc3d7b84fcbc1..23fe7c4c1844d321efed6b7b886c422761ad6594 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 org.jetbrains.annotations.VisibleForTesting; + + public class VecDeltaCodec { + private static final double TRUNCATION_STEPS = 4096.0; +- private Vec3 base = Vec3.ZERO; ++ public Vec3 base = Vec3.ZERO; // Paper + + @VisibleForTesting + static long encode(double value) { +diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java +index 027f2734b0ff226437f4c94430215929b6ea2219..35f627c58e93c03ee58b44877398432bba57dc2d 100644 +--- a/src/main/java/net/minecraft/server/level/ChunkMap.java ++++ b/src/main/java/net/minecraft/server/level/ChunkMap.java +@@ -1748,10 +1748,14 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider + 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 + int i = ChunkMap.this.getPlayerViewDistance(player); + double d0 = (double) Math.min(this.getEffectiveRange(), i * 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) && ChunkMap.this.isChunkTracked(player, this.entity.chunkPosition().x, this.entity.chunkPosition().z); + // Paper start - Configurable entity tracking range by Y +diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java +index 0373b2de2b992b648f346d6df3960a3586a54567..22eec853588ded2d255ab69d408f8e987832abe2 100644 +--- a/src/main/java/net/minecraft/server/level/ServerEntity.java ++++ b/src/main/java/net/minecraft/server/level/ServerEntity.java +@@ -164,7 +164,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; |