Some fixes, some errors

This commit is contained in:
Norbi Peti 2019-05-08 17:49:11 +02:00
parent 9ba0c3e820
commit 751cc5eb92
4 changed files with 34 additions and 29 deletions

View file

@ -9,6 +9,7 @@ import org.virtualbox_6_0.*;
import sznp.virtualcomputer.events.MachineEventHandler;
import sznp.virtualcomputer.events.VBoxEventHandler;
import sznp.virtualcomputer.renderer.GPURenderer;
import sznp.virtualcomputer.util.COMUtils;
import sznp.virtualcomputer.util.Scancode;
import javax.annotation.Nullable;
@ -85,7 +86,7 @@ public final class Computer {
handler.setProgress(progress);
handler.registerTo(progress.getEventSource()); //TODO: Show progress bar some way?
console.getDisplay().attachFramebuffer(0L,
new IFramebuffer(new COMFrameBuffer(console.getDisplay(), true)));
COMUtils.gimmeAFramebuffer(new COMFrameBuffer(console.getDisplay(), true)));
}
private void sendMessage(@Nullable CommandSender sender, String message) {

View file

@ -6,14 +6,13 @@ import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.virtualbox_6_0.IEventListener;
import org.virtualbox_6_0.IVirtualBox;
import org.virtualbox_6_0.VirtualBoxManager;
import sznp.virtualcomputer.events.VBoxEventHandler;
import sznp.virtualcomputer.renderer.BukkitRenderer;
import sznp.virtualcomputer.renderer.GPURenderer;
import sznp.virtualcomputer.renderer.IRenderer;
import sznp.virtualcomputer.util.COMUtils;
import sznp.virtualcomputer.util.Utils;
import sznp.virtualcomputer.util.VBoxLib;
import java.io.File;
@ -26,7 +25,7 @@ public class PluginMain extends JavaPlugin {
private static final int MCX = 5;
private static final int MCY = 4;
private BukkitTask mousetask;
private IEventListener listener;
private VBoxEventHandler listener;
public static PluginMain Instance;
//public static ByteBuffer allpixels = ByteBuffer.allocate(640 * 480 * 4); // It's set on each change
@ -67,12 +66,12 @@ public class PluginMain extends JavaPlugin {
System.setProperty("sun.boot.library.path", vbpath);
if (System.getProperty("java.library.path") == null || System.getProperty("java.library.path").isEmpty())
System.setProperty("java.library.path", vbpath);
COMUtils.addLibraryPath(vbpath);
Utils.addLibraryPath(vbpath);
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom"); //TODO: Test for MSCOM
vbl.RTR3InitExe(0, "", 0);
IVirtualBox vbox = manager.getVBox();
listener = new VBoxEventHandler().registerTo(vbox.getEventSource());
(listener = new VBoxEventHandler()).registerTo(vbox.getEventSource());
new Computer(this, manager, vbox); //Saves itself
ccs.sendMessage("§bLoading Screen...");
try {
@ -119,7 +118,7 @@ public class PluginMain extends JavaPlugin {
e.printStackTrace(); - VBox claims the listener was never registered (can double register as well)
}*/
if (listener != null)
((VBoxEventHandler) listener.getTypedWrapped()).disable(); //The save progress wait locks with the event
listener.disable(); //The save progress wait locks with the event
if (Computer.getInstance() != null)
Computer.getInstance().pluginDisable(ccs);
ccs.sendMessage("§aHuh.");

View file

@ -3,14 +3,13 @@ package sznp.virtualcomputer;
import org.mozilla.interfaces.IEvent;
import org.mozilla.interfaces.IEventListener;
import sznp.virtualcomputer.util.COMObjectBase;
import java.util.function.Consumer;
import sznp.virtualcomputer.util.IEventHandler;
/**
* A Bukkit-like event system which calls the appropriate methods on an event.
*/
public final class EventHandler extends COMObjectBase implements IEventListener {
private final Consumer<org.virtualbox_6_0.IEvent> handler;
private final IEventHandler handler;
private boolean enabled = true;
/**
@ -18,7 +17,7 @@ public final class EventHandler extends COMObjectBase implements IEventListener
*
* @param handler The handle method that handles what needs to be handled
*/
public EventHandler(Consumer<org.virtualbox_6_0.IEvent> handler) {
public EventHandler(IEventHandler handler) {
this.handler = handler;
}
@ -26,7 +25,7 @@ public final class EventHandler extends COMObjectBase implements IEventListener
public final void handleEvent(IEvent iEvent) {
if (!enabled)
return;
handler.accept(new org.virtualbox_6_0.IEvent(iEvent));
handler.handleEvent(new org.virtualbox_6_0.IEvent(iEvent));
}
public void disable() {

View file

@ -3,6 +3,7 @@ package sznp.virtualcomputer.util;
import lombok.val;
import org.virtualbox_6_0.IEvent;
import org.virtualbox_6_0.IEventSource;
import org.virtualbox_6_0.IFramebuffer;
import org.virtualbox_6_0.VBoxEventType;
import org.virtualbox_6_0.xpcom.IUnknown;
import sznp.virtualcomputer.EventHandler;
@ -11,11 +12,12 @@ import java.lang.reflect.InvocationTargetException;
import java.util.List;
public final class COMUtils {
private COMUtils() {}
private COMUtils() {
}
//public static void registerListener(IEventSource source, IEventListener listener, VBoxEventType... types) {
public static org.virtualbox_6_0.IEventListener registerListener(IEventSource source, IEventHandler listener, List<VBoxEventType> types) {
val ret = new org.virtualbox_6_0.IEventListener(new EventHandler(listener::handleEvent));
val ret = new org.virtualbox_6_0.IEventListener(new EventHandler(listener));
source.registerListener(ret, types, true);
return ret;
}
@ -30,4 +32,8 @@ public final class COMUtils {
return null;
}
}
public static IFramebuffer gimmeAFramebuffer(IMCFrameBuffer frameBuffer) {
return new IFramebuffer(frameBuffer); //TODO
}
}