Remix.run Logo
applfanboysbgon 20 hours ago

> One time I tried to write Doom for a platform, from scratch. I got the 3D BSP renderer working and could move around a space with walls. I was looking for reference for how to implement the rest of the game and didn't find it. I didn't realize you're supposed to port Doom to a platform by starting from the original Doom code and not by writing it from scratch, because the only detailed enough reference is the code itself.

This is the greatest misunderstanding of a programmer's job I've ever seen (by someone who apparently programs). Of course you don't write a game from scratch every time you port it to a new platform. You aren't even really supposed to be "referencing" the game code. The game code is built on a series of abstractions over the hardware. You swap in a set of abstractions for different hardware. If the game is properly encapsulated, you may not even need to touch what would be considered the "game" code rather than the engine code, or only minimally to update API boundaries.

eg.

Layer 0: Hardware

Layer 1: OS

Layer 2: DirectX

Layer 3: Engine code, has functions like Draw3D(params) which call DirectX functions

Layer 4: Game code, which calls Draw3D(params)

If you swap in OpenGL for DirectX, you simply change engine code so that Draw3D calls OpenGL instead of DirectX as appropriate, and the game code is still just happily plopping along with the exact same Draw3D calls ignorant of whether those are being served with DirectX or OpenGL. This applies all the same even if Layer 2 is a software renderer, as Doom's was. Ditto for OS layers or anything else.

If you want to reverse engineer it from scratch for learning, have at it, but why in God's name would you think that's what porting entails? And even after you understand porting is not about writing from scratch, you should understand that this has no relevance to your overall point. I'd also note that it is possible to reverse engineer a game from scratch without ever referencing the original source code -- that's called a decompilation project, it's intensive and time-consuming work, but it can be done.