Part 1: Introduction.Part 2: MultithreadingPart 3: Rendering (Approx. Translation - in the process of translation)
Part 4: Doom classic - integration (Approx. Translation - in the process of translation)
November 26, 2012 ID Software released the source code
Doom 3 BFG edition (just a month after the game appeared on store shelves). The idTech4 engine, which is almost 10 years old, was updated with the solutions used in idTech 5 (
Rage is the first game on this engine), and it was very interesting to get acquainted with its source code.
I would call the engine idTech4 improved, because in essence, this is idTech4, but using idTech5 elements:
- Threading system
- Sound system
- Resource Management System
Until now, the most attractive aspect is the flow control system: Doom 3 was developed at the dawn of the era of multi-core systems, when few computers used
SMP . Now the rules have changed, even the phones are equipped with several cores and the game engine must be multi-threaded in order to use the full potential of the machine.
')
I hope that this will inspire people to understand the source code, improve their skills and become better engineers.
First contact

Getting to know Doom 3 BFG is impressive, because To run from source, you need to do only 2 steps:
- Get the sources located on GitHub:
git clone https://github.com/id-Software/DOOM-3-BFG
- Open Visual Studio 2010 Express and press F8 to compile. Done!
Note: If the Direct3D SDK is installed, the complete project is compiled in less than a minute, issuing 5 minimal warnings.
Debug mode
Only 3 steps are needed to start tinkering with Visual Studio 2010 Express:
- In the debug command line, specify the base path:
+set fs_basepath "C:\Program Files\Steam\SteamApps\common\DOOM 3 BFG Edition" +set r_fullscreen 0
- Open the project "Doom3BFG".
- Press F5

Readability source code
Subset C ++:
Doom 3 BFG is written in C ++, a language so great that it can be used both to create great code and for such an abomination from which
your eyes will bleed . Fortunately, ID Software used a subset of the C ++ language, close to “C with Classes,” which will not be so difficult to understand:
- There are no exceptions.
- No links (pointers are used)
- Minimal pattern usage
- Constants everywhere
- Classes
- Polymorphism
- Inheritance
And despite the multithreading, the code does not use smart pointers or
Boost . What a relief (after all, this is what usually makes code unreadable).
Comments
There are a lot of comments and they are quite useful, as they, as a rule, describe what goes on in the most important places of the next block in one sentence. Here is an example from
ParallelJobList.cpp
:
int idJobThread::Run() { threadJobListState_t threadJobListState[MAX_JOBLISTS]; int numJobLists = 0; int lastStalledJobList = -1; while ( !IsTerminating() ) {
In general, the reader gets a direct understanding of each part of the algorithm, and I hope that this will inspire people to write better code: after all, when developing software, it’s not important to be a big ace than others. It is equally important to be able to work in a team by creating code:
- Exquisitely designed
- Easy to read, using comments where appropriate.
Doom 3 BFG has high rates in both of these positions.
What changed?
- 2 projects "Game" (Doom III classic and ressurection) are combined into one project
- Removed cUrl
- Removed the stupid DoomDLL name ... It was actually generating DOOM3.EXE
- Removed outdated Maya tools for exporting md5 models, animations and camera paths.
- Removed TypeInfo, added RTTI / Introspection instead.
Solution Explorer (solution explorer) in Visual Studio has become noticeably cleaner (before and after):


Doom 3 BFG Sub Projects
Projects
| Builds
| Observations
|
Amplitude | Amplitude.lib | Used in Doom Classic: A tool to adjust the amplitude of the WAV. |
Doom3bfg | Doom3BFG.exe | Engine Doom 3 BFG. |
doomclassic | doomclassic.lib | Seriously revised Doom1 / 2 engine. |
external | external.lib | Sources jpeg-6 and zlib.
|
Game-d3xp | Game-d3xp.lib | A single library of the game, including the original game + expansion + new levels. Please note that now it is going to a static library instead of a DLL.
|
idLib | idLib.lib | Package software tools id software to work with the file system.
|
timidity | timidity.lib | Used in Doom Classic to convert MIDI files to WAV format.
|
New architecture

The architecture is significantly different from the original Doom III: now everything is compiled into one monolithic executable file (the original Doom III was compiled into one executable file and one DLL containing the game logic). This was done for two reasons (according to the main developer Brian Harris):
- Consoles such as PS3 / Xbox360 do not support dynamic libraries in the best way.
- Speed ​​up development speed. When using dll library there are problems with memory allocation. This generates errors that are difficult to track.
Changes related to development for consoles:
The orientation of the Xbox 360 and PS3 in the project, initially focused on the PC led to many important updates:
- As mentioned earlier, the whole game is contained in one executable file.
- In the game, PAK files (which are ZIP archives) are used to store various parts. The high latency of the DVD drives pushed ID Software to the following resource allocation: one file, it contains everything you need for one load level.
- Game assets were textual, but in order to reduce load time, some of the assets, such as models and animation, are now binary (.bmd5mesh and .bmd5anim).
- Doom 3 was designed to work with a resolution of 640x480 with a 4: 3 aspect ratio. Currently, TVs and monitors most often have an aspect ratio of 16: 9, so all the menus have been redone. Probably, in order to speed up development, it is implemented on Adobe Flash. Doom 3 BFG uses its own Flash interpreter (/ neo / swf /). Again, Flash is used to speed development.
- Shader rendering was rewritten using GLSL 1.5. HLSL shaders can be converted on the fly.
- To obtain an acceptable frame rate, the flashlight could not be used with a weapon. (Approx. Trans. - in the original there is the phrase "Now with Doom 3” Most likely, it means not “duck taped”, but “duct taped "- Scotch tape, i.e." Now, in Doom 3 BFG it can be attached to a weapon ... ")
- Since the PC menu is now cross-platform PC has largely lost rendering settings: we get a simple version that is used in both PCs and consoles.
Multithreading
In the 10 years that have passed between the development of the old and the new engine, a paradigm shift has occurred: the “free cheese” has ended, and the game engines must be developed using multi-threading. Therefore, the most attractive thing to read in a Doom III BFG is the idTech5 Threading architecture. (Detailed review in the second part of the translation).
Rendering
There are 2 main changes:
- Powered by Open GL 3.2 Profile Compatibility using GLSL Shaders 1.5.
- The use of multithreading (up to four threads working simultaneously).
(Detailed overview in the third part of the translation)
Doom classic
Doom III BFG allows you to play Doom 1 and Doom 2. At first glance, the simple task is to integrate the old Doom1 engine into the new Doom 3 BFG: just redirect all the inputs / outputs! But given the split-screen mode on the PS3 and Xbox360, this is not realizable. (Detailed overview in the 4th part of the translation)
Post is a translation, but because published from the sandbox - I can not change the type of post. Subsequent parts will be arranged correctly. Translation errors, typos are happy to correct, write in HP.The original of the first part - Fabien Sanglard