Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Where can I find good (well organized) examples of game code? I'm hoping that I can pick up some organizational tips. Most examples in books are too short and leave out lots of detail for the sake of brevity. I'm particularly interested on how to group your variables and methods so that another programmer would know where to look in the code. For example initializers at the top, then methods that take input, then methods that update views.

I don't care about a particular language, as long as its OOP. I looked at the Quake 2 and 3 sources, but they're straight C and not much help for getting tips on organizing your objects.

So, have you seen some good source? Any pointers to code that makes you say "wow, that's well organized" would be great.

share|improve this question
1  
This isn't really a direct answer, so I'll just leave it as a comment. I recommend checking out the book Large-Scale C++ Software Design by John Lakos. It was very enlightening for me. –  BRaffle Aug 16 '10 at 14:14

7 Answers 7

up vote 15 down vote accepted

Several commercial games have had their source code released. Some of the games are listed here. There's no guarantee that the code in these is well organized, but by looking at some source code from games that were commercially successful you might get a good idea what works in practice.

Also, while not a game, OpenSceneGraph has many of the components of a game and is well architected in C++, using different design patterns, plug-ins, etc. It's a big enough code base and has been around long enough that you can learn a lot from it.

share|improve this answer
1  
Thanks, the Wikipedia list was useful. Spring is really well organized - all the methods are grouped by general function (load/save, drawing, etc) github.com/spring/spring/blob/master/rts/Game/Game.h Aquaria made me feel better about my own code organization: hg.icculus.org/icculus/aquaria/file/f08b7288f92c/Aquaria/… I shouldn't criticize though, real artists ship. –  smasher Jul 25 '10 at 15:55
    
I would add Ogre as a good reference with OpenSceneGraph... –  Klaim Oct 14 '10 at 16:39

Battle for Wesnoth is a:

Free, turn-based tactical strategy game with a high fantasy theme, featuring both single-player, and online/hotseat multiplayer combat

Free as in open-sourced, under GPL. I just found/downloaded it, so can't say what the gameplay is like yet, but it's gotten great reviews. Nor do I know if their code is "well-organized" :) But hey, it's open-source.

share|improve this answer
    
Really funny :) :p –  Qchmqs Apr 9 '12 at 17:59

I'm pretty meticulous about my code, so you might find my in-progress roguelike Amaranth useful to skim over.

share|improve this answer

If you're looking for good OOP - I quite liked the object model of the Doom3 SDK.
Ogre3D is a heavy OOP design but I emphasise heavy as i think it's quite bloated with lots of examples and plug ins.

Let me know what you think.

share|improve this answer

I have source code to libraries and full games on my site Another Early Morning you can also find some projects on my GitHub page. Not all of it is a shining example of quality, but then that tends to happen when you want to ship something.

share|improve this answer

Prototype, winner of one of the Shmup-Dev competitions:

http://xout.blackened-interactive.com/ProtoType/Prototype.html

And the source code:

http://xout.blackened-interactive.com/dump/new/ProtoType_src.zip

Since I'm a code newbie I can't say much about the quality, but just skimming over it gave me some insights. Have fun.

share|improve this answer

I've got the source for a simple one we're using for a code war competition at Windward Wrocks. I think it's well organized and it is pretty simple. But certain parts were created quickly, not well. With that said, even in the largest game development teams, there are parts in those that are written quickly, not well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.