Page 1 of 9 123 ... LastLast
Results 1 to 10 of 86

Thread: HOWTO: The Best Way To Play Games On Ubuntu

  1. #1
    Join Date
    Jun 2006
    Beans
    471

    HOWTO: The Best Way To Play Games On Ubuntu

    Hi,

    I think I have found the best way of running games on Ubuntu. By creating a new X server you get to run games faster, toggle between running games and your desktop using [Ctrl]+[Alt] + F7, and by starting the new X server as a new daemon you can stop it without any fuss if it goes down - a much more likely prospect where games are concerned. Also there are no issues with Compiz or the Xfce panel.

    Anyway there was a project to allow you to launch games on a new X server but it appears to be long dead so I've made this script to do it for you.

    This is a script to install 'x.game'. Copy the code into 'install-x.game' and run 'chmod +x install-x.game' and run it as root (using sudo or gksudo). (You will need the Universe package repository enabled for installing.)

    Zenity based prompts will guide you through the rest.

    Warning: Whilst I've done my best to get this to work responsibly and tested it out on my system to get rid of bugs it does require some modification of sensitive system files such as '/etc/sudoers'. This is because for some reason you require su privileges to change the virtual terminal (the [Alt] + F keys). To get round this I create a group 'chvt' who are allowed to run 'sudo chvt' without being asked for a password. (edit) This has been improved a bit in the new version and thanks to Cappy who pointed out a few issues I had in the old script.

    Known Bugs:
    • There is still a problem with the way 'x.game' handles spaces in file names if anyone knows a way to do this properly then let me know.
    • xrandr and other screen tools don't work properly on the new X server and cause it to crash. I'm rewriting 'winefix' to work with this method of starting games and provide useful functions.
    • The performance boost I get on my dual core PC is not matched by my low-end 1Ghz powerpc that receives a performance drop with the extra overhead of having an extra xserver running.


    Usage: Run 'x.game start PROGRAM' to start a new server and launch a game. And 'x.game stop' to stop a server that's not responding properly. Otherwise right click on the desktop and click on exit to close a server.

    Change desktops with [Ctrl] + [Alt] + F7 (normally these are assigned as one higher each time you reboot X) to go to your Ubuntu desktop and press [Ctrl] + [Alt] + F12 to go to x.game.

    Lets you select the users who can access chvt and therefore x.game. If you want to add users then add them to the 'chvt' group.

    (edit) Vesion 0.4 - New uninstall option has been added and a number of errors have been fixed.
    (edit) Vesion 0.5 - Gives you a notification icon to let you know that x.game is running, Has been tested for hardy.
    (edit) Vesion 0.6 - Installer now lets you select the users to be allowed chvt access, Has been tested for hardy.
    (edit) Vesion 0.7 - Removed references to gksudo script needs to be run now as root. Has been tested for hardy.
    (edit) Vesion 0.8 - Proper user specific x authorization and fixes for a problem with 0.7. Has been tested for hardy.

    install-x.game
    Code:
    #!/bin/bash
    #x.game linux game daemon
    #Version 0.8
    #written by mikey <abc.mikey@googlemail.com>
    
    function gettmpdir {
    	TMPDIR=$(mktemp /tmp/x.game.XXXXXXXXXX || zenity --info --text="Error unable to create temp directory in /tmp."; exit 1)
    }
    
    function uninstall {
    	zenity --question --text="Uninstall x.game?"
    	if [ $? = 1 ]; then 
    		exit 0
    	fi
    	gettmpdir
    	awk '{ if ($1 ~ /^allowed_users=/) { printf "#"; print; } else print }' /etc/X11/Xwrapper.config > $TMPDIR
    	grep "#allowed_users=" /etc/X11/Xwrapper.config | head -n 1 | sed "s/#//" >> $TMPDIR
    	mv $TMPDIR /etc/X11/Xwrapper.config
    	groupdel chvt
    	gettmpdir
    	sed "s/^\%chvt ALL= NOPASSWD: \/usr\/bin\/chvt$//" /etc/sudoers > $TMPDIR
    	visudo -c -f $TMPDIR
    	if [ $? != 0 ]; then 
    		zenity --info --text="Error updating /etc/sudoers!"
    		exit 1
    	fi
    	if [ -e /etc/sudoers.tmp ]; then 
    		zenity --info --text="Error updating /etc/sudoers! Locked by another user. Try again later."
    		exit 1
    	fi
    	chmod 0440 $TMPDIR
    	chown 0:0 $TMPDIR
    	mv $TMPDIR /etc/sudoers
    	USERS=$(awk -F: '{if ($3>=1000 && $3 < 65534) print $1 }' /etc/passwd)
    	IFS="
    "
    	for USR in $USERS
    	do
    		USRHOME=$(awk -F:  -v user="$USR"  '{if ($1==user) print $6 }' /etc/passwd)
    		echo "Removing xauth for $USR in $USRHOME/.Xauthority"
    		sudo -u $USR xauth -f $USRHOME/.Xauthority remove :1.1
    	done
    	zenity --question --text="Uninstall openbox and feh?"
    	if [ $? = 0 ]; then 
    		apt-get remove openbox feh --yes
    	fi
    	rm /usr/local/bin/x.game
    	rm /usr/share/pixmaps/xgame.xpm
    	zenity --info --text="x.game uninstalled."
    }
    
    #Check that we are running as root
    if [ "$USER" != "root" ]; then
    	zenity --info --text="Must be run as 'root'. Try 'sudo'."
    	exit 1
    fi
    
    if [ "$1" = "--uninstall" ]; then
    	uninstall
    	exit 0
    elif [ -n "$1" ]; then
    	echo "Usage: $0 [--uninstall]"
    	exit 1
    fi
    
    zenity --question --text="Install x.game?"
    if [ $? = 1 ]; then 
    	exit 0
    fi
    #replace "allowed_users=console"
    #Allow any user to start an XServer
    gettmpdir
    awk '{ if ($1 ~ /^allowed_users=/) { printf "#"; print; } else print }' /etc/X11/Xwrapper.config > $TMPDIR
    echo "allowed_users=anybody" >> $TMPDIR
    mv $TMPDIR /etc/X11/Xwrapper.config
    #Add group 'chvt' and add current user to group
    groupadd chvt
    USERS=$(awk -F: '{if ($3>=1000 && $3 < 65534) print "TRUE "$1 }' /etc/passwd)
    ANS=$(zenity  --list  --text="Select users to access x.game?" --checklist  --column "Allow" --column "User" $USERS)
    IFS="|"
    for USR in $ANS
    do
            usermod -a -G chvt $USR
    	#Authorise X for user on display :1 
    	USRHOME=$(awk -F:  -v user="$USR"  '{if ($1==user) print $6 }' /etc/passwd)
    	sudo -u $USR xauth -f $USRHOME/.Xauthority add :1.1 . $(mcookie)
    done
    IFS="
    "
    #Add group 'chvt' to no password group for command 'chvt'
    gettmpdir
    cat /etc/sudoers > $TMPDIR; echo "%chvt ALL= NOPASSWD: /usr/bin/chvt" >> $TMPDIR
    visudo -c -f $TMPDIR
    if [ $? != 0 ]; then 
    	zenity --info --text="Error updating /etc/sudoers!"
    	exit 1
    fi
    if [ -e /etc/sudoers.tmp ]; then 
    	zenity --info --text="Error updating /etc/sudoers! Locked by another user. Try again later."
    	exit 1
    fi
    chmod 0440 $TMPDIR
    chown 0:0 $TMPDIR
    mv $TMPDIR /etc/sudoers
    #Install required programs from Universe
    apt-get install openbox feh --yes
    zenity --info --text="Select a background image for desktop."
    while true; do
    	FILE=$(zenity --file-selection)
    	RES=$(echo "${FILE}" | grep -i ".jpg$")
    	if [ -n "${RES}" ]; then
    		break
    	else
    		zenity --question --text="Invalid file name. Try again?"
    		if [ $? = 1 ]; then 
    			exit 0
    		fi
    	fi
    done
    gettmpdir
    head -n 5 $0 > $TMPDIR
    echo "BGIMAGE=\"${FILE}\"" >> $TMPDIR
    tail -n 83 $0 >> $TMPDIR
    mv $TMPDIR /usr/local/bin/x.game
    chmod +rx /usr/local/bin/x.game
    #Install icon
    gettmpdir
    echo '/* XPM */
    static char * xgame_xpm[] = {
    "32 32 2 1",
    " 	c None",
    ".	c #000000",
    "                                ",
    "                                ",
    "                                ",
    "                                ",
    "                                ",
    "                                ",
    "                                ",
    "           .                    ",
    "          ...       ..          ",
    "         ....     .....         ",
    "         .....   ......         ",
    "          ..... ......          ",
    "          ...........           ",
    "           .........            ",
    "            .......             ",
    "             ......             ",
    "             .......            ",
    "            .........           ",
    "           ...........          ",
    "           ....  ......         ",
    "          .....  .......        ",
    "         .....     .....        ",
    "         ....       ...         ",
    "          ...        .          ",
    "           .                    ",
    "                                ",
    "                                ",
    "                                ",
    "                                ",
    "                                ",
    "                                ",
    "                                "};' > $TMPDIR
    mv $TMPDIR /usr/share/pixmaps/xgame.xpm
    chmod +r /usr/share/pixmaps/xgame.xpm
    zenity --info --text="Successfully installed.\nRun 'x.game start [program]'."
    exit 0
    
    PIDFILE="${HOME}/.xgame.pid"
    WMPATH="/usr/bin/openbox"
    function start {
    	if [ -f "/tmp/.X1-lock" ]; then
    		echo "X Display :1 already open"
    		sudo chvt 12
    		DISPLAY=:1
    	else
    		echo "Starting Daemon:"
    		zenity --notification --text="x.game running..." --window-icon=/usr/share/pixmaps/xgame.xpm &
    		echo $! > /tmp/x.game-notification
    		start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --make-pidfile --name xgame --startas /usr/bin/xinit -- $WMPATH -- :1 vt12 &
    		sleep 2s
    		DISPLAY=:1
    		feh --bg-scale "$BGIMAGE" & 
    	fi
    	PROGRAM=$1
    	echo "Program: $PROGRAM"
    	if [ "$PROGRAM" != "" ]; then
    		execute $*
    	fi
    }
    function stop {
    	echo "Stoping Daemon:"
    	start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --name xinit --startas /usr/bin/xinit 
    	kill `cat /tmp/x.game-notification`
    }
    function execute {
    	if [ -f "/tmp/.X1-lock" ]; then
    		echo "Switching to display :1"
    		sudo chvt 12
    		DISPLAY=:1
    	else
    		echo "Display :1 is not running!"
    		echo "Try 'x.game start PROGRAM'"
    		exit 1	
    	fi
    	PROGRAM=$1
    	shift
    	if [ "$PROGRAM" == "" ]; then
    		echo "Usage: "
    		echo "x.game [start | stop] [PROGRAM] [parameters]"
    		exit 1
    	else
    		while (( "$#" )); do
    			if [[ -n "$1" && $1 == *\ * ]]; then
    				ARGS="$ARGS \"$1\""
    			else
    				ARGS="$ARGS $1"
    			fi
    			shift
    		done
    	fi
    	echo $PROGRAM $ARGS
    	echo $ARGS | xargs $PROGRAM
    }
    #START OF SCRIPT
    IFS="
    "
    SS=$1
    echo "Selecting: $SS"
    case "$SS" in
    	start)
    		echo "Starting:"
    		shift
    		start $*
    		;;
    	stop)
    		echo "Stoping:"
    		shift
    		stop $*
    		;;
    	restart)
    		echo "Restarting:"
    		shift
    		stop $*
    		start $*
    		;;
    	*)
    		echo "Executing:"
    		execute $*
    esac
    exit 0
    Last edited by mikeym; April 14th, 2008 at 10:43 AM. Reason: Updating Script to version 0.8

  2. #2
    Join Date
    Jul 2005
    Location
    UK
    Beans
    582
    Distro
    Ubuntu

    Re: HOWTO: The Best Way To Play Games On Ubuntu

    Good tip, I'll put that on Free Gamer!
    Wand good Free Software games?
    Free Gamer - Open source game resource
    FreeGameDev - Free Software games community

  3. #3
    Join Date
    Jan 2008
    Beans
    371
    Distro
    Ubuntu Studio 10.04 Lucid Lynx

    Re: HOWTO: The Best Way To Play Games On Ubuntu

    It won't matter if your graphics card doesn't have T&L chips to support 3D rendering.

  4. #4
    Join Date
    Jun 2006
    Beans
    471

    Re: HOWTO: The Best Way To Play Games On Ubuntu

    Sorry I'm not an expert on graphics cards or even the way X works.

    You will still need the hardware for playing games. The advantage you get from running them on a separate X server is that you don't have much of an overhead from your desktop. The Window Manager I've selected (openbox) is extremely light weight. I've noticed a great performance boost in my games over any other method that I've tried - quite a few.

    This is good when combined with the extra convenience you get from running games like this.

  5. #5
    Join Date
    Jun 2006
    Beans
    471

    Re: HOWTO: The Best Way To Play Games On Ubuntu

    Hi,

    Can anyone confirm that they've tried this and if it's working on their system?

  6. #6
    Join Date
    Jul 2006
    Location
    on the bleeding edge
    Beans
    1,011

    Re: HOWTO: The Best Way To Play Games On Ubuntu

    did not work on my system, got this output:

    Code:
    khaal@Xeraphim:~/no-backup/apps/etqw$ x.game etqw
    Selecting: etqw
    Executing:
    Display :1 is not running!
    Try 'x.game start PROGRAM'
    khaal@Xeraphim:~/no-backup/apps/etqw$ xg
    xgamma    xgc       xgettext
    khaal@Xeraphim:~/no-backup/apps/etqw$ x.game start etqw
    Selecting: start
    Starting:
    Starting Daemon:
    
    
    X Window System Version 1.3.0
    Release Date: 19 April 2007
    X Protocol Version 11, Revision 0, Release 1.3
    Build Operating System: Linux Ubuntu (xorg-server 2:1.3.0.0.dfsg-12ubuntu8.3)
    Current Operating System: Linux Xeraphim 2.6.22-14-rt #1 SMP PREEMPT RT Tue Feb 12 09:57:10 UTC 2008 i686
    Build Date: 18 January 2008
            Before reporting problems, check http://wiki.x.org
            to make sure that you have the latest version.
    Module Loader present
    Markers: (--) probed, (**) from config file, (==) default setting,
            (++) from command line, (!!) notice, (II) informational,
            (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
    (==) Log file: "/var/log/Xorg.1.log", Time: Wed Feb 20 10:20:04 2008
    (==) Using config file: "/etc/X11/xorg.conf"
    (II) Module already built-in
    The XKEYBOARD keymap compiler (xkbcomp) reports:
    > Warning:          Type "ONE_LEVEL" has 1 levels, but <RALT> has 2 symbols
    >                   Ignoring extra symbols
    Errors from xkbcomp are not fatal to the X server
    /usr/local/bin/x.game: line 19: feh: command not found
    Program: etqw
    Switching to display :1
    etqw
    xargs: etqw: No such file or directory
    khaal@Xeraphim:~/no-backup/apps/etqw$ /usr/bin/xinit:  No such file or directory (errno 2):  no program named "/usr/bin/openbox" in PATH
    
    Specify a program on the command line or make sure that /usr/bin
    is in your path.
    
    
    waiting for X server to shut down FreeFontPath: FPE "/usr/share/fonts/X11/misc" refcount is 2, should be 1; fixing.

    Tried to switch to the second X-server, but it was only blank.

  7. #7
    Join Date
    Jun 2006
    Beans
    471

    Re: HOWTO: The Best Way To Play Games On Ubuntu

    Looks like the install failed to install feh (a image display program for showing a background) and openbox (the light weight window manager).

    What output do you get if you run:

    Code:
    sudo apt-get install openbox
    sudo apt-get install feh
    from the terminal?

  8. #8
    Join Date
    Jul 2006
    Location
    on the bleeding edge
    Beans
    1,011

    Re: HOWTO: The Best Way To Play Games On Ubuntu

    You're most correct - I didn't have them installed. but why go and install all these packages? isnt it just easier to run the games in another plain X-server?

  9. #9
    Join Date
    Jun 2006
    Beans
    471

    Re: HOWTO: The Best Way To Play Games On Ubuntu

    The X server wont process keypresses without a window manager running. I believe this is a bug but it's one that's on Ubuntu. It also makes windows work correctly if you're running something that's not always fullscreen such as steam.

    Feh is just for showing a background image on the desktop. No necessary but welcome after spending lost of time testing with the hatch background.

    Can I ask what was preventing the script from installing openbox and feh? What did you do to install them?

  10. #10
    Join Date
    Apr 2006
    Beans
    16

    Re: HOWTO: The Best Way To Play Games On Ubuntu

    I tried this and the screen went to a blank screen with cross hatches and the cursor as an x. The Alt - F7 key stroke didn't work so I had to restart.

    I was trying to run WoW from Wine, so maybe that had something to do with it. Heres what I tried to run...

    x.game start WINEDEBUG=-all wine /home/justin/.wine/drive_c/"Program Files"/"World of Warcraft"/WoW.exe

Page 1 of 9 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •