• Ever wanted an RSS feed of all your favorite gaming news sites? Go check out our new Gaming Headlines feed! Read more about it here.
  • We have made minor adjustments to how the search bar works on ResetEra. You can read about the changes here.

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
I'm sure a lot of people are like, "yeah, of course, all FPS games after took inspiration from it" but that's underselling what Id Tech 1 did. The things the doom engine did go well beyond FPS games or even rendering graphics period. Doom laid the foundation that virtually all game engines today descend from.

Several years back, Dreamcast scenester and general amazing dude ChillyWilly had ported Doom to the DC, but his old code no longer builds because of various changes to the KOS library that powers the port. Because of this, earlier this year, I took my first stab at porting doom to a platform:

D9BpcGIWkAAHIiR


I began with ChillyWilly's port as a base, then worked backwards. I have worked with modern engines over the years - Source, Unreal Engine 4, Unity - but never really dove deep into how Doom worked. That's not to say I was unfamiliar with Doom, I had been making Doom WADs for years, so I generally knew of things like BSP and lumps, but not really how any of it worked. Around the same time I began porting doom, I also picked up Fabien Sanglard's Doom Engine black book. This was not the first blackbook I'd read. I had read the Wolfenstein black book prior, and years earlier, when learning graphics programming, I read Michael Abrash's Graphics Programming black book (which is, really, the Quake black book). Most draw a linear path between these 3 games: Wolfenstein -> Doom -> Quake. But that really undersells how it all progressed. Things I had thought Quake had come up with, actually came from doom. Further, I learned that Doom and Quake share much more in common than Wolfenstein and Doom share in common. One thing dawned on me: To study Doom, is to study how modern video games work. Doom is, IMO, the very best place for anybody to start if they want to know how modern video games function and operate on a conceptual level. So much of what Doom does directly applies to modern engines.

With interest in Id Tech 1 growing, and a project in hand, I started where most doom ports begin: converting the 4 main files that are platform dependent. Doom's engine is genius, honest to god genius. It was built with cross platform compatibility in mind. The platform most people play doom on, IBM PC, was NOT the platform Doom was written on. It was written on the NeXT platform, and id knew most people did not have access to NeXT computers. Doom, thusly, is a prime example of how to write a cross platform game, one of the best models. Doom spares no detail in creating everything from the ground up, including fundamental data structures.

For example, doom shows you how to elegantly sanitize malloc -- malloc is a C function that interfaces with kernels in your operating system to request and reserve a block of memory. But how kernels operate on memory varies not only from OS to OS, but even revision of OS to OS. Malloc, thusly, is malliable, over time, as C has evolved, malloc too has changed. It's not wise to rely on malloc to handle memory in C. People who don't do low level programming but operate in higher programming languages like Java might hear things about how C is a "nightmare" because you have to "manually manage memory." A lot of that "nightmare" comes from how much malloc changes over the years. Doom shows you how to manually manage your memory. It uses malloc in the most broad sense, only using it to request a single large pool of memory, which it then handles and breaks into smaller chunks itself. It, in essence, creates it's own micro OS within that chunk of memory. It is doom, not your OS or its kernel, that fiddles with the memory. To do this, it builds every data type it uses from the ground up. That let carmack and crew design custom, portable data structures in low level memory, bit by bit, byte by byte. That might seem rote to anyone who has done engine programming these days, but that's the point. Doom set that standard. Everybody follows doom's model.

Going further, Doom impliments OOP in C. Programmers might have heard that C is classically "not an OOP language." That's not quite true. C is a very low level language, exposing memory directly to the programmer. As such, it doesn't provide any OOP abstraction, but you're absolutely free to write your own yourself. When Doom was created, OOP wasn't really a common thing. None the less, Doom implements its own OOP concepts through pointers, function callbacks, etc. The OLD style of OOP. But Doom's methods are elegant, it's a great OOP implementation. With liberal use of void* pointers and explicit casting, Doom manages to perform a pattern that wouldn't become popularized till really 5 or so years later!

Back to porting doom: Doom is written to be portable. By writing so much of the engine in custom, operating-system-independent wrappers, it was built so that the core function of the engine was self contained. There are only really 4 files that are platform dependent, those files control the lowest level functions of the engine. Things like calling out to the video card, requesting memory, polling hardware. These 4 files are the core of doom's engine. They are written not to actually do larger functions, but rather to provide a framework of commands that the rest of the engine can call to do complex things. Like, a function to draw pixels on the screen. When you port doom, you write those functions for the hardware, which is how it becomes so portable. If you can write a low level function that places pixels on the screen, matching the interface doom defines, the rest of the engine can use it and thusly do everything it needs to do regarding graphics. That is one of the secrets to why Doom is so widely ported. This concept of portability was not necessarily created by Doom itself -- I've seen Amiga/Genesis/SNES games that work the same way with company-specific libraries that worked the same way which could be placed inside larger assembler code -- but Doom does it very well. More than that, while some other games did this, most did not. It was more common in 1993 for ports of games to essentially be entire rewrites than have modular code like this. And in the Amiga/Genesis/SNES examples I cite, the entire games usually weren't written to be modular, only pieces. Things like the graphics system might work in a modular fashion, but then the memory management might be entirely different among the games. They were often half-ports, half-bespoke-remakes. Doom is truly portable.

I rewrote those core functions in a few days and got Doom running on the Dreamcast. Really cool, very good lesson. But that isn't going far enough. Doom has way, way more lessons to teach if you dive in. Writing those core functions will teach you how to make a nice modern interface, get you thinking about portability, but the Doom Engine itself will teach you many more concepts the deeper you dive in. For example, Doom teaches you the concept of decoupling the game's internal logic from internal hardware. Old games used to have this problem where how well the game performed was dependent on the hardware it ran on. The logic was usually very closely tied to the hardware, using things like the screen's refresh rate to tie to logic. Doom doesn't do that. Doom implements what is called Fixed Timestep, which uses real-world time as a metric. For example, movement. In many old games, movement is handled in number of spaces jumped per frame. On frame 1, you are at position X, on frame 2, you are on position X+A, on frame 3, you are on position X+A+A, and so forth. Your position depends on that A variable and also which frame you are looking at, A is essentially your speed. This means your motion is not constant if the frames are not constant. If it takes 1 microsecond between frames 1 and 2, but 10 microseconds between frames 2 and 3, your velocity will not be linear, it'll be logarithmic. Doom doesn't work like this. Doom calculates delta between frames. One frame 1, your position is X, on frame 2, your position is X + Delta(frame1), on frame 3, your position is X + Delta(frame2). The delta is how much time passed between the current frame and last frame, calculated using a constant velocity. If you are moving at 1 space per unit of time, and between frame 1 and frame 2, 1 unit of time passes, then the delta is 1 space. But if 10 units of time pass between frames 2 and frames 3, then the delta is 10 spaces, meaning you move at a linear 1 space per unit of time. This decouples the refresh rate of the hardware from the game speed. Game speed is dependent on external, real time, not the load of the computer. Again, this sort of thing is rote today, but largely because Doom showed everyone how it was done.

Another great example of how Doom establishes the model of modern game design is with its rendering system. People will say things like "Doom isn't 3D" but that's completely wrong. Doom IS 3D, it's the map layouts that are 2D. But Doom's rendering system is pretty much the basis of all modern rendering systems today. The main difference between the way Doom renders and wolfenstein renders is owed to how they process the polygons that make up the world. Wolfenstein uses a raymarcher, basically a system where the game shoots rays out from the players perspective, and paints the screen line by line. It is rendering lines. The world is made up of a bunch of tiny lines that make up walls. Doom does not work like that. Doom renders the world per object. This is a massive difference because, to accomplish this, it needed a way to very speedily traverse the world. Enter Binary Space Partitioning. Binary Space Partioning, at the time of Doom's release, was something really only used in the academic world. It was stuff that, like, the military used for simulations, or NASA used for the space shuttle. It was the most cutting edge 3D traversal system around. BSP works by subdividing the world into many partitions to create nodes (called lumps in doom) that contain single objects. BSP helps order the world into lumps so that, when you render the world around you, you don't have to render everything.

Kotaku once ran an infamous article where they talked about Frustrum Culling as though it was a new technique Horizon Zero Dawn used to speed things up:

tumblr_inline_oqh1hamavB1tm46jo_500.gifv


Many people laughed and pointed out that it wasn't unique to that game, it was an old technique, which is correct. Many games used it before Horizon Zero Dawn. BUT NO 3D GAME USED IT BEFORE DOOM. Doom is the genesis of this technique, the magic behind how this technique works is BSP. Even today, modern 3D engines use BSP to speed things up. Without BSP, even modern graphics cards would be too slow to render. BSP is the "magic" that makes rendering large worlds possible. BSP is an ordering technique that sets everything up in a way that graphics technologies can speedily figure out what is or isn't in a Frustrum . Without this ability to order objects, if everything was out of order in memory, it would simply be to slow.

More to the point about doom being actual 3D -- while the map is an arrangement of objects on a flat plane, the objects themselves are NOT 2D. They are fully 3D, with both an X and Z component, plus a height component that is functionally a Y component. That's the trick to how Doom works so fast, it's a bunch of 3D objects, laid out on a 2D plane so that the early BSP traversal implementation didn't have to work so hard. Once CPUs became faster, it became possible to have BSP traversal in 3 dimensions (meaning operating on more data) and the process pretty seamlessly transitioned into 3D maps in Quake. But the core concept was there in Doom, just operating on less data to accomplish the same feat.

Another example of how Doom teaches great concepts: Event handling. In games prior, things like joystick polling were done at intervals, in simplistic ways. Every bit of the game would have its own routine to check input. Like, mario. The title screen has a part where it checks input, then determines if start is pressed to proceed. Then, once the game begins, an entirely separate piece of code in the game loop checks input, and figures out what to do if you press right, or A, or B, or whatever. Each screen, each game mode, had its own input checking stuff. Doom doesn't work like this. There is one centeral, modular piece of technology (one of the core functions I mentioned above) that polls for input, independently of the rest of the game. To let this piece of technology talk to the rest of the game, it implements what is known as an Event Handler, which is a global queue of events that get passed from mode to mode. Events are queued using hardware interrupts, a way for the processor in your computer to receive a message outside of your program, directly from the joystick, which makes it say "oh shit, let's stop running the main code for a bit, and jump to this routine immediately, then when it's done, let's go back to exactly where we were in the main code." In Doom's instance, the IRQ code that is run when the joystick (or keyboard, or mouse) flags input, is a piece of code that takes the information polled, configures it into a package, then places it into the event queue. Then, individual game modes themselves have event handlers. They don't poll the input, they just handle the input if any exists. This means, for example, the menu in Doom does not need to check for input. Nor does the gameloop. Instead, they just have routines that, if input exists at all, will get executed. If no input exists, they don't get executed. This concept of events is a major change to how games work. All game engines today operate off of events, it's the main concept behind blueprints in things like UE4:

EventHitEX.jpg


Again, this might seem rote today, but that's because DOOM popularized it. It's rote, because everyone is copying doom.

I could keep going on and on about how this kind of stuff is laid out. Doom standardized game networking, for example, teaching synchronization methods. Doom popularized the concept of releasing editors and tools. Doom did a ton of things that all games today crib off of. Doom is, hands down, the most important and groundbreaking and trendsetting game of the last 30 years. Hell, I might say ever. Probably the most important game ever released.

Pay your respects to Doom. It's legacy endures, the entire game industry owes it a huge technical debt.
 
Last edited:

CountAntonio

Member
Oct 25, 2017
21,730
I remember seeing it for the first time on my friends PC and I had only experienced consoles at that point. I just couldn't believe it. It seemed so far beyond any tech I'd experienced I felt like I was time traveling.
 

laxu

Member
Nov 26, 2017
2,782
On top of that it's also a great game rather than just a great tech demo.
 

Yataran

Member
Jul 17, 2018
439
Copenhagen, DK
I love it. Thanks so much for the detailed explanation.
I remember seeing it for the first time on my friends PC and I had only experienced consoles at that point. I just couldn't believe it. It seemed so far beyond any tech I'd experienced I felt like I was time traveling.
I remember the first time I saw Doom. It was during early secondary school and I was at a classmate's home. He showed us this hot new game... But in my mind it was so weird. I had never seen anything like it, and I don't know if it was that he had reduced the screen size or what but back then I could not understand what was going on. However, not long after I saw Doom 2 at another friend's home... And I was in love with the game!
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
On top of that it's also a great game rather than just a great tech demo.

Doom's game design IS great, I really miss that kind of very speedy, fast, arena FPS that doom created and Quake 3 perfected. But sadly, that sort of game design has gone out of favor. I wish it would come back, personally. In contrast, the design of Doom's engine remains foundational. Game engines are still built in the mold of Id Tech 1. You can trace pretty much everything every modern game engine does back to Doom.

So while it's a great game, and I 100% don't disagree, the engine itself has had the more enduring legacy. The engine changed the entire video game industry forever.
 

DanteMenethil

Member
Oct 25, 2017
8,062
Fantastic post op. Dissecting DOOM's design patterns and porting it should be incoporated in game programming classes
 

Kthulhu

Member
Oct 25, 2017
14,670
The platform most people play doom on, IBM PC, was NOT the platform Doom was written on. It was written on the NeXT platform, and id knew most people did not have access to NeXT computers

Is there a story behind this? I know NeXT was targeted at education which is part of how the web was built for NeXT/Unix originally, but why'd they develop on NeXT vs DOS or early Windows?
 
Oct 25, 2017
6,033
Milwaukee, WI
Next time anyone tells you games are being held back by old hardware.

Show them Wolfenstein 3D

Carmack worked with the limitations of PC hardware at the time for Captain Keen and it lead to Doom.
 

Mumford

Member
Oct 25, 2017
81
You have enlightened me as someone who truly didn't understand any of this despite knowing that DOOM was the FPS granddaddy and a precursor to many modern engines, but I had no idea it was this far reaching. This is really incredible work, thank you!
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
Next time anyone tells you games are being held back by old hardware.

Show them Wolfenstein 3D

But that's a poor example, because wolfenstein 3D was held back by old hardware. Carmack already had concepts he wanted to work into id tech 1 in mind when he was writing Wolf3D, but the hardware outright couldn't do them yet. Wolfenstein is a much simpler game than doom, they conceptually aren't very similar at all, but not because Carmack hadn't come up with the concepts, but because the 386 couldn't handle said concepts.

The 486 is the point where hardware had progressed just enough to make his concepts actually work. There was a tipping point, and the 486 was it. If you want to make that claim about hardware game games, point to Doom, not Wolf3D.
 
Oct 25, 2017
6,033
Milwaukee, WI
But that's a poor example, because wolfenstein 3D was held back by old hardware. Carmack already had concepts he wanted to work into id tech 1 in mind when he was writing Wolf3D, but the hardware outright couldn't do them yet. Wolfenstein is a much simpler game than doom, they conceptually aren't very similar at all, but not because Carmack hadn't come up with the concepts, but because the 386 couldn't handle said concepts.

The 486 is the point where hardware had progressed just enough to make his concepts actually work. There was a tipping point, and the 486 was it. If you want to make that claim about hardware game games, point to Doom, not Wolf3D.

Of course, I wont deny that hardware will dictate which ideas end up in a game. However, at the time, Wolfenstein 3D was far and away a top tier game in look and performance.

Jumping off the main post, I think Quake has been greatly undervalued in games history. Pretty much everything Carmack did was mindblowing. Even RAGE can be appreciated from a certain view. MEGATEXTURES
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
You have enlightened me as someone who truly didn't understand any of this despite knowing that DOOM was the FPS granddaddy and a precursor to many modern engines, but I had no idea it was this far reaching. This is really incredible work, thank you!

There is a reason why everyone took notice of VR once John Carmack and Michael Abrash jumped on board. Carmack had changed the industry twice before, once by himself with id tech 1, then again with the help of Abrash with id tech 2. Those two teaming up to try it again is one of the most exciting things ever.
 

Molto

Member
Oct 27, 2017
1,022
Good stuff, that was really interesting. Where can I find your port of Doom for the DC? Would love to give that a go.
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
Of course, I wont deny that hardware will dictate which ideas end up in a game. However, at the time, Wolfenstein 3D was far and away a top tier game in look and performance.

Jumping off the main post, I think Quake has been greatly undervalued in games history. Pretty much everything Carmack did was mindblowing. Even RAGE can be appreciated from a certain view. MEGATEXTURES

Quake is super important, but quake was mainly iterative of Doom's concepts. Doom, by contrast, was not very iterative of Wolfenstein. It was pretty much a clean conceptual break. Two different approaches to try and accomplish the same type of thing. Quake was the same concepts Doom used, just using much more modern hardware (and thus writing the book on how to use modern hardware with those concepts).
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
Good stuff, that was really interesting. Where can I find your port of Doom for the DC? Would love to give that a go.

I never released it, but you can download chilly willy's build on lots of places like DCemulation. There's really no need for me to release a build of my port, since they play the same way. It was a rewrite just to get it to build, which isn't really useful to anybody unless they know how to actually build and compile and deploy dreamcast games through, like, DC-tool-ip.

That chillywilly's old build has been perfectly fine to play for years is precisely why the source code fell into deprecation as KOS changed, as there is little reason to ever rebuild it outside of education.
 

LastCaress

Avenger
Oct 29, 2017
1,682
I love reading about theses things. I mean I don't understand most of it, but I still enjoy reading about it.
 

daedalius

Member
Oct 27, 2017
1,061
I played it for the first time when I was 10 I think, and it's still burned into my memory. It's probably the most memorable game outside of something like Mario and Zelda.

I still play it today!
 

BradleyLove

Member
Oct 29, 2017
1,464
Krejlooc It'd be fascinating one day if you had the opportunity to break down the Freescape engine, and how that compares to the likes of ID.
 

Garchia3.0

Member
Dec 20, 2018
1,859
I gave a presentation on the DOOM Engine for one of my CS classes and explained how the algorithm worked and it's complexity. That dude Carmack was brilliant. Awesome thread!
 

Pororoka

Member
Nov 1, 2017
1,210
MX
I'm reading the blackbook and I'm trying to take notes to consult some stuff that I don't quite grasp at a later time but so far has been an incredible read.

sIsl3eM.gif
 
Oct 27, 2017
39,148
Agreed. Just looking at the mods being produced for Doom on the various source ports of the game just shows how good this engine was.

You have people making Sonic fan games, racing games, games in games and so much more in such an old engine. It is truly an amazing engine and John Carmack was a genius for coming up with something like this.
 

Garrison

Member
Oct 27, 2017
2,904
Remember playing it on the Snes back in the day and wondering how the hell did they get that game in there. lol
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
I gave a presentation on the DOOM Engine for one of my CS classes and explained how the algorithm worked and it's complexity. That dude Carmack was brilliant. Awesome thread!

I'm about to run out for the day to do some work, but someone remind me in the future and I'll break down how Carmacks' "Black Magic" fast inverse square root algorithm works. It's unbelievable. It's an algorithm that shouldn't exist. He didn't create it, but he knew of it, which is mind blowing in and of itself. The super quick explaination is that finding an inverse square root is a bit of guesswork where you use a seed to create samples to find the square root. Not all seeds are created equal, and certain magic numbers will yield an inverse square root faster than others. Carmack used an insanely, seemingly random number to do his that performs the inverse square root astonishingly fast. His explanation of how it works:

sqrt.png


It would honestly take super computers of the time years to find this magic number, how carmack knew about it is a mystery. You can actually write an entire book about this algorithm because there is so much awesome shit in it. And yes, the comments on the right, "what the fuck??" etc, are carmack's comments/explanation lol.
 

Raccoon

Member
May 31, 2019
15,896
About to give your post a read Krejlooc, but just wanted to give you a shout out on how impressively detailed your posts are. I was fascinated by your Steam OS thread last month:


It was a great read as someone who finished their CS degree last year, and has been working as a software dev for the past 3 years. Keep up the great work.
as a dipshit cs student in uni, I concur. keep up the great threads krejlooc
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
You have people making Sonic fan games, racing games, games in games and so much more in such an old engine. It is truly an amazing engine and John Carmack was a genius for coming up with something like this.

A tangent, but the Sonic the Hedgehog engine itself is also a technical marvel. It should not be possible to do that kind of shit on a sega genesis. Yuji Naka is a fucking genius. Maybe not carmack genius, but holy shit. Sonic's engine is so much more modern than it has any right to be. It has, for example, a prototypical Entity-Component System, like a decade before they became envogue. ECS is shit unity does.

When I first started studying the Sonic engine, I would see functions repeated throughout the source code. "How sloppy Yuji Naka is, what poor form" I would think in my stupid ignorance. No, that's not sloppy. That is insane optimization. Naka was counting individual clock cycles, and realizing that sometimes branching execution farther away in code would take 1 or 2 extra cycles to compute the larger address which he needed every single last one of. So rather than waste those cycles to jump further in code, he'd duplicate the function at precise moments so certain bits of the engine wouldn't have to jump as far.

I can't express quickly how smart and well designed that engine is. It's a miracle it runs on a 7 mhz 68000. It's honestly a very advanced math engine.
 
Oct 25, 2017
2,644
Fantastic and lucid read, as always. I think it's easy for younger players, or those who only engaged with games of that era as end-users, to lose sight of just how unfamiliar the entire concept of a hardware-independent middleware was to the enthusiast public until the heyday of Quake and Unreal in the late 1990s. To put it in perspective, Doom predated the advent of DirectX.

Even so, the sheer thoroughness with which the Doom engine implements everything all the way down to its own self-contained memory management is mostly new to me. It's apt to pithily describe it as a micro-OS. I think its contributions as a rendering system are well known to anyone who gets as far as an introductory college course on computer graphics—Carmack is a household name in the field whether you deal with games or not—but quite a lot of what the OP elucidates about the entire underlying architecture and its intrinsic portability isn't nearly as acknowledged among non-engineers.

I'm about to run out for the day to do some work, but someone remind me in the future and I'll break down how Carmacks' "Black Magic" fast inverse square root algorithm works. It's unbelievable. It's an algorithm that shouldn't exist. He didn't create it, but he knew of it, which is mind blowing in and of itself. The super quick explaination is that finding an inverse square root is a bit of guesswork where you use a seed to create samples to find the square root. Not all seeds are created equal, and certain magic numbers will yield an inverse square root faster than others. Carmack used an insanely, seemingly random number to do his that performs the inverse square root astonishingly fast. His explanation of how it works:

sqrt.png


It would honestly take super computers of the time years to find this magic number, how carmack knew about it is a mystery. You can actually write an entire book about this algorithm because there is so much awesome shit in it. And yes, the comments on the right, "what the fuck??" etc, are carmack's comments/explanation lol.

I've seen this trick come up often totally apart from Carmack (usually as a classic stock example of "black magic", as it were). Bitwise arithmetic is largely over my head—which is why I don't work on optimization—but I think a lot of trickery like this was circulated as hacker folk wisdom, and I don't know if there has been any substantial scholarly work to track this sort of knowledge dissemination (though I have some idea of who to ask). The thing that separates an ace like Carmack from your everyday programmer is precisely that he would hunt for this stuff and add it to his repertoire to pull out on a moment's notice as needed.
 

spam musubi

Member
Oct 25, 2017
9,381
I'm about to run out for the day to do some work, but someone remind me in the future and I'll break down how Carmacks' "Black Magic" fast inverse square root algorithm works. It's unbelievable. It's an algorithm that shouldn't exist. He didn't create it, but he knew of it, which is mind blowing in and of itself. The super quick explaination is that finding an inverse square root is a bit of guesswork where you use a seed to create samples to find the square root. Not all seeds are created equal, and certain magic numbers will yield an inverse square root faster than others. Carmack used an insanely, seemingly random number to do his that performs the inverse square root astonishingly fast. His explanation of how it works:

sqrt.png


It would honestly take super computers of the time years to find this magic number, how carmack knew about it is a mystery. You can actually write an entire book about this algorithm because there is so much awesome shit in it. And yes, the comments on the right, "what the fuck??" etc, are carmack's comments/explanation lol.

I once gave a half an hour talk about this algorithm specifically, haha. Doom is truly brilliant. I recommend the doom bible to anyone who wants to learn more. Also just look at the source code. It's surprisingly easy to understand. I've written my own doom style ray caster across several languages (including python and game maker) and it's a really fun exercise.
 
Oct 25, 2017
5,581
Racoon City
Doom's source code is so damn good to just read through, you'll learn so much simply reading and writing them out yourself.
I'm about to run out for the day to do some work, but someone remind me in the future and I'll break down how Carmacks' "Black Magic" fast inverse square root algorithm works. It's unbelievable. It's an algorithm that shouldn't exist. He didn't create it, but he knew of it, which is mind blowing in and of itself. The super quick explaination is that finding an inverse square root is a bit of guesswork where you use a seed to create samples to find the square root. Not all seeds are created equal, and certain magic numbers will yield an inverse square root faster than others. Carmack used an insanely, seemingly random number to do his that performs the inverse square root astonishingly fast. His explanation of how it works:

sqrt.png


It would honestly take super computers of the time years to find this magic number, how carmack knew about it is a mystery. You can actually write an entire book about this algorithm because there is so much awesome shit in it. And yes, the comments on the right, "what the fuck??" etc, are carmack's comments/explanation lol.

Man we were shown this in school during one of our algorthm classes. And was explained what he did, and when I say everyone in class was like "wtf!?" we meant it.
 

banter

Member
Jan 12, 2018
4,127
This is heavy, I'm going to have to save this thread to read again once I get a little more knowledge on the subject. I'm a physics student so when people find something difficult and compare it to rocket science, I'm thinking "well, rocket science isn't all that difficult really". But this stuff, this is what I would call difficult. Physics is very logical with one thing leading to another. Computer science is fucking wild to me. The shit that people come up with just 🤯 and this thread is just pushing that point further. John Carmack is a legend. DOOM is still a great game to play today in it's original fit and finish and that's pretty amazing in its own right.

Hell of a thread OP. This kind of stuff makes me look forward to the pain that my future CS classes (I've only had intro to C, but again I'm in physics not CS) will bring me.
 

ascii42

Member
Oct 25, 2017
5,798
Yeah. Doom's engine is fascinating, and Wolfenstein before it. What was the first FPS to allow for multi-level design? As in an area directly on top of another area. Dark Forces? I feel like it was possible in the Marathon games, but I can't remember.
 

Man God

Member
Oct 25, 2017
38,307
But that's a poor example, because wolfenstein 3D was held back by old hardware. Carmack already had concepts he wanted to work into id tech 1 in mind when he was writing Wolf3D, but the hardware outright couldn't do them yet. Wolfenstein is a much simpler game than doom, they conceptually aren't very similar at all, but not because Carmack hadn't come up with the concepts, but because the 386 couldn't handle said concepts.

The 486 is the point where hardware had progressed just enough to make his concepts actually work. There was a tipping point, and the 486 was it. If you want to make that claim about hardware game games, point to Doom, not Wolf3D.
DOOM was Crysis if Crysis was as popular as Super Mario Bros 3. People actually did go out and drop 2000+ to play this game. PCs were advertised as being DOOM compatible.
 

SrirachaX

Member
Apr 12, 2019
236
As always, I love reading your threads Krejlooc. I've known that the older id engines were crafted so well which is why a lot of games use them as a base or for inspiration, but never knew why that was so. The design of game engines is a very interesting topic to me.
 
Oct 27, 2017
72
Fantastic thread. I've done some dabbling with Doom's source myself although not to your extent. One thing I don't think the OP mentioned is how clean and easy to read the codebase is - as a younger dev who cut his teeth in the mid-late 00s with easier to use OpenGL libraries, reading C code from that era is usually unpleasant and messy but Doom's is as straightforward as possible and well commented when necessary.

On a side note, do you have a go-to place to find source code for console games from that era like Sonic? Or are you just reading disassembled ASM?
 

DanteLinkX

Banned
Oct 27, 2017
3,730
I know shit about programing and I found this read to be awesome, you truly are something OP. Keep up the good work, someone give this guy a raise.
 

Corralx

Member
Aug 23, 2018
1,176
London, UK
Great post. I want to add a couple of corrections and/or trivia about the BSP part, tho.

Another great example of how Doom establishes the model of modern game design is with its rendering system. People will say things like "Doom isn't 3D" but that's completely wrong. Doom IS 3D, it's the map layouts that are 2D. But Doom's rendering system is pretty much the basis of all modern rendering systems today. The main difference between the way Doom renders and wolfenstein renders is owed to how they process the polygons that make up the world. Wolfenstein uses a raymarcher, basically a system where the game shoots rays out from the players perspective, and paints the screen line by line. It is rendering lines. The world is made up of a bunch of tiny lines that make up walls. Doom does not work like that. Doom renders the world per object. This is a massive difference because, to accomplish this, it needed a way to very speedily traverse the world. Enter Binary Space Partitioning. Binary Space Partioning, at the time of Doom's release, was something really only used in the academic world. It was stuff that, like, the military used for simulations, or NASA used for the space shuttle. It was the most cutting edge 3D traversal system around. BSP works by subdividing the world into many partitions to create nodes (called lumps in doom) that contain single objects. BSP helps order the world into lumps so that, when you render the world around you, you don't have to render everything.

Kotaku once ran an infamous article where they talked about Fustrum Culling as though it was a new technique Horizon Zero Dawn used to speed things up:

tumblr_inline_oqh1hamavB1tm46jo_500.gifv


Many people laughed and pointed out that it wasn't unique to that game, it was an old technique, which is correct. Many games used it before Horizon Zero Dawn. BUT NO 3D GAME USED IT BEFORE DOOM. Doom is the genesis of this technique, the magic behind how this technique works is BSP. Even today, modern 3D engines use BSP to speed things up. Without BSP, even modern graphics cards would be too slow to render. BSP is the "magic" that makes rendering large worlds possible. BSP is an ordering technique that sets everything up in a way that graphics technologies can speedily figure out what is or isn't in a fustrum. Without this ability to order objects, if everything was out of order in memory, it would simply be to slow.

More to the point about doom being actual 3D -- while the map is an arrangement of objects on a flat plane, the objects themselves are NOT 2D. They are fully 3D, with both an X and Z component, plus a height component that is functionally a Y component. That's the trick to how Doom works so fast, it's a bunch of 3D objects, laid out on a 2D plane so that the early BSP traversal implementation didn't have to work so hard. Once CPUs became faster, it became possible to have BSP traversal in 3 dimensions (meaning operating on more data) and the process pretty seamlessly transitioned into 3D maps in Quake. But the core concept was there in Doom, just operating on less data to accomplish the same feat.

It's not well known but the first game using BSP is actually Wolfenstein, or to be more precise, its SNES port.
Carmack used the SNES port of Wolfenstein as a test bed for the technique, and a sort of proof of concept that it would have worked on a bigger scale in DOOM.
In the end, DOOM was shipped a couple months before Wolfenstein's SNES port, so it's still the first commercial title to use it. :p

Also Quake did not use BSP for rendering, just map/world representation afaik, and used instead what was likely the first implementation/concept of Potential Visibility Set to render its geometry, which is still in use by modern games like Hitman.
At the same time I think it's inaccurate to say BSP are still in use, because they don't really cope that well with fully 3D scene, and have made room for more complex and flexible variants, like PVS, BVH, Octree, K-d tree and such (usually more than one at the same time too).
 
Oct 26, 2017
9,939
The thing I always remember about Doom back in the day is that it was the "dream" game. I would stare at screenshots in magazines and try and imagine what it would look like in motion as nobody I knew had anything that could play it. It seemed like a different world of video games altogether.