Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Add QEMU #53

Open
Delta2Force opened this issue Jul 28, 2020 · 27 comments
Open

Add QEMU #53

Delta2Force opened this issue Jul 28, 2020 · 27 comments
Labels
enhancement New feature or request

Comments

@Delta2Force
Copy link
Owner

QEMU can be accessed using a VNC server, which shouldn't be too hard to implement. QEMU exists for all platforms, so it should work pretty well. I would add an option at the start to use VirtualBox or QEMU.

@Delta2Force Delta2Force added the enhancement New feature or request label Jul 28, 2020
@Meister1593
Copy link

Huge plus for that, it would be really good to use also QEMU.

@Delta2Force
Copy link
Owner Author

Delta2Force commented Jul 31, 2020

I'm currently working on this, you can watch my progress on the qemu branch.

I've got the setup GUI (the one when you start the game) working with QEMU, I've only tested it on Linux yet though and I will test it using Windows later on (before publishing the version). The rest of the implementation should be incredibly simple, just connect to the screen using VNC and get a feed in VMRunnable, create VHDs using the qemu command, start the VM by creating a long command, stop it by just killing the process, maybe I can detect if it's manually shut down if the process stops on it's own, and it should be all set by then.

@CoccodrillooXDS
Copy link
Collaborator

I know that QEMU has multiple architectures, which ones are you going to support?

@Delta2Force
Copy link
Owner Author

x86_64 and i386 (normal 64-bit and 32-bit architectures)

@jakovsch
Copy link

I wonder if the implementation of a real VNC client for the ingame screen means that it will be able to connect to any remote stream over the network (not only on the local PC).

If so, would it be possible for the server running the game to also be running many VMs with Vbox or Qemu/KVM, all managed by this mod through APIs like libvirt in case of Qemu and Vbox API?

@CoccodrillooXDS
Copy link
Collaborator

That would be awesome if @Delta2Force is able to do that, and it could also kinda help with #3

@Delta2Force
Copy link
Owner Author

I wonder if the implementation of a real VNC client for the ingame screen means that it will be able to connect to any remote stream over the network (not only on the local PC).

If so, would it be possible for the server running the game to also be running many VMs with Vbox or Qemu/KVM, all managed by this mod through APIs like libvirt in case of Qemu and Vbox API?

Theoretically, yes! It would be a really cool idea. For it to work cables would have to be added first though, so different PCs can have different screens and such.

@y2k04
Copy link
Collaborator

y2k04 commented Aug 4, 2020

I'm currently working on this, you can watch my progress on the qemu branch.

I've got the setup GUI (the one when you start the game) working with QEMU, I've only tested it on Linux yet though and I will test it using Windows later on (before publishing the version). The rest of the implementation should be incredibly simple, just connect to the screen using VNC and get a feed in VMRunnable, create VHDs using the qemu command, start the VM by creating a long command, stop it by just killing the process, maybe I can detect if it's manually shut down if the process stops on it's own, and it should be all set by then.

https://blogs.oracle.com/vaibhav/listing-java-process-from-java
https://www.baeldung.com/java-process-api

@Delta2Force
Copy link
Owner Author

Ok, currently the input is a bit weird. I don't have a clue how to solve it other than maybe using a different VNC library. You can try it out by compiling the qemu branch.

@Meister1593
Copy link

Meister1593 commented Aug 7, 2020

I have tried building and using Qemu, i think it works, but it seems i have no display , and no way to know which port are used for vnc (or even if vnc is working)
I built mod using Gradle from JetBrains Idea 2020
System: Arch KDE, linux-5.7.12-arch1-1, qemu 5.0.0-8
Java 11, changing Java to either openjdk-8 or oracle-jre 8 does not help ( it even crashes game when right clicking on screen )
Minecraft log
mcvmcomputers_1
mcvmcomputers_2

@CoccodrillooXDS
Copy link
Collaborator

Screenshot
@Meister1593, the VNC Server is "localhost:1", You can see it from the process info like you did (just after the QEMU executable file).
@Delta2Force, QEMU starts and works if you connect manually to it (via a VNC Viewer program). The input from the game doesn't work at all (black screen and no input passes from the game to QEMU/VNC)

@Meister1593
Copy link

Meister1593 commented Aug 8, 2020

Screenshot
@Meister1593, the VNC Server is "localhost:1", You can see it from the process info like you did (just after the QEMU executable file).
@Delta2Force, QEMU starts and works if you connect manually to it (via a VNC Viewer program). The input from the game doesn't work at all (black screen and no input passes from the game to QEMU/VNC)

I tried using vnc viewer with this ip:port and it worked! Though, it's quite slow, even Arch iso was loading like 5 mins, which is really slow. I shared 8 gigs of ram and cpu divided by two (6 threads), usually it starts in less than 1 min in VirtualManager (qemu).

Input from game crashes my game btw. Log

@Meister1593
Copy link

Meister1593 commented Sep 2, 2020

I did some research and coding about this implementation and found some things:

  1. Enabling KVM greatly increases performance, like radically. (from 3-5 mins loading of arch down to 30-60 seconds)
  2. No keymap for lower case characters (which is fine since we send capslock? maybe? (not really, works 50/50) i implemented lowercase check for this and it works always).
  3. For some unknown reason, when you first use screen everything is fine, then if you use it again, all characters you type does not work properly , keysums and etc does not change, it seems something wrong with vernacular, but i've not checked whole code about input handling.
  4. To use mod every time you rejoin world, you have to break screen and place it again (or place another screen)
  5. I've changed graphics to virtio and it solved problem with freezing screen, but this needs additional checking.
  6. Updating keymaps and cursor through VMRunnable is terrible idea since it's very slow, very unnatural feeling when trying to type or move cursor.
  7. What IDE guys are you using? Intellij Idea making warnings about NPE, cases where some stuff is overcomplicated or just not needed (default values and generic types), wrong indentation. Allover the project.

Sadly, i haven't found any java vnc library except ones that uses C mappings (JNA)

Meister1593 added a commit to Meister1593/MCVmComputers that referenced this issue Sep 2, 2020
Added kvm as default option (TODO to check if KVM enabled for OS)
Changed graphics adapter to Virtio from std (TODO to check if virtio presented in system, if not - fallback to std)
Added lower-case latin keys for sending to VNC (Althrough, caps lock should be sent and be used, it's not always working for some reason)
Meister1593 added a commit to Meister1593/MCVmComputers that referenced this issue Sep 6, 2020
 Fixed issue when input was weird after unfocusing and focusing again (timer-based input disabler)
 Synchronized blocks on keys list to prevent concurrent modifications, task scheduler for key inputs

Serious fixes for Delta2Force#53 issue, but not all.
TODO: black screens every rejoin (have to replace each to see new image) and repeat keys on input.
@Meister1593
Copy link

Meister1593 commented Sep 6, 2020

Basically issue with input was: unfocusing from screen caused keys about unpressing not to be added to vnc keys scheduler.
I've uploaded timer-based fix with other stuff too, this is not over yet with issues)

@Delta2Force
Copy link
Owner Author

Can you do a pull request on here with your changes?

@Meister1593
Copy link

Meister1593 commented Sep 9, 2020

Can you do a pull request on here with your changes?

I wasn't sure about making pull request since it's not all fixes, but if you said about it, then sure i will make it.

@Meister1593
Copy link

Generally speaking, there is a need a centralized handling for all input, no matter from where. Else somewhere you would handle input using GLFW directly in one render frame, and in other you would process it using mixin, this causes issues, as you can see with GuiFocus and VMRunnable.

@Meister1593
Copy link

Meister1593 commented Sep 23, 2020

I did some fixes and changes, but i found other bugs...
Linux mint or any other distro with UI launch 50/50 times and when they launch, they don't appear to update GUI on screen at all, or at least when i try to interact with screen, it doesn't move mouse or press any button (in vnc they're fine).
EDIT: I found the root of problem, it was input handling in VMRunnable. I will try to make input handling better, since it's very slow

@Delta2Force
Copy link
Owner Author

I just noticed this:


Does it still start the VM if KVM is disabled or it's launched using Windows?

@Meister1593
Copy link

Meister1593 commented Sep 23, 2020

I just noticed this:

Does it still start the VM if KVM is disabled or it's launched using Windows?

I don't have Windows right now, and it probably won't start without KVM.
Not sure if windows includes it by default or you have to enable it, but this specific command about kvm should be checked for available kvm before adding it.
Note: this gives a huge boost in performance, so disabling it would kill any reason to use QEMU.
Maybe there's alternative solution (like hyper-v, not sure if qemu supports it), but this is what i just noticed on most qemu tutorials

@Meister1593
Copy link

Meister1593 commented Sep 23, 2020

Currently the QEMU to display output and input handling is very slow and there's always a chance for freezed screen.
Most likely because of conversions of bytestreams to array of bytes and nativeimage, and all of this in two completely different parts of code.
Basically everything but qemu works real slow

@TheEeveeLovers
Copy link

Anybody say Cables? #37

@kristibektashi
Copy link

kristibektashi commented Nov 22, 2020

I just noticed this:

Does it still start the VM if KVM is disabled or it's launched using Windows?

I don't have Windows right now, and it probably won't start without KVM.
Not sure if windows includes it by default or you have to enable it, but this specific command about kvm should be checked for available kvm before adding it.
Note: this gives a huge boost in performance, so disabling it would kill any reason to use QEMU.
Maybe there's alternative solution (like hyper-v, not sure if qemu supports it), but this is what i just noticed on most qemu tutorials

You can use Intel HAXM with QEMU on Windows to greatly improve performance (Intel processors only, I'm pretty sure AMD has something similar too, but the mod would have to recognize if the CPU is Intel or AMD and use the correct driver)

Edit: I did a quick Google search and I couldn't find AMD's equalivent to Intel HAXM driver (Android studio has their own driver but I don't think that would work). You can still use HAXM on Intel processors but for AMD you should either stick with VirtualBox or add Hyper-V support (#144 )

Edit 2: I just found out you can use Hyper-V with QEMU on Windows using the -accel whpx argument (requires Hyper-V and Windows Hypervisor Platform feature installed)

@Delta2Force
Copy link
Owner Author

I have a new idea about doing qemu alltogether: what about turning QEMU into a JNI library and just calling all the functions directly within the mod? I'm looking into this right now, but it should be possible.

@Meister1593
Copy link

I have a new idea about doing qemu alltogether: what about turning QEMU into a JNI library and just calling all the functions directly within the mod? I'm looking into this right now, but it should be possible.

isn't this gonna be kinda madness taking care of such huge thing as making qemu adapter for JNI?
Virtualbox had it's own library for java, but qemu? Sounds really big.

@y2k04
Copy link
Collaborator

y2k04 commented Mar 3, 2023

I have a new idea about doing qemu alltogether: what about turning QEMU into a JNI library and just calling all the functions directly within the mod? I'm looking into this right now, but it should be possible.

@Delta2Force I may have found something that could help:
https://stackoverflow.com/questions/18414441/making-a-connection-to-qemu-with-libvirt-java-api
https://libvirt.org
https://gitlab.com/libvirt/libvirt-java

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants