Thread: I encourage everyone to have a glance over the Quake II source code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    110

    I encourage everyone to have a glance over the Quake II source code

    Better yet, any source code that was released by ID software.

    You can find it all, here:

    https://github.com/id-Software/Quake-2

    It is so incredibly clean, elegant and pushes everything out of the C programming language including some Godlike pointer hacking and bit field manipulation. Function pointers and callbacks are made to look smooth.

    This is the work of the programming God John Carmack and his team Brian Hook and George Cash.

    The opinions are not new, this article outlines the beauty of Doom III's source code:
    The Exceptional Beauty of Doom 3's Source Code

    These guys were magicians and I aspire to be like them one day.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Sounds like a nightmare to me.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    My props to John Carmack and his team. And I like the fanboy in you, but this raises a question: If John is God, then what do you call Dennis Ritchie? Meta-God??

  4. #4
    Registered User
    Join Date
    Mar 2016
    Posts
    110
    Quote Originally Posted by stevesmithx View Post
    My props to John Carmack and his team. And I like the fanboy in you, but this raises a question: If John is God, then what do you call Dennis Ritchie? Meta-God??
    Yep, Dennis Ritchie and Kernighan Meta Gods

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Vespasian_2 View Post
    Yep, Dennis Ritchie and Kernighan Meta Gods
    And Ken Thompson and Bjarne Stroustrup.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I've looked over this code before. It's... eh... decent, I guess. There are plenty of tricks and hacks that make the code fast enough to pull off a really awesome video game -- and I don't dispute whatsoever that Quake II was an awesome game -- but it's hardly a shining example of clean, well-architected code.

    It got the job done and made Carmack and his coworkers a lot of money. That's all well and good for Carmack, but you're not Carmack. You should set your sights a little higher if you're looking for examples of well-designed code.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by brewbuck View Post
    but it's hardly a shining example of clean, well-architected code
    What code is?

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Yarin View Post
    What code is?
    Windows 2000
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  9. #9
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by Elkvis View Post
    I forgot how good this was. They really comment well.
    Code:
    // HACK ON TOP OF HACK ALERT
    A paragon of code quality if I don't say so myself.

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Yarin View Post
    What code is?
    The source code of Clang.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  11. #11
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by brewbuck View Post
    The source code of Clang.
    That was funny. Now, an application that isn't obviously a C programming tool.

    I think you are being too hard on Mr. Carmack and the OP. From constraints in the development time to the mediocre skill level of a large portion of professional developers, it's always a reason to rejoice when we can find generally smart and clean production code that also respects best practices in such a complex language like C or C++.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #12
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Mario F. View Post
    That was funny. Now, an application that isn't obviously a C programming tool.

    I think you are being too hard on Mr. Carmack and the OP. From constraints in the development time to the mediocre skill level of a large portion of professional developers, it's always a reason to rejoice when we can find generally smart and clean production code that also respects best practices in such a complex language like C or C++.
    I'm just not moved to tears by the use of a function pointer...

    My biggest problem with this code is the complete lack of tests. I mean, not a single test to be found anywhere. It also has "break" and "continue" statements all over the place. If it was code I was reviewing at work, I'd reject it for either of those reasons.

    Again, I'm not saying the code sucks, or Carmack is stupid, or anything like that. I just don't see anything super impressive here.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  13. #13
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by brewbuck View Post
    The source code of Clang.
    Which means nothing, because Clang is nothing but a glorified debugger. Anyone who has tried to use Clang for "real" code, should know what I'm referring to, i.e. Clang producing ud2 instructions unnecessarily, without warning.

    Edit: RANT: anyone who tries to defend Clang here is automatically wrong. This has been an issue for over 3 years now, and has not been fixed.
    Last edited by Epy; 04-04-2016 at 02:53 PM.

  14. #14
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Epy View Post
    Which means nothing, because Clang is nothing but a glorified debugger. Anyone who has tried to use Clang for "real" code, should know what I'm referring to, i.e. Clang producing ud2 instructions unnecessarily, without warning.

    Edit: RANT: anyone who tries to defend Clang here is automatically wrong. This has been an issue for over 3 years now, and has not been fixed.
    Your pet frustration notwithstanding, clang is pretty much taking over everything now. Android and iOS are both compiled with it, and Microsoft is switching to it. Get over it, man.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then enlighten us as to the problem because from what I see the problem is very vague.

    From what I gather, you're complaining about how clang generates these trap instructions for undefined behaviour because they are messing up your code. And as the article says, they're generated because the compiler cannot always catch undefined behaviour at compile time. Are you trying to imply there's a bug that causes these instructions to trap when there's actually no undefined behaviour at all?
    Last edited by Elysia; 04-05-2016 at 12:05 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ .NET Quake 3 Source Port
    By bengreenwood in forum Game Programming
    Replies: 0
    Last Post: 03-16-2012, 08:02 PM
  2. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  3. Understanding something in Quake 2 Source Code
    By bengreenwood in forum C Programming
    Replies: 5
    Last Post: 08-05-2009, 02:22 PM
  4. Understanding a Line of Quake 2 Source Code
    By bengreenwood in forum C++ Programming
    Replies: 6
    Last Post: 08-04-2009, 03:15 PM
  5. Replies: 3
    Last Post: 05-08-2004, 10:58 AM