mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 08:06:41 +01:00
58 lines
3.8 KiB
Diff
58 lines
3.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
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 05ac41e136da43284fb24a6b698ebd36318278fb..5ca3ad7b3d7606accd0a58b3c708fadb349608f7 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.0D;
|
|
- 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 eb08e086ee57a41de550dbae130a7d68562e1728..1da687083a52b97b6245185eb2e73380da5ae8fd 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
@@ -1337,9 +1337,13 @@ 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
|
|
double d0 = (double) Math.min(this.getEffectiveRange(), io.papermc.paper.chunk.PlayerChunkLoader.getSendViewDistance(player) * 16); // Paper - per player view distance
|
|
- 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);
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
index 841bb7741ae6b0e9cb98120ee1649b93ef4c3dab..4ebe6bdc01b2d80fc84ba31aae9eb9ac26339436 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
@@ -152,7 +152,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;
|