Most game programming books are one of two things: very specific – particular game engines, physics, rendering, AI – or very general, for the beginner.
Robert Nystrom’s Game Programming Patterns is right in the middle.
As the title indicates, the book doesn’t focus on a particular engine, individual component or language, though examples are given in a stripped down C++. Instead, Nystrom’s book takes its cue from the Gang of Four’s Design Patterns - presenting a problem, then a pattern that attempts to resolve complexity with higher aspirations of reusability and performance, both for the computer and the programmer.
GPP is an excellent companion to its inspiration for even the general design pattern enthusiasts. Games, at this point in time, are something most programmers have some level if not expert knowledge in, even if that’s only as a player. Framing design patterns within this context allows Nystrom to provide examples that are relatable and can move away from the Gang of Four’s need to be as neutral as possible when outlining their ideas. In other words - it clicks better because the content is very close to our experience.
The book is organized around groups of patterns and most of the chapters are focused on problems that are unique to game development.
The first section revisits several of the Gang of Four’s canonized patterns – command, flyweight, observer, prototype, singleton, state – even taking a number of them to task as misused, bad or at the very least poorly described by the original authors. Nystrom certainly could have chosen other patterns (composite, builder and visitor spring to mind), in fact, it’d be awesome if he extended the series, but he had to find a limit someplace.
The other sections dive more deeply into game programming specifics including sequencing, behavioral structures, decoupling, and optimization, but the descriptions still keep the discussion on the pattern level. These chapters cover problems that specifically arise in game development, as opposed to say web development, and Nystrom is even more strong-handed in the tone - use the pattern when you need it, not just because.
The patterns discussed near the end of the book specifically belabour this point, as their optimizations aim really make code more complex and difficult to debug, but can greatly affect performance for games that need it.
Overall, Nystrom’s book was a like a great pair programming buddy. He presents most patterns in the book initially as “hey, let’s just get it working”, then through the introduction of a pattern, refactors, and then asks question of “do we really need this?”, all the while with asides and geek notes in the sidebars.
While this information can come from other places targeted at game developers, Nystrom’s a good writer. I mentioned above that this book fits in the middle, in truth it probably does lean more towards the beginner, that said, the value of the book for the more experienced is to gain another perspective on patterns and code practices from an author who delights in it.
Game Programming Patterns is indeed useful for its titular topic, but as a whole, it made programming, patterns used or not, just fun.
Friday, June 12, 2015