VirtualBox: Virtual machine with Linux for TDM

From The DarkMod Wiki
Jump to navigationJump to search

This guide was written for TDM 2.06.

Intro

While Windows is the main platform of TheDarkMod, Linux is also officially supported. If you use Windows as the main OS, you may find it useful to have a Linux VM to fix any platform-specific issues.

Note: Virtual machine is perfectly suitable for everything except running the game itself. While you can build TDM and build + test tdm_update, running the game engine in a virtual machine is not a good idea, mainly due to OpenGL drivers required. As of 2.06, it is yet possible to run the game in VirtualBox, but: with low FPS, without any modern graphical features, and probably with some mouse weirdness.

For simplicity, this guide sticks to the simplest case: Ubuntu distribution, LTS version (e.g. Ubuntu 16.04).


Install VirtualBox

Go to VB downloads page: https://www.virtualbox.org/wiki/Downloads

Choose "Windows hosts" link and download installer. Run installer to install VirtualBox.

Most likely you do not need the "VirtualBox Extension Pack".

Run VirtualBox, Go to "File"->"Preferences". Make sure "Default Machine Folder" is set to the path where you want to store your VMs. Note that each of them takes about 5-10 GB of disk space.

Create VM

Click on "New" button, switch to "Expert Mode".

Choose "Type" = "Linux", "Version" = "Ubuntu (xy-bit)" (according to the bitness you want).

Enter name of your VM. I recommend having two VMs: the first one with clean install of Ubuntu, and the second one for work cloned from the first one. In such case it's better to name the VM being created "Clean Ubuntu 16.04 xy-bit".

Now click on "Create" button. Specify "File location" --- that's where the virtual disk (of size 5-10 GB) will be. Click on "Create" button to finish creating VM.

Configure VM

You can now do some changes in VM configuration. Some of them (enabling 3D acceleration) are necessary to run TDM, but most of them are for only better experience. It is not necessary to change configuration right now, you can also do it after installing Ubuntu.

Choose your VM and click on "Settings" button.

First of all, go to "Display" tab and check the "Enable 3D acceleration" checkbox. This allows OpenGL programs inside VM to use your GPU almost directly. You may also want to bump "Video Memory" e.g. to 64 MB here, although it seems to have no effect.

Second, go to "System" tab. You probably want to increase "Base Memory" to at least 2 GB. Open "Processor" subtab and increase "Processor(s)" slider to the number of physical cores your CPU has. This allows you to do parallel builds.

Then, go to "Storage" tab. Choose "Controller: SATA" and enable the checkbox "Use Host I/O Cache". This speeds up file access, although probably it does not affect shared folders.

Lastly, configure shared directories in "Shared Folders" tab. Generally, you want to share the root of all darkmod stuff (both source code and assets), so that you can access it directly on Linux. So click the button to add new shared directory, then choose the "Folder Path" on your computer, enable "Auto-mount" checkbox, and hit "OK".

Also it might be convenient to enable copy/pasting from guest to host and back. In "General" tab, open "Advanced" subtab, and set "Shared Clipboard" to "Bidirectional".

Install Ubuntu

Go to alternative download page on Ubuntu website: https://www.ubuntu.com/download/alternative-downloads

Go to BitTorrent section. Choose the LTS version you like, e.g. "Ubuntu 16.04 Desktop (64-bit)". Note that you can choose the bitness of OS (32-bit or 64-bit) here. Keep in mind that you can only run TDM on Linux guest of same bitness: you cannot run 64-bit TDM on 32-bit Linux guest, and you cannot run 32-bit TDM on 64-bit Linux guest. Starting from 18.04, there is no 32-bit version of Ubuntu, which makes it impossible to run 32-bit TDM on newer Ubuntu in VirtualBox. That's why I recommend using 16.04 version for now.

Run VirtualBox. Choose the freshly created VM and click "Start" button to run it. When asked for start-up disk, choose the Ubuntu ISO just downloaded.

When Ubuntu starts up, click on "Install Ubuntu" button. You should enable the "Download updates while installing Ubuntu" checkbox. Aside from that, just agree to whatever defaults installer throws at you. Proceed to the end of installation process.

Configure Ubuntu

In order to run TDM, OpenGL driver is needed, which can be installed with "VirtualBox Guest Additions".

Run your Ubuntu VM. In VirtualBox menu, choose "Devices"->"Insert Guest Additions CD image". When a dialog box appears suggesting to install stuff, click on "Run" button.

The next thing to be done is to allow your user access shared directories. Open terminal and execute the following command (replace yourUserName with name of your user in Ubuntu):

   sudo usermod -aG vboxsf yourUserName

Finally, shut down Ubuntu.

Congratulations! Now you have a fresh Ubuntu VM ready for building and maybe running TheDarkMod !

Clean/work clones

If you intend to have two versions of VM (a "fresh" one and a "work" one), then it is a perfect moment to clone your VM. If you are satisfied with having only one VM, then skip this section.

Right-click your VM and choose "Clone". Better choose "Full Clone" option to make sure VMs are completely separate after cloning. Enter the name of your new VM (e.g. "Ubuntu x64 (work)") and hit "Clone".

Build and run TDM

Run your work VM and open terminal.

Go to source code directory in the shared folder. In my case it is:

   cd /media/sf_TheDarkMod/darkmod_src

From here you can build TDM in the usual way, as described in the TDM compilation guide. Of course, you have to install some packages before first build.

In order to run TDM, go to the assets directory:

   cd /media/sf_TheDarkMod/darkmod

And run the freshly built binary:

   ./thedarkmod.x64

If you are lucky, you will see TDM main menu =)

If you have problems with mouse, go to "Input" menu and click on "Mouse Integration" to disable it. Then click into VM and it will grab mouse properly. Press right Ctrl key when you want to return back to host OS. If you don't want to disable mouse integration, then you can try to set in_nowarp 1 in game console. This is a stupid hack: you won't be able to play well with it.

Aside from issues with mouse and old & slow OpenGL, the TDM runs perfectly fine inside VM.

Note: As of now, hardware acceleration in VirtualBox Linux guest is limited to OpenGL 2.1 with some extensions. So when TDM team migrates to something newer (e.g. OpenGL 3), you won't be able to run TDM in VirtualBox VM any more.