Directly using VirtualBox from Java #5
3 changed files with 11 additions and 11 deletions
|
@ -53,15 +53,14 @@ public class DirectRenderer implements IRenderer {
|
|||
@SuppressWarnings("deprecation")
|
||||
public void render(ByteBuffer allpixels, long x, long y, long width, long height) { // TODO
|
||||
try {
|
||||
for (int i = startindex, j = 0; i < startindex + 128 * 128 && i < allpixels.limit()
|
||||
&& j < buffer.length; i += 4, j++)
|
||||
for (int i = startindex, j = 0; i < allpixels.limit() - 4 && j < buffer.length; i += 4, j++)
|
||||
buffer[j] = MapPalette
|
||||
.matchColor(new Color(allpixels.get(i), allpixels.get(i + 1), allpixels.get(i + 2)));
|
||||
final Field field = map.getClass().getField("worldmap");
|
||||
final Field field = map.getClass().getDeclaredField("worldMap");
|
||||
field.setAccessible(true);
|
||||
WorldMap wmap = (WorldMap) field.get(map);
|
||||
wmap.flagDirty(0, 0);
|
||||
wmap.flagDirty(128, 128); // Send the whole image - TODO: Only send changes
|
||||
wmap.flagDirty(127, 127); // Send the whole image - TODO: Only send changes
|
||||
} catch (Exception e) {
|
||||
if (ex != null && (e.getMessage() == ex.getMessage()
|
||||
|| (e.getMessage() != null && e.getMessage().equals(ex.getMessage()))))
|
||||
|
|
|
@ -76,13 +76,16 @@ public class MCFrameBuffer implements IFramebuffer {
|
|||
|
||||
@Override
|
||||
public void notifyChange(long screenId, long xOrigin, long yOrigin, long width, long height) {
|
||||
if (width > 640 || height > 480)
|
||||
return; // Don't even try to render too large resolutions
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
|
||||
display.querySourceBitmap(0L, holder); // TODO: Test if it crashes here
|
||||
byte[] arr = new byte[10];
|
||||
System.out.println("Arr0:" + arr[0]);
|
||||
display.querySourceBitmap(0L, holder);
|
||||
byte[] arr = PluginMain.allpixels.array();
|
||||
holder.value.getTypedWrapped().queryBitmapInfo(arr, new long[] { width }, new long[] { height },
|
||||
new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() },
|
||||
new long[] { getPixelFormat() }); // These are out params but whatever
|
||||
System.out.println("Arr0:" + arr[0]);
|
||||
PluginMain.allpixels.limit((int) (width * height * 4));
|
||||
for (IRenderer r : PluginMain.renderers)
|
||||
if (r instanceof BukkitRenderer)
|
||||
((BukkitRenderer) r).setAllPixels(PluginMain.allpixels);
|
||||
|
|
|
@ -11,8 +11,6 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.mozilla.xpcom.Mozilla;
|
||||
import org.mozilla.xpcom.internal.XPCOMImpl;
|
||||
import org.virtualbox_5_2.*;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -27,7 +25,7 @@ public class PluginMain extends JavaPlugin {
|
|||
private BukkitTask mousetask;
|
||||
|
||||
public static PluginMain Instance;
|
||||
public static ByteBuffer allpixels = null; // It's set on each change
|
||||
public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480); // It's set on each change
|
||||
public static ArrayList<IRenderer> renderers = new ArrayList<>();
|
||||
|
||||
// Fired when plugin is first enabled
|
||||
|
@ -53,7 +51,7 @@ public class PluginMain extends JavaPlugin {
|
|||
System.setProperty("java.library.path", vbpath);
|
||||
addLibraryPath(vbpath);
|
||||
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
|
||||
VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load(vbpath + "/libvboxjxpcom.so");
|
||||
VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom");
|
||||
vbl.RTR3InitExe(0, "", 0);
|
||||
vbox = manager.getVBox();
|
||||
session = manager.getSessionObject(); // TODO: Events
|
||||
|
|
Loading…
Reference in a new issue