Still no display

This commit is contained in:
Norbi Peti 2018-06-16 01:55:42 +02:00
parent a888795be5
commit 123bce5027
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
6 changed files with 67 additions and 48 deletions

View file

@ -39,13 +39,7 @@
<goals> <goals>
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
<configuration> <configuration />
<pluginExecution>
<action>
<execute />
</action>
</pluginExecution>
</configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>

View file

@ -41,11 +41,6 @@
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
<configuration> <configuration>
<pluginExecution>
<action>
<execute />
</action>
</pluginExecution>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>

View file

@ -1,16 +1,16 @@
package sznp.virtualcomputer; package sznp.virtualcomputer;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas; import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapRenderer; import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView; import org.bukkit.map.MapView;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
public class BukkitRenderer extends MapRenderer implements IRenderer { public class BukkitRenderer extends MapRenderer implements IRenderer {
private ByteBuffer allpixels; private ByteBuffer allpixels;
private BufferedImage image; private BufferedImage image;
@ -54,7 +54,7 @@ public class BukkitRenderer extends MapRenderer implements IRenderer {
for (int i = startindex, j = 0; i < startindex + 128 * 128; i = i + 4, j++) { for (int i = startindex, j = 0; i < startindex + 128 * 128; i = i + 4, j++) {
int b, g, r; int b, g, r;
b = allpixels.get(i) & 0xFF; b = allpixels.get(i) & 0xFF; //TODO: <-- IndexOutOfBoundsException sometimes
g = allpixels.get(i + 1) & 0xFF; g = allpixels.get(i + 1) & 0xFF;
r = allpixels.get(i + 2) & 0xFF; r = allpixels.get(i + 2) & 0xFF;

View file

@ -1,18 +1,19 @@
package sznp.virtualcomputer; package sznp.virtualcomputer;
import java.awt.Color; import net.minecraft.server.v1_12_R1.WorldMap;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Map;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_12_R1.map.RenderData; import org.bukkit.craftbukkit.v1_12_R1.map.RenderData;
import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapPalette; import org.bukkit.map.MapPalette;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView; import org.bukkit.map.MapView;
import net.minecraft.server.v1_12_R1.WorldMap; import java.awt.*;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.Map;
public class DirectRenderer implements IRenderer { public class DirectRenderer implements IRenderer {
private int startindex; private int startindex;
@ -26,8 +27,6 @@ public class DirectRenderer implements IRenderer {
* The ID of the current map * The ID of the current map
* @param world * @param world
* The world to create new maps in * The world to create new maps in
* @param allpixels
* The raw pixel data from the machine in BGRA format
* @param startindex * @param startindex
* The index to start from in allpixels * The index to start from in allpixels
* @throws Exception * @throws Exception
@ -47,16 +46,41 @@ public class DirectRenderer implements IRenderer {
this.startindex = startindex; this.startindex = startindex;
this.buffer = render.buffer; this.buffer = render.buffer;
map.addRenderer(new DummyRenderer());
}
private final class DummyRenderer extends MapRenderer {
@Override
public void render(MapView map, MapCanvas canvas, Player player) {
if(allpixels != null)
DirectRenderer.this.render(allpixels, x, y, width, height); //Render after zeroing whole map
}
} }
private Exception ex; private Exception ex;
private ByteBuffer allpixels;
private long x, y, width, height;
private long lastrender;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void render(ByteBuffer allpixels, long x, long y, long width, long height) { // TODO public void render(ByteBuffer allpixels, long x, long y, long width, long height) { // TODO
this.allpixels=allpixels;
this.x=x;
this.y=y;
this.width=width;
this.height=height;
if(System.nanoTime()-lastrender<100*1000*1000)
return;
lastrender=System.nanoTime();
try { try {
for (int i = startindex, j = 0; i < allpixels.limit() - 4 && j < buffer.length; i += 4, j++) boolean hascolor=false;
buffer[j] = MapPalette for (int i = startindex, j = 0; i < allpixels.limit() - 4 && j < buffer.length; i += 4, j++) {
.matchColor(new Color(allpixels.get(i), allpixels.get(i + 1), allpixels.get(i + 2))); buffer[j] = MapPalette.matchColor(new Color(allpixels.get(i), allpixels.get(i + 1), allpixels.get(i + 2)));
if(allpixels.get(i+2)>10)
hascolor=true;
}
if(hascolor)
System.out.println("Some color!");
final Field field = map.getClass().getDeclaredField("worldMap"); final Field field = map.getClass().getDeclaredField("worldMap");
field.setAccessible(true); field.setAccessible(true);
WorldMap wmap = (WorldMap) field.get(map); WorldMap wmap = (WorldMap) field.get(map);

View file

@ -6,7 +6,10 @@ import org.mozilla.interfaces.IFramebuffer;
import org.mozilla.interfaces.IFramebufferOverlay; import org.mozilla.interfaces.IFramebufferOverlay;
import org.mozilla.interfaces.nsISupports; import org.mozilla.interfaces.nsISupports;
import org.mozilla.xpcom.Mozilla; import org.mozilla.xpcom.Mozilla;
import org.virtualbox_5_2.*; import org.virtualbox_5_2.BitmapFormat;
import org.virtualbox_5_2.Holder;
import org.virtualbox_5_2.IDisplay;
import org.virtualbox_5_2.IDisplaySourceBitmap;
public class MCFrameBuffer implements IFramebuffer { public class MCFrameBuffer implements IFramebuffer {
private IDisplay display; private IDisplay display;
@ -76,6 +79,7 @@ public class MCFrameBuffer implements IFramebuffer {
} }
private BukkitTask tt; private BukkitTask tt;
private BukkitTask tttt;
@Override @Override
public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) { public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) {
@ -86,12 +90,12 @@ public class MCFrameBuffer implements IFramebuffer {
* if (width > 640 || height > 480) { tt = Bukkit.getScheduler().runTaskTimerAsynchronously(PluginMain.Instance, () -> display.setVideoModeHint(0L, true, false, 0, 0, 640L, 480L, 32L), 5, 5); * if (width > 640 || height > 480) { tt = Bukkit.getScheduler().runTaskTimerAsynchronously(PluginMain.Instance, () -> display.setVideoModeHint(0L, true, false, 0, 0, 640L, 480L, 32L), 5, 5);
* return; // Don't even try to render too large resolutions } * return; // Don't even try to render too large resolutions }
*/ */
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> { tt = Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
display.querySourceBitmap(0L, holder); display.querySourceBitmap(0L, holder);
byte[] arr = PluginMain.allpixels.array(); byte[] arr = PluginMain.allpixels.array();
long[] w = new long[1], h = new long[1], bpp = new long[1], bpl = new long[1], pf = new long[1]; long[] w = new long[1], h = new long[1], bpp = new long[1], bpl = new long[1], pf = new long[1];
holder.value.getTypedWrapped().queryBitmapInfo(arr, w, h, bpp, bpl, pf); holder.value.getTypedWrapped().queryBitmapInfo(arr, w, h, bpp, bpl, pf);
System.out.println("Arr10:" + arr[10]); System.out.println("Arr0:" + arr[0]);
System.out.println("whbppbplpf: " + w[0] + " " + h[0] + " " + bpp[0] + " " + bpl[0] + " " + pf[0]); System.out.println("whbppbplpf: " + w[0] + " " + h[0] + " " + bpp[0] + " " + bpl[0] + " " + pf[0]);
if (width * height > 640 * 480) if (width * height > 640 * 480)
PluginMain.allpixels.limit(640 * 480 * 4); PluginMain.allpixels.limit(640 * 480 * 4);
@ -108,9 +112,13 @@ public class MCFrameBuffer implements IFramebuffer {
@Override @Override
public void notifyUpdate(long x, long y, long width, long height) { public void notifyUpdate(long x, long y, long width, long height) {
for (IRenderer r : PluginMain.renderers) if(tttt != null)
if (r instanceof DirectRenderer) tttt.cancel(); //We are getting updates, but the pixel array isn't updated - VB reacts slowly
((DirectRenderer) r).render(PluginMain.allpixels, x, y, width, height); tttt = Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
for (IRenderer r : PluginMain.renderers)
if (r instanceof DirectRenderer)
((DirectRenderer) r).render(PluginMain.allpixels, x, y, width, height);
}, 5);
} }
@Override @Override

View file

@ -1,11 +1,7 @@
package sznp.virtualcomputer; package sznp.virtualcomputer;
import java.io.File; import com.google.common.collect.Lists;
import java.lang.reflect.Field; import jnr.ffi.LibraryLoader;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
@ -13,9 +9,11 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.virtualbox_5_2.*; import org.virtualbox_5_2.*;
import com.google.common.collect.Lists; import java.io.File;
import java.lang.reflect.Field;
import jnr.ffi.LibraryLoader; import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
public class PluginMain extends JavaPlugin { public class PluginMain extends JavaPlugin {
private IVirtualBox vbox; private IVirtualBox vbox;
@ -57,10 +55,10 @@ public class PluginMain extends JavaPlugin {
session = manager.getSessionObject(); // TODO: Events session = manager.getSessionObject(); // TODO: Events
ccs.sendMessage("§bLoading Screen..."); ccs.sendMessage("§bLoading Screen...");
try { try {
throw new NoClassDefFoundError("Test error pls ignore"); //throw new NoClassDefFoundError("Test error pls ignore");
/*for (short i = 0; i < 20; i++) for (short i = 0; i < 20; i++)
renderers.add(new DirectRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4)); // TODO: The pixels are selected in a horribly wrong way probably renderers.add(new DirectRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4)); // TODO: The pixels are selected in a horribly wrong way probably
ccs.sendMessage("§bUsing Direct Renderer, all good");*/ ccs.sendMessage("§bUsing Direct Renderer, all good");
} catch (NoClassDefFoundError e) { } catch (NoClassDefFoundError e) {
for (short i = 0; i < 20; i++) for (short i = 0; i < 20; i++)
renderers.add(new BukkitRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4)); renderers.add(new BukkitRenderer(i, Bukkit.getWorlds().get(0), i * 128 * 128 * 4));