Compiler Support

To develop a professional game engine that is to be taken seriously—even if our goal is to build 2D games rather than 3D games—we will benefit from writing code that is not tied down to any single development tool (which I like to call being vendor agnostic). In other words, several different compilers will compile the engine in this book without modification. You might be surprised how “lazy” your C++ coding can become when you get too used to a single vendor’s tool (such as Visual C++) and that tool’s automatic features. I’ve run into numerous cases where my Visual C++ code generates warnings—if not errors—in another compiler (such as GCC). Writing code for multiple compilers teaches you to write robust code that is hardened against bugs. One good example is Microsoft’s sprintf_s function, which does not exist in the standard C library—it’s a custom version of sprintf in the Microsoft libraries. By being aware of problems like this, you can learn to avoid them altogether. (In this case, I would prefer to use std::ostringstream to format a string instead.)

My favorite compiler is not Visual C++. I have nothing against Microsoft—they developed DirectX, after all, which is what we’re basing most of our engine on. The problem with Visual C++ is that it is in the midst of a family feud of sorts. There are now several generations of the compiler that disagree with each other—the versions from 1998, 2003, 2005, and 2008, to be specific. While the old Visual C++ 6.0 dating back to 1998 might be considered grossly out of date today, I certainly would expect Visual C++ 7.1 from 2003 to still be in favor. But the reality of the situation is that none of these versions is compatible with each other. If you create a project in one version, it will most likely not work in another. That makes it very difficult to support Visual C++ because most aspiring C++ programmers (namely, beginners) usually assume that the product name is the most important measure of compatibility—if it’s called Visual C++, then it will compile Visual C++ code, right? Hmm. One would assume as much, but the situation is complicated by the fact that each new version breaks compatibility with prior versions. Software is complicated enough without throwing these strange problems into the mix. When professional developers struggle with compatibility problems, one can only wonder how beginners fare!

So, what can we do about this problem? The most important thing is that we write code that will compile on all of these compilers. For all intents and purposes, each version of Visual C++ must be treated like a different compiler. It helps to even consider them as the products of different vendors, since Microsoft changes direction with the wind—and there’s nothing more frustrating to a C++ programmer than finding his or her two- to three-year old engine or library no longer works with the latest compiler (which is the case today).

Here is a list of compilers that are still relevant today, which should all be able to compile the engine and examples from this book. Specifically, I am focusing on Dev-C++ 5.0 and Visual C++ 2005 SP1 and providing projects for these two compilers on the book’s CD. Due to the way the projects are configured, you will find it very easy to add additional compiler support to the existing configurations—as long as a compatible DirectX 9 library is available for your compiler. Note that in the case of the Microsoft compilers, the Professional, Enterprise, and Express (free) editions all function the same.

  • Dev-C++ 5.0 (MinGW / CygWin)

  • Borland C++ 6.0

  • Visual C++ 7.1 (2003)

  • Visual C++ 8.0 (2005)

  • Visual C++ 8.0 (2005 SP1)

  • Visual C++ 9.0 (2008)

Advice

Projects for the compilers shown in bold text in the compiler list are available on the CD.


If you are completely new to game development, you will find this book to be a serious challenge because we don’t cover the basics here—this is an Advanced title. However, if you aren’t sure where to begin, I recommend you use Dev-C++ 5.0 (technically, the version is 4.9.9.2 beta). Why? First of all, Dev-C++ is based on the world-class GCC compiler, which is used in all of the professional console development kits (for systems like the Wii and PS3). Secondly, Dev-C++ is small. The installer is tiny, and the full installation is only about 120 MB. (Contrast that with Visual C++, which weighs in at five times that size.) Third, Dev-C++ has fewer dependencies, and its binary executable code (built with GCC) does not embed a manifest file like Visual C++ does.

Advice

A manifest file describes the runtime libraries required to run an executable program built with Visual Studio (any language). The manifest was supposed to eliminate the DLL dependency problems that developers had to deal with in past versions of Microsoft’s development tools. However, “DLL nightmare” has been replaced with “Manifest nightmare,” to the extent that many Visual C++ programs will not even run on the same PC they are compiled on.


We want to be able to write advanced 2D games with the least amount of difficulty, which is why I’m making so many strong suggestions this early on. If you use a complex compiler, plan to deal with complex challenges inherent in using such software. But if you don’t need feature overload, going with a simpler compiler (such as Dev-C++) will make game development equally simple and painless.

Advice

As of late 2007, Firaxis Games was still using Visual C++ 2003. You can tell by downloading the latest Civilization IV SDK (for the Beyond the Sword expansion). This is a fairly common situation in game engine “mod” development kits.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset