The Man Behind The Curtain January 31st, 2015
I love peeking behind the scenes. I like knowing how things were made. I think most people do really, it's something built-in to humans.
Historically, video games don't give out the source code. And why should they - after all, a game is made for players. You're supposed to be having fun playing it, not trying to peek behind the curtain.
But for us programmers, there's a few gems out there. A small number of commercial games do have source code releases. I've been meaning for a while to do a round-up of them, so here it is.
Somewhat disappointingly, almost all of these are PC games. Finding source code to console or arcade games is incredibly rare, and a shame, as I think many programmers don't realize the different approaches to programming that exist on non-PC platforms.
Many of these games have improved community versions based off of these original source drops, which I've deliberately not linked to as I want to show the games as they originally were, not ported to SDL or whatever. So please bear in mind, if you're after a more modern upgrade, there may well be one out there somewhere.
Wherever possible, I've linked to the original source drops as released by the original developer. Where that is not possible, I've re-hosted the original files locally. (sometimes re-zipping for convenience, to avoid the numerous self-extracting EXEs that people like to use)
Many of these games are included in Fabien Sanglard's excellent series of informative and very well-written code reviews. I've added links to the code reviews where appropriate. If you want to know more about how a game works (and isn't that why you're here, after all?), go check it out.
You'll also notice that many of the games are from the id Software/Apogee lineage. This is not a co-incidence. id should be congratulated for their open attitude to releasing their older source. The source to older commercial games has little commercial value any more, and often will be lost entirely. Surely it's better that someone can learn something from it, rather than it being lost to the mists of time? It is, however, a shame that so many of the releases are all FPSs.
!!! Disclaimer: This is not an exhaustive list, and further more I don't really want it to be. I've deliberately only included games that I like and feel are important enough to be mentioned here. So if there's some obscure commercial game you like that's not listed, tough. Hey it's my blog, I'll put what I want on it. Get your own blog and put it there :)
So without further ado, starting chronologically:
Colossal Cave Adventure (1976)
"You are in a maze of twisty little passages, all alike."
A slight cheat perhaps - it's debatable if this is technically a commercial game. It certainly has been sold commercially though, and it's of such historic significance that I'm listing it anyway.
In case you didn't know, this game is why adventure games are called "adventure" games - they're all named after this.
The original version was in Fortran, so it's going to be hard work for modern coders to pick through. Later versions were in C, so perhaps try those too.
- Source code: http://rickadams.org/adventure/
Not to be confused with the later "Catacomb 3D" (see below), this game is an early 2D incarnation. Developed by John Carmack before id Software formed, this is written entirely in Turbo Pascal. While commonplace at the time, it fell out of favor once C started to dominate.
- Source code (DOS):
Prince Of Persia (1989)
- Jordan Mechner
- Apple II / DOS / many more
- Code review
Prince Of Persia wowed gamers with its (for the time) revolutionary fluid animation, Hollywood-style storytelling, and exciting exploration.
Like many games of the time, this is written entirely in assembly language, making it hard for modern readers to figure out what's going on.
If you haven't already, please watch Jordan Mechner's excellent GDC talk where he details the making of this fantastic game. Go do it now.
- Source code (Apple II):
SimCity basically invented a whole genre when it came out. The heart of its city simulation revolves around using cellular-automata-inspired algorithms, operating on the various municipal properties. This makes a good example of having to pop open the source code to really figure out the actual workings of the gameplay mechanics.
The source to the 1990 Unix port was released in 2008 as part of the OLPC project.
- Source code (Unix version):
Hovertank 3D / Catacomb 3D (1991)
- Id Software
This marks the first of the id Software 3D series. Both of these games use the same raycasting technique refined in the later Wolfenstein game, but Hovertank had yet to include texture mapping.
Star Control II (1992)
Star Control 2 is just... well.. it's just different. It dates from an earlier age, when games weren't expected to fit neatly into preconceived genres. Like so many contemporary games, it has an unmistakable "90s VGA" feel to it, with colors picked not because they looked nice but because they were in the default DPaint palette.
I recommend reading The Escapist's review for a modern look back at it.
The source presented below is derived from the 3D0 port, because the original PC source was lost. Unfortunately this is an all too common occurrence, with many old games simply disappearing once everyone leaves the company.
- Source code (3D0):
Wolfenstein 3D / Blake Stone (1992/3)
While based on the earlier Catacomb engine, Wolf3D marked a notable upgrade, featuring VGA graphics. But at its heart, it was just plain more fun.
Like many of id's releases, the source code is (relatively) readable for modern eyes, although the core parts are written in 16-bit assembly language (something its sequel Doom managed to stay away from).
Of particular note is the method they use for drawing vertical lines, where they actually dynamically generate different drawing functions for each possible wall height.
Fabien has a guide on getting the original source to compile using the original development tools.
Blake Stone, an Apogee spin-off title based on the same engine, was released in 1993, one week before Doom. As you can imagine, it struggled to gain attention and faded off into obscurity afterwards.
- Wolf3D source code:
- Blake Stone source code:
In many ways, Doom is the ultimate engine to study. At the time of release, it broke new ground in every way possible; a fully-immersive first-person world, not limited to a flat plane like its predecessor Wolfenstein. It had lighting, texture mapping, and invented DeathMatch.
But perhaps its most significant contribution is popularizing the idea of the "engine". Before Doom, games tended to be tied very tightly with their data. Doom encouraged the idea of the data-driven game - an engine detached from its source assets. This allowed the newly-developing mod community to take it in entirely new directions (see for example, Aliens TC or Fistful Of Doom).
- Source code:
In the wake of 1993's Doom, many companies were rushing about trying to play catch-up, resulting in a wave of "Doom clones". One company, Parallax, managed to create something completely different.
Descent allowed the player to fly a ship through a maze of underground passages. Its innovative portal technology allowed it to feature full 3D, with rooms not limited to Doom's 2.5D (something that id Software's Quake would not feature until a year later).
- Source code:
Gravity Force 2 (1994)
- Jens Andersson and Jan Kronqvist
Anyone of a certain age may well remember this. Amiga Power once rated it the 2nd-best game of all time.
Perhaps this isn't really a commercial game. It's debatable. It was released as paid shareware, and then later (due to its popularity) licensed to be given away free on an Amiga Power coverdisk. I'm including it as, to be honest, there's very few games of the era that give away any source code at all. So if you want to see how a 16-bit game was made, here's where you might look.
GF2 still has a homepage (see the link below). Be sure to check out this interview with the authors
- Source code:
Heretic / Hexen (1994/5)
Many Doom-clones littered the market in the wake of Doom's fallout, but Raven's offerings are unique for two reasons: 1) for actually licensing the Doom engine, and 2) for actually being any good.
Notable improvements over Doom include (famously) the ability to look up and down, but only a little. Hexen also used a custom scripting language for its game events, something that was a relatively new idea at the time, but has since gone on to be commonplace. It also popularized the "hub-world" system of level progression.
- Source code:
Rise Of The Triad: Dark War (1995)
ROTT was an odd beast. It dervies from the Wolfenstein 3D engine, and it's interesting to see how they managed to work around the limitations of their flat-world Wolf3D engine to create height-ish effects.
Although Apogee tried to stick as many bells and whistles on it as possible, it simply couldn't compete once 1993's Doom was released. Still, it was a lot of fun. PC Gamer summed it up well:
It didn't ask you to aim up or down, quick save every few minutes, or worry about fiddling with graphics settings. It did, however, beg you to explode, shoot, and instagib everything.
Marathon 2: Durandal (1995)
The Marathon series were famous at the time for basically being about the only games available on the Apple Macintosh. And to be honest, well... I think it's fair to say they fall into the category of "Doom clone". 3 months after its release, id Software released the famous "qtest" build of Quake, which allowed players to get a teaser of what was coming.
Macs at the time were often thought to be only used by writers and artists, and despite Marathon's best efforts, that image largely stuck. The small company that made it did however go on to have moderate success on other platforms.
Duke Nukem 3D / Shadow Warrior (1996)
Out of the many Doom clones, the 3D Realms games are some of the few to try and take the technology in new directions.
Powered by Ken Silverman's famous Build Engine, they added many new features such as sloped floors, rooms-above-rooms, mirrors.
Unfortunately, while it pulls of some very impressive technical feats, the source code itself is... well... let's try and be nice and polite here, awful. I've looked at it several times and still have literally no idea what any of it does. Luckily Fabien's code review manages to shed some light on it.
For more information on the Build Engine, see the author's homepage.
- Duke Nukem 3D source code:
- Shadow Warrior source code:
- Build engine source code:
Quake 1/2/3 (1996-1999)
- Id Software
- GT Interactive / Activision
- DOS / Windows / others
- Code review
- fabiensanglard.net (Quake 1)
fabiensanglard.net (Quake 3)
I'm not going to write much about Quake. You probably already know most of it. Its landmark software renderer allowed a full 3D texture mapped world, with no 2.5D hacks or cheating.
Perhaps there are some less known things about its source though. As far as I know, this is the first commercial game to be compiled with an open-source compiler (DJGPP for DOS, an early gcc port).
It came with its own scripting language, "Quake C" (later lcc for Quake 3). This was created not to ease development, but specifically so that players could make their own custom modifications. This, along with Doom's PWAD system, helped to launch the mod community.
Quake 1 had a innovative surface caching mechanism to cache the shading results. Once 3D accelerators became common however, this fell out of fashion. I wonder if it's time for a revisit? id's later game "Rage" used a similar idea.
One other notable thing about Quake is that it was absolutely rock-solid. Both the rasterizing and collision detection never glitched or slipped, unlike many contemporary games for years after.
- Quake source code:
- Quake 2 source code:
- Quake 3 source code:
I like Abuse. (wait, that sounds wrong).
It caused a mild stir when it came out due to several innovations. It had a really cool mouse+keyboard joint control scheme, which was kinda new at the time. It had dynamic lighting, which for a platformer was unheard of.
But that's not what I liked most. From a programmer's point of view, the most interesting thing in the game is the "visual Lisp" system that it contains.
The entire game is scripted in a custom Lisp-like language. So things like enemy behaviors are fully configurable at runtime, rather than being compiled in.
Even more interesting perhaps is the way events can be hooked up inside the (built-in!) map editor: you can visually drag lines from a switch to a door, or from a tripwire to a enemy-spawner. Including adding in AND/OR gates, all visually as hidden level objects. It's certainly something I've not seen in other editors.
Unfortunately, I don't think it was a great commercial success, and only two years later was released as open-source. The second Crack Dot Com game, Golgotha, was also released as open-source, including all the art assets.
- Abuse source code:
- Golgotha source code:
Aliens versus Predator (1999)
- Rebellion Developments
- Fox Interactive / Electronic Arts / Sierra On-Line
- Windows / Mac
Honestly, I'm just hugely relieved to see a FPS listed here that isn't based off id Software's engines.
While it didn't have much in the way of technical innovation, the single-player campaign was a blast.
This remains a good example of a non-idTech engine.
Freespace 2 (1999)
Technically a descendent of the Descent franchise but not really, FreeSpace 2 is an entirely space-based single and multi-player flight-combat game.
FreeSpace 2 is an excellent example of how opening up the source code has allowed the game's lifespan to continue on for years after it otherwise would have died out, with various content packs and engine upgrades being released.
The Operative: No One Lives Forever (2000)
- Monolith Productions
- Fox Interactive / Sierra Entertainment / MacPlay
- Windows / Mac / PlayStation 2
The LithTech engine has a long history, although has often taken a backseat to the more famous Quake and Unreal engines.
I haven't poked around in the NOLF source too much, but I suspect it may only be the source code to the game part, and not the actual LithTech engine itself. Certainly, despite this game being released for the PlayStation 2, there's no chance to see the workings of a PlayStation 2 game in there.
I feel this is a shame - developing for the PS2 would be considered completely alien for many programmers nowadays, benefiting from a much more data-oriented approach than today's APIs allow.
MechCommander 2 (2001)
The idea of Microsoft and open-source historically haven't gone together. But, they're starting to relax a little in their old age.
Still, it's nice to see that big companies are starting to adopt a more open attitude to things that otherwise have zero commercial value for them but immense historical value.
- Source code:
Doom 3 (2004)
- Id Software
- Windows / Mac / Linux / Xbox / PS3
- Code review
Doom 3 remains one of the best examples to look at if you want to study a modern AAA game engine.
At the time of its release, it innovated in many areas. Its method of baking high-res source models onto low-res game assets is now standard in all commercial games.
The source has many other interesting finds - its physics system alone is worth a look to see how it attains continuous collision detection.
This is the first of the id engines to be written in C++ instead of C. One thing about all the older id engines is that they had a very clear simplicity to them due to it. Doom 3 manages to keep that, but it does mark a notable change in direction. Comparing id's C++ style to other C++ engines is this list certainly reveals different approaches.
Doom 3 was also (in)famous for using stencil shadows for all its lighting. It's debatable as to whether this was an "interesting experiment" or something that should have been pursued further, but the fill-rate costs associated with it mean that almost all games nowadays tend to prefer shadow maps instead. Still, perhaps that will come around again one day.
Fabien Anglard's excellent code review is well worth the read, as usual.
- Source code:
BFG edition source code:
Gish was notable for its unique blobby-physics gameplay (as well as its unusual time signatures...), so it's nice to be able to pick apart the source and find out how it was done. No third-party physics engines here.
Many people commented on Casey Muratori's Handmade Hero project recently to say how "no-one would write a real game like that". Well here's an example of someone doing just that with good success.
It's interesting that Gish is written entirely in C - something that doesn't happen much nowadays. While it's not the neatest code I've ever seen, it's a very good example of how a game doesn't have to be a giant sprawling codebase with hundreds of external dependencies.
- Adam Saltsman
- Semi-Secret / Beatshapers / Kittehface
- Flash / iOS / PSP / Android / Ouya
It's not the most complex game, but does it need to be? If you want to learn how to write a game, start with something simpler. Here it is.
Prototyped in only 5 days, and ported to iOS in 10, Canabalt shows how you build up a simple idea into something worthwhile. In many ways, it's a return to the 8-bit days when new genres could be invented every week. It's a shame therefore that there have been so many clones of it, with people preferring to stick with someone else's idea rather than grow their own.
Canabalt showed how simple things could be if we let them. Learn from it, and use it to launch your own dreams.
Ones I missed
UPDATE: Thanks to the many eagle-eyed readers who, after reading this, flocked to mention some other games I missed out. I may do a proper update for them, but here's a brief list:
- Jagged Alliance 2
- Star Wars Jedi Knight: Jedi Academy / Jedi Outcast
- Arx Fatalis
- Penumbra Overture
- Meridian 59
- Commander Keen: Keen Dreams
I'll try and track down proper links for them.
There's a few other games I should mention. These have not had a source-code release; instead they have been reverse engineered by fans. While this doesn't provide the same information as the actual source code, it can still be worth a look:
- Another World - http://fabiensanglard.net/anotherWorld_code_review/
If nothing else, for the love of god please watch the excellent GDC making-of talk.
- Heart of the Alien - http://hota.sourceforge.net (sequel to the above).
- Strike Commander - http://fabiensanglard.net/reverse_engineering_strike_commander/index.php
- Little Big Adventure -https://code.google.com/p/twin-e/
And lastly, the following games have had their source-code leaked illegally, so I won't give them any further attention:
- Half Life 2
- Falcon 4.0
- Turrican III
- Mr. Nutz: Hoppin' Mad
- Trespasser (oh all-right, go read the code review.)
Written by Richard Mitton,
software engineer and travelling wizard.
Follow me on twitter: http://twitter.com/grumpygiant