From 7ded14ad0ab1c8c64c703a035766cc80ca18726d Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 23 Mar 2013 19:08:49 +1100 Subject: [PATCH] Limit Custom Map Rendering The default CraftBukkit render sequence for maps is ridiculously slow. By only using it when a custom renderer has been added (rarely in most cases), we can fallback to the Vanilla renderer for general usage. This leads to a much higher effiency overall, especially if no plugins are rendering such maps. --- .../0045-Limit-Custom-Map-Rendering.patch | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 CraftBukkit-Patches/0045-Limit-Custom-Map-Rendering.patch diff --git a/CraftBukkit-Patches/0045-Limit-Custom-Map-Rendering.patch b/CraftBukkit-Patches/0045-Limit-Custom-Map-Rendering.patch new file mode 100644 index 0000000000..623f8fc25a --- /dev/null +++ b/CraftBukkit-Patches/0045-Limit-Custom-Map-Rendering.patch @@ -0,0 +1,86 @@ +From fe1107743148622b05f1eb1c2a6f697f3a0261a5 Mon Sep 17 00:00:00 2001 +From: md_5 +Date: Sat, 23 Mar 2013 19:08:41 +1100 +Subject: [PATCH] Limit Custom Map Rendering + +The default CraftBukkit render sequence for maps is ridiculously slow. By only using it when a custom renderer has been added (rarely in most cases), we can fallback to the Vanilla renderer for general usage. This leads to a much higher effiency overall, especially if no plugins are rendering such maps. +--- + .../net/minecraft/server/WorldMapHumanTracker.java | 25 ++++++++++++++-------- + .../org/bukkit/craftbukkit/map/CraftMapView.java | 2 +- + 2 files changed, 17 insertions(+), 10 deletions(-) + +diff --git a/src/main/java/net/minecraft/server/WorldMapHumanTracker.java b/src/main/java/net/minecraft/server/WorldMapHumanTracker.java +index bf3e6fe..c59ac18 100644 +--- a/src/main/java/net/minecraft/server/WorldMapHumanTracker.java ++++ b/src/main/java/net/minecraft/server/WorldMapHumanTracker.java +@@ -1,6 +1,7 @@ + package net.minecraft.server; + + import java.util.Iterator; ++import org.bukkit.map.MapCursor; + + public class WorldMapHumanTracker { + +@@ -41,23 +42,29 @@ public class WorldMapHumanTracker { + int i; + int j; + +- org.bukkit.craftbukkit.map.RenderData render = this.worldMap.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) trackee.getBukkitEntity()); // CraftBukkit ++ // Spigot start ++ boolean custom = this.worldMap.mapView.renderers.size() != 0; ++ org.bukkit.craftbukkit.map.RenderData render = (custom) ? this.worldMap.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) trackee.getBukkitEntity()) : null; // CraftBukkit + + if (--this.g < 0) { + this.g = 4; +- abyte = new byte[render.cursors.size() * 3 + 1]; // CraftBukkit ++ abyte = new byte[((custom) ? render.cursors.size() : this.worldMap.g.size()) * 3 + 1]; // CraftBukkit + abyte[0] = 1; + i = 0; + + // CraftBukkit start +- for (i = 0; i < render.cursors.size(); ++i) { +- org.bukkit.map.MapCursor cursor = render.cursors.get(i); +- if (!cursor.isVisible()) continue; + +- abyte[i * 3 + 1] = (byte) (cursor.getRawType() << 4 | cursor.getDirection() & 15); +- abyte[i * 3 + 2] = (byte) cursor.getX(); +- abyte[i * 3 + 3] = (byte) cursor.getY(); ++ // Spigot start ++ for (Iterator iterator = ((custom) ? render.cursors.iterator() : this.worldMap.g.values().iterator()); iterator.hasNext(); ++i) { ++ org.bukkit.map.MapCursor cursor = (custom) ? (MapCursor) iterator.next() : null; ++ if (cursor != null && !cursor.isVisible()) continue; ++ WorldMapDecoration deco = (custom) ? null : (WorldMapDecoration) iterator.next(); ++ ++ abyte[i * 3 + 1] = (byte) (((custom) ? cursor.getRawType() : deco.type) << 4 | ((custom) ? cursor.getDirection() : deco.rotation) & 15); ++ abyte[i * 3 + 2] = (byte) ((custom) ? cursor.getX() : deco.locX); ++ abyte[i * 3 + 3] = (byte) ((custom) ? cursor.getY() : deco.locY); + } ++ // Spigot end + // CraftBukkit end + + boolean flag = !itemstack.z(); +@@ -92,7 +99,7 @@ public class WorldMapHumanTracker { + abyte1[2] = (byte) j; + + for (int i1 = 0; i1 < abyte1.length - 3; ++i1) { +- abyte1[i1 + 3] = render.buffer[(i1 + j) * 128 + i]; // CraftBukkit ++ abyte1[i1 + 3] = ((custom) ? render.buffer : this.worldMap.colors)[(i1 + j) * 128 + i]; + } + + this.c[i] = -1; +diff --git a/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java b/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java +index b28d6a3..e70e4e4 100644 +--- a/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java ++++ b/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java +@@ -18,7 +18,7 @@ import org.bukkit.map.MapView; + public final class CraftMapView implements MapView { + + private final Map renderCache = new HashMap(); +- private final List renderers = new ArrayList(); ++ public final List renderers = new ArrayList(); // Spigot + private final Map> canvases = new HashMap>(); + protected final WorldMap worldMap; + +-- +1.8.1-rc2 +