Question:

How are popular games written in c made?

by  |  earlier

0 LIKES UnLike

I know the Sims 2 was written in c , but I'm wondering how they do it. I mean, what do they use, a compiler? (I know they don't, but...)

Just curious.

 Tags:

   Report

3 ANSWERS


  1. I hope you do not intend to learn writting a game by asking this question as game creation is a complex process. True to a certain extent that a compiler is used but rarely now anyone codes in C++ for  games, except for the game engine writers.

    There are two entities in case of modern games.

    1. Game engine

    2. Game Script.

    Think of game engine as a program that takes care of your keyboard, joystick, mouse etc; is responsible for drawing any graphics, images, animation on screen and also takes care of all the sound you hear during game like music or other effects. There are many companies that write and sell game engines. These engines are written in core languages like C, C++, C#, Pascal, Delphi etc. The engine does not contain any sounds, graphics or any stuff like that. Think of it as a CD player.

    The other thing is Game script. It is also a language unlike the conventional ones it is understood only by the game engine for which it is created. The game creaters buy the Game engine (there are many open source, or freeware game engines also available) and have designers who create the graphics, sounds, music and the game levels. All these things are put together using the Game script language. The language contains instructions for the game engine like

    1. Where are the graphics available

    2. How many of them to be loaded.

    3. what actions (keyboard, mouse) are recognized?

    4. What is the logic like how the scoring would be done, increase score, how would the enemies act. etc. think of this the a Cd that contains all your data.

    The final game you see is the the combination of game engine + graphics+sounds+script. Or to the analogy of CD Player. it is as you get a package of CD's with CD player included with the stuff.  Together these things makeup the games you see and play.

    The game engine writers never bother writting games although in some cases they do (Doom 3 by idSoft).  


  2. Yes, a compiler is used - it's more complicated than that, though. There is a whole build system, which can become very complicated, especially in large commercial games.

    A game can be built from several different pieces of code. It can even be written in more than one programming language - for example, Civilisation 4 is written in both C++ and python. Many games use different scripting engines (WoW and Supreme Commander both use Lua).

    C++ source code is transformed into executable code known as object code by the compiler. At this stage it can't be run from Windows, though, since it doesn't contain the necessary information to do that (such as the "PE header" required by windows). It's then usually placed in a temporary file ending in .obj. These .obj files are linked together with other .obj and .lib files by a linker, to form .exe and .dll files (which do contain a PE header) or .lib files which can be fed into the linker again.

    The segmenting of the code into many files is necessary because C++ code is divided into manageable portions which will be worked on by different teams. A typical game the size of The Sims 2 could span from thousands of files to hundreds of thousands of files - millions of lines of code (which is probably a factor in why they take years to make...).

    Then even more tools do things such as modifying the .exe/.dll to embed resources like icons, version information and data for different languages. However, at any stage in the entire process, it could be different from how I've said, because build systems differ a lot.

    There are many ways of organizing these files. For small projects, a single visual studio project might suffice. But at the size of a commercial title, it would become very unwieldy to manage, which is why there are many different build systems - msbuild, scons, bjam, makefiles, and others. There could well be employees hired especially to work on the build system.



    The files themselves are usually stored in Version Control System (VCS) such as Subversion, Mercurial, CVS, git, bazaar, or Visual SourceSafe (eww). This allows different people to work on different parts of the code, and commit changes to the code without other people losing their work. It also keeps a full history of the source code so that if changes are made that cause bugs (this is known as a "regression") or reduce performance, they can be "backed out" and the code can be restored to its previous state. This is extremely useful!

    The VCS may also be used to store game assets such as artwork, models, textures, etc., or these may be stored in a separate content management system designed especially for this purpose (such as AlienBrain). Other than that I don't know a great deal about the art side of the game development process, sorry.

    Then there may be automated build systems which build the game to check that it builds correctly and run automated tests. In addition to this, there would be a QA team to run tests that machines cannot run (such as play testing) and to find and triage bugs - that is, prioritize them, clarify them, and generally manage them so that it's easier for the development teams to actually fix them.

    It often takes a long time to build the game (or its associated tools, such as level editors) from scratch - hours, even. This is why there are usually powerful machines with many CPUs and lots of RAM, dedicated to building the game and archiving build results.

    Of course, before all this, the game has to be designed (at least, partly - some of the design work will take place after development has begun), but I don't know a great deal about that, either.

    Anyway, I hope this satisfies your curiosity! I may have written slightly too much :) Don't let it scare you, though - it's not always complicated, and it's actually not too difficult to get used to if you have to.  

  3. You can start learning C++ with these video tutorials:

    http://xoax.net/comp/cpp/console/index.p...

    They are perfect for beginners. This one can get you started by showing you how to install a free compiler:

    http://xoax.net/comp/cpp/console/Lesson0...

    Here are some simple games with code downloads that you can use to get some ideas:

    http://xoax.net/comp/cpp/console/Lesson9...

    http://xoax.net/comp/cpp/console/Lesson2...

    http://xoax.net/comp/cpp/console/Lesson2...

    These tutorials can get you started with graphics programming in OpenGL:

    http://xoax.net/comp/cpp/opengl/index.ph...

    You can go through the tutorials and if you have questions on them or anything else in C++, please post to me here:

    http://xoax.net/forum/

    Best of luck!

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.