From 8e183b0da664e192b70c0b86e430872939963db4 Mon Sep 17 00:00:00 2001 From: Barnaby <22575741+barnabwhy@users.noreply.github.com> Date: Wed, 10 Jul 2024 00:03:32 +0100 Subject: [PATCH] Remove bitwise thing+ Small optimisation --- ...-in-CraftMapCanvas.drawImage-by-limi.patch | 55 +++++++------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/patches/server/1029-Reduce-work-done-in-CraftMapCanvas.drawImage-by-limi.patch b/patches/server/1029-Reduce-work-done-in-CraftMapCanvas.drawImage-by-limi.patch index 0a74f4f8c15ad..81c7b52685990 100644 --- a/patches/server/1029-Reduce-work-done-in-CraftMapCanvas.drawImage-by-limi.patch +++ b/patches/server/1029-Reduce-work-done-in-CraftMapCanvas.drawImage-by-limi.patch @@ -7,44 +7,10 @@ Subject: [PATCH] Reduce work done in CraftMapCanvas.drawImage by limiting size diff --git a/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java b/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java -index ff59f759669620795ef355c988b664bdcda39f52..54a3c1cea840f45385f1102988f8d2c8c415127b 100644 +index ff59f759669620795ef355c988b664bdcda39f52..a5e98571d6d83390761c11e28a0bc3c4415799cd 100644 --- a/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java +++ b/src/main/java/org/bukkit/craftbukkit/map/CraftMapCanvas.java -@@ -59,8 +59,10 @@ public class CraftMapCanvas implements MapCanvas { - - @Override - public void setPixel(int x, int y, byte color) { -- if (x < 0 || y < 0 || x >= 128 || y >= 128) -+ // Paper start - Optimise bounds check using bitwise operations -+ if ((x & -128) != 0 || (y & -128) != 0) - return; -+ // Paper end - if (this.buffer[y * 128 + x] != color) { - this.buffer[y * 128 + x] = color; - this.mapView.worldMap.setColorsDirty(x, y); -@@ -69,15 +71,19 @@ public class CraftMapCanvas implements MapCanvas { - - @Override - public byte getPixel(int x, int y) { -- if (x < 0 || y < 0 || x >= 128 || y >= 128) -+ // Paper start - Optimise bounds check using bitwise operations -+ if ((x & -128) != 0 || (y & -128) != 0) - return 0; -+ // Paper end - return this.buffer[y * 128 + x]; - } - - @Override - public byte getBasePixel(int x, int y) { -- if (x < 0 || y < 0 || x >= 128 || y >= 128) -+ // Paper start - Optimise bounds check using bitwise operations -+ if ((x & -128) != 0 || (y & -128) != 0) - return 0; -+ // Paper end - return this.base[y * 128 + x]; - } - -@@ -91,12 +97,41 @@ public class CraftMapCanvas implements MapCanvas { +@@ -91,12 +91,41 @@ public class CraftMapCanvas implements MapCanvas { @Override public void drawImage(int x, int y, Image image) { @@ -90,3 +56,20 @@ index ff59f759669620795ef355c988b664bdcda39f52..54a3c1cea840f45385f1102988f8d2c8 } @Override +diff --git a/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java b/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java +index 0cbbd915631904fe8c6effefb92895422b33eff6..cf0920e5f84b35647882fb963e9972af4e8427e0 100644 +--- a/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java ++++ b/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java +@@ -23,8 +23,10 @@ public class CraftMapRenderer extends MapRenderer { + @Override + public void render(MapView map, MapCanvas canvas, Player player) { + // Map +- for (int x = 0; x < 128; ++x) { +- for (int y = 0; y < 128; ++y) { ++ // Paper start - Swap inner and outer loops here to (theoretically) improve cache locality ++ for (int y = 0; y < 128; ++y) { ++ for (int x = 0; x < 128; ++x) { ++ // Paper end + canvas.setPixel(x, y, this.worldMap.colors[y * 128 + x]); + } + }