Half-Life 2
gDoom for Half Life 2


Omri mentioned a mod called gmDoom last month, which allows you to bring the Doom experience, including weapons, enemies, HUD, and entities, into Garry's Mod. After watching a few weeks pass as bugs were squashed and updates were released, I decided it was finally time to pull-start this particular chainsaw and take it for a spin. I also decided, instead of just playing around, to really play. Specifically, I wanted to play through the entirety of the Half-Life 2 campaign, using only the gmDoom HUD and weapons. Space Marine, welcome to City 17!

Hm? What? Who? Space Marine is skeptical.

After getting off the train in City 17, I realize how happy I am to be an angry, violent Space Marine instead of a befuddled, bespectacled scientist. Gordon Freeman didn't pick up a weapon until a good half-hour into Half-Life 2, but Doomguy is always packing a pistol, a chainsaw, and his fists. Rather than wandering through the beginning of the game, helplessly watching as citizens are abused at the hands of the Metrocops, I can immediately right some wrongs by applying a healthy dose of SPACE VIOLENCE.

So, when I see a Metrocop shove a citizen, I punch him to death (the Metrocop, to be clear). That annoying flying camera robot gets a taste from my pistol. What's this? Other cops, standing around doing nothing violent? Not on my watch! They die. I approach a couple citizens as well, just to see if weapons work on them too. (Weapons work on them too.) Oh, and that cop who tries to make me pick up a soda can and put it in the garbage? I saved the chainsaw for him.

Marines. Always. Recycle.

Before long, I'm in the canals, fighting enemies who can actually fight back. It mostly works well: the weapons are effective and feel natural after a few minutes of play, though you have to be pretty darn precise with your aim for long-distance kills. It's also a genuinely neat experience: the sights and sounds of the throwback Doom weapons mixed with the atmosphere and enemies of Half-Life 2. It's double-nostalgic. It's like combining two tastes I love, bacon and chocolate, into one violent, historic mouthful of video game.

Something else I notice: while it feels a little odd in this day and age to play a game where you're constantly staring at your own face, it does make your health quite a priority. Instead of a percentage or a colored bar, you get to look at your sad mug streaked with blood, a pretty visceral reminder that it's not your health meter taking damage: it's your own face. Finding medkits feels a lot more urgent when you're hurt so bad your hair is bleeding.

Space Marine needs food, badly.

Ammo for my Doom weapons, naturally, is not stocked in City 17, so I just spawn some for myself from the Garry's Mod menu when I run out. I try to also give myself new weapons when it feels appropriate. When Metrocops start using machine guns, for example, I give myself Doom's chaingun. When I remember that you don't get a shotgun until you get to Ravenholm, I give myself one anyway, because screw that.

After escaping City 17, I wind up deciding to skip the second half of the canal levels. Making a Space Marine drive a crummy boat powered by a fan just seems insulting. It's like making Willy Wonka eat a celery stick. He knows not of, and cares not for, such primitive tools. Fast-forward, then, to Ravenholm!

Plus a quick stop in Black Mesa East to kill a disgusting alien. You're welcome, Vance family!

In the zombie-patrolled streets of Ravenholm, our Space Marine seems quite comfy. Hideous shambling monsters, blood, gore, horror: these are what Doomguy was made for. I admit, I do pine for the Gravity Gun, because flinging giant circular blades into zombies is still awesome. The super shotgun works just fine, though.

These zombies don't shoot back? You got off easy this time, Earth.

After blasting my way through Ravenholm with kindred spirit Father Gregori, I decide to skip the driving sections of HL2 as well, mostly because the driving feels like 100% Half-Life 2 and 0% Doom, and the mix is what's really making this fun. I skip to the lighthouse at the end of the coastal maps, and dig in with the resistance as they fight off the Combine attack.

After defeating a few waves of drop-ship soldiers, I run into a little problem when the Synth Gunship arrives. I've given myself Doom 2's rocket launcher, but it only fires in a straight line, as opposed to HL2's laser-guided launcher. The Gunship doesn't shoot my rockets down, but there's no need: I keep missing because the Gunship keeps moving. Try as I might, I just can't hit the sucker. He, however, has no problem hitting me. It's time to call in reinforcements.

No shame in a Marine calling for backup. SPACE backup.

I use G-Mod to spawn a Doom Cyberdemon-- shut up, that is TOTALLY FAIR-- and the gunship and the Cyberdemon immediately decide they hate each other. (Isn't introducing one enemy to another enemy always awkward, like when your work friends meet your personal friends?) Unfortunately, the Cyberdemon is also unable to hit the gunship. Finally, exasperated, I just take out my G-Mod physics tool and hold the stupid gunship in place, letting the demon blast it to pieces. ALSO FAIR.

Hold still. This will only hurt a lot.

And, having used a physics tool from 2006 to help a cyborg demon from 1993 kill a biosynthetic airship from 2004... that's where my play-through of Half-Life2 abruptly comes to an end. It was a fun experiment, sure, but holding a three-dimensional gunship in the sky with my finger so a two-dimensional demon can whomp on it serves as a massive reminder: I don't just have two great games to play with here, I've got three, and I've all but forgotten about the Garry's Mod part of the experience. I've been eating bacon and chocolate, YES, but I've been completely neglecting the GLORIOUS BOTTLE OF BOURBON sitting right there to wash it all down with.

Time to switch from playing Half-Doom 2 and start playing a game I call Make Everything Fight Everything Else By The Lighthouse For Six Straight Hours!

Combine vs. Heavy Weapon Dudes!

The Combine win!

Pinky vs. Combine!

Pinky wins!

Arch-vile vs. Antlion Guard!

Antlion Guard wins -- but Arch-vile really does raise the dead Doom monsters! Awesome.

Antlion Guard vs. Spiderdemon!

Spiderdemon wins (eventually)!

Helicopter vs. Pain Elementals and Lost Souls!

Draw. Spawned helicopter doesn't seem to ever die, and Pain Elementals never seem run out of Lost Souls.

After making Everything fight Everything Else for six hours, I do, eventually, return to Half-Life 2 proper, mainly to see if I can take down a Strider with a Doom 2 rocket launcher (I can, and quite handily) and to try out the plasma cannon on the Combine (it works amazingly well). And, of course, to unleash the BFG on a store-front full of Combine soldiers.

Looks like the store... *sunglasses* ...is CLOSED.

Putting this mod into that other mod and putting both mods into Half-Life 2 is amazing. Do it! Do it now!

Installation: Mostly simple! However, you'll need a WAD file from one of the Doom games to import all the assets. If you don't own a Doom game, you can use a WAD file from the free shareware version of Doom and still get most of the weapons (I used Doom2.wad; full list of what the various WAD files give you access to here). Drop the WAD in the garrysmod/garrysmod folder in your Steam directory. Then, just subscribe to the mod on Steam Workshop and when you boot up Garry's Mod, it will be enabled. You can spawn all your weapons and monsters from the menu by pressing Q, and enable the HUD using the console code doom_cl_hud 1.

Also, and perhaps this is obvious, but you'll need Half-Life 2 installed for all the Half-Life 2 stuff.
DOOM 3 Resurrection of Evil
bethesda vine tease


It starts with a dizzying shot of barbed wire. Then we see a glimpse of an LP—The Moonbeam Trio, directed by George Shackley. A quick Googling reveals that the Library of Congress has recordings. Then we see sheet music from Bach’s Air on the G String, and it's back to barbed wire. It's a four second Vine video tweeted by Bethesda Softworks. What it means is for us to futilely wave speculation at, but we're suckers for a puzzle, so why don't we try?

Air on the G String comes from Bach’s Orchestral Suite No. 3 in D major, and gets its name from the violin and piano arrangement by August Wilhelmj, a German child prodigy. You can actually hear Wilhelmj—or a violinist suspected to be him—play a different song via the medium of wax recording.

Air on the G String is Wilhelmj's claim to fame, and one of Bach's most famous works. If it all sounds very Fallout-ey, Bethesda Softworks VP of PR and Marketing Pete Hines says, "Guess again."

Alright, we will. If we take The Moonbeam Trio to be a nod to the 1930s and 1940s, Wolfenstein is a decent bet, but let's go even deeper. Air on the G String and the Moonbeam Trio have something in common: violins. Rearrange "Vine Violins" and you get "I involve sin," so clearly we're talking about Doo—wait, that's stretching too far, isn't it?

There's no way to know for sure what Bethesda is teasing, but conversation motivated by curiosity is fun, so we'll let you take it from here:

DOOM 3 Resurrection of Evil
Doom 4 Hell


Doom 4 will eventually emerge from development hell, but exactly when is still uncertain. Bethesda Vice President of Marketing and Public Relations Pete Hines tells Kotaku that id's Doom 4 team has started over on a "new version" of the game after being unhappy with the initial quality of the game.

"An earlier version of Doom 4 didn't exhibit the quality and excitement that id and Bethesda intend to deliver and that Doom fans worldwide expect,” Hines explains. “As a result, id refocused its efforts on a new version of Doom 4 that promises to meet the very high expectations everyone has for this game and this franchise. When we’re ready to talk about the Doom 4 id is making, we will let folks know.”

A couple years ago, rumors swirled of an "indefinite" delay to Doom 4 over the tepid response to Rage's release, though Hines called the reports "bollocks" during that time. Hopefully id has settled on its final design direction for Doom 4's makeover. And hey, if it needs help, we've got plenty of ideas.
DOOM + DOOM II
DoomRL


You can't escape Doom. After tearing open a portal to Hell on the Source engine, it's aiming its slavering maw at the roguelike genre with DoomRL, where you'll have to escape a dark and infested facility of demonic horror while also worrying about the looming threat of permadeath. No pressure or anything.

All the roguelike trappings show up alongside sound effects and graphical sprites lifted directly from the FPS. You'll frag beasties in quick, turn-based battles while scrounging for ammo, health, armor, and keycards. Three classes—Marine, Scout, and Technician—determine your stat spread and passive traits, and there are over 30 randomized levels and mod support for extra user-made floors.

DoomRL already has a dedicated community talking shop and contributing content over on its official website, and the latest version, 0.9.9.7, released yesterday after a little over a year in development. You'll probably want to brush up on the game's wiki as well before jumping in.
Half-Life 2
gmDoom


As far as giving an older game the Source treatment, GhorsHammer's gmDoom port project is probably the quickest to elicit a "Holy %)#@" out of me since Black Mesa. It chainsaws out the UI, enemy, and weapon sprites from the proto-FPS and stitches them into Garry's Mod with astonishing smoothness. I can't imagine how downing a Strider with a blast from the BFG would work, but after seeing it in action in GhorsHammer's video, I can't imagine how it wouldn't work.

The mod is undergoing a final round of bug testing and tweaks, and it'll show up in Steam Workshop sometime this week for download. It looks like the Frankensteinian bridge between Doom and Source flows both ways, as you're seemingly able to set up fights against classic hellspawn such as the Cacodemon and Revenant while touting Half-Life 2's arsenal. That includes vehicles, and running over crowds of Imps in Episode Two's muscle car while blasting E1M1 sounds all kinds of awesome.
DOOM + DOOM II
doooom


Article by Nathan Ditum

Apparently refusing to avail itself of the teleportation technology that kickstarted its earliest predecessor, Doom 4 has been creeping towards us slowly from the shadows since it was announced in May 2008. Since then it’s been teased, mentioned, and even glimpsed in a leaked selection of artwork that suggested anyone looking for finely detailed neo-classical balconies was in for one serious thrill ride when the game finally arrived.

We’re less focused on the neo-classical balconies, though, and more on the shooting and the hellspawn. Here are a few ideas we’d like to see propping up the big first-person shooter’s return.

Barrels



This is a call for barrels in an emblematic sense, which is exciting as it’s something that might never have happened before. The thinking behind it is that the barrels in the original Doom and Doom II weren’t necessarily a sublime piece of game design, but did and do effectively recall the /style/ of play. They’re placed apparently at random, but also in places where an early shotgun blast will set off the exaggerated “ker-TUSH”explosion followed by the slick sound of entirely inside-out enemies capitulating to gravity. There is a cartoon kineticism to the original games, epitomised in the barrels, and in dodgeable fireballs, and the ability to strafe so quickly you can see the side of the rocket you’ve just fired. Translating this directly would be disastrous, obviously, but a sense of it is what was missing from the hollow horror of Doom 3, and will be crucial to Doom 4 (and if that leaked art is anything to go buy, it looks like we’re covered).

Hell



It’s very important that the game take us to Hell in a literal, lakes of fire, citadel of Pandemonium, walls of the agonised damned way. This is what gave the brash original its exploitation punch - you’re not popping your way through a familiarly demonic arcade metropolis, you’re in /actual/ Hell, a Roger Corman stakes raising that contributes significantly to Doom’s shotgun abandon. The leaked art shows New York torn apart by some kind of pan-dimensional event, the poor Public Library getting a very similar going over to the one it received in Ghostbusters II. It looks like an up-to-date-ing of Doom II’s Hell On Earth scenario, and Id Software has talked about gameplay involving post-civilisation survival. We’re fine with all of that, as long as the upshot is that we get to go back to Hell and shoot it in its face.

An unshakeable faith in the power of the shotgun...



...except when there’s a plasma weapon handy. Doom more or less defined the 1-2-3-4, fist-pistol-shotgun-chaingun notion of armoury escalation in first-person shooters. It is the standard from which Halo deviated with its potent handgun and two weapon limit, which many others have followed. How Doom 4 returns to and passes comment upon this is unclear, but by virtue of its lineage simply including guns in the style of any other shooter is not an option. It needs to either knowingly defy or satisfyingly play upon expectations - make the shotgun a death-packing standout maybe, or offer a chainsaw attachment to all weapons - and it must remember the direct feedback and deadly simplicity which made scaling Doom’s firearm pyramid such a thumping rush.

A hero generic to the point of invisibility



This sounds counter-intuitive if not deliberately askew. But! If ever there was a series to free us from the tyranny of shooters that bleed feelings and force character into action then it is surely Doom 4. Stop leaking emotion all over our loading screens. Stop sending us impassioned grunts recorded in downtown LA soundbooths that are intended to somehow make shooting demons more meaningful, as if there could be any meaning more powerful than them being demons and us having a gun. Doom is about purity of purpose and big expositional screens filled with small red text that tell all the story you need apart from a small angry face raising its eyebrows and occasionally becoming a bruise with a orifice in the middle. It would be excellent if it could stay this way - and happily, from the looks of the leaked art the character designs couldn’t get more generic without having their virtual features sanded down to a raw nub.

An engine that works



Rage was designed to show what id Tech 5 could really do. For months, marketing materials and developer diaries crooned about the new engine's "mega textures" that would give artists complete mastery over the surface detail of Rage's rust-coloured canyons. But come launch day, it just didn't work. The textures took long moments to load in every time you turned your head, offering smeary geometry where there should have been fine detail. Whether id decide to pursue the claustrophobic survival horror trappings of Doom 3 or joyously embrace the lurid slaughter of Doom 1 and 2, the engine needs to show us the treasures promised by Carmack and co. in the run up to Rage.

What would you like to see from Doom 4? Do you want to mow down the hordes of hell, or cower in the dark with a flashlight?
DOOM 3

The Exceptional Beauty of Doom 3's Source CodeThis is a story about Doom 3's source code and how beautiful it is. Yes, beautiful. Allow me to explain.


After releasing my video game Dyad I took a little break. I read some books and watched some movies I'd put off for too long. I was working on the European version of Dyad, but that time was mostly waiting for feedback from Sony quality assurance, so I had a lot of free time. After loafing around for a month or so I started to seriously consider what I was going to do next. I wanted to extract the reusable/engine-y parts of Dyad for a new project.


When I originally started working on Dyad there was a very clean, pretty functional game engine I created from an accumulation of years of working on other projects. By the end of Dyad I had a hideous mess.


In the final six weeks of Dyad development I added over 13k lines of code. MainMenu.cc ballooned to 24,501 lines. The once-beautiful source code was a mess riddled with #ifdefs, gratuitous function pointers, ugly inline SIMD and asm code—I learned a new term: "code entropy." I searched the internet for other projects that I could use to learn how to organize hundreds of thousands of lines of code. After looking through several large game engines I was pretty discouraged; the Dyad source code wasn't actually that bad compared to everything else out there!


Unsatisfied, I continued looking, and found a very nice analysis of id Software's Doom 3 source code by the computer expert Fabien Sanglard.


I spent a few days going through the Doom 3 source code and reading Fabien's excellent article when I tweeted:


It was the truth. I've never really cared about source code before. I don't really consider myself a "programmer." I'm good at it, but for me it's just a means to an end. Going through the Doom 3 source code made me really appreciate good programmers.


***

To put things into perspective: Dyad has 193k lines of code, all C++. Doom 3 has 601k, Quake III has 229k and Quake II has 136k. That puts Dyad somewhere in between Quake II and Quake III. These are large projects.


When I was asked to write this article, I used it as an excuse to read more source code from other games, and to read about programming standards. After days of research I was confused by my own tweet that started this whole thing: what would "nice looking"—or "beautiful", for that matter—actually mean when referring to source code? I asked some programmer friends what they thought that meant. Their answers were obvious, but still worth stating:


  • Code should be locally coherent and single-functioned: One function should do exactly one thing. It should be clear about what it's doing.
  • Local code should explain, or at least hint at the overall system design.
  • Code should be self-documenting. Comments should be avoided whenever possible. Comments duplicate work when both writing and reading code. If you need to comment something to make it understandable it should probably be rewritten.

There's an idTech 4 coding standard (.doc) that I think is worth reading. I follow most of these standards and I'll try to explain why they're good and why specifically they make the Doom 3 code so beautiful.


Unified Parsing and Lexical Analysis

One of the smartest things I've seen from Doom is the generic use of their lexical analyzer[1] and parser [2]. All resource files are ascii files with a unified syntax including: scripts, animation files, config files, etc; everything is the same. This allows all files to be read and processed by a single chunk of code. The parser is particularly robust, supporting a major subset of C++. By sticking to a unified parser and lexer all other components of the engine needn't worry about serializing data as there's already code for that. This makes all other aspect of the code cleaner.


Const and Rigid Parameters

Doom's code is fairly rigid, although not rigid enough in my opinion with respect to const[3]. Const serves several purposes which I believe too many programmers ignore. My rule is "everything should always be const unless it can't be" I wish all variables in C++ were const by default. Doom almost always sticks to a "no in-out" parameter policy; meaning all parameters to a function are either input or output never both. This makes it much easier to understand what's happening with a variable when you pass it to a function. For example:


The Exceptional Beauty of Doom 3's Source Code


This function definition this makes me happy!


Just from a few consts I know many things:


  • The idPlane that gets passed as an argument will not be modified by this function. I can safely use the plane after this function executes without checking for modifications of the idPlane.
  • I know the epsilon won't be changed within the function, (although it could easily be copied to another value and scaled for instance, but that would be counter productive)
  • front, back, frontOnPlaneEdges and backOnPlaceEdges are OUT variables. These will be written to.
  • the final const after the parameter list is my favourite. It indicates idSurface::Split() won't modify the surface itself. This is one of my favourite C++ features missing from other languages. It allows me to do something like this:

    void f(const idSurface &s) {
    s.Split(....);
    }


    if Split wasn't defined as Split(...) const; this code would not compile. Now I know that whatever is called f() won't modify the surface, even if f() passes the surface to another function or calls some Surface::method(). Const tells me a lot about the function and also hints to a larger system design. Simply by reading this function declaration I know surfaces can be split by a plane dynamically. Instead of modifying the surface, it returns new surfaces, front and back, and optionally frontOnPlaneEdges and backOnPlaneEdges.


The const rule, and no input/output parameters is probably the single most important thing, in my eyes, that separate good code from beautiful code. It makes the whole system easier to understand and easier to edit or refactor .


Minimal Comments

This is a stylistic issue, but one beautiful thing that Doom usually does is not over-comment. I've seen way too much code that looks like:


The Exceptional Beauty of Doom 3's Source Code


I find this extremely irritating. I can tell what this method does by its name. If its function can't be inferred from its name, its name should be changed. If it does too much to describe it in its name, make it do less. If it really can't be refactored and renamed to describe its single purpose then it's okay to comment. I think programmers are taught in school that comments are good; they aren't. Comments are bad unless they're totally necessary and they're rarely necessary. Doom does a reasonable job at keeping comments to a minimum. Using the idSurface::Split() example, lets look at how it's commented:


// splits the surface into a front and back surface, the surface itself stays unchanged
// frontOnPlaneEdges and backOnPlaneEdges optionally store the indexes to the edges that lay on the split plane
// returns a SIDE_?


The first line is completely unnecessary. We learned all that information from the the function definition. The second and third lines are valuable. We could infer the second line's properties, but the comment removes potential ambiguity.


Doom's code is, for the most part, judicial with its comments, which it makes it much easier to read. I know this may be a style issue for some people, but I definitely think there is a clear "right" way to do it. For example, what would happen if someone changed the function and removed the const at the end? Then the surface *COULD* be changed from within the function and now the comment is out of sync with the code. Extraneous comments hurt the readability and accuracy of code thus making the code uglier.


Spacing

Doom does not waste vertical space:


Here's an example from t_stencilShadow::R_ChopWinding():


The Exceptional Beauty of Doom 3's Source Code


I can read that entire algorithm on 1/4 of my screen, leaving the other 3/4s to understand where that block of code fits relative to its surrounding code. I've seen too much code like this:


The Exceptional Beauty of Doom 3's Source Code


This is going to be another point that falls under "style." I programmed for more than 10 years with the latter style, forcing myself to convert to the tighter way while working on a project about six years ago. I'm glad I switched.


The latter takes 18 lines compared to 11 in the first. That's nearly double the number of lines of code for the *EXACT* same functionality. It means that the next chunk of code doesn't fit on the screen for me. What's the next chunk?


The Exceptional Beauty of Doom 3's Source Code


That code makes no sense without the previous for loop chunk. If id didn't respect vertical space, their code would be much harder to read, harder to write, harder to maintain and be less beautiful.


Another thing that id does that I believe is "right" and not a style issue is they *ALWAYS* use { } even when optional. I think it's a crime to skip the brace brackets. I've seen so much code like:


The Exceptional Beauty of Doom 3's Source Code


That is ugly code, it's worse than than putting { } on their own line. I couldn't find a single example in id's code where they skipped the { }. Omitting the optional { } makes parsing this while() block more time consuming than it needs to be. It also makes editing it a pain, what if I wanted to insert an if-statement branch within the else if (c > d) path?


Minimal Templates

Id did a huge no-no in the C++ world. They re-wrote all required STL[4] functions. I personally have a love-hate relationship with the STL. In Dyad I used it in debug builds to manage dynamic resources. In release I baked all the resources so they could be loaded as quickly as possible and don't use any STL functionality. The STL is nice because it provides fast generic data structures; it's bad because using it can often be ugly and error prone. For example, let's look at the std::vector<T> class. Let's say I want to iterate over each element:


The Exceptional Beauty of Doom 3's Source Code


That does get simplified with C++11:


The Exceptional Beauty of Doom 3's Source Code


I personally don't like the use of auto, I think it makes the code easier to write but harder to read. I might come around to the usage of auto in the coming years, but for now I think it's bad. I'm not even going to mention the ridiculousness of some STL algorithms like std:for_each or std::remove_if.


Removing a value from an std::vector is dumb too:


The Exceptional Beauty of Doom 3's Source Code


Gee, that's going to be typed correctly by every programmer every time!


id removes all ambiguity: they rolled their own generic containers, string class, etc. They wrote them much less generic than the STL classes, presumably to make them easier to understand. They're minimally templated and use id-specific memory allocators. STL code is so littered with template nonsense that it's impossible to read.


C++ code can quickly get unruly and ugly without diligence on the part of the programmers. To see how bad things can get, check out the STL source code. Microsoft's and GCC's[5] STL implementations are probably the ugliest source code I've ever seen. Even when programmers take extreme care to make their template code as readable as possible it's still a complete mess. Take a look at Andrei Alexandrescu's Loki library, or the boost libraries—these are written by some of the best C++ programmers in the world and great care was taken to make them as beautiful as possible, and they're still ugly and basically unreadable.


id solves this problem by simply not making things overly generic. They have a HashTable<V> and a HashIndex class. HashTable forces key type to be const char *, and HashIndex is an int->int pair. This is considered poor C++ practice. They "should" have had a single HashTable class, and written partial specialization for KeyType = const char *, and fully specialized <int, int>. What id does is completely correct and makes their code much more beautiful.


This can be further examined by contrasting 'good C++ practice' for Hash generation and how id does it.


It would be considered by many to be good practice to create a specific computation class as a parameter to the HashTable like so:


The Exceptional Beauty of Doom 3's Source Code


this could then be specialized for a particular type:


The Exceptional Beauty of Doom 3's Source Code


Then you could pass the ComputeHashForType as a HashComputer for the HashTable:


The Exceptional Beauty of Doom 3's Source Code


This is similar to how I did it. It seems smart, but boy is it ugly! What if there were more optional template parameters? Maybe a memory allocator? Maybe a debug tracer? You'd have a definition like:


The Exceptional Beauty of Doom 3's Source Code


Function definitions would be brutal!


The Exceptional Beauty of Doom 3's Source Code


What does that even mean? I can't even find the method name without some aggressive syntax highlighting. It's conceivable that there'd be more definition code than body code. This is clearly not easy to read and thus not beautiful.


I've seen other engines manage this mess by offloading the template argument specification to a myriad of typedefs. This is even worse! It might make local code easier to understand, but it creates another layer of disconnect between local code and the overarching system logic, making the local code not hint towards system design, which is not beautiful. For example, lets say there was code:


The Exceptional Beauty of Doom 3's Source Code


and


The Exceptional Beauty of Doom 3's Source Code


and you used both and did something like:


The Exceptional Beauty of Doom 3's Source Code


It's possible that the StringHashTable's memory allocator, StringAllocator, won't contribute to the global memory, which would cause you confusion. You'd have to backtrack through the code, find out that StringHashTable is actually a typedef of a mess of templates, parse through the template code, find out that it's using a different allocator, find that allocator... blah blah, ugly.


Doom does the complete "wrong" thing according to common C++ logic: it writes things as non-generic as possible, using generics only when it makes sense. What does Doom's HashTable do when it needs to generate a hash of something? It calls idStr::GetHash(), because the only type of key it accepts is a const char *. What would happen if it needs a different key? My guess is they'd template the key, and force just call key.getHash(), and have the compiler enforce that all key types have an int getHash() method.


Remnants of C

I don't know how much of id's original programming team is with the company anymore, but John Carmack at least comes from a C background. All id games before Quake III were written in C. I find many C++ programmers without a strong C background over-C++ize their code. The previous template example was just one case. Three other examples that I find often are:


  • over-use set/get methods
  • use stringstreams
  • excessive operator overloading.

id is very judicial in all these cases.


Often one may create a class:


The Exceptional Beauty of Doom 3's Source Code


This is a waste of lines of code and reading time. It takes longer to write it, and read it compared to:


The Exceptional Beauty of Doom 3's Source Code


What if you're often increasing var by some number n?


The Exceptional Beauty of Doom 3's Source Code


vs


The Exceptional Beauty of Doom 3's Source Code


The first example is much easier to read and write.


id doesn't use stringstreams. A stringstream contains probably the most extreme bastardization of operator overloads I've ever seen: <<.


For example:


The Exceptional Beauty of Doom 3's Source Code


That's ugly. It does have strong advantages: you can define the equivalent of Java's toString() method per class w/o touching a class' vtables, but the syntax is offensive, and id chose to not use. Choosing to use printf() instead of stringstreams makes their code easier to read, and thus I think it's the correct decision.


The Exceptional Beauty of Doom 3's Source Code


Much nicer!


The syntax for SomeClass' operator << would be ridiculous too:


The Exceptional Beauty of Doom 3's Source Code


[Side note: John Carmack has stated that static analysis tools revealed that their common bug was incorrect parameter matching in printf(). I wonder if they've changed to stringstreams in Rage because of this. GCC and clang both find printf() parameter matching errors with -Wall, so you don't need expensive static analysis tools to find these errors.]


Another thing that makes the Doom code beautiful is the minimal use of operator overloads. Operator overloading is a very nice feature of C++. It allows you to do things like:


The Exceptional Beauty of Doom 3's Source Code


Without overloading these operations would be more time consuming to write and parse. Doom stops here. I've seen code that doesn't. I've seen code that will overload operator '%' to mean dot product or operator Vector * Vector to do piece-wise vector multiplication. It doesn't make sense to make the * operator for cross product because that only exists in 3D, what if you wanted to do:
some_2d_vec * some_2d_vec, what should it do? What about 4d or higher? id's minimal operator overloading leaves no ambiguity to the reader of the code.


Horizontal Spacing

One of the biggest things I learned from the Doom code was a simple style change. I used to have classes that looked like:


The Exceptional Beauty of Doom 3's Source Code


According to id's Doom 3 coding standard, they use real tabs that are 4 spaces. Having a consistent tab setting for all programmers allows them horizontally align their class definitions:


The Exceptional Beauty of Doom 3's Source Code


They rarely put the inline functions inside the class definition. The only time I've seen it is when the code is written on the same line as the function declaration. It seems this practice is not the norm and is probably frowned upon. This method of organizing class definitions makes it extremely easy to parse. It might take a little more time to write, since you'd have re-type a bunch of information when defining the methods:


The Exceptional Beauty of Doom 3's Source Code


I'm against all extra typing. I need to get stuff done as fast as possible, but this is one situation where I think a little extra typing when defining the class more than pays for itself each time the class definition needs to be parsed by a programmer. There are several other stylistic examples provided in the Doom 3 Coding Standards (.doc) that contribute to the beauty of Doom's source code.


Method Names

I think Doom's method naming rules are lacking. I personally enforce the rule that all method names should begin with a verb unless they can't.


For example:


The Exceptional Beauty of Doom 3's Source Code


is much better than:


The Exceptional Beauty of Doom 3's Source Code


Yes, it's Beautiful.

I was really excited to write this article, because it gave me an excuse to really think about what beautiful code is. I still don't think I know, and maybe it's entirely subjective. I do think the two biggest things, for me at least, are stylistic indenting and maximum const-ness.


A lot of the stylistic choices are definitely my personal preferences, and I'm sure other programmers will have different opinions. I think the choice of what style to use is up to whoever has to read and write the code, but I certainly think it's something worth thinking about.


I would suggest everyone look at the Doom 3 source code because I think it exemplifies beautiful code, as a complete package: from system design down to how to tab space the characters.


Shawn McGrath is a Toronto-based game developer and the creator of the acclaimed PlayStation 3 psychedelic puzzle-racing game Dyad. Find out more about his game. Follow him on Twitter.



Footnotes


[1] A lexical analyzer converts the characters of source code, (in the relevent context), into a series of tokens with semantic significance. Source code may look like:


x = y + 5;


A lexical analyzer (or "lexer" for short), might tokenize that source as such:
x => variable
= => assignment operator
y => variable
+ => additional operator
5 => literal integer
; => end statement


This string of tokens is the first of many steps in converting source code to a running program. following lexical analysis the tokens are fed into a parser, then a compiler, then a linker, and finally a virtual machine, (in the case of compiled languages a CPU). There can be intermediate steps inserted between those main steps, but the ones listed are generally considered to be the most fundamental.


[2] A parser is (usually) the next logical step following lexical analysis in machine understanding of language, (computer language/source code in this context, but the same would apply for natural language). A parser's input is a list of tokens generated by a lexical analyzer, and outputs a syntactic tree: a "parse tree."


In the example: x = y + 5, the parse tree would look like:


The Exceptional Beauty of Doom 3's Source Code


[3] "const" is a C++ keyword that ensures that a variable cannot be changed, or that a method will not change the contents of its class. "const" is shortform for "constant." It's worth noting that C++ includes a workaround, either via const_cast[T] or a C-style cast: (T *). Using these completely breaks const, and for the sake of argument I prefer to ignore their existence and never use them in practice.


[4]STL stands for "standard template library" It's a set of containers, algorithms, and functions commonly used by C++ programmers. It's supported by every major compiler vendor with varying levels of optimization and error reporting facilities.


[5]GCC - GNU Compiler Collection: a set of compiler supporting multiple programming languages. For the case of this article it refers to the GNU C/C++ compiler. GCC is a free compiler, with full source code available for free and works on a wide array of computers and operating systems. Other commonly used compilers include: clang, Microsoft Visual C++, IBM XL C/C++, Intel C++ Compiler.


DOOM 3 Resurrection of Evil
masseffect3_smarteck


Running a website called Dead End Thrills (about pictures of grafix), I spend a lot of time playing with visual mods. When PCG asked me to list my favourites from 2012, I agreed thinking I could do it in the style of the prize round from Bullseye. "You'll be up all night 'cause it don't look like shite." "Act well-heeled with this depth-of-field." But that wouldn't work overseas, they said, and stopped being funny after two examples.

Here's a straightforward top ten, then, in no particular order.
SweetFX
Battlefield 3 screenshot by Jim Snook (jim2point0)

No sooner had Nvidia's Timothy Lottes introduced FXAA (a 'fast approximate' antialiasing solution effective, unusually, upon deferred rendering and shader aliasing) than 'some dude' (their username - bet it's a lady) weaponised it into a DLL injector for most DirectX games. Copy it into the same folder as the game's binary and it hooks the calls to DirectX, softening the edges most AA methods can't reach.

Then things got interesting. Tonemapping, digital vibrance, luma sharpening and other neat effects got thrown into the mix, giving us the power to customise the look of most modern games. It's also one of the most reliable, no-nonsense screen capture tools: just hit your assigned hotkey and a lossless image plops into the game's folder.

Christian Jensen's SweetFX is the next evolution. Using SMAA for antialiasing, its features include S-Curve contrast adjustment and a filmic Cineon DPX treatment. Popular presets for these injectors include the Mass Effect 3 'Illumination' mod and James Snook's work with Borderlands 2 and Dishonored. When it comes to cheap, powerful tweaks to colour, image quality and luminosity, PC gamers have never had it so good.



Smarteck's Mass Effect 3 textures
Additional screen.

Back in February, the official Mass Effect Twitter account confirmed that “when the full game releases, hi-res textures will be built into the game!” And so we learned that when BioWare uses an exclamation mark, it's because it can't quite believe what it's saying - because it isn't true. Altogether now: 'Crikey, these textures are taking a while to update. Oh, they have updated and the costumes still look like Ceefax.'

Some months later Smarteck, a member of BioWare's long-suffering community forum, has led an effort to retexture not just Mass Effect 3 but all of its DLC as well. Inspired by the sterling efforts of 'Jean-Luc' with his ME2 textures, he's made the game's costumes and environments palatable, if not strictly 'hi-res'. Some detail texturing here and artistic licence there can't always cover the initial upscaling that's gone on.

The other quirk is that you need ancient memory patcher Texmod to actually inject the stuff into the game. It adds something in the region of ten minutes to the initial load time and can cause issues of varying severity if you try and inject too much. All of that said, it has the not-insignificant effect of making the game compatible with your eyes.



Durante's 'DSFix' for Dark Souls
Screenshot by Midhras

I'm going to paraphrase a bit here. From Software: "We can't do it." NeoGAF poster Durante: "I bet I can do it in half an hour." 23 minutes later: "Look at that! Sometimes I surprise even myself." An awkward silence now follows into eternity, save for all the whooping and cheering of users who'd just about written off the PC port of the magnificent Dark Souls.

Unlocking the game's internal frame buffer with his 'DSFix', Durante revealed assets that were clearly fit for more than pitiful sub-720p rendering. Then, among other things, he added ambient occlusion, uncapped the framerate and improved the game's texture filtering. And there was much rejoicing - and nagging for further features.

It's hard to recall a PC version that's been rescued from the brink of utter rejection quite like Dark Souls, and certainly not rescued by players themselves. The wrong lighting model going into Resident Evil 4, the performance tailspin of DX11 Arkham City: such things are usually patched with some urgency by the developers. Souls fans had barely lit the torches, much less found the pitchforks and a way to still type, by the time the game was fixed.



ENB Series for Skyrim and Fallout 3
Outspoken graphics programmer Boris Vorontsov might just be one of the most important people in PC gaming right now. No joke. His ENB wrappers and injectors have brought to many games the kind of generational leap in quality people expect from modern graphics cards, but seldom receive beyond those tech demos where fairies in Nvidia-branded loincloths ride turtles into battle with Decopunk death balloons. Those exist, right?

But where do you begin? Vorontsov has banned the hosting of his core dlls anywhere but on his own website; then you have the community-made presets. That's where effects like indirect lighting, subsurface scattering and complex ambient occlusion are wrangled into something complementing (or wildly departing, depending upon taste) the game's original look.

The last year has seen several masters of this bizarre artform emerge. In one niche you've got Midhras and his deep and luscious 'Midhrastic' presets for Skyrim and Fallout 3. In another, Trillville (aka Anthemios) and his muted but cinematic 'TV ENB', again for both games. And there's the fantastical (but surprisingly GPU-light) Seasons Of Skyrim by Bronze316. There's loads, basically, so get looking.



Sikkmod/Wulfen's Textures for Doom 3
Additional screens: 1, 2 and 3.

Not strictly from this year but here by virtue of significant recent updates. If Rage left you questioning the genius/foresight/influence/marbles of one John Carmack, let the properly modded Doom 3 splash all over your grumpy face like a hyper-demonic poo pump (or whatever those things are).

To put it really crudely, user Sikkpin brings the effects while Wulfen (and to a lesser extent another modder called Monoxead) brings the textures. There's a lot more to it, though. Sikkmod adds a beautifully implemented list of options to the game's menu, letting you toggle but also heavily customise things like ambient occlusion, colour grading, bloom and HDR. The icing on the cake, though, is the experimental parallax occlusion mapping (POM).

Given supporting ultra-quality textures like Wulfen's, POM adds a relatively primitive relief effect to the game's grungy surfaces. It's also an effect, though, that makes you want to reach out and touch all the stuff you really don't want to have on your fingers. The caveat - and it's a big one - is that it's far more demanding and less reliable than tessellation in a DX11 game. When the effect breaks, it breaks bad. Still worth it? Absolutely.



REX: Real Environment Xtreme
Alternative screens: 1 and 2

Of course you're aware that the flight sim community takes things rather seriously. Where modding is concerned, they build planes like they're actually building planes. The manual for one of these suckers is bigger than the manual for my car; in fact, the 2005 Honda Jazz feels less realistic all round. Meanwhile, when these modders are building the weather, they do it better than God. His clouds have been rubbish for years.

You'll get the lot if you invest the considerable time and money required by Flight Simulator X and its biggest mod, Real Environment Xtreme. The latest version is called REX Essential and is soon to be improved by REX Essential Overdrive. Assuming your mind can handle something so essentially overriding, what that gives you is almost 10gb of clouds, runways, dawns, dusks, reefs, waves... an awful lot of photorealistic stuff.

The way the mod works is to build a weather profile for the particular flight you add to your planner. It takes a while to import the necessary textures and runs a background app to keep track of them, but it's well worth the rigmarole. Add it to things like TileProxy and a high-fidelity terrain mesh and you have a game that makes Microsoft Flight look like... well, Microsoft Flight.



Skywind/Morrowind Overhaul
Screenshot from Morrowind Overhaul site.

The heart says Skywind but the head says Morrowind Overhaul, the one you can actually play. The magpie in me likes Skywind’s shiny stuff, but the historian bristles at the idea of just transplanting Morrowind into the framework and tech of a really quite different game. Not that it stopped the Dragonborn DLC, but that's not quite the same thing.

The screenshots of Skywind are marvellous, of course, in that specific way that most ENB-assisted shots are. Beautiful art and beautiful technology on occasionally decent terms. Can the authors pull it off without inflicting a violent mood swing on the game? We're a long way from finding out: they just made the difficult decision to take several steps back in order to bypass some serious obstacles, and now there's just a skeletal worldspace to explore.

Morrowind Overhaul has had a lot longer to gather its greatest hits collection of mods for the original game. Crucially, it suffers none of the legal issues surrounding asset-porting that affect Skywind and its Oblivion-based predecessor, Morroblivion, so isn't such a kludge of community-only content. And hey, even if you don't like it, the divine beauty of its installer will still come to you in dreams.



GLSL shaders for Minecraft
When no one can even agree on Notch's motives for the game's look - I want to call it 'Voxel Art' but its polygons won't let me - you can imagine the confusion over how Minecraft should be modded. Maybe that's the beauty of it. At the very least you get the comedy of people striving to make it 'photorealistic', as if waiting for the mod that shrinks each block to 1 cubic pixel so they can make a perfect replica of Crysis.

Better, I think, to flatter the blocks without pretending they're something they're not. I'd love to see realtime radiosity in Minecraft but suspect my computer wouldn't. (You should have heard the noise while rendering these 4K screenshots.) What we do have, though, is the ongoing work on daxnitro's abandoned GLSL Shader mod. Some of it's awful, like the lens flare and depth of field effects, but you can turn those off in the shader files and still enjoy sumptuous light and shadowing.

What I was looking for was a realtime version of the renders described here. It warms me to know I'm still looking at a game. I have to warn you, though, that finding the right shaders for the right version of the mod, for the right version of Minecraft, was an utter chore. Each small update of Minecraft requires a new version of the mod, and each new version of the mod tends to break something, whether it's the lovely new water shader or Nvidia compatibility. It might not even work at all.

You need to learn this stuff for yourself, really, as there's a lot of trial and error. Start by reading the thread for Sonic Ether’s Unbelievable Shaders (SEUS). Then look at Sonic Ether’s updates page on Facebook and figure out why he chose such an abhorrent solution as Facebook for an updates page (hint: you can’t). If, like me at 2AM, you’ve followed all of these instructions and have more questions than answers, you could always try chocapic13’s preset here which I turned to in desperation, and which actually worked.

Crysis 2 MaLDoHD Mod


Screenshot from MaLDoHD site

Real soldiers don't look at the enemy, they look at the floor. They stand by their fallen comrades, lower their guns and think, "That is a dirty puddle, all right, but is it a wow puddle?" Then they get shot. Bleeding out, they look up at the sky and think, "No, those clouds aren't doing it for me at all. This is simply unacceptable."

Thanks to the jargon-tastic MaLDoHD mod, the shoegazing soldier doesn't have to die disillusioned any more. Fears that Crysis 2 would become any less MAXIMUM with age can be safely laid to rest.

He's suffered for his mod, this Maldo. His computer "burst" in October, reveals his blog, and some believed he was dead. So you'll just have to settle for the "1894 textures and 1297 materials" in the existing beta version of MaLDoHD; those, and all the effects such as SSDO, object tessellation and penumbra shadowing. Sucks, huh.

The RAR file is 1.5gb and expands to over 2gb. The configuration process remains, as even MAXIMUM GAMER Craig Pearson had to admit, "a bit of a faff". His install guide still applies, though, so check it out.



Deus Ex New Vision
Screenshot from Deus Ex New Vision ModDB page.

Any visual mod for Deus Ex has its work cut out. My lasting memory of the original graphics is how freshly waxed the floors looked, not how the characters resembled ice sculptures on a balmy day. Accept the rather mathematical art as a style choice, though, or a trade-off for the game’s complexities, and you’ve ticked the first box for installing New Vision.

As well as enabling DX10, New Vision gives most of the game’s textures a fourfold increase in size and quality, bringing them into line with a modern game. It does it by exploiting the seldom-used S3TC standard of the original Unreal Engine.

Installing it is simple, especially if you have the Steam version which includes the required patches. The single installer asks if you want to install a modified launcher (you do if you want FOV options and enhanced resolution options) on top of the new textures, then you just run the game as usual.

Sucked helplessly into Ion Storm's universe for what’s probably the tenth time, you might just realise that old geometry and HD textures aren’t always a bad combination. New Vision is the work of top-tier artists with an obvious respect for the source material, and these are genuine 1024x1024 textures rather than horrid upsamples. Rather than drag the game kicking and screaming into 2012, though, they invite you back to 2000 with augmented eyes.
DOOM + DOOM II
Quake II Enforcer


Quake II was one of the first FPS epics to espouse the pristine logic of firing rockets at one's feet to jump higher. Id's memorable shooter didn't skimp on the bullet count either, and in celebration of its 15th anniversary yesterday, Creative Director Tim Willits shared a few did-you-knows (via Eurogamer) surrounding the art and multiplayer.

For instance, just three artists crafted the 2D and 3D visuals for Quake II's entirety, delivering an orange-tinged world of metal and flame shuddering beneath a massive human military offensive. An earlier suggested title for the game was WOR, but id changed the name after realizing Quake II's fast-paced action better suited the renowned series.

Lastly, Willits' multiplayer arena of choice, The Edge, hides over 50 trick jumps for handy hoppers, though Willits only designed two of them. The rest were discovered by early adopters of ye olde drum-and-bass jump videos.

The remainder of December holds further commemorations for PC gaming greats of the 1990s. WarCraft II hits 17 in just two days, with id following right behind with a 19-year-old Doom anniversary on Monday. Planescape: Torment, Black Isle's masterful RPG, turns 13 next Wednesday. Id returns yet again with tough platformer Commander Keen's 22nd birthday on the 17th, and nothing boosts holiday cheer like the sorcerous cultists of Raven Software's Heretic which dings 18 on the 23rd.
DOOM + DOOM II
DOS games


The team over at RGB Classic Games is giving us our nostalgia fixes in the form of Java-based DOS emulation. They currently host over 300 games from days of yore including Doom, Commander Keen, Earthworm Jim, and many more that didn't get spotlighted because they were too far down the alphabetically-organized page. And it's totally free.

It almost seems too good to be true. You might expect the hammer of legal action to be looming just above the dusty library of classics, but the site's intentions appear noble. As it explains: "The highest ideals of this site are to support the authors by providing links to their web sites and ordering information for the full versions of games that are still sold, and to encourage the authors of classic games to preserve their games for future generations by making them available for sale or as freeware. If you enjoy a shareware game, please consider buying it from the author.

"All of the games on this site are freely distributable because they are shareware, freeware, or because the copyright holder has officially and legally released all rights to the public domain (abandonware)."

Assuming that's the case, the site shouldn't see any problems, but if it does offend a copyright holder, we'd expect a simple removal of the game in question to suffice. Cue up some Nirvana and have a look for yourself.
...