The Linux Gamers' HOWTO

Peter Jay Salzman

Frédéric Delanoy

Copyright © 2001, 2002 Peter Jay Salzman

Copyright © 2003, 2004 Peter Jay Salzman, Frédéric Delanoy

2004-11-13 v.1.0.6<<BR>>

Abstract

The same questions get asked repeatedly on Linux related mailing lists and news groups. Many of them arise because people don't know as much as they should about how things "work" on Linux, at least, as far as games go. Gaming can be a tough pursuit; it requires knowledge from an incredibly vast range of topics from compilers to libraries to system administration to networking to XFree86 administration ... you get the picture. Every aspect of your computer plays a role in gaming. It's a demanding topic, but this fact is shadowed by the primary goal of gaming: to have fun and blow off some steam.

This document is a stepping stone to get the most common problems resolved and to give people the knowledge to begin thinking intelligently about what is going on with their games. Just as with anything else on Linux, you need to know a little more about what's going on behind the scenes with your system to be able to keep your games healthy or to diagnose and fix them when they're not.

&lt;[[mailto:p(at)dirac(dot)org|p(at)dirac(dot)org]]&gt; / http://www.dirac.org/p.

Distributed subject to the Open Software License, ver 1.1

1. Administra

If you have ideas, corrections or questions relating to this HOWTO, please email me. By receiving feedback on this howto (even if I don't have the time to answer), you make me feel like I'm doing something useful. In turn, it motivates me to write more and add to this document. You can reach me at &lt;[[mailto:p(at)dirac(dot)org|p(at)dirac(dot)org]]&gt;. My web page is http://www.dirac.org/p and my Linux pages are at http://www.dirac.org/linux. Please do send comments and suggestions for this howto. Even if I don't take your suggestions, your input is graciously received.

I assume a working knowledge of Linux, so I use some topics like runlevels and modules without defining them. If there are enough questions (or even protests) I'll add more basic information to this document.


1.1. Authorship and Copyright

This document is copyright (c) 2001-2002 Peter Jay Salzman, &lt;[[mailto:p(at)dirac(dot)org|p(at)dirac(dot)org]]&gt;; 2003-2004 Peter Jay Salzman and Frédéric Delanoy. Permission is granted to copy, distribute and/or modify this document under the terms of the Open Software License, Version 1.1, except for the provisions I list in the next paragraph. I hate HOWTO's that include the license; it's a tree killer. You can read the OSL at http://opensource.org/licenses/osl-1.1.txt.

If you want to create a derivative work or publish this HOWTO for commercial purposes, I would appreciate it if you contact me first. This will give me a chance to give you the most recent version. I'd also appreciate either a copy of whatever it is you're doing or a spinach, garlic, mushroom, feta cheese and artichoke heart pizza.


1.2. Acknowledgements

Thanks goes out to these people for extensive comments, corrections, and diffs. Their effort is above and beyond the call of duty:

Frédéric Delanoy, Moritz Muehlenhoff &lt;[[mailto:jmm(at)Informatik(dot)uni-bremen(dot)de|jmm(at)Informatik(dot)uni-bremen(dot)de]]&gt;, Mike Phillips, Ioan Rogers &lt;[[mailto:buck(at)aiur(dot)co(dot)uk|buck(at)aiur(dot)co(dot)uk]]&gt;

I would also like to thank the following people for sending in comments and corrections. Without their help, there would be more typos and mistakes than you could shake a stick at:

Michael McDonnell?


1.3. Latest Versions and Translations

The latest version can be found at http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/lgh/LG-HOWTO or http://www.dirac.org/linux/writing, but this is my own personal working copy. The version at my personal web site might be broken if I'm working on the HOWTO. The version at sourceforge is bleeding edge but guaranteed to be not broken, however it may have glitches, like unfinished paragraphs. :)

The most recent stable version can be found at http://www.tldp.org.


1.3.1. Russian

Dmitry Samoyloff &lt;[[mailto:dsamoyloff(at)yandex(dot)ru|dsamoyloff(at)yandex(dot)ru]]&gt; is the maintainer of the Russian translation. The most recent version can be found at http://www.dirac.org/linux/writing.


1.3.2. Hungarian

László Daczi &lt;[[mailto:dacas(at)korhaz(dot)rethy(dot)hu|dacas(at)korhaz(dot)rethy(dot)hu]]&gt;, the Hungarian LDP coordinator, announced that a Hungarian translation was produced by Szilard Ivan, and is available at http://tldp.fsf.hu/HOWTO/Linux-Gamers-HOWTO-hu.


2. Definitions: Types Of Games

Not everyone knows the different types of games that are out there, so in an effort to form a common language that we can all use, I'll run through each game type and provide a very brief history.


2.1. Arcade style

Although arcade games had their heydey in the 80's, they are nonetheless very popular. Nothing will ever replace walking into a dark, crowded and noisy arcade gallery, popping a quarter into your favorite machine and playing an old fashioned game of Space Invaders. Arcade style games attempt to simulate the arcade games themselves. There is such a vast number of these things that it's nearly impossible to enumerate them all, but they include clones of Asteroids, Space Invaders, Pac-Man, Missile Command and Galaxian.


2.2. Card, logic and board games

Computer based card games simulate a card game like poker or solitaire. The program can simulate your opponent(s).

Logic games usually simulate some well known logic puzzle like Master Mind or the game where you have put sliding numbered tiles in order inside a box.

Computer based board games simulate some kind of board game you'd play on a table top with friends, like monopoly, Mille Bourne, chess or checkers. The program can simulate your opponent.


2.3. Text Adventure (aka Interactive Fiction)

Once upon a time, when Apple ][, Commodore, and Atari ruled the world, text adventures were the game of choice of `intelligent folk'. You are given a scenario and can interact with the world you're placed in:

<tablebgcolor="#e0e0e0" tablewidth="100%"> You are in a room. It is pitch dark and you're likely to be eaten by a grue. &gt; Light lantern with match. You light the lantern. This room appears to be a kitchen. There's a table with a book in the center. You also see an oven, refrigerator and a door leading east. &gt; Open the oven. In the oven you see a brown paper bag. &gt; Take the bag. Open the bag. Close the oven. Inside the bag is a some garlic and a cheese sandwich. The oven door is now closed.

Back then, text adventures were self contained executables on a disk or casette. These days there's usually a data file and an interpreter. The interpreter reads data files and provides the gaming interface. The data files are the actual game itself, similar to the relationship between first person shooters ([2.7]) and wad files.

The first adventure game was Adventure (actually “ADVENT”, written on a PDP-1 in 1972). You can play Adventure yourself (actually, a descendent); it comes with “bsd games” on most Linux distros. Text adventures became popularized by Scott Adams ([11.5]) and reached their height of popularity in the late 80's with Infocom ([11.4]) which are also playable under Linux.

As computer graphics became easier and more powerful, text adventures gave rise to graphic adventures. The death of commercial interactive fiction more or less coincided with the bankruptcy of Infocom.


2.4. Graphical Adventures

Graphical adventures are, at heart, text adventures on steroids. The degree to which they use graphics varies widely. Back in the 80's, they were little more than text adventures which showed a screen of static graphics. When you picked up an item, the background would be redrawn without the item appearing. The canonical example would be the so-called `Hi-Res Adventures' like The Wizard And The Princess. Later on, the sophisticated graphical adventures had your character roaming around the screen, and you could even use a mouse, but the interface remained purely text.

Next there are the `point and click adventures' which basically have no text interface at all, and often have dynamic graphics, like a cat wandering around the room while you're deciding what to do next. In these games, you point at an object (say, a book) and can choose from a pull-down list of functions. Kind of like object oriented adventuring. :) There aren't many graphical adventures written natively for Linux. The only one I can think of is Hopkins FBI (which happens to be my favorite game for Linux).


2.5. Simulation (aka Sims)

Simulations strive to immerse the player behind the controls of something they normally wouldn't have access to. This could be something real like a fighter jet or something imaginary like a mechanized warrior combat unit. In either case, sims strive for realism.

Some sims have little or no strategy. They simply put you in a cockpit to give you the thrill of piloting a plane. Some are considerably complex, and there's often a fine line between sims and strats ([2.6]). A good example would be Heavy Gear III or Flight Gear. These days sims and strats are nearly indistinguishable, but a long time ago, sims were real time while strats were turn based. This is awkward for modern day use, since a game like Warcraft which everyone knows as a strat, would be a sim by definition.


2.6. Strategy (aka Strats)

Strategy games have their roots in old Avalon type board games like Panzer Leader and old war strategy games published by SSI. Generally, they simulate some kind of scenario. The scenario can be peaceful, like running a successful city (SimCity?), or not, like illegal drug selling operation (DrugWars?) or an all-out war strategy game like Myth II. The types of games usually take a long time to complete and require a lot of brainpower.

Strats can be further divided into two classes: real time and turn based. Real time strats are based on the concept of you-snooze-you-lose. For example, you're managing a city and a fire erupts somewhere. The more time it takes for you mobilize the fire fighters, the more damage the fire does. Turn based strats are more like chess---the computer takes a turn and then the player takes a turn.


2.7. First Person Shooter (aka FPS)

What light through yonder window breaks? It must be the flash of the double barreled shotgun! We have a long and twisted history with FPS games which started when id Software open sourced code for Doom. The code base has forked and merged numerous times. Other previously closed engines opened up, many engines are playable via emulators, many commercial FPS games were released for Linux and there are quite a number of FPS engines which started life as open source projects. Although you may not be able to play your favorite FPS under Linux (Half-Life plays great under winex) Linux definitely has no deficiency here!

First person shooters are characterized by two things. First, you pretty much blow up everything you see. Second, the action takes place in first person. That is, through the eyes of the character who's doing all the shooting. You may even see your hands or weapon at the bottom of the screen. They can be set in fantasy (Hexen), science fiction (Quake II), present day `real world' (Soldier Of Fortune) and many other settings.

Like text adventures, FPS fit the engine/datafile format. The engine refers to the actual game itself (Doom, Quake, Heretic2) and plays out the maps and bad guys outlined by the datafile (doom2.wad, pak0.pak, etc). Many FPS games allow people to write their own non-commercial datafile. There are hundreds, even thousands of non-commercial Doom datafiles that you can download for free off the net. Often, companies release their engines to the open source community so we can hack and improve them. However, the original data files are kept proprietary. To this day, you still have to purchase doom.wad.


2.8. Side Scrollers

Side scrollers are similar to FPS but you view your character as a 2D figure who runs around various screens shooting at things or performing tasks. Examples would be Abuse for Linux and the original Duke Nukem. They don't necessarily have to be violent, like xscavenger, a clone of the old 8-bit game Lode Runner.


2.9. Third Person Shooters

Similar to FPS, but you view your character in third person and in 3D. On modern third person shooters you can usually do some really kick-butt maneuvers like Jackie Chan style back flips and side rolls. The canonical example would be Tomb Raider. On the Linux platform, we have Heretic 2 and Heavy Metal FAKK2.


2.10. Role Playing Game (aka RPG)

Anyone who has played games like Dungeons & Dragons or Call of Cthulhu knows exactly what an RPG is. You play a character, sometimes more than one, characterized by traits (eg strength, dexterity), skills (eg explosives, basket weaving, mechanics) and properties (levels, cash). As you play, the character becomes more powerful and the game adjusts itself accordingly, so instead of fighting orcs, at high levels you start fighting black dragons. The rewards increase correspondingly. At low levels you might get some gold pieces as a reward for winning a battle. At high levels, you might get a magic sword or a kick-butt assault rifle.

RPG's generally have a quest with a well defined ending. In nethack you need to retrieve the amulet of Yendor for your god. In Ultima II, you destroy the evil sorceress Minax. At some point, your character becomes powerful enough that you can `go for it' and try to complete the quest.

While the insanely popular Ultima series, written by Richard Garriot (aka Lord British) for Origin, was not the first RPG, it popularized and propelled the RPG genre into mainstream. Ultima I was released in 1987 and was the game that launched 9 (depending on how you want to count them) very popular sequels, finishing with Ultima IX: Ascension. You can play Ultima VII under Linux with Exult ([11.7]).

The canonical RPG on Linux is Rogue (the ncurses library started life as a screen handling routine for Rogue!) and it has infinite variants like Zangband and Nethack (which has many variants itself). Some RPG's are quite complicated and great feats of programming. There seems to be a deficiency of commercial RPGs for Linux. Not counting the rogue variants, there's also a deficiency of open source RPGs too.


3. Libraries

We'll run through the different gaming libraries you'll see under Linux.


3.1. What is Glide2?

Glide2 is a low level graphics API and driver that accesses 3D hardware accelerated functions on 3dfx's Voodoo I, II and III cards, under XFree86 3.x.

A program can only use the special hardware accelerated features of these cards by using the Glide2 library in one of two ways:

  • directly written using Glide2 (Myth II, Descent III)
  • indirectly using Mesa built with a Glide2 backend to simulate OpenGL (Rune, Unreal Tournament)

3dfx opened up the specifications and source code to the open source community. This allowed Daryll Strauss to port Glide2 to Linux which enabled XFree86 3.x users to use Voodoo I, II and III cards under Linux.

Since Glide2 accesses the video card directly, Glide2 applications will either need to be run by root or be setuid root. A way around this was to create the kernel 3dfx module. This module (and its device file /dev/3dfx) allows Glide2 graphical hardware acceleration for non-root users of non-setuid applications.

Unfortunately, Glide2 is also a dead issue. It's only used for Voodoo I, II, III boards (which are becoming outdated), under XFree86 3.x (most people use XFree86 4.x). And since 3dfx is now a defunct company, it's a sure bet that no more work will be done on Glide2 and no more games will be written using Glide2.


3.2. What is Glide3?

Unlike Glide2, Glide3 is not an API used for game programming. It exists only to support DRI on Voodoo III, IV and V boards under XFree86 4.x. None of the games which use Glide2 will work with Glide3. This shouldn't be a surprise since Glide2 and Glide3 support different video cards and different versions of XFree86. The only video card that can use both Glide2 (under XFree86 3.x) and Glide3 (under XFree86 4.x) is the Voodoo III. It's reported that a Voodoo III using Glide2 will outperform a Voodoo III using Glide3.

When you use a Voodoo III, IV or V under XFree86 4.x, you want to use a version of Mesa (see [3.4]) which was compiled to use Glide3 as a backend to ensure hardware accelerated OpenGL on your system.


3.3. What is OpenGL?

OpenGL is a high level graphics programming API originally developed by SGI, and it became an industry standard for 2D and 3D graphics programming. It's defined and maintained by the Architectural Revision Board (ARB), an organization which include representatives from SGI, IBM, DEC, and Microsoft. OpenGL provides a powerful, complete and generic feature set for 2D and 3D graphics operations.

There are 3 canonical parts to OpenGL:

  • GL: The OpenGL core calls
  • GLU: The utility calls
  • GLUT: OS independent window event (mouse, keyboard, etc.) handler.

OpenGL is not only an API, it's also an implementation, written by SGI. The implementation tries to use hardware acceleration for various graphics operations whenever available, which depends on what videocard you have in you computer. If hardware acceleration is not possible for a specific task, OpenGL falls back on software rendering. This means that when you get OpenGL from SGI, if you want any kind of hardware acceleration at all, it must be OpenGL written and compiled specifically for some graphics card. Otherwise, all you'll get is software rendering. The same thing is true for OpenGL clones, like Mesa.

OpenGL is the open source equivalent to Direct3D, a component of DirectX ([3.14]). The important difference being that since OpenGL is open (and DirectX is closed), games written in OpenGL are much easier to port to and co-develop on Linux than games written using DirectX.


3.4. What is Mesa?

Mesa <http://www.mesa3d.org&gt; is a free implementation of the OpenGL API, designed and written by Brian Paul. While it's not officially certified (that would take more money than an open source project has), it's an almost fully compliant OpenGL implementation conforming to the ARB specifications. It's reported that Mesa is even faster than SGI's own OpenGL implementation.

Just like OpenGL, Mesa makes use of hardware acceleration whenever possible. When a particular graphics task isn't able to be hardware accelerated by the video card, it's software rendered; the task is done by your computer's CPU instead. This means that there are different builds of Mesa depending on what kind of video card you have. Each build uses a different library as a backend renderer. For example, if you have a Voodoo I, II or III card under XFree86 3.x, you'd use mesa+glide2 (written by David Bucciarelli) which is the Mesa implementation of OpenGL that uses Glide2 as a backend to render for graphical operations.


3.5. What is DRI?

Graphics rendering has 3 players: the client application (like Quake 3), the X server and the hardware (the graphics card). Previously, client applications were prohibited from writing directly to hardware, and there was a good reason for this. A program that is allowed to directly write to hardware can crash the system in any number of ways. Rather than trusting programmers to write totally bug free, cooperative programs that access hardware, Linux simply disallowed it. However, that changed under X 4.x with DRI (Direct Rendering Infrastructure <http://www.dri.sourceforge.net&gt;. DRI allows X clients to write 3D rendering information directly to the video card in a safe and cooperative manner.

DRI gets the X server out of the way so the 3D driver (Mesa or OpenGL) can talk directly to the hardware. This speeds things up. The 3D rendering information doesn't even have to be hardware accelerated. On a technical note, this has a number of virtues.

  • Vertex data doesn't have to be encoded/decoded via GLX.
  • Graphics data isn't sent over a socket to the X server.
  • On uni-processor machines the CPU doesn't have to change context between XFree86 and its client to render the graphics.

3.6. What is GLX?

GLX is the X extension used by OpenGL programs, it is the glue between the platform independent OpenGL and platform dependent X.


3.7. What is Utah GLX?

Utah-GLX is the precursor to DRI. It makes some different design decisions regarding separation of data and methods of accessing the video card like relying on root access rather than creating the kernel infrastructure for secure access. It provides support for a few cards which are not well supported by DRI like the ATI Rage Pro family, S3 Virge (although anyone using this for gaming is, well, nuts), and an open source TNT/TNT2 driver (which is very incomplete). The TNT/TNT2 driver is based on reverse-engineering of the obfuscated source code release of the X 3.3 drivers by nVidia. However, they're really incomplete, and effectively, unusable.


3.8. What is xlib?

Every once in awhile you'll see some sicko (said with respect) write a game in xlib. It is a set of C libraries which comprise the lowest level programming interface for XFree86. Any graphics programming in X ultimately makes use of the xlib library.

It's not an understatement to say that xlib is long winded, arcane and complicated. Because of this, there are lots of libraries like SDL ([3.10]) for 2D graphics, OpenGL ([3.3]) for 3D graphics and widget sets ([3.9]) for widgets within windows which hide the details of different aspects of xlib programming.

While some games are written in xlib, like the Doom Editor Yadex, xlib itself is not a serious game writing library. Most games don't need the low-level interface that xlib provides. In addition, by using the higher level libraries, a game writer can develop his game on multiple platforms, even ones that don't use XFree86.


3.9. What is a widget set?

Widgets are objects that make up a GUI application's interface. They include things like text entry boxes, pulldown menus, slider bars, radio buttons and much more. A widget set is a collection of related widgets that are designed to have a common interface and a consistant "feel". Gtk is the canonical widget set on Linux, but there are many others like fltk (a small C++ widget set), Xaw, Qt (the widget set of KDE), and Motif (the widget set used by Netscape). Motif used to be the king of widget sets in the Unix world, but it was very expensive to license. The Open Group finally opened up Motif's license for open source operating systems, but it was too little too late. There are many completely open source widget sets which are more complete and much nicer looking than Motif, including Lesstif, a totally free Motif clone.


3.10. What is SDL (Simple DirectMedia? Layer)?

SDL <http://www.libsdl.org&gt; is a library by Sam Lantiga (graduate of UCD, yeah!). It's actually a meta-library, meaning that not only is it a graphics library which hides the details of xlib programming, it provides an easy interface for sound, music and event handling. It's LGPL'd and provides joystick and OpenGL support as well. Unlike xlib ([3.8]), SDL is very suited for game programming.

The most striking part of SDL is that it's a cross platform library. Except for a few details, a program written in SDL will compile under Linux, MS Windows, BeOS, MacOS, MacOS X, Solaris, IRIX, FreeBSD, QNX and OSF. There are SDL extensions written by various people to do things like handle any graphics format you care to mention, play mpegs, display truetype fonts, sprite handling and just about everything under the sun. SDL is an example of what all graphics libraries should strive for.

Sam had an ulterior motive for writing such a cool library. He was the lead programmer for Loki Software (he now codes for Blizzard Software), which used SDL in all of its games except for Quake3.


3.11. What is GGI?

GGI <http://www.ggi-project.org&gt; is a project which aims to implement a graphics abstraction layer in lower level code, put graphics hardware support into a common codebase, and bring higher stability and portability to graphics applications. LibGGI applications run on SVGAlib, fb, and X servers among others. Judging from their screenshots, this is quite a powerful library.

Applications that use LibGGI directly include Heroes, Ultrapoint, Quake, and Berlin. Most applications that use SVGALib can be run on X or any other LibGGI backend by using a wrapper library which re-implements SVGALib ([3.12]) using LibGGI. SDL ([3.10]) and clanlib ([3.15]) applications can display on LibGGI but often the native drivers for these libraries are faster, however it's a good way to get SDL, clanlib, and SVGALib applications to run where they would not before.

GGI has a sister project, KGI, which is developing a kernel-level alternative to systems like the linux framebuffer and the DRI. This project is much less far along than LibGGI itself, but promises to combine DRI-level speeds and the stability and security UNIX users expect.


3.12. What is SVGAlib? Frame buffer? Console?

The console is the dark non-graphical screen you look at when your computer first boots up (and you don't have xdm or gdm running). This is opposed to the X environment which has all sorts of GUI things like xterms. It's a common misconception that X means graphics and console means no graphics. There are certainly graphics on the console—we will discuss the two most common ways to achieve this.

SVGAlib is a graphics library that lets you draw graphics on the console. There are many graphical applications and games that use SVGAlib like zgv (a console graphical image viewer), prboom and hhexen. I happen to be a fan of this library and of graphical console games in general; they are extremely fast, fullscreen and compelling. There are three downsides to SVGAlib. First, SVGAlib executables need to be run by root or be setuid root, however, the library releases root status immediately after the executable begins to run. Secondly, SVGAlib is video card dependent–if your video card isn't supported by SVGAlib, you're out of luck. Third, SVGAlib is Linux only. Games written in SVGAlib will only work on Linux.

Frame buffers are consoles implemented by a graphics mode rather than a BIOS text mode. Why simulate text mode in a graphical environment? This allows us to run graphical things in console, like allowing us to choose any font we want the console to display (which is normally set by BIOS). There's a good Framebuffer HOWTO available from LDP. Graphical console games written using the frame buffer suffer from the same deficiencies of the SVGA library: not all hardware is supported and the code will only run on Linux.


3.13. What is OpenAL?

OpenAL <http://www.openal.org&gt; aims to be for sound what OpenGL is for graphics. It started as a joint project between Loki Software and Creative Labs, setting out to be a vendor neutral and cross platform API for audio - the audio equivalent of OpenGL ([3.3]). Loki is no longer in business, but Creative and the Open Source community have kept the project alive. It is licensed LGPL and the specs can be obtained for free from the OpenAL website. It has support from nVidia (nForce2/3 based motherboards come with OpenAL MS Windows libraries for the on-board audio), Apple has added OpenAL to their audio framework for OSX and it can also be found powering the Epic Games Unreal Engine

Currently, it's not all cross-platform goodness. There is almost no support for enhancements like EAX or any hardware acceleration on Linux, though it does it exist in the Windows implementation. However, if you have a Creative SoundBlaster? or Audigy sound card (with an emu10x chip), and you use ALSA sound drivers, you can get OpenAL libraries from http://www.lost.org.uk that provide hardware acceleration and decent surround support.


3.14. What is DirectX?

DirectX is a collection of proprietary multimedia API's, first developed by Microsoft in 1995, for its various Windows OS's. It's a mistake to say something like "DirectX is like OpenGL" or "DirectX is like SDL", as is commonly said in DirectX tutorials. Multimedia API's are more centralized on Windows than they are on Linux. A more accurate statement would be something like "DirectX is like DRI, OpenGL and SDL combined". As of October 2004, the most recent version of DirectX is 9c. The components of DirectX are:

DirectDraw:: DirectDraw? gives direct access to video memory, like DRI, so 2D graphics can be blitted directly to the video card. DirectDraw? is like the graphical component of SDL, but the direct video card access is done by DRI rather than SDL. This is why a game can easily take out a Windows system but should not take down a Linux system.Direct3D (D3D):: Direct3D, like OpenGL, provides a 3D graphics API. Whereas OpenGL is open source, lower level and compiles under a multitude of operating systems, D3D is proprietary, higher level and only compiles on Windows. D3D first appeared in DirectX 2, released in 1996.DirectAudio:: DirectAudio? is a combination of 2 audio API's, DirectSound? and DirectMusic?, which allows direct access to the sound card for sound and music playback.DirectInput:: DirectInput? gives support for gaming input devices such as joysticks.DirectPlay:: DirectPlay? gives support for simplified networking for multiplayer gaming.DirectShow:: DirectShow? provides support for movie files like AVI and MPG. It was a separate API from DirectX, but was integrated with DirectX 8.DirectSetup:: This API provides a way to install DirectX from within an application to simplify game installation.

Depending on the version of DirectX you're talking about, DirectX support in winex ([10.5.3]) ranges from well supported to "kind of" supported. It's poorly supported by wine ([10.5.1]), barely supported by vmware ([10.5.5]) and unsupported by Win4Lin ([10.5.4]).

One comment about portability: Each component of DirectX has multiple corresponding library on Linux. Moreover, a game writer who uses libraries like OpenGL, GGI or SDL will write a game which will trivially compile on Windows, Linux and a multitude of other OS's. Yet game companies persist using DirectX and therefore limit their audience to Windows users only. If you're a game writer, please consider using cross platform libraries and stay away from DirectX.

A company named realtechVR started an open source project, DirectX Port, <http://www.v3x.net/directx&gt; which, like wine, provides a Direct3D emulation layer that implements Direct3D calls. The project was focused on the BeOS platform, but is now focused on MacOS and Linux. You can get the latest cvs from their sourceforge page at <http://sourceforge.net/projects/dxglwrap&gt;.


3.15. Clanlib

ClanLib? is a medium level development kit. At its lowest level, it provides a platform independent (as much as that is possible in C++) way of dealing with display, sound, input, networking, files, threading and such. ClanLib? builds a generic game development framework, giving you easy handling of resources, network object replication, graphical user interfaces (GUI) with theme support, game scripting and more.


4. XFree86 and You

If you're going to game under X, it's crucial that you know a bit about X. The "X Window User HOWTO", and especially "man XF86Config" are required reading. Don't short change yourself; read them. They have an extremely high "information to space" ratio. Many problems can be fixed easily if you know your way around XF86Config (or XF86Config-4).


4.1. Getting information about your X system

Whether you're trying to diagnose an X problem or requesting help from a mailing list or Usenet newsgroup, you'll want to have as much information available as possible. These are a set of tools you can use to obtain that information.


4.1.1. Probeonly

One of the best diagnostic tools and sources of information about your X system is probeonly output. To use it, kill X if it's already running and from a console, type:

<tablebgcolor="#e0e0e0" tablewidth="100%"> X -probeonly 2&gt; X.out

Yes, that's a single dash; so much for standards. The output of X goes to stderr, so we have to redirect stderr with "2>" to a file named X.out. This file will have almost everything there is to know about your X system. It's crucial that you know the difference between the various markers you'll see in probeonly output:

<tablebgcolor="#e0e0e0" tablewidth="100%"> (--) probed (**) from config file (==) default setting (++) from command line (!!) notice (II) informational (WW) warning (EE) error (??) unknown.

Here's an example of some information I gleaned from my output:

I'm running at 16 bpp color:

<tablebgcolor="#e0e0e0" tablewidth="100%"> (**) TDFX(0): Depth 16, (--) framebuffer bpp 16

X has detected what my videocard chipset and videoram are:

<tablebgcolor="#e0e0e0" tablewidth="100%"> (--) Chipset 3dfx Voodoo5 found (--) TDFX(0): VideoRAM: 32768 kByte Mapping 65536 kByte

4.1.2. Getting info about your setup: xvidtune

xvidtune is your friend when your X screen is shifted a little bit too far to the right, or if the vertical length is too small to fit on your monitor. However, it's a great diagnostic tool also. It'll give you:

  • the hsync/vsync range specified in your XF86Config file
  • the 4 horizontal and 4 vertical numbers which defines your videomode (the 1st horizontal/vertical numbers gives the screen resolution). These 8 numbers will tell you which modeline your X uses. See the XFree86 Video Timings Howto for more information. Note that explicit modelines are no longer necessary, since XFree 4.0.1 and up computes modetimings automatically based on your monitor's and video card's capabilities. However, there may be times when you'll want to play around with mode timings, like for weird hardware or if want to tweak your display.
  • the "dot clock" your videocard is running at.

4.1.3. Getting info about your setup: xwininfo

xwininfo tells you all sorts of information about X windows. And actually, your "background" or "root" window is considered a window too. So when xwininfo asks you to click on the window you want the information on, click on your background. It'll tell you things like screen and window resolution, color depth, window gravity state (which gives a hint to the window manager about where to place new windows), backing store usage and more.


4.1.4. Other sources of information

xdpyinfo gives cool stuff, like X version and loaded extensions (invaluable when trying to see what's missing, like GLX, DRI, XFree86-VidMode?, etc.).


4.1.5. Getting information about your 3D system

glxinfo gives lots of useful information about OpenGL like whether direct rendering enabled, the currently installed versions of glx and mesa, vendor/renderer strings, the GL library files being used and more.


4.2. Playing Games In X Without a Window Manager

When playing a game under X, you should consider starting X without a window manager (WM). Heavyweight WMs, like Enlightenment, or full-blown desktop environments like GNOME or KDE, may produce a noticeable slow down. Even lightweight WMs, like twm, rob your CPU of clock cycles (and in twm's case, even full screen games will have a frame around the window). Running a game without a WM or DE depends on how you access X. If you usually log in to a Virtual Console and start X with "startx" try the following:

Modify ~/.xinitrc, which tells X what to run upon starting. Here is what my .xinitrc looks like:

<tablebgcolor="#e0e0e0" tablewidth="100%"> #quake3 +set r_gldriver libGR.so.1 #exec ut #lsdldoom -server 2 #exec tribes2 exec /usr/bin/enlightenment

You'll usually see a window or desktop manager being executed from this file (GNOME or KDE). Comment out the lines containing the WM or desktop manager with a pound sign (#) and place your game on a new line with any command line arguments you want to pass. If the game is not located in your $PATH, give its full path name.

If you log directly into X using gdm, then things are a little different. These instructions are for gdm 2.4 or greater. They *may* work with kde, but I cannot say for certain.

First, check your gdm.conf (usually in /etc/X11/gdm or /etc/gdm) file for a line that says begins "SessionDesktopDir=blah". One of the directories listed as options should be "/usr/share/xsessions", and is the directory which will be used in this example. As root, change to the "/usr/share/xsessions" directory and take a look at its contents. It should contain some .desktop files, each corresponding to an entry you'll see in gdm's Session menu, e.g gnome.desktop, enlightenment.destop. This example will show you how to log in to Doom3. Copy any of the desktop files to "doom3.desktop" and open the new file in your favourite text editor. The file will be full of alternative languages, so cut out everything you don't want and make the file look like this:

<tablebgcolor="#e0e0e0" tablewidth="100%"> [Desktop Entry] Encoding=UTF-8 Name=DOOM III Comment=iD's Doom III #if game is not in path, remember to put the full path here Exec=/usr/games/doom3/doom3 # no icon yet, only the top three are currently used Icon= Type=Application

Save the file and log out of your window manager. At the gdm login screen, you should now see "DOOM III" as an option in "Sessions". Naturally you can add a .desktop file for each game you have installed


5. Various Topics

5.1. Memory Type Range Registers

Starting with Pentium class processors and including Athlon, K6-2 and other CPUs, there are Memory Type Range Registers (MTRR) which control how the processor accesses ranges of memory locations. Basically, it turns many smaller separate writes to the video card into a single write (a burst). This increases efficiency in writing to the video card and can speed up your graphics by 250% or more.

See /usr/src/linux/Documentation/mtrr.txt for details. Note that since this file was written, XFree86 has been patched to automatically detect your video RAM base address and size and set up the MTRRs.


5.2. Milking performance from your system for all it's worth

  • If for some reason you're using X 3.3, follow the instructions given by mtrr.txt (see [5.1]) to set up your MTRRs. X 4.0 does this automatically for you.
If you're playing a game under X, don't run a window manager, and certainly don't run a desktop manager like GNOME or KDE. See [4.2] for details.Kill all non-essential processes (you'll have to do this as root) by using the startup scripts on your system. On Debian, the startup scripts for run-level 2 are located in /etc/rc2.d/. You can kill a service in an orderly manner by sending its startup script the `stop' command:<tablestyle="width:90%; background-color:#E0E0E0"> # cd /etc/rc2.d # ./ntpd stop Another (radical) option is to simply put yourself in single-user mode with<tablestyle="width:90%; background-color:#E0E0E0"> # telinit 1 This will even get rid of getty; your system will only be running whatever is absolutely crucial to its operation. You'll have something like 10 processes running. The downside is that you'll have to play the game as root. But your process table will be a ghost town, and all that extra CPU will go straight to your game.

5.3. About libraries on Linux

A common problem you'll see in gaming is a library file not being found. They're kind of mysterious and have funny names, so we'll go over libraries on Linux for a bit. There are two types of libraries, static and dynamic. When you compile a program, by default, gcc uses dynamic libraries, but you can make gcc use static libraries instead by using the -static switch. Unless you plan on compiling your games from source code, you'll mainly be interested in dynamic libraries.


5.3.1. Dynamic libraries

Dynamic libraries, also called a “shared library”, provide object code for an application while it's running. That is, code gets linked into the executable at run time, as opposed to compile time. They're analagous to the .dll's used by Windows. The program responsible for linking code “on the fly” is called /etc/ld.so, and the dynamic libraries themselves usually end with .so with a version number, like:

<tablebgcolor="#e0e0e0" tablewidth="100%"> /usr/lib/libSDL.so /lib/libm.so.3

When using gcc, you refer to these libraries by shaving off the strings lib, .so and all version numbers. So to use these two libraries, you would pass gcc the -lSDL -lm options. gcc will then place a memo inside the executable' that says to look at the files /usr/lib/libSDL.so and /lib/libm.so.3` whenever an SDL or math function is used.


5.3.2. Static libraries

In contrast to dynamic libraries which provide code while the application runs, static libraries contain code which gets linked (inserted) into the program while it's being compiled. No code gets inserted at run time; the code is completely self-contained. Static libraries usually end with .a followed by a version number, like:

<tablebgcolor="#e0e0e0" tablewidth="100%"> /usr/lib/libSDL.a /usr/lib/libm.a

The .a files are really an archive of a bunch of .o (object) files archived together, similar to a tar file. You can use the nm to see what functions a static library contains:

<tablebgcolor="#e0e0e0" tablewidth="100%"> % nm /usr/lib/libm.a ... e_atan2.o: 00000000 T __ieee754_atan2 e_atanh.o: 00000000 T __ieee754_atanh 00000000 r half 00000010 r limit 00000018 r ln2_2 ...

When using gcc, you refer to these libraries by shaving off the strings “lib”, “.a” and all version numbers. So to use these two libraries, you would pass gcc the -lSDL -lm options. gcc will then bolt on' code from /usr/lib/SDL.a and /usr/lib/libm.a` whenever it sees a math function during the compilation process.


5.3.3. How are library files found

If you compile your own games, your biggest problem with libraries will either be that gcc can't find a static library or perhaps the library doesn't exist on your system. When playing games from binary, your library woes will be either be that ld.so can't find the library or the library doesn't exist on your system. So it makes some sense to talk about how gcc and ld.so go about finding libraries in the first place.

gcc looks for libraries in the standard system directories plus any directories you specify with the -L option. You can find what these standard system directories are with gcc -print-search-dirs

ld.so looks to a binary hash contained in a file named /etc/ld.so.cache for a list of directories that contain available dynamic libraries. Since it contains binary data, you cannot modify this file directly. However, the file is generated from a text file /etc/ld.so.conf which you can edit. This file contains a list of directories that you want ld.so to search for dynamic libraries. If you want to start putting dynamic libraries in /home/joecool/privatelibs, you'd add this directory to /etc/ld.so.conf. Your change doesn't actually make it into /etc/ld.so.cache until you run ldconfig; once it's run, ld.so will begin to look for libraries in your private directory.

Also, even if you just add extra libraries to your system, you must update ld.so.cache to reflect the presence of the new libraries.


5.3.4. Finding Out What Libraries a Game Depends On

Most commercial Linux games will be dynamically linked against various LGPL libraries, such as OpenAL or SDL. For these examples, Bioware's NeverWinter? Nights <http://nwn.bioware.com&gt; will be used.

To find out what libraries a game uses, we can use the "ldd" command. Cd to /usr/games/nwn, or wherever you installed it and take a look at the files. You should see a file called nwmain; this is the actual game binary. Type "ldd nwmain" and you'll see:

<tablebgcolor="#e0e0e0" tablewidth="100%"> $ ldd nwmain linux-gate.so.1 =&gt; (0xffffe000) libm.so.6 =&gt; /lib/libm.so.6 (0x40027000) libpthread.so.0 =&gt; /lib/libpthread.so.0 (0x40049000) libGL.so.1 =&gt; /usr/lib/libGL.so.1 (0x4009b000) libGLU.so.1 =&gt; /usr/X11R6/lib/libGLU.so.1 (0x40103000) libmss.so.6 =&gt; not found libSDL-1.2.so.0 =&gt; /usr/lib/libSDL-1.2.so.0 (0x40178000) libc.so.6 =&gt; /lib/libc.so.6 (0x401ff000) /lib/ld-linux.so.2 (0x40000000) libGLcore.so.1 =&gt; /usr/lib/libGLcore.so.1 (0x40319000) libnvidia-tls.so.1 =&gt; /usr/lib/libnvidia-tls.so.1 (0x409f1000) libXext.so.6 =&gt; /usr/X11R6/lib/libXext.so.6 (0x409f3000) libX11.so.6 =&gt; /usr/X11R6/lib/libX11.so.6 (0x40a01000) libdl.so.2 =&gt; /lib/libdl.so.2 (0x40acd000) libstdc++.so.5 =&gt; /usr/lib/libstdc++.so.5 (0x40ad1000) libgcc_s.so.1 =&gt; /usr/lib/libgcc_s.so.1 (0x40b88000) libasound.so.2 =&gt; /usr/lib/./libasound.so.2 (0x40b90000)

ldd shows all the libraries a dynamic executable relies on, and shows you where they are. It also "pulls in" the dependencies of the dependencies. For instance, while NWN does not itself depend on libnvidia-tls.so, the Nvidia supplied libGL on my system does.

Missing libraries?

In the example above, we can see that nwmain wants libmss.so.6, and the linker cannot find it. Usually, a missing library is a crash waiting to happen. There is one other thing to consider though: The majority of games are actually launched by a "wrapper", a shell script that performs some magic prior to launching the game. In the case of NWN, the wrapper is called nwn. Let's take a look at that now:

<tablebgcolor="#e0e0e0" tablewidth="100%"> $ less nwn #!/bin/sh # This script runs Neverwinter Nights from the current directory export SDL_MOUSE_RELATIVE=0 export SDL_VIDEO_X11_DGAMOUSE=0 # If you do not wish to use the SDL library included in the package, remove # ./lib from LD_LIBRARY_PATH export LD_LIBRARY_PATH=./lib:./miles:$LD_LIBRARY_PATH ./nwmain $@

This script sets up some environment variables, then launches the game binary with whatever command line options we added. The relevant part here is the environment variable called "LD_LIBRARY_PATH". This is a way of adding to the linkers search path. Try copying the line to your shell and seeing what happens when you re-run ldd.

<tablebgcolor="#e0e0e0" tablewidth="100%"> $ export LD_LIBRARY_PATH=./lib:./miles:$LD_LIBRARY_PATH $ ldd nwmain linux-gate.so.1 =&gt; (0xffffe000) libm.so.6 =&gt; /lib/libm.so.6 (0x40027000) libpthread.so.0 =&gt; /lib/libpthread.so.0 (0x40049000) libGL.so.1 =&gt; /usr/lib/libGL.so.1 (0x4009b000) libGLU.so.1 =&gt; /usr/X11R6/lib/libGLU.so.1 (0x40103000) libmss.so.6 =&gt; ./miles/libmss.so.6 (0x40178000) libSDL-1.2.so.0 =&gt; ./lib/libSDL-1.2.so.0 (0x401ec000) libc.so.6 =&gt; /lib/libc.so.6 (0x4025e000) /lib/ld-linux.so.2 (0x40000000) libGLcore.so.1 =&gt; /usr/lib/libGLcore.so.1 (0x40378000) libnvidia-tls.so.1 =&gt; /usr/lib/libnvidia-tls.so.1 (0x40a50000) libXext.so.6 =&gt; /usr/X11R6/lib/libXext.so.6 (0x40a52000) libX11.so.6 =&gt; /usr/X11R6/lib/libX11.so.6 (0x40a60000) libdl.so.2 =&gt; /lib/libdl.so.2 (0x40b2c000) libstdc++.so.5 =&gt; /usr/lib/libstdc++.so.5 (0x40b30000) libgcc_s.so.1 =&gt; /usr/lib/libgcc_s.so.1 (0x40be7000)

As you can see, this gives us slighly different results. The NWN library directories have been prepended to the search path, so now the linker can find libmss.so.6 in the "./miles" directory, and also finds the local copy of libSDL first, no longer using the system copy.

There's another benefit of these scripts: they are easily edited to allow you to provide your own copy of a library. Any game-supplied copy of a library such as OpenAL or SDL is likely to be compiled for the lowest common denominator, probably i486 or i686. If you have a Pentium4 or an AthlonXP, you could compile you own version specifically for your processor. The compiler will try to optimise the resulting binary, giving some increase in performance. See the homepage for GCC for more information this at [GCC site.]

Making NWN use your system copy is easy. It says so in the wrapper script! Remove "./lib:" from the LD_LIBRARY_PATH line, and you're good to go.

Another nice little trick is for games that use OpenAL for their sound output (e.g. Unreal based games: UT, Postal, Rune, etc.). Since the Open Sound System's (OSS) deprecation in favour of ALSA, all Linux distributions I've seen now ship with ALSA support as default, with OSS support actually being supplied via ALSA's compatability modules. The copies of openal.so distributed with games often do NOT support ALSA, so making the game use a copy compiled yourself will allow you to use ALSA natively.


6. When Bad Things Happen To Good People

Of course we can't cover every Bad Thing that happens, but I'll outline some items of common sense.

There are two types of bad things: random and repeatable. It's very difficult to diagnose or fix random problems that you don't have any control over when they happen or not. However, if the problem is repeatable "it happens when I press the left arrow key twice", then you're in business.


6.1. RTFM!

Read the friendly manual. The `manual' can take on a few forms. For open source games there's the readme files that come with the game. Commercial games will have a printed manual and maybe some readme files on the CD the game came on. Don't forget to browse the CD your game came on for helpful tips and advice.

Don't forget the game's website. The game's author has probably seen people with your exact same problem many times over and might put information specific to that game on the website. A prime example of this is Loki Software's online FAQs located at http://faqs.lokigames.com.


6.2. Look For Updates and Patches

If you're playing an open source game that you compiled, make sure you have the newest version by checking the game's website. If your game came from a distro make sure there's not an update rpm/deb for the game.

Commercial game companies like Loki release patches for their games. Often a game will have MANY patches (Myth2) and some games are unplayable without them (Heretic2). Check the game's website for patches whether you have a problem running the game or not; there may be an update for a security problem that you may not even be aware of.

By the way, Loki now has a utility that searches for Loki Software on your hard drive and automatically updates them. Check out http://updates.lokigames.com.


6.3. Newsgroups

If you don't know what netnews (Usenet) is, then this is definitely worth 30 minutes of your time to learn about. Install a newsreader. I prefer console tools more, so I use tin, but slrn is also popular. Netscape has a nice graphical "point and click" newsreader too.

For instance, I can browse Loki Software's news server with tin -g news.lokigames.com. You can also specify which news server to use using the $NNTP environment variable or with the file /etc/nntpserver.


6.4. Google Group Search

Every post made to Usenet gets archived at Google's database at http://groups.google.com. This archive used to be at http://www.deja.com, but was bought by Google. Many people still know the archive as "deja".

It's almost certain that whatever problem you have with Linux, gaming related or not, has already been asked about and answered on Usenet. Not once, not twice, but many times over. If you don't understand the first response you see (or if it doesn't work), then try one of the other many replies. If the page is not in a language you can understand, there are many translation sites which will convert the text into whatever language you like, including http://www.freetranslation.com and http://translation.lycos.com. My web browser of choice, Opera (available at http://www.opera.com) allows you to use the right mouse button to select a portion of text and left click the selection to translate it into another language. Very useful when a Google group search yields a page in German which looks useful and my wife (who reads German well) isn't around.

The Google group search has a basic and advanced search page. Don't bother with the simple search. The advanced search is at http://groups.google.com/advanced_group_search.

It's easy to use. For example, if my problem was that Quake III crashed everytime Lucy jumps, I would enter "linux quake3 crash lucy jumps" in the "Find messages with all of the words" textbox.

There are fields for which newsgroup you want to narrow your search to. Take the time to read and understand what each field means. I promise you. You won't be disappointed with this service. Use it, and you'll be a much happier person. Do note that they don't archive private newsgroups, like Loki Software's news server. However, so many people use Usenet, it almost doesn't matter.


6.5. Debugging: call traces and core files

This is generally not something you'll do for commercial games. For open source games, you can help the author by giving a corefile or stack trace. Very quickly, a core file (aka core dump) is a file that holds the "state" of the program at the moment it crashes. It holds valuable clues for the programmer to the nature of the crash -- what caused it and what the program was doing when it happened. If you want to learn more about core files, I have a great gdb tutorial at http://www.dirac.org/linux.

At the *very* least, the author will be interested in the call stack when the game crashed. Here is how you can get the call stack at barf-time:

Sometimes distros set up their OS so that core files (which are mainly useful to programmers) aren't generated. The first step is to make your system allow unlimited coresizes:

<tablebgcolor="#e0e0e0" tablewidth="100%"> ulimit -c unlimited

You will now have to recompile the program and pass the -g option to gcc (explaining this is beyond the scope of this document). Now, run the game and do whatever you did to crash the program and dump a core again. Run the debugger with the core file as the 2nd argument:

<tablebgcolor="#e0e0e0" tablewidth="100%"> $ gdb CoolGameExecutable core

And at the (gdb) prompt, type "backtrace". You'll see something like:

<tablebgcolor="#e0e0e0" tablewidth="100%"> #0 printf (format=0x80484a4 "z is %d.\n") at printf.c:30 #1 0x8048431 in display (z=5) at try1.c:11 #2 0x8048406 in main () at try1.c:6

It may be quite long, but use your mouse to cut and paste this information into a file. Email the author and tell him:

  1. The game's name
  2. Any error message that appears on the screen when the game crashes.
  3. What causes the crash and whether it's a repeatable crash or not.
  4. The call stack

If you have good bandwidth, ask the author if he would like the core file that his program dumped. If he says yes, then send it. Remember to ask first, because core files can get very, very big.


6.6. Saved Games

If your game allows for saved games, then sending the author a copy of the saved game is useful because it helps the tech reproduce whatever is going wrong. For commercial games, this option is more fruitful than sending a core file or call stack since commercial games can't be recompiled to include debugging information. You should definitely ask before sending a save game file because they tend to be long, but gaming companies usually have lots of bandwidth. Mike Phillips (formerly of Loki Software) mentioned that sending in saved games to Loki is definitely a good thing.

Needless to say, this only applies if your game crashes reproducably at a certain point. If the game segfaults every time you run it, or is incredibly slow, a saved game file won't be of much help.


6.7. What to do when a file or library isn't being found (better living through strace)

Sometimes you'll see error messages that indicate a file wasn't found. The file could be a library:

<tablebgcolor="#e0e0e0" tablewidth="100%"> % ./exult ./exult: error while loading shared library: libSDL-1.2.so.0: cannot load shared object file: No such file or directory

or it could be some kind of data file, like a wad or map file:

<tablebgcolor="#e0e0e0" tablewidth="100%"> % qf-client-sdl IP address 192.168.0.2:27001 UDP Initialize Error: W_LoadWadFile: couldn't load gfx.wad

Suppose gfx.wad is already on my system, but couldn't be found because it isn't in the right directory. Then where IS the right directory? Wouldn't it be helpful to know where these programs looked for the missing files?

This is where strace shines. strace tells you what system calls are being made, with what arguments, and what their return values are. In my `Kernel Module Programming Guide' (due to be released to LDP soon), I outline everything you may want to know about strace. But here's a brief outline using the canonical example of what strace looks like. Give the command:

<tablebgcolor="#e0e0e0" tablewidth="100%"> strace -o ./LS_LOG /bin/ls

The -o option sends strace's output to a file; here, LS_LOG. The last argument to strace is the program we're inspecting, here, "ls". Look at the contents of LS_LOG. Pretty impressive, eh? Here is a typical line:

<tablebgcolor="#e0e0e0" tablewidth="100%"> open(".", O_RDONLY|O_NONBLOCK|0x18000) = 4

We used the open() system call to open "." with various arguments, and the return value of the call is 4. What does this have to do with files not being found?

Suppose I want to watch the StateOfMind? demo because I can't ever seem to get enough of it. One day I try to run it and something bad happens:

<tablebgcolor="#e0e0e0" tablewidth="100%"> % ./mind.i86_linux.glibc2.1 Loading &amp; massaging... Error:Can't open data file 'mind.dat'.

Let's use strace to find out where the program was looking for the data file.

<tablebgcolor="#e0e0e0" tablewidth="100%"> strace ./mind.i86_linux.glibc2.1 2&gt; ./StateOfMind_LOG

Pulling out vim and searching for all occurrences of mind.dat, I find the following lines:

<tablebgcolor="#e0e0e0" tablewidth="100%"> open("/usr/share/mind.dat",O_RDONLY) = -1 ENOENT (No such file) write(2, "Error:", 6Error:) = 6 write(2, "Can\'t open data file \'mind.dat\'."..., ) = 33

It was looking for mind.dat in only one directory. Clearly, mind.dat isn't in /usr/share. Now we can try to locate mind.dat and move it into /usr/share, or better, create a symbolic link.

This method works for libraries too. Suppose the library libmp3.so.2 is in /usr/local/include but your new game "Kill-Metallica" can't find it. You can use strace to determine where Kill-Metallica was looking for the library and make a symlink from /usr/local/include/libmp3.so.2 to wherever Kill-Metallica was looking for the library file.

strace is a very powerful utility. When diagnosing why things aren't being found, it's your best ally, and is even faster than looking at source code. As a last note, you can't look up information in source code of commercial games from Lokisoft or Tribsoft. But you can still use strace with them!


6.8. Hosed consoles

Sometimes a game will exit abnormally and your console will get `hosed'. There are a few definitions of a hosed console. The text characters could look like gibberish. Your normally nice black screen could look like a quasi-graphics screen. When you press ENTER, a newline doesn't get echo'ed to the screen. Sometimes, certain keys of the keyboard won't respond. Logging out and back in don't always work, but there are a few things that might:

  • If you don't see any character on the screen as you type in, your terminal settings may be wrong. Try "stty echo". This should let input characters echo again.
  • At the prompt, type "reset". This should clear up many problems, including consoles hosed by an SVGAlib or ncurses based game.
  • Try running the game again and normally. Once I had to kill Quake III in a hurry, so I performed a Ctl-Alt-Backspace. The console was hosed with a quasi-graphics screen. Running Quake III and quitting normally fixed the problem.
  • The commands deallocvt and openvt will work for most of the other problems you'll have. deallocvt N kills terminal N entirely, so that Alt-FN doesn't even work anymore. openvt -c N starts it back up.
  • If certain keys on your keyboard don't work, be creative. If you want to reboot but the o' key doesn't work, try using halt. One method I've come up with is typing a command at the prompt and using characters on the screen with mouse cut/paste. For example, you can type "ps ax", and you're sure to have an h', a', l' and a `t' somewhere on the screen. You can use the mouse to cut and paste the word "halt".
  • The most regrettable option is a reboot. If you can, an orderly shutdown is preferable; use "halt" or "shutdown". If you can't, ssh in from a another machine. That sometimes works when your console is very badly hosed. In the worst case scenario, hit the reset or power switch.

Note that if you use a journalling filesystem like ext3, reiserfs or xfs, hitting the power switch isn't all that bad. You're still supposed to shutdown in an orderly manner, but the filesystem integrity will be maintained. You won't normally see an fsck for the partitions that use the journalling filesystem.


6.9. Locked System

When a computer "locks", also called "hung", the keyboard and mouse become completely unresponsive. This is a direct consequence of a bug in the Linux kernel. While Linux is known for stability, these things do happen, especiallly for gaming which entails highly synchronized hardware events which occur very fast, even to a computer. When a computer locks, it can be a "hard lock", meaning the kernel has completely stopped functioning. This often indicates misbehaving or faulty hardware. There's no recovery from this kind of lock other than pressing the reset or power button. The lock can also be a "soft lock", meaning that the kernel is still functioning in some capacity. It's possible to recover from this gracefully.

  • The first thing you should try is to hit control-alt-backspace which kills X. If you gain control of your system, the kernel wasn't really locked in the first place. If this didn't work after a few seconds, you'll definitely want to reboot the system using the following instructions.