domingo, 23 de septiembre de 2012

Why and how I use a single terminal sesion to play full screen games in Ubuntu 12.04


An artist rendition of playing video games in Unity. via Wikipedia commons

I am still a gamer at heart. You know. Video games taught me how to be a better perform through cartoony violence. They made me want to become a programmer so I could make my own video games (It is not working greatly).

Using ubuntu, I have to resort to using WINE (not an emulator) to play some of my favorite games. Thus performance is not estelar to begin with, specially in latest games such as Starcraft 2 and Diablo 3.

To make matters worse, ubuntu's default desktop environment, while very useful and good for my taste, is terrible for performance. For starters, it uses desktop compositing, and at least in 12.04 LTS, it lacks a feature to disable compositing while playing full screen video games. Worse, even compared with other Desktop environments that use compositing, it is really slow.

So, what to do? Change to another desktop environment? I actually like Unity, you know.

No one said you should use only one desktop environment

Actually, since heavy duty video games tend to run in full screen mode. And since most (if not all) of Unity's features are not accessible when a full screen game is running. What we can do is install a light desktop environment and just switch to it temporarily when playing video games!. After playing the game, you can close your session and once again return to unity for work and web browsing! This is a good compromise.

No one said you should always use a desktop environment

Though honestly, when a full screen game is running, you care a lot about those FPS, and even the lightest desktop environments still use some resources. How about an even more extreme measure? How about running a single terminal window? Without any other application (background or not) running? This will really ensure most of your resources go to the game.

The how to

Those selectable X desktop sessions work in a transparent way by using configuration files with extension .desktop in the system directory /usr/share/xsessions/. We can create one of our own that just runs the terminal program. Open a terminal and type the following command (Starts text editor gEdit with administrator rights) and creates a terminal.desktop file at the location we want).

sudo gedit /usr/share/xsessions/terminal.desktop

Type this:

[Desktop Entry]
Name=Terminal
Comment=This session logs you into Terminal
Exec=gnome-terminal
TryExec=gnome-terminal
Icon=
Type=Application

For further optimizations, you could try to create your own Icon (and complete the Icon= filed). You can also use a different terminal command, I use gnome-terminal because it is good enough and it comes preinstalled in ubuntu.

Save the file. Close your user sesion. In the login screen, find the option to change the desktop sesion. An option called Terminal should appear.

More

Your terminal sesion will probably look a little messed up. The window will be misplaced and there will not be a title bar. It does not matter, we are not doing this for the looks, just to be able to type commands.

You can customize the terminal a little. Create a new terminal profile that will be used for this desktop sesion. If you called the profile "DesktopTerminal" you can make the terminal sesion start with it by modifying the .desktop file and putting this in the Exec= field:
Exec=gnome-terminal  --window-with-profile=DesktopConsole

In order to exit from the terminal sesion. Just type the exit command and press enter.

You would need to know how to run your favorite games through a terminal. I use .sh scripts. Like this script that is conveniently saved in my ~/scripts/sc2.sh:

#!/bin/bash 
#Change the CPU frequency model to "performance", it keeps the CPU in fast mode
cpufreq-selector -g "performance"
#This fixes some sound issues in WINE games:
rm -r ~/.pulse ~/.asound* ~/.pulse-cookie
# enter folder and run starcraft II without output
cd "/home/vx/gamestuff/StarCraft II"
WINEDEBUG=-all wine "StarCraft II.exe" > /dev/null

Even more

This is more advanced, but since games might be buggy in WINE, you might need some control of things whilst trying to play. You can press Alt+Control+F1 and a different kind of terminal sesion will appear. These terminal sesions, cannot run graphical applications but it can do everything command line. (To return to your screen press Alt+Control+F7 (or perhaps F8, F9 or F10 depending on the screen).

From the special terminal sesion, you can execute commands while your WINE game is possibly frozen. A useful command is: "pkill wine". Which will kill all instances of WINE and allow you to exit the game if it is locked.

No hay comentarios:

Publicar un comentario en la entrada