Refactoring: Guard Macro Body

You have a C/C++ macro that needs to perform several statements or contains conditional statements.

Wrap the statements in a do { } while (0) construct to ensure that the statements are executed in the proper order and that the use of the macro doesn’t interfere with other control structures in the program.

Read the rest of this entry »

Direct3D Graphics Pipeline Update

Its been quite a while since I uploaded a new version of the draft of my book. Rest assured, I’m still working on the book and I really do plan on finishing it someday! However, I’ve gotten some feedback that the installer for the samples will sometimes fail. Since I haven’t gotten any detailed log files back from anyone who experienced the failure, I’ve been trying to figure out how to diagnose the problem and correct it. The samples also needed updating to Visual Studio .NET 2005 — and I guess now they’ll need updating to Visual Studio .NET 2008! So I’ve been working on my installer code by fitting unit tests to the code in an attempt to find the underlying problem that people have reported. My manual testing with old versions of Windows (that need updating of their DirectX runtime) with VMWare haven’t reproduced the problem that people have described, so I’m hoping that fitting everything in the installer with unit tests will help me identify the problem. I’ll also be converting the installer for the sample code to use WiX (Windows Installer XML) instead of the deployment project type in Visual Studio. This will make the installer more robust and will eliminate the script hackiness I had to do in my white paper. It will also make the installer source accessible to people who don’t have the Professional edition of Visual Studio since it will use only free tools. Once all the samples and source have been appropriately updated, I’ll go back to incorporating 9.0c changes into my manuscript.

Faking Out The Win32 API With Templates

When writing a unit test, you want to hold the code under test in a vice. You want the code under test to collaborate with objects whose behavior you control so that you can inject controlled conditions into the code under test. This is fairly straightforward when the code under test collaborates with a class that implements an interface. You can simply write a test harness class with the desired behavior. The test harness class is usually called a “fake” object or a “mock” object. It is not the real collaborator, but an object whose purpose is to inject the desired conditions into the code under test to validate its behavior under different circumstances.

However, Win32 code has another sort of collaborator that is more difficult to fake — the global functions in the Win32 API. What happens when your code calls LoadLibrary and the file can’t be found? Furthermore, with a true unit test you don’t even want to do file I/O because that will make the test run slow. You want unit tests to run as fast as possible because you will be running them often as you make changes to the production code.

Read the rest of this entry »

“Professional XNA Game Programming” by Benjamin Nitschke

Overall I liked this book. Like most books that are “first” on a subject there are a few small errors that reflect how the XNA Framework changed between early betas and the final release. This is just the facts of life when you buy the “first” book on a new technology given the lead times on books. Its just not feasible to rework a book extensively based on the final code and have the book come out “first”. Even with that disclaimer, this is still a good book for the game developer that wants to learn about the XNA Framework and write a single set of source that runs on Windows and on the Xbox 360. This book covers XNA Game Studio Express 1.0

Read the rest of this entry »