If It Is Good To Read Great Code, What Is Some Great Code I Should Read?

Started by
6 comments, last by ericrrichards22 7 years, 9 months ago

If it is good to read great code, what is some great c++ code I should read worth reading? (c++ & lua)

In other words "What is some good code to read?"

(imagine as if a friend is asking about good books. Eg. reply "The Stranger")
If you want feel free to post the difficulty level of the read (Beginner, Intermediate, Advanced, Expert)

focus-languages: C++, Lua

focus-areas: Game Engines, AI, Gameplay-Programming, editors
(& feel free to include anything worth going out side of the focus areas and languages)



Thanks,

This question was inpired by this tutorial:
http://www.tutorialspoint.com/developers_best_practices/code_reading.htm

===

links to code:

User: Link
WoopsASword: CrytekEngine: https://github.com/CRYTEK-CRYENGINE/CRYENGINE
georger.araujo: Game Coding Complete Code: https://github.com/georgerbr/gamecode4/tree/vs2013
ericrrichards22: idTech source code: https://github.com/id-Software
ericrrichards22: Dinodeck: https://github.com/dinodeck/dinodeck
ericrrichards22: Game Programming AI by example source code: http://www.jblearning.com/Catalog/9781556220784/student/

Honerable mentions (gateway to code, but not a direct link to code specifically)
efolkertsma: "Beautiful Code". https://www.amazon.com/Beautiful-Code-Leading-Programmers-Practice/dp/0596510047
Kolrabi: Fabien Sanglard (not source code, but a as a way source of code reviews and as a gateway to some open source projects.

edit(s):
removed focus on self to better focus on the question about resources.(used strike throughs)
Added links to recomendations.

note: this is just about resource collection to help on one of the many aspects of improvement.

Advertisement

Your problem is not to read the code of any project out of the world but will be to understand what happens behind the scenes and this needs some experience in whatever is be done and this wont come from reading the code automaticaly rather than simply sit down and read something about what is going on (like in the docs delivered from the source codes vendor).

You focused in your post on 4 different areas of production that have different standards to know.

  • Game Engine (generic) are huge collections of utility code to run all tasks thatw ere needed inside a game like rendering, math, asset management and basic API handling to place assets wherever they are needed, many many OS dependent stuff for filesystem, networking and much more. Here you should go ahead and fetch a book about that topic
  • AI is another very special topic you need to understand the behavior handling of an AI agent, interacting with the game and its rules, how to manage behavior trees and assembling patterns
  • Gameplay is heavy depending on the game you are looking at and even that makes it so special. You could look at any AAA titles gameplay code and will find something different from the other reads because there dont exist any shema F patterns
  • Editor tools are just programs handling anything of the above 3 points but in a human readable way and that is all you need to know about them. If you see an editor tool for designing open world chunks then the major work is done by the engine it depends on behind

I dont think you will get anything of this in less than a year to basicaly understand the topic so you should focus on one thing first and then step to the others. I would advice to begin reading about game engine architecture and take a look at some commercial ones like Unity3D or Unreal and some free open source ones like Urho3D and you will see that any other of your points of interest appears automaticaly to investigate what happens inside the big bad engine world

Fabien Sanglard has code reviews for some classic computer games that were open sourced. He usually gives a quick overview of the code base and then goes into more details about a few of the subsystems. And you can follow along in your editor. I highly recommend having a look at it.

blah :)

First of all, it is worth reading ALL kind of code.

As a musician I know how to appritiate all kind of music, in all kind of generes.

This include classical musical sheets, rock improvisations, metal riffs and even pop chords.

For me it is the same with code, I read all kind of languages, with all kind of technologies.

The pure purpose is to learn, what kind of code you learn is up to you. (My advice, read all kind).

However, you've asked C++ code.

So my recommendation is this:

https://github.com/CRYTEK-CRYENGINE/CRYENGINE

There is a book called: "Beautiful Code". I have read bits and pieces of it and I think it is a reasonable book.

In any case if I can give one personal piece of advice, based on what I have seen in my career. There is no 'off hand' right or wrong way. Therefore don't try to make up a strict rule set based on the code you read and try to retro fit particular problems into the approaches you have read by other people. Often times a particular situation requires a unique (or at least modified) approach to be good. (There are a lot of opinionated people out there that promote 'their' line of thinking because it worked in their circumstances and therefore it must work in all circumstances, right?!? (e.g. Mike Acton with his data driven development))

Depending on how new you are to programming I would start with smaller scale software and avoid diving into large scale engine such as Unreal, CryTek, etc. Because realistically if you haven't had enough experience on smaller things/first hand, meaning you haven't hit the problems they describe personally... it is very hard to see their architecture and understand fully why they did what they did. For me personally on the code base I work on there are times where I disagree with the architecture... sometimes I am right (as in I have valid arguments that the majority of people I talk to agree with) and sometimes I am wrong (meaning the reverse). (edit, I forgot to add) Often when I am wrong it is because I did not fully understand the set of problems they were trying to solve, or the constraints that were there. So I would avoid trying to form an opinion without understanding the full problem.

Just a quick note to responders.

Thanks for all of your replies. I'm a bit beyond the beginner level. (MS in CS, etc). But I don't want the focus of this to be on me. Or, things to worry about or etc. etc. All things can be used for good or bad. All I want to know is.

What do you consider some great sources of beautiful code. That is the focus. That is all I care about.
The purpose of reading this code is different perspectives etc. Reading to open ones mind.

So, with that said, some thanks is due.
@efolkertsma: for your recommendation of "Beautiful Code". https://www.amazon.com/Beautiful-Code-Leading-Programmers-Practice/dp/0596510047
@WoopsASword: for your recommendation of the CrytekEngine: https://github.com/CRYTEK-CRYENGINE/CRYENGINE
@Kolrabi: for your mention of Fabien Sanglard
as a way source of code reviews and as a gateway to some open source projects.

All other replies are appreciated, but the focus is on code, and good code to read.

Eg. What books would you reccomend? Except instead of books, code.

Thank you, and keep them coming. :)

There's the code (for VS 2013 & 2015) for Game Coding Complete, 4th ed. It's in C++ and integrates Lua scripting. The difficulty level is intermediate to advanced. You can learn a great deal from just the source code, but consider buying the book – it will be a great help.

The released IdTech source code is pretty interesting (https://github.com/id-Software). It's maybe not the cleanest, most pristine examples, but for historical reasons, it is very important. If you get into the Quake 1 code base, some excellent companion works are Michael Abrash's Game Programming Black Book (a truly massive tome, if you have a dead-tree version, but there is some gold on the Quake rendering engine and BSPs), and Fabian Sanglard's blog, which has already been mentioned.

I've been working through How To Make an RPG, which is pretty interesting, and also looking at the game engine that it uses, Dinodeck. Similar to Game Coding Complete (it's on the 4th edition now? I still have the 2nd...), it features Lua scripting into a C++ engine.

The source code to Matt Buckland's Programming Game AI By Example is another favorite of mine.

Eric Richards

SlimDX tutorials - http://www.richardssoftware.net/

Twitter - @EricRichards22

This topic is closed to new replies.

Advertisement