oreilly.comSafari Books Online.Conferences.


Free Frags with Cube: The Linux First-Person Shooter
Pages: 1, 2

Tuning the Networking and Graphics

Most of Cube is van Oortmerssen's own original work, but it includes pieces from other projects. He built the entire multi-player code, which works over the Internet or on a LAN, but the network layer itself is enet. The enet library implements a portable interface for UDP traffic, performing all of the necessary bookkeeping and bandwidth management.

Lee Salzman, a 20-year-old undergraduate student at Carnegie-Mellon University in Pittsburgh, Pennsylvania, developed enet for Cube. He explains that "Cube's earlier networking used TCP, which ended up being rather disastrous due to buffering and synchronization provided by the protocol. This caused a substantial amount of lag when data was sent at even moderately frequent rates."

Related Articles:

Opening Up the PlayStation 2 with Linux -- Howard Wen takes a look at Sony's upcoming Linux distribution kit for the PlayStation 2.

Linux Gaming Resources -- All work and no play makes for dull penguins. Liven up your Linux box with these invigorating game resources.

An individual Cube client sends out a seemingly insignificant amount of data, only about 1K/s. The bulk of these messages are small object position updates sent to the server up to 30 times per second (30Hz), for the server to broadcast to other clients. Position updates are sent frequently, and any given updates may subsume a previous one. Cube's networking layer tries to optimize for this case of frequent, redundant data. Salzman chose to implement a mostly unreliable packet model over UDP that provides sequencing of packets and optional re-transmission.

Another major technical issue that didn't work out exactly as planned is the LOD, or Level of Detail system. This subsystem calculates the time needed to render a particular piece of geometry in relation to the amount of space it takes up on the screen. For example, a nearby object should be more detailed than an object that is farther away. LOD maximizes the processing time for more detailed objects and minimizes that for less detailed ones.

Implementing this system successfully in Cube was a challenge. Changing the number of polygons on an object is not easy to do seamlessly without having distracting visual artifacts ("popping") appear. This is especially prevalent on slower processors. Van Oortmerssen settled on having the engine calculate how much it should scale back on its use of the LOD system when the polygon processing load becomes too heavy.

"LOD is less useful that I thought, but it's still useful," says van Oortmerssen. "Recomputing LOD in Cube is not a problem at all, only visual artifacts are."

Quick and Easy Map Making

Compared to most commercially made 3-D graphics engines, Cube is not as sophisticated in the eye candy department. Its geometry is somewhat limited. For one, it doesn't support advanced shader techniques. (Van Oortmerssen himself chose not to add these features since he wanted to keep Cube's original code design as elegantly simple as possible. They may be added by other developers in the future.) The attractiveness of the included maps is due to the skill of their artists.

An attractive map location.

Those interested in creating their own game with Cube should try their hand at editing maps for the engine first. Using the engine's map-making tool is a very quick and direct, WYSIWYG process. It gives you the ability to edit a map from within the game itself and to see immediately how things look. With most commercial engine editors, there is a substantial delay between editing the geometry and seeing the compiled level with rendered lighting and shadows.

"This immediate feedback cycle is one of the main advantages to Cube mapping," says John Fitzgibbons, a 24-year-old Web developer in Seattle, WA, who created two of the maps included with Cube. He has also made game maps for the DOOM and Quake engines. "It's probably most significant for lighting, because most Quake series editors show what the geometry looks like but have no provision for previewing the lighting."

Though you can generate simple map architecture rapidly, doing anything that pushes the graphical limits of Cube can be an artistic challenge. "You really have to think hard about how to implement some of the more interesting architectural features," says van Oortmerssen. "But limitations tend to bring out the best in mappers. If you look through some of the maps, you'll see that mappers have gotten rather creative with Cube's minimalistic features."

Make Games Without Needing to Use a Licensed Engine

Regardless of the engine being used, negotiating creativity within technical limitations is forever an issue in game development. Cube's likeliest appeal may be to hobbyists who make original maps, models, and other elements for the Quake III, Unreal Tournament and Half-Life engines. Van Oortmerssen has provided this scene the means to create an entire game--not just a "mod"--from scratch, unrestricted by the licenses and costs of a commercially produced engine.

It may be yet another first-person shooter engine, but Cube is one that the game mod community can use, without limitations, as the basis for their own creations.

Howard Wen is a freelance writer who has contributed frequently to O'Reilly Network and written for,, and Wired, among others.

Return to the Linux DevCenter.

Linux Online Certification

Linux/Unix System Administration Certificate Series
Linux/Unix System Administration Certificate Series — This course series targets both beginning and intermediate Linux/Unix users who want to acquire advanced system administration skills, and to back those skills up with a Certificate from the University of Illinois Office of Continuing Education.

Enroll today!

Linux Resources
  • Linux Online
  • The Linux FAQ
  • Linux Kernel Archives
  • Kernel Traffic

  • Sponsored by: