Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/Spigot-Server-Patches/0246-Improve-Structures-Checking.patch
Zach Brown 6f2009754d
Stop explicitly blocking Vanilla Method Profiler
At the time this was re-added, there was concern around how the JIT
would handle the system property that enabled it.

This shouldn't be a problem, and as such we no longer need to block
access to it.

The Vanilla Method Profiler will not provide much to most users however
there is no harm in providing it as an option. For most users, the
recommended and supported method for determining performance issues with
Paper will continue to be Timings.
2018-03-31 14:55:42 -04:00

200 Zeilen
8.8 KiB
Diff

From 2de082f53860d4623c135b9c1f8daf6cb161a32b Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 11 Nov 2017 17:57:39 -0500
Subject: [PATCH] Improve Structures Checking
Improves performance by keying every chunk thats part of a structure to a hashmap
instead of only the first one.
This allows us to avoid iterating the entire structures value set to see
if a block position is inside of a structure.
This should have pretty decent performance improvement to any standard world
that has been around for a whilewith lots of structures due to ineffeciencies
in how MC stores structures (even unloaded chunks has structured data loaded)
diff --git a/src/main/java/net/minecraft/server/StructureBoundingBox.java b/src/main/java/net/minecraft/server/StructureBoundingBox.java
index db419cd9..d9329bd4 100644
--- a/src/main/java/net/minecraft/server/StructureBoundingBox.java
+++ b/src/main/java/net/minecraft/server/StructureBoundingBox.java
@@ -4,12 +4,14 @@ import com.google.common.base.MoreObjects;
public class StructureBoundingBox {
- public int a;
- public int b;
- public int c;
- public int d;
- public int e;
- public int f;
+ public int a; // Paper - If changes, verify low/high getters
+ public int b; // Paper - If changes, verify low/high getters
+ public int c; // Paper - If changes, verify low/high getters
+ public int d; // Paper - If changes, verify low/high getters
+ public int e; // Paper - If changes, verify low/high getters
+ public int f; // Paper - If changes, verify low/high getters
+ public BaseBlockPosition getLowPosition() { return new BaseBlockPosition(a, b, c); } // Paper
+ public BaseBlockPosition getHighPosition() { return new BaseBlockPosition(d, e, f); } // Paper
public StructureBoundingBox() {}
@@ -114,6 +116,7 @@ public class StructureBoundingBox {
this.f += k;
}
+ public boolean contains(BaseBlockPosition baseblockposition) { return b(baseblockposition); } // Paper - OBFHELPER
public boolean b(BaseBlockPosition baseblockposition) {
return baseblockposition.getX() >= this.a && baseblockposition.getX() <= this.d && baseblockposition.getZ() >= this.c && baseblockposition.getZ() <= this.f && baseblockposition.getY() >= this.b && baseblockposition.getY() <= this.e;
}
diff --git a/src/main/java/net/minecraft/server/StructureGenerator.java b/src/main/java/net/minecraft/server/StructureGenerator.java
index e8263baa..f4dfba8f 100644
--- a/src/main/java/net/minecraft/server/StructureGenerator.java
+++ b/src/main/java/net/minecraft/server/StructureGenerator.java
@@ -6,6 +6,7 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import java.util.Iterator;
+import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
@@ -14,6 +15,7 @@ public abstract class StructureGenerator extends WorldGenBase {
private final Timing timing = MinecraftTimings.getStructureTiming(this); // Paper
private PersistentStructure a;
protected Long2ObjectMap<StructureStart> c = new Long2ObjectOpenHashMap(1024);
+ protected Long2ObjectMap<StructureStart> allStructures = new Long2ObjectOpenHashMap(1024); // Paper - Holds ref to structures for every chunk its part of, where as the one above this only holds the vanilla oriented ones.
public StructureGenerator() {}
@@ -29,6 +31,7 @@ public abstract class StructureGenerator extends WorldGenBase {
if (this.a(i, j)) {
StructureStart structurestart = this.b(i, j);
+ populateStructure(structurestart); // Paper
this.c.put(ChunkCoordIntPair.a(i, j), structurestart);
if (structurestart.a()) {
this.a(i, j, structurestart);
@@ -106,6 +109,19 @@ public abstract class StructureGenerator extends WorldGenBase {
@Nullable
protected StructureStart c(BlockPosition blockposition) {
+ // Paper start - replace method
+ StructureStart structureStart = allStructures.get(ChunkCoordIntPair.asLong(blockposition));
+ if (structureStart != null && structureStart.isSizeable() && structureStart.getBoundingBox().contains(blockposition)) {
+ List<StructurePiece> structurePieces = structureStart.getStructurePieces();
+ for (StructurePiece piece : structurePieces) {
+ if (piece.getBoundingBox().contains(blockposition)) {
+ return structureStart;
+ }
+ }
+ }
+
+ return null;
+ /*
ObjectIterator objectiterator = this.c.values().iterator();
while (objectiterator.hasNext()) {
@@ -125,11 +141,16 @@ public abstract class StructureGenerator extends WorldGenBase {
}
return null;
+ */
}
public boolean a(World world, BlockPosition blockposition) {
if (this.g == null) return false; // Paper
this.a(world);
+ // Paper start - Replace method
+ StructureStart structureStart = this.allStructures.get(ChunkCoordIntPair.asLong(blockposition));
+ return structureStart != null && structureStart.isSizeable() && structureStart.getBoundingBox().contains(blockposition);
+ /* // comment out rest
ObjectIterator objectiterator = this.c.values().iterator();
StructureStart structurestart;
@@ -142,7 +163,7 @@ public abstract class StructureGenerator extends WorldGenBase {
structurestart = (StructureStart) objectiterator.next();
} while (!structurestart.a() || !structurestart.b().b((BaseBlockPosition) blockposition));
- return true;
+ return true;*/ // Paper end
}
@Nullable
@@ -177,6 +198,7 @@ public abstract class StructureGenerator extends WorldGenBase {
StructureStart structurestart = WorldGenFactory.a(nbttagcompound1, world);
if (structurestart != null) {
+ populateStructure(structurestart); // Paper
this.c.put(ChunkCoordIntPair.a(i, j), structurestart);
}
}
@@ -187,6 +209,27 @@ public abstract class StructureGenerator extends WorldGenBase {
}
+ // Paper start
+ private void populateStructure(StructureStart structurestart) {
+ for (StructurePiece piece : structurestart.getStructurePieces()) {
+ populateStructure(structurestart, piece.getBoundingBox());
+ }
+ populateStructure(structurestart, structurestart.getBoundingBox());
+ }
+ private void populateStructure(StructureStart structurestart, StructureBoundingBox bb) {
+ if (bb == null) {
+ return;
+ }
+ final BaseBlockPosition low = bb.getLowPosition();
+ final BaseBlockPosition high = bb.getHighPosition();
+ for (int x = low.getX() >> 4, maxX = high.getX() >> 4; x <= maxX; x++) {
+ for (int z = low.getZ() >> 4, maxZ = high.getZ() >> 4; z <= maxZ; z++) {
+ allStructures.put(ChunkCoordIntPair.asLong(x, z), structurestart);
+ }
+ }
+ }
+ // Paper end
+
private void a(int i, int j, StructureStart structurestart) {
this.a.a(structurestart.a(i, j), i, j);
this.a.c();
diff --git a/src/main/java/net/minecraft/server/StructurePiece.java b/src/main/java/net/minecraft/server/StructurePiece.java
index 93903bc6..fcc13f81 100644
--- a/src/main/java/net/minecraft/server/StructurePiece.java
+++ b/src/main/java/net/minecraft/server/StructurePiece.java
@@ -53,6 +53,7 @@ public abstract class StructurePiece {
public abstract boolean a(World world, Random random, StructureBoundingBox structureboundingbox);
+ public StructureBoundingBox getBoundingBox() { return d(); } // Paper - OBFHELPER
public StructureBoundingBox d() {
return this.l;
}
diff --git a/src/main/java/net/minecraft/server/StructureStart.java b/src/main/java/net/minecraft/server/StructureStart.java
index b6abc74e..f9bb953d 100644
--- a/src/main/java/net/minecraft/server/StructureStart.java
+++ b/src/main/java/net/minecraft/server/StructureStart.java
@@ -19,10 +19,12 @@ public abstract class StructureStart {
this.d = j;
}
+ public StructureBoundingBox getBoundingBox() { return b(); } // Paper - OBFHELPER
public StructureBoundingBox b() {
return this.b;
}
+ public List<StructurePiece> getStructurePieces() { return c(); } // Paper - OBFHELPER
public List<StructurePiece> c() {
return this.a;
}
@@ -137,7 +139,7 @@ public abstract class StructureStart {
}
- public boolean a() {
+ public boolean isSizeable() { return a(); } public boolean a() { // Paper - OBFHELPER
return true;
}
--
2.14.3