9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-22 08:19:31 +00:00
Files
Gale/patches/server/0035-Optimize-entity-coordinate-key.patch
Dreeam a6f7132cde Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@dcbd99d Fix Owen's typos (#11179)
PaperMC/Paper@f82bea6 Add argument for FinePosition to brig API (#11094)
PaperMC/Paper@694b120 Remove Entity tracker field
PaperMC/Paper@f774787 Copy missed changes to chunk system from Folia
PaperMC/Paper@50bdfc3 Null check tracker in Entity#resendPossiblyDesyncedEntityData
PaperMC/Paper@3234b20 Do not allow chunk unloading outside of the regular tick loop
PaperMC/Paper@0246a9d Add mob bucket items to item id to entity map in DataConverter
2024-07-29 22:48:25 +08:00

50 lines
2.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Wed, 23 Nov 2022 23:32:51 +0100
Subject: [PATCH] Optimize entity coordinate key
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Optimize entity coordinate key"
By: Kevin Raneri <kevin.raneri@gmail.com>
As part of: Pufferfish (https://github.com/pufferfish-gg/Pufferfish)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Pufferfish description *
When executing getCoordinateKey for entities (a hotpath), the JVM is
required to repeatedly cast doubles to longs. The performance impact of
this depends on the CPU architecture, but generally switching between
FPU and ALU incurs a significant performance hit. The casted/rounded
data is already available in the blockPosition struct, so we use that
instead of re-doing the casting.
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/CoordinateUtils.java b/src/main/java/ca/spottedleaf/moonrise/common/util/CoordinateUtils.java
index 31b92bd48828cbea25b44a9f0f96886347aa1ae6..036c1a287db04c0191e5f84b027ea68d31447cbc 100644
--- a/src/main/java/ca/spottedleaf/moonrise/common/util/CoordinateUtils.java
+++ b/src/main/java/ca/spottedleaf/moonrise/common/util/CoordinateUtils.java
@@ -16,7 +16,7 @@ public final class CoordinateUtils {
}
public static long getChunkKey(final Entity entity) {
- return ((Mth.lfloor(entity.getZ()) >> 4) << 32) | ((Mth.lfloor(entity.getX()) >> 4) & 0xFFFFFFFFL);
+ return ((long) (entity.blockPosition.getZ() >> 4) << 32) | ((entity.blockPosition.getX() >> 4) & 0xFFFFFFFFL); // Gale - Pufferfish - optimize entity coordinate key - eliminate double->long cast in hotpath
}
public static long getChunkKey(final ChunkPos pos) {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 7349dee46483632cffa88d11694e2cd3a6fad911..8e79c569eb6b49382d1335ab8a247506db6afe95 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -315,7 +315,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public double yo;
public double zo;
private Vec3 position;
- private BlockPos blockPosition;
+ public BlockPos blockPosition; // Gale - Pufferfish - optimize entity coordinate key - private -> public
private ChunkPos chunkPosition;
private Vec3 deltaMovement;
private float yRot;