From 515fb1f4d1bb7eef69610e6cc7360284590b3618 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 22 Apr 2019 01:04:01 +0200 Subject: [PATCH] Server version independence, deps Hopefully made the renderer version-independent --- .../dependency-reduced-pom.xml | 6 ----- VirtualComputer-Core/pom.xml | 14 ++-------- .../virtualcomputer/renderer/GPURenderer.java | 27 ++++++++++++++----- VirtualComputerMSCOM/pom.xml | 8 ++++++ VirtualComputerXPCOM/pom.xml | 7 +++++ 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/VirtualComputer-Core/dependency-reduced-pom.xml b/VirtualComputer-Core/dependency-reduced-pom.xml index 91f01b0..3a2283f 100644 --- a/VirtualComputer-Core/dependency-reduced-pom.xml +++ b/VirtualComputer-Core/dependency-reduced-pom.xml @@ -134,12 +134,6 @@ 6.0 compile - - org.bukkit - craftbukkit - 1.12.2-R0.1-SNAPSHOT - provided - diff --git a/VirtualComputer-Core/pom.xml b/VirtualComputer-Core/pom.xml index 5645b7b..f5234f1 100644 --- a/VirtualComputer-Core/pom.xml +++ b/VirtualComputer-Core/pom.xml @@ -51,22 +51,12 @@ 1.12-R0.1-SNAPSHOT provided - - org.virtualbox - VirtualBox - 6.0 - - - org.virtualbox - VirtualBox-MSCOM - 6.0 - - + net.java.dev.jna diff --git a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/renderer/GPURenderer.java b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/renderer/GPURenderer.java index 2bdfe3b..a45b96e 100644 --- a/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/renderer/GPURenderer.java +++ b/VirtualComputer-Core/src/main/java/sznp/virtualcomputer/renderer/GPURenderer.java @@ -1,6 +1,6 @@ package sznp.virtualcomputer.renderer; -import net.minecraft.server.v1_12_R1.WorldMap; +import lombok.val; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.map.MapCanvas; @@ -10,18 +10,22 @@ import org.bukkit.map.MapView; import sznp.virtualcomputer.PluginMain; import sznp.virtualcomputer.util.Timing; +import java.awt.*; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.function.BiConsumer; public class GPURenderer extends MapRenderer implements IRenderer { private byte[] buffer; private final GPURendererInternal kernel; - private WorldMap wmap; private int mapx, mapy; //Store at central location after conversion private static int[] colors_; private int changedX = 0, changedY = 0, changedWidth = 640, changedHeight = 480; + private BiConsumer flagDirty; //This way it's version independent, as long as it's named the same private static ArrayList renderers = new ArrayList<>(); + private static Method flagDirtyMethod; public GPURenderer(short id, World world, int mapx, int mapy) throws Exception { MapView map = IRenderer.prepare(id, world); @@ -43,7 +47,16 @@ public class GPURenderer extends MapRenderer implements IRenderer { this.mapy = mapy; Field field = map.getClass().getDeclaredField("worldMap"); field.setAccessible(true); - wmap = (WorldMap) field.get(map); + val wmap = field.get(map); + if (flagDirtyMethod == null) + flagDirtyMethod = wmap.getClass().getMethod("flagDirty", int.class, int.class); + flagDirty = (x, y) -> { + try { + flagDirtyMethod.invoke(wmap, x, y); + } catch (Exception e) { + e.printStackTrace(); + } + }; kernel = new GPURendererInternal(mapx, mapy, colors_); renderers.add(this); @@ -78,16 +91,16 @@ public class GPURenderer extends MapRenderer implements IRenderer { int yy = y + changedHeight >= 128 ? 127 : y + changedHeight; //System.out.println("local: ("+x+", "+y+") "+w+"x"+h); kernel.render(buffer); - wmap.flagDirty(x, y); - wmap.flagDirty(xx, yy); // Send the changes only + flagDirty.accept(x, y); + flagDirty.accept(xx, yy); // Send the changes only changedX = Integer.MAX_VALUE; //Finished rendering changedY = Integer.MAX_VALUE; //TODO: Render as soon as we receive new image changedWidth = -1; //Finished rendering changedHeight = -1; } else { kernel.render(buffer); - wmap.flagDirty(0, 0); - wmap.flagDirty(127, 127); // Send everything + flagDirty.accept(0, 0); + flagDirty.accept(127, 127); // Send everything } } catch (Exception e) { e.printStackTrace(); diff --git a/VirtualComputerMSCOM/pom.xml b/VirtualComputerMSCOM/pom.xml index 1eff82e..49668ac 100644 --- a/VirtualComputerMSCOM/pom.xml +++ b/VirtualComputerMSCOM/pom.xml @@ -14,4 +14,12 @@ 2.1-SNAPSHOT + + + org.virtualbox + VirtualBox-MSCOM + 6.0 + + + \ No newline at end of file diff --git a/VirtualComputerXPCOM/pom.xml b/VirtualComputerXPCOM/pom.xml index bb25a5d..9135c5f 100644 --- a/VirtualComputerXPCOM/pom.xml +++ b/VirtualComputerXPCOM/pom.xml @@ -11,5 +11,12 @@ VirtualComputer-XPCOM + + + org.virtualbox + VirtualBox + 6.0 + + \ No newline at end of file