2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Byteflux <byte@byteflux.net>
|
|
|
|
Date: Wed, 2 Mar 2016 11:59:48 -0600
|
|
|
|
Subject: [PATCH] Optimize explosions
|
|
|
|
|
|
|
|
The process of determining an entity's exposure from explosions can be
|
|
|
|
expensive when there are hundreds or more entities in range.
|
|
|
|
|
|
|
|
This patch adds a per-tick cache that is used for storing and retrieving
|
|
|
|
an entity's exposure during an explosion.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2023-03-14 19:36:39 +01:00
|
|
|
index 19d7a4da730cf260407d6216b8dbba958ec8f84c..efa4db568cf5189a3a83beb137748f57b34ca6e4 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2023-03-14 19:36:39 +01:00
|
|
|
@@ -1406,6 +1406,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
this.profiler.pop();
|
|
|
|
this.profiler.pop();
|
|
|
|
+ worldserver.explosionDensityCache.clear(); // Paper - Optimize explosions
|
|
|
|
}
|
|
|
|
|
|
|
|
this.profiler.popPush("connection");
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Explosion.java b/src/main/java/net/minecraft/world/level/Explosion.java
|
2023-03-14 19:36:39 +01:00
|
|
|
index 594ac935ae8f77fc16be90ac178581cbdfc65eb7..d21422dfac366037398101626d7d33640725f018 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/Explosion.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Explosion.java
|
2022-12-07 19:32:25 +01:00
|
|
|
@@ -221,7 +221,7 @@ public class Explosion {
|
2021-06-11 14:02:28 +02:00
|
|
|
d8 /= d11;
|
|
|
|
d9 /= d11;
|
|
|
|
d10 /= d11;
|
2021-06-12 00:37:16 +02:00
|
|
|
- double d12 = (double) Explosion.getSeenPercent(vec3d, entity);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ double d12 = this.getBlockDensity(vec3d, entity); // Paper - Optimize explosions
|
|
|
|
double d13 = (1.0D - d7) * d12;
|
|
|
|
|
|
|
|
// CraftBukkit start
|
2023-03-14 19:36:39 +01:00
|
|
|
@@ -503,4 +503,84 @@ public class Explosion {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
private BlockInteraction() {}
|
|
|
|
}
|
|
|
|
+ // Paper start - Optimize explosions
|
|
|
|
+ private float getBlockDensity(Vec3 vec3d, Entity entity) {
|
2022-06-09 10:51:45 +02:00
|
|
|
+ if (!this.level.paperConfig().environment.optimizeExplosions) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return getSeenPercent(vec3d, entity);
|
|
|
|
+ }
|
|
|
|
+ CacheKey key = new CacheKey(this, entity.getBoundingBox());
|
|
|
|
+ Float blockDensity = this.level.explosionDensityCache.get(key);
|
|
|
|
+ if (blockDensity == null) {
|
|
|
|
+ blockDensity = getSeenPercent(vec3d, entity);
|
|
|
|
+ this.level.explosionDensityCache.put(key, blockDensity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return blockDensity;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static class CacheKey {
|
|
|
|
+ private final Level world;
|
|
|
|
+ private final double posX, posY, posZ;
|
|
|
|
+ private final double minX, minY, minZ;
|
|
|
|
+ private final double maxX, maxY, maxZ;
|
|
|
|
+
|
|
|
|
+ public CacheKey(Explosion explosion, AABB aabb) {
|
|
|
|
+ this.world = explosion.level;
|
|
|
|
+ this.posX = explosion.x;
|
|
|
|
+ this.posY = explosion.y;
|
|
|
|
+ this.posZ = explosion.z;
|
|
|
|
+ this.minX = aabb.minX;
|
|
|
|
+ this.minY = aabb.minY;
|
|
|
|
+ this.minZ = aabb.minZ;
|
|
|
|
+ this.maxX = aabb.maxX;
|
|
|
|
+ this.maxY = aabb.maxY;
|
|
|
|
+ this.maxZ = aabb.maxZ;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean equals(Object o) {
|
|
|
|
+ if (this == o) return true;
|
|
|
|
+ if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
+
|
|
|
|
+ CacheKey cacheKey = (CacheKey) o;
|
|
|
|
+
|
|
|
|
+ if (Double.compare(cacheKey.posX, posX) != 0) return false;
|
|
|
|
+ if (Double.compare(cacheKey.posY, posY) != 0) return false;
|
|
|
|
+ if (Double.compare(cacheKey.posZ, posZ) != 0) return false;
|
|
|
|
+ if (Double.compare(cacheKey.minX, minX) != 0) return false;
|
|
|
|
+ if (Double.compare(cacheKey.minY, minY) != 0) return false;
|
|
|
|
+ if (Double.compare(cacheKey.minZ, minZ) != 0) return false;
|
|
|
|
+ if (Double.compare(cacheKey.maxX, maxX) != 0) return false;
|
|
|
|
+ if (Double.compare(cacheKey.maxY, maxY) != 0) return false;
|
|
|
|
+ if (Double.compare(cacheKey.maxZ, maxZ) != 0) return false;
|
|
|
|
+ return world.equals(cacheKey.world);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int hashCode() {
|
|
|
|
+ int result;
|
|
|
|
+ long temp;
|
|
|
|
+ result = world.hashCode();
|
|
|
|
+ temp = Double.doubleToLongBits(posX);
|
|
|
|
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
|
|
+ temp = Double.doubleToLongBits(posY);
|
|
|
|
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
|
|
+ temp = Double.doubleToLongBits(posZ);
|
|
|
|
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
|
|
+ temp = Double.doubleToLongBits(minX);
|
|
|
|
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
|
|
+ temp = Double.doubleToLongBits(minY);
|
|
|
|
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
|
|
+ temp = Double.doubleToLongBits(minZ);
|
|
|
|
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
|
|
+ temp = Double.doubleToLongBits(maxX);
|
|
|
|
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
|
|
+ temp = Double.doubleToLongBits(maxY);
|
|
|
|
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
|
|
+ temp = Double.doubleToLongBits(maxZ);
|
|
|
|
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
2023-03-14 19:36:39 +01:00
|
|
|
index 537ce62ba966cc5765b9e7e48e1ba043fa1a6df9..ad42b1f9dae76a507a6eca51d096b7774905f623 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
2023-03-14 19:36:39 +01:00
|
|
|
@@ -168,6 +168,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
2021-06-11 14:02:28 +02:00
|
|
|
private org.spigotmc.TickLimiter entityLimiter;
|
|
|
|
private org.spigotmc.TickLimiter tileLimiter;
|
|
|
|
private int tileTickPosition;
|
|
|
|
+ public final Map<Explosion.CacheKey, Float> explosionDensityCache = new HashMap<>(); // Paper - Optimize explosions
|
|
|
|
|
|
|
|
public CraftWorld getWorld() {
|
|
|
|
return this.world;
|