Some fixes and attempts to fix the screen

This commit is contained in:
Norbi Peti 2021-02-20 18:16:54 +01:00
parent 4a89e547a4
commit e23e062be9
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 49 additions and 20 deletions

View file

@ -66,8 +66,10 @@ public final class Computer {
synchronized (session) { synchronized (session) {
if (plugin.runEmbedded.get()) if (plugin.runEmbedded.get())
machine.lockMachine(session, LockType.VM); //Run in our process <-- Need the VM type to have console access machine.lockMachine(session, LockType.VM); //Run in our process <-- Need the VM type to have console access
else else {
machine.launchVMProcess(session, "headless", Collections.emptyList()); //Run in a separate process val progress = machine.launchVMProcess(session, "headless", Collections.emptyList()); //Run in a separate process
onStartSetProgress(progress, sender);
}
} }
} catch (VBoxException e) { } catch (VBoxException e) {
if (e.getResultCode() == 0x80070005) { //lockMachine: "The object functionality is limited" if (e.getResultCode() == 0x80070005) { //lockMachine: "The object functionality is limited"
@ -100,22 +102,35 @@ public final class Computer {
* @param sender The sender which started the machine * @param sender The sender which started the machine
*/ */
public void onLock(CommandSender sender) { public void onLock(CommandSender sender) {
System.out.println("A");
machine = session.getMachine(); // This is the Machine object we can work with machine = session.getMachine(); // This is the Machine object we can work with
final IConsole console = session.getConsole(); final IConsole console = session.getConsole();
if (plugin.runEmbedded.get()) { //Otherwise it's set while starting the VM
IProgress progress = console.powerUp(); // https://marc.info/?l=vbox-dev&m=142780789819967&w=2
onStartSetProgress(progress, sender);
}
System.out.println("B");
System.out.println("State: " + console.getState());
listener = handler.registerTo(console.getEventSource());
System.out.println("State: " + console.getState());
val fb = new MCFrameBuffer(console.getDisplay(), plugin, direct);
System.out.println("C");
if (plugin.runEmbedded.get())
fb.startEmbedded();
String fbid = console.getDisplay().attachFramebuffer(0L,
COMUtils.gimmeAFramebuffer(fb));
System.out.println("State: " + console.getState());
System.out.println("D"); //TODO: No UpdateImage
fb.setId(fbid);
framebuffer = fb;
}
private void onStartSetProgress(IProgress progress, CommandSender sender) {
if (handler != null) if (handler != null)
handler.disable(); handler.disable();
handler = new MachineEventHandler(Computer.this, sender); handler = new MachineEventHandler(Computer.this, sender);
listener = handler.registerTo(console.getEventSource());
IProgress progress = console.powerUp(); // https://marc.info/?l=vbox-dev&m=142780789819967&w=2
handler.setProgress(progress); handler.setProgress(progress);
handler.registerTo(progress.getEventSource()); //TODO: Show progress bar some way? handler.registerTo(progress.getEventSource()); //TODO: Show progress bar some way?
val fb = new MCFrameBuffer(console.getDisplay(), plugin, direct);
if (plugin.runEmbedded.get())
fb.start();
String fbid = console.getDisplay().attachFramebuffer(0L,
COMUtils.gimmeAFramebuffer(fb));
fb.setId(fbid);
framebuffer = fb;
} }
private void sendMessage(@Nullable CommandSender sender, String message) { private void sendMessage(@Nullable CommandSender sender, String message) {

View file

@ -109,7 +109,7 @@ public class PluginMain extends ButtonPlugin {
System.setProperty("java.library.path", vbpath); System.setProperty("java.library.path", vbpath);
Utils.addLibraryPath(vbpath); //TODO: Jacob DLL must be in the server folder Utils.addLibraryPath(vbpath); //TODO: Jacob DLL must be in the server folder
final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath()); final VirtualBoxManager manager = VirtualBoxManager.createInstance(getDataFolder().getAbsolutePath());
if (!windows) { if (!windows && runEmbedded.get()) {
VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom"); VBoxLib vbl = LibraryLoader.create(VBoxLib.class).load("vboxjxpcom");
vbl.RTR3InitExe(0, "", 0); vbl.RTR3InitExe(0, "", 0);
} }

View file

@ -71,6 +71,7 @@ public class GPURenderer extends MapRenderer implements IRenderer {
renderers.add(this); renderers.add(this);
map.addRenderer(this); map.addRenderer(this);
enabled = true; //Enable at each plugin (re)enable
} }
@Override @Override

View file

@ -25,7 +25,13 @@ public class MCFrameBuffer implements IMCFrameBuffer {
private final Holder<IDisplaySourceBitmap> holder = new Holder<>(); private final Holder<IDisplaySourceBitmap> holder = new Holder<>();
private final Logger logger; private final Logger logger;
private final PluginMain plugin; private final PluginMain plugin;
/**
* Whether the VM is running inside the server
*/
private final boolean embedded; private final boolean embedded;
/**
* Whether the GPU is being used to render
*/
private final boolean direct; private final boolean direct;
private BukkitTask tt; private BukkitTask tt;
/** /**
@ -103,9 +109,7 @@ public class MCFrameBuffer implements IMCFrameBuffer {
@Override @Override
public void notifyUpdate(long x, long y, long width, long height) { public void notifyUpdate(long x, long y, long width, long height) {
/*if (this.width > 1024 || this.height > 768) if (shouldUpdate.get())
return;*/
if (!direct || shouldUpdate.get())
return; //Don't wait for lock, ignore update since we're updating everything anyway - TODO: Not always return; //Don't wait for lock, ignore update since we're updating everything anyway - TODO: Not always
synchronized (this) { synchronized (this) {
shouldUpdate.set(true); shouldUpdate.set(true);
@ -129,9 +133,7 @@ public class MCFrameBuffer implements IMCFrameBuffer {
updateScreen((int) x, (int) y, (int) width, (int) height); updateScreen((int) x, (int) y, (int) width, (int) height);
} }
public void start() { public void startEmbedded() {
if (!direct)
return;
running = true; running = true;
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
try { try {
@ -140,7 +142,7 @@ public class MCFrameBuffer implements IMCFrameBuffer {
while (!shouldUpdate.get()) while (!shouldUpdate.get())
wait(1000); wait(1000);
if (pointer == null) { if (pointer == null) {
System.out.println("Screen pointer is null"); logger.warning("Embedded screen data pointer is null");
shouldUpdate.set(false); shouldUpdate.set(false);
continue; continue;
} }
@ -155,18 +157,29 @@ public class MCFrameBuffer implements IMCFrameBuffer {
} }
private void updateScreenDirectInternal(byte[] pixels, int x, int y, int width, int height) { private void updateScreenDirectInternal(byte[] pixels, int x, int y, int width, int height) {
if (pixels == null) {
logger.warning("Direct pixel data is null");
return;
}
Timing t = new Timing(); Timing t = new Timing();
GPURenderer.update(pixels, this.width, this.height, x, y, width, height); GPURenderer.update(pixels, this.width, this.height, x, y, width, height);
if (t.elapsedMS() > 60) //Typically 1ms max if (t.elapsedMS() > 60) //Typically 1ms max
logger.warning("Update took " + t.elapsedMS() + "ms"); logger.warning("Direct update took " + t.elapsedMS() + "ms");
} }
private void updateScreenIndirectInternal(ByteBuffer buffer, int x, int y, int width, int height) { private void updateScreenIndirectInternal(ByteBuffer buffer, int x, int y, int width, int height) {
if (buffer == null) {
logger.warning("Indirect pixel buffer is null");
return;
}
if (this.width * this.height > 640 * 480) if (this.width * this.height > 640 * 480)
buffer.limit(640 * 480 * 4); buffer.limit(640 * 480 * 4);
else else
buffer.limit(this.width * this.height * 4); buffer.limit(this.width * this.height * 4);
Timing t = new Timing();
BukkitRenderer.update(buffer, x, y, width, height); BukkitRenderer.update(buffer, x, y, width, height);
if (t.elapsedMS() > 60)
logger.warning("Indirect update took " + t.elapsedMS() + "ms");
} }
/** /**