Sunday, November 13, 2011

Programming Game AI Chapter 2

Continuing on from my introduction to this blog, Mat Buckland's book Programming Game AI by Example is excellent so far. His math and physics introductions are just enough for anybody to understand how important the subjects of math and physics are to game development. His introduction to game state engines as a precursor to Game AI and a creation of a FSM (Finite State Machine) with just a few lines of code with the West World Messaging example is both simple and very interesting. His website for the book has a snapshot of chapter 2 introduction and some of the code. One problem?
The code is in C++ and I was not familiar with the language. So I had to take a quick detour to C++ land (which I found both confusing and enlightening) to just pick up enough language to port the first example. Hence you will find that the first example is a clear port of the C++ code. I have tried my best to stay true to the original code and have retained all the names of methods and instance variables and I have also retained Mat's comments in my code. That way, anybody studying my port can make a one-to-one relation to the C++ code in the book. I have not used any of the Objective-C @properties or @synthesize directives except in the third example.
 
But the third example, WestWorldWithMessaging, threw me for a loop. I was introduced to C++ structures (Telegram.h) that can contain their own functions and initializers, which I believe is not possible in C or Objective-C. So for now I have just converted that to a class hoping that I can keep using a class in the future examples too. I have also converted the void* into an Objective-C id object. One more thing, I have left out some of the functions that Mat had in example 3 (in Telegram.h) that were not used in the example’s execution as such. I will cross that bridge when I come to it in future examples.

 
I will be posting the links to the Xcode Projects for all examples so far and Doxygen generated source code documentation very soon with class diagrams. And I apologize for long singleton initializing method names. Should have shortened them, but was following the syntax that I found at Cocoa with Love. Excellent Objective-C/Cocoa blog by the way.

0 comments:

Post a Comment