Directly using VirtualBox from Java #5

Merged
NorbiPeti merged 60 commits from directvb into master 2019-04-18 23:29:21 +00:00
3 changed files with 11 additions and 11 deletions
Showing only changes of commit 0af3905f86 - Show all commits

View file

@ -53,15 +53,14 @@ public class DirectRenderer implements IRenderer {
@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
try { try {
for (int i = startindex, j = 0; i < startindex + 128 * 128 && i < allpixels.limit() for (int i = startindex, j = 0; i < allpixels.limit() - 4 && j < buffer.length; i += 4, j++)
&& j < buffer.length; i += 4, j++)
buffer[j] = MapPalette buffer[j] = MapPalette
.matchColor(new Color(allpixels.get(i), allpixels.get(i + 1), allpixels.get(i + 2))); .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); field.setAccessible(true);
WorldMap wmap = (WorldMap) field.get(map); WorldMap wmap = (WorldMap) field.get(map);
wmap.flagDirty(0, 0); 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) { } catch (Exception e) {
if (ex != null && (e.getMessage() == ex.getMessage() if (ex != null && (e.getMessage() == ex.getMessage()
|| (e.getMessage() != null && e.getMessage().equals(ex.getMessage())))) || (e.getMessage() != null && e.getMessage().equals(ex.getMessage()))))

View file

@ -76,13 +76,16 @@ public class MCFrameBuffer implements IFramebuffer {
@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) {
if (width > 640 || height > 480)
return; // Don't even try to render too large resolutions
Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> { Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, () -> {
display.querySourceBitmap(0L, holder); // TODO: Test if it crashes here display.querySourceBitmap(0L, holder);
byte[] arr = new byte[10]; byte[] arr = PluginMain.allpixels.array();
System.out.println("Arr0:" + arr[0]);
holder.value.getTypedWrapped().queryBitmapInfo(arr, new long[] { width }, new long[] { height }, holder.value.getTypedWrapped().queryBitmapInfo(arr, new long[] { width }, new long[] { height },
new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() }, new long[] { getBitsPerPixel() }, new long[] { getBytesPerLine() },
new long[] { getPixelFormat() }); // These are out params but whatever 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) for (IRenderer r : PluginMain.renderers)
if (r instanceof BukkitRenderer) if (r instanceof BukkitRenderer)
((BukkitRenderer) r).setAllPixels(PluginMain.allpixels); ((BukkitRenderer) r).setAllPixels(PluginMain.allpixels);

View file

@ -11,8 +11,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.mozilla.xpcom.Mozilla;
import org.mozilla.xpcom.internal.XPCOMImpl;
import org.virtualbox_5_2.*; import org.virtualbox_5_2.*;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -27,7 +25,7 @@ public class PluginMain extends JavaPlugin {
private BukkitTask mousetask; private BukkitTask mousetask;
public static PluginMain Instance; 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<>(); public static ArrayList<IRenderer> renderers = new ArrayList<>();
// Fired when plugin is first enabled // Fired when plugin is first enabled
@ -53,7 +51,7 @@ public class PluginMain extends JavaPlugin {
System.setProperty("java.library.path", vbpath); System.setProperty("java.library.path", vbpath);
addLibraryPath(vbpath); addLibraryPath(vbpath);
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath()); 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); vbl.RTR3InitExe(0, "", 0);
vbox = manager.getVBox(); vbox = manager.getVBox();
session = manager.getSessionObject(); // TODO: Events session = manager.getSessionObject(); // TODO: Events